tests: Trim .nim files trailing whitespace

via OSX: find . -name '*.nim' -exec sed -i '' -E 's/[[:space:]]+$//' {} +
This commit is contained in:
Adam Strzelecki 2015-09-04 23:04:32 +02:00
commit e80465dacf
372 changed files with 4486 additions and 4486 deletions

View file

@ -1,2 +1,2 @@
# Test the new initialization for modules
write(stdout, "Hello from module! ")
# Test the new initialization for modules
write(stdout, "Hello from module! ")

View file

@ -1,6 +1,6 @@
# Test a submodule
#type
# TStringArr = array [0.. *] of string
proc exportme* = discard
# Test a submodule
#type
# TStringArr = array [0.. *] of string
proc exportme* = discard

View file

@ -25,7 +25,7 @@ proc GetBottleNumber(n: int): string =
for bn in countdown(99, 1):
const cur = GetBottleNumber(bn)
echo(cur, " on the wall, ", cur, ".")
echo("Take one down and pass it around, ", GetBottleNumber(bn-1),
echo("Take one down and pass it around, ", GetBottleNumber(bn-1),
" on the wall.\n")
echo "No more bottles of beer on the wall, no more bottles of beer."

View file

@ -2,20 +2,20 @@ discard """
file: "tack.nim"
output: "125"
"""
# the Ackermann function
proc ack(x, y: int): int =
if x != 0:
if y != 0:
return ack(x-1, ack(x, y-1))
return ack(x-1, 1)
else:
return y + 1
# if x == 0: return y + 1
# elif y == 0: return ack(x-1, 1)
# else: return ack(x-1, ack(x, y-1))
# echo(ack(0, 0))
write(stdout, ack(3, 4)) #OUT 125
# the Ackermann function
proc ack(x, y: int): int =
if x != 0:
if y != 0:
return ack(x-1, ack(x, y-1))
return ack(x-1, 1)
else:
return y + 1
# if x == 0: return y + 1
# elif y == 0: return ack(x-1, 1)
# else: return ack(x-1, ack(x, y-1))
# echo(ack(0, 0))
write(stdout, ack(3, 4)) #OUT 125

View file

@ -3,9 +3,9 @@ discard """
line: 7
errormsg: "identifier expected, but found 'keyword atomic'"
"""
var
var
atomic: int
echo atomic

View file

@ -7,7 +7,7 @@ when false:
p(1, 3):
echo 1
echo 3
p(1, 1, proc() =
echo 1
echo 2)

View file

@ -1,6 +1,6 @@
import os
proc getDllName: string =
proc getDllName: string =
result = "mylib.dll"
if fileExists(result): return
result = "mylib2.dll"

View file

@ -2,14 +2,14 @@ discard """
file: "temit.nim"
output: "509"
"""
# Test the new ``emit`` pragma:
# Test the new ``emit`` pragma:
{.emit: """
static int cvariable = 420;
""".}
proc embedsC() =
proc embedsC() =
var nimVar = 89
{.emit: """printf("%d\n", cvariable + (int)`nimVar`);""".}

View file

@ -13,7 +13,7 @@ proc emit*(emitter: EventEmitter, event: string, args: EventArgs) =
for fn in nodes(emitter.events[event]):
fn.value(args) #call function with args.
proc on*(emitter: var EventEmitter, event: string,
proc on*(emitter: var EventEmitter, event: string,
fn: proc(e: EventArgs) {.nimcall.}) =
if not hasKey(emitter.events, event):
var list: DoublyLinkedList[proc(e: EventArgs) {.nimcall.}]
@ -21,10 +21,10 @@ proc on*(emitter: var EventEmitter, event: string,
append(emitter.events.mget(event), fn)
proc initEmitter(emitter: var EventEmitter) =
emitter.events = initTable[string,
emitter.events = initTable[string,
DoublyLinkedList[proc(e: EventArgs) {.nimcall.}]]()
var
var
ee: EventEmitter
args: EventArgs
initEmitter(ee)

View file

@ -13,11 +13,11 @@ type
proc handleprintevent*(e: TEventArgs) =
write(stdout, "HandlePrintEvent: Output -> Handled print event\n")
proc handleprintevent2*(e: TEventArgs) =
var args: TPrintEventArgs = TPrintEventArgs(e)
write(stdout, "HandlePrintEvent2: Output -> printing for " & args.user)
var ee = initEventEmitter()
var eventargs: TPrintEventArgs

View file

@ -1,8 +1,8 @@
iterator fibonacci(): int =
iterator fibonacci(): int =
var a = 0
var b = 1
while true:
while true:
yield a
var c = b
b = a

View file

@ -1,4 +1,4 @@
#
#
import times, os
var start = epochTime()

View file

@ -1,7 +1,7 @@
type
type
Bar = object
x: int
Foo = object
rheap: ref Bar
rmaybe: ref Bar
@ -31,7 +31,7 @@ proc test(maybeFoo: var Foo,
maybeFoo.list[3] = bb
maybeFoo.listarr[3] = bb
acc(maybeFoo) = bb
var localFoo: Foo
localFoo.rstack = bb
localFoo.list[3] = bb

View file

@ -6,7 +6,7 @@ discard """
{.hint[XDeclaredButNotUsed]: off.}
var
x: int
echo x #OUT 0

View file

@ -2,11 +2,11 @@ discard """
file: "tinit.nim"
output: "Hello from module! Hello from main module!"
"""
# Test the new init section in modules
import minit
write(stdout, "Hello from main module!\n")
#OUT Hello from module! Hello from main module!
# Test the new init section in modules
import minit
write(stdout, "Hello from main module!\n")
#OUT Hello from module! Hello from main module!

View file

@ -3,14 +3,14 @@ discard """
line: 12
errormsg: "type mismatch: got (int literal(3))"
"""
# Test in out checking for parameters
proc abc(x: var int) =
x = 0
proc b() =
abc(3) #ERROR
b()
# Test in out checking for parameters
proc abc(x: var int) =
x = 0
proc b() =
abc(3) #ERROR
b()

View file

@ -14,12 +14,12 @@ proc parseURL(url: string): TURL =
var m: array[0..6, string] #Array with the matches
newSeq(m, 7) #ERROR
discard regexprs.match(url, re(pattern), m)
result = (protocol: m[1], subdomain: m[2], domain: m[3] & m[4],
result = (protocol: m[1], subdomain: m[2], domain: m[3] & m[4],
port: m[5], path: m[6].split('/'))
var r: TUrl
r = parseUrl(r"http://google.com/search?var=bleahdhsad")
echo(r.domain)

View file

@ -1,18 +1,18 @@
# test the new LastModificationTime() proc
import
os, times, strutils
proc main() =
var
a, b: TTime
a = getLastModificationTime(paramStr(1))
b = getLastModificationTime(paramStr(2))
writeLine(stdout, $a)
writeLine(stdout, $b)
if a < b:
write(stdout, "$2 is newer than $1\n" % [paramStr(1), paramStr(2)])
else:
write(stdout, "$1 is newer than $2\n" % [paramStr(1), paramStr(2)])
main()
# test the new LastModificationTime() proc
import
os, times, strutils
proc main() =
var
a, b: TTime
a = getLastModificationTime(paramStr(1))
b = getLastModificationTime(paramStr(2))
writeLine(stdout, $a)
writeLine(stdout, $b)
if a < b:
write(stdout, "$2 is newer than $1\n" % [paramStr(1), paramStr(2)])
else:
write(stdout, "$1 is newer than $2\n" % [paramStr(1), paramStr(2)])
main()

View file

@ -2,10 +2,10 @@ discard """
output: "(x: string here, a: 1)"
"""
proc simple[T](a: T) =
proc simple[T](a: T) =
var
x = "string here"
echo locals()
simple(1)

View file

@ -76,7 +76,7 @@ proc main[T]() =
b = (1, 2, 3)
myType = b
echo myType
var myType2: MyType2
var c: MyType2
c = (1.0, 2.0)

View file

@ -14,7 +14,7 @@ proc newConnection =
proc cb {.closure.} =
discard
first.callback = cb
newConnection()

View file

@ -1,49 +1,49 @@
# Test the implementation of the new operator
# and the code generation for gc walkers
# (and the garbage collector):
type
PNode = ref TNode
TNode = object
data: int
str: string
le, ri: PNode
TStressTest = ref array [0..45, array [1..45, TNode]]
proc finalizer(n: PNode) =
write(stdout, n.data)
write(stdout, " is now freed\n")
proc newNode(data: int, le, ri: PNode): PNode =
new(result, finalizer)
result.le = le
result.ri = ri
result.data = data
# now loop and build a tree
proc main() =
var
i = 0
p: TStressTest
while i < 1000:
var n: PNode
n = newNode(i, nil, newNode(i + 10000, nil, nil))
inc(i)
new(p)
write(stdout, "Simple tree node allocation worked!\n")
i = 0
while i < 1000:
var m = newNode(i + 20000, nil, nil)
var k = newNode(i + 30000, nil, nil)
m.le = m
m.ri = k
k.le = m
k.ri = k
inc(i)
write(stdout, "Simple cycle allocation worked!\n")
main()
# Test the implementation of the new operator
# and the code generation for gc walkers
# (and the garbage collector):
type
PNode = ref TNode
TNode = object
data: int
str: string
le, ri: PNode
TStressTest = ref array [0..45, array [1..45, TNode]]
proc finalizer(n: PNode) =
write(stdout, n.data)
write(stdout, " is now freed\n")
proc newNode(data: int, le, ri: PNode): PNode =
new(result, finalizer)
result.le = le
result.ri = ri
result.data = data
# now loop and build a tree
proc main() =
var
i = 0
p: TStressTest
while i < 1000:
var n: PNode
n = newNode(i, nil, newNode(i + 10000, nil, nil))
inc(i)
new(p)
write(stdout, "Simple tree node allocation worked!\n")
i = 0
while i < 1000:
var m = newNode(i + 20000, nil, nil)
var k = newNode(i + 30000, nil, nil)
m.le = m
m.ri = k
k.le = m
k.ri = k
inc(i)
write(stdout, "Simple cycle allocation worked!\n")
main()

View file

@ -7,5 +7,5 @@ var x: ref int
new(x)
x[] = 3
echo x[]
echo x[]

View file

@ -1,6 +1,6 @@
# new test for sets:
const elem = ' '
var s: set[char] = {elem}
assert(elem in s and 'a' not_in s and 'c' not_in s )
# new test for sets:
const elem = ' '
var s: set[char] = {elem}
assert(elem in s and 'a' not_in s and 'c' not_in s )

View file

@ -1,12 +1,12 @@
# test the new unsigned operations:
import
strutils
var
x, y: int
x = 1
y = high(int)
writeLine(stdout, $ ( x +% y ) )
# test the new unsigned operations:
import
strutils
var
x, y: int
x = 1
y = high(int)
writeLine(stdout, $ ( x +% y ) )

View file

@ -11,7 +11,7 @@ proc wrap[T]() =
var x: proc (x, y: T): int
x = notConcrete
wrap[int]()

View file

@ -5,10 +5,10 @@ discard """
"""
# BUG: following compiles, but should not:
proc nodeOfDegree(x: int): bool =
proc nodeOfDegree(x: int): bool =
result = false
proc main =
proc main =
for j in 0..2:
for i in 0..10:
if not nodeOfDegree(1) >= 0: #ERROR_MSG type mismatch

View file

@ -1,4 +1,4 @@
# This test is now superfluous:
proc a(a: int) =
return
# This test is now superfluous:
proc a(a: int) =
return

View file

@ -2,34 +2,34 @@ discard """
file: "tpos.nim"
output: "6"
"""
# test this particular function
proc mypos(sub, s: string, start: int = 0): int =
var
i, j, M, N: int
M = sub.len
N = s.len
i = start
j = 0
if i >= N:
result = -1
else:
while true:
if s[i] == sub[j]:
inc(i)
inc(j)
else:
i = i - j + 1
j = 0
if (j >= M) or (i >= N): break
if j >= M:
result = i - M
else:
result = -1
var sub = "hello"
var s = "world hello"
write(stdout, mypos(sub, s))
#OUT 6
# test this particular function
proc mypos(sub, s: string, start: int = 0): int =
var
i, j, M, N: int
M = sub.len
N = s.len
i = start
j = 0
if i >= N:
result = -1
else:
while true:
if s[i] == sub[j]:
inc(i)
inc(j)
else:
i = i - j + 1
j = 0
if (j >= M) or (i >= N): break
if j >= M:
result = i - M
else:
result = -1
var sub = "hello"
var s = "world hello"
write(stdout, mypos(sub, s))
#OUT 6

View file

@ -9,17 +9,17 @@ proc QuickSort(list: seq[int]): seq[int] =
left.add(list[i])
elif list[i] > pivot:
right.add(list[i])
result = QuickSort(left) &
pivot &
result = QuickSort(left) &
pivot &
QuickSort(right)
proc echoSeq(a: seq[int]) =
for i in low(a)..high(a):
echo(a[i])
var
list: seq[int]
list = QuickSort(@[89,23,15,23,56,123,356,12,7,1,6,2,9,4,3])
echoSeq(list)

View file

@ -1,7 +1,7 @@
# implements and tests an efficient radix tree
## another method to store an efficient array of pointers:
## We use a radix tree with node compression.
## another method to store an efficient array of pointers:
## We use a radix tree with node compression.
## There are two node kinds:
const BitsPerUnit = 8*sizeof(int)
@ -15,7 +15,7 @@ type
len: int8
keys: array [0..31, int8]
vals: array [0..31, PRadixNode]
TRadixNodeFull = object of TRadixNode
b: array [0..255, PRadixNode]
TRadixNodeLeafBits = object of TRadixNode
@ -27,43 +27,43 @@ type
var
root: PRadixNode
proc searchInner(r: PRadixNode, a: int): PRadixNode =
proc searchInner(r: PRadixNode, a: int): PRadixNode =
case r.kind
of rnLinear:
var x = cast[ptr TRadixNodeLinear](r)
for i in 0..ze(x.len)-1:
for i in 0..ze(x.len)-1:
if ze(x.keys[i]) == a: return x.vals[i]
of rnFull:
of rnFull:
var x = cast[ptr TRadixNodeFull](r)
return x.b[a]
else: assert(false)
proc testBit(w, i: int): bool {.inline.} =
proc testBit(w, i: int): bool {.inline.} =
result = (w and (1 shl (i %% BitsPerUnit))) != 0
proc setBit(w: var int, i: int) {.inline.} =
proc setBit(w: var int, i: int) {.inline.} =
w = w or (1 shl (i %% BitsPerUnit))
proc resetBit(w: var int, i: int) {.inline.} =
proc resetBit(w: var int, i: int) {.inline.} =
w = w and not (1 shl (i %% BitsPerUnit))
proc testOrSetBit(w: var int, i: int): bool {.inline.} =
proc testOrSetBit(w: var int, i: int): bool {.inline.} =
var x = (1 shl (i %% BitsPerUnit))
if (w and x) != 0: return true
w = w or x
proc searchLeaf(r: PRadixNode, a: int): bool =
proc searchLeaf(r: PRadixNode, a: int): bool =
case r.kind
of rnLeafBits:
var x = cast[ptr TRadixNodeLeafBits](r)
return testBit(x.b[a /% BitsPerUnit], a)
of rnLeafLinear:
var x = cast[ptr TRadixNodeLeafLinear](r)
for i in 0..ze(x.len)-1:
for i in 0..ze(x.len)-1:
if ze(x.keys[i]) == a: return true
else: assert(false)
proc exclLeaf(r: PRadixNode, a: int) =
proc exclLeaf(r: PRadixNode, a: int) =
case r.kind
of rnLeafBits:
var x = cast[ptr TRadixNodeLeafBits](r)
@ -71,8 +71,8 @@ proc exclLeaf(r: PRadixNode, a: int) =
of rnLeafLinear:
var x = cast[ptr TRadixNodeLeafLinear](r)
var L = ze(x.len)
for i in 0..L-1:
if ze(x.keys[i]) == a:
for i in 0..L-1:
if ze(x.keys[i]) == a:
x.keys[i] = x.keys[L-1]
dec(x.len)
return
@ -98,7 +98,7 @@ proc excl*(r: PRadixNode, a: ByteAddress): bool =
if x == nil: return false
exclLeaf(x, a and 0xff)
proc addLeaf(r: var PRadixNode, a: int): bool =
proc addLeaf(r: var PRadixNode, a: int): bool =
if r == nil:
# a linear node:
var x = cast[ptr TRadixNodeLinear](alloc(sizeof(TRadixNodeLinear)))
@ -107,23 +107,23 @@ proc addLeaf(r: var PRadixNode, a: int): bool =
x.keys[0] = toU8(a)
r = x
return false # not already in set
case r.kind
of rnLeafBits:
case r.kind
of rnLeafBits:
var x = cast[ptr TRadixNodeLeafBits](r)
return testOrSetBit(x.b[a /% BitsPerUnit], a)
of rnLeafLinear:
of rnLeafLinear:
var x = cast[ptr TRadixNodeLeafLinear](r)
var L = ze(x.len)
for i in 0..L-1:
for i in 0..L-1:
if ze(x.keys[i]) == a: return true
if L <= high(x.keys):
x.keys[L] = toU8(a)
inc(x.len)
else:
else:
# transform into a full node:
var y = cast[ptr TRadixNodeLeafBits](alloc0(sizeof(TRadixNodeLeafBits)))
y.kind = rnLeafBits
for i in 0..ze(x.len)-1:
for i in 0..ze(x.len)-1:
var u = ze(x.keys[i])
setBit(y.b[u /% BitsPerUnit], u)
setBit(y.b[a /% BitsPerUnit], a)
@ -131,8 +131,8 @@ proc addLeaf(r: var PRadixNode, a: int): bool =
r = y
else: assert(false)
proc addInner(r: var PRadixNode, a: int, d: int): bool =
if d == 0:
proc addInner(r: var PRadixNode, a: int, d: int): bool =
if d == 0:
return addLeaf(r, a and 0xff)
var k = a shr d and 0xff
if r == nil:
@ -147,14 +147,14 @@ proc addInner(r: var PRadixNode, a: int, d: int): bool =
of rnLinear:
var x = cast[ptr TRadixNodeLinear](r)
var L = ze(x.len)
for i in 0..L-1:
for i in 0..L-1:
if ze(x.keys[i]) == k: # already exists
return addInner(x.vals[i], a, d-8)
if L <= high(x.keys):
x.keys[L] = toU8(k)
inc(x.len)
return addInner(x.vals[L], a, d-8)
else:
else:
# transform into a full node:
var y = cast[ptr TRadixNodeFull](alloc0(sizeof(TRadixNodeFull)))
y.kind = rnFull
@ -162,55 +162,55 @@ proc addInner(r: var PRadixNode, a: int, d: int): bool =
dealloc(r)
r = y
return addInner(y.b[k], a, d-8)
of rnFull:
of rnFull:
var x = cast[ptr TRadixNodeFull](r)
return addInner(x.b[k], a, d-8)
else: assert(false)
proc incl*(r: var PRadixNode, a: ByteAddress) {.inline.} =
proc incl*(r: var PRadixNode, a: ByteAddress) {.inline.} =
discard addInner(r, a, 24)
proc testOrIncl*(r: var PRadixNode, a: ByteAddress): bool {.inline.} =
proc testOrIncl*(r: var PRadixNode, a: ByteAddress): bool {.inline.} =
return addInner(r, a, 24)
iterator innerElements(r: PRadixNode): tuple[prefix: int, n: PRadixNode] =
iterator innerElements(r: PRadixNode): tuple[prefix: int, n: PRadixNode] =
if r != nil:
case r.kind
of rnFull:
case r.kind
of rnFull:
var r = cast[ptr TRadixNodeFull](r)
for i in 0..high(r.b):
if r.b[i] != nil:
if r.b[i] != nil:
yield (i, r.b[i])
of rnLinear:
of rnLinear:
var r = cast[ptr TRadixNodeLinear](r)
for i in 0..ze(r.len)-1:
for i in 0..ze(r.len)-1:
yield (ze(r.keys[i]), r.vals[i])
else: assert(false)
iterator leafElements(r: PRadixNode): int =
iterator leafElements(r: PRadixNode): int =
if r != nil:
case r.kind
of rnLeafBits:
of rnLeafBits:
var r = cast[ptr TRadixNodeLeafBits](r)
# iterate over any bit:
for i in 0..high(r.b):
for i in 0..high(r.b):
if r.b[i] != 0: # test all bits for zero
for j in 0..BitsPerUnit-1:
if testBit(r.b[i], j):
for j in 0..BitsPerUnit-1:
if testBit(r.b[i], j):
yield i*BitsPerUnit+j
of rnLeafLinear:
of rnLeafLinear:
var r = cast[ptr TRadixNodeLeafLinear](r)
for i in 0..ze(r.len)-1:
for i in 0..ze(r.len)-1:
yield ze(r.keys[i])
else: assert(false)
iterator elements*(r: PRadixNode): ByteAddress {.inline.} =
for p1, n1 in innerElements(r):
iterator elements*(r: PRadixNode): ByteAddress {.inline.} =
for p1, n1 in innerElements(r):
for p2, n2 in innerElements(n1):
for p3, n3 in innerElements(n2):
for p4 in leafElements(n3):
for p4 in leafElements(n3):
yield p1 shl 24 or p2 shl 16 or p3 shl 8 or p4
proc main() =
const
numbers = [128, 1, 2, 3, 4, 255, 17, -8, 45, 19_000]
@ -224,31 +224,31 @@ main()
when false:
proc traverse(r: PRadixNode, prefix: int, d: int) =
proc traverse(r: PRadixNode, prefix: int, d: int) =
if r == nil: return
case r.kind
of rnLeafBits:
case r.kind
of rnLeafBits:
assert(d == 0)
var x = cast[ptr TRadixNodeLeafBits](r)
# iterate over any bit:
for i in 0..high(x.b):
for i in 0..high(x.b):
if x.b[i] != 0: # test all bits for zero
for j in 0..BitsPerUnit-1:
if testBit(x.b[i], j):
for j in 0..BitsPerUnit-1:
if testBit(x.b[i], j):
visit(prefix or i*BitsPerUnit+j)
of rnLeafLinear:
of rnLeafLinear:
assert(d == 0)
var x = cast[ptr TRadixNodeLeafLinear](r)
for i in 0..ze(x.len)-1:
for i in 0..ze(x.len)-1:
visit(prefix or ze(x.keys[i]))
of rnFull:
of rnFull:
var x = cast[ptr TRadixNodeFull](r)
for i in 0..high(r.b):
if r.b[i] != nil:
if r.b[i] != nil:
traverse(r.b[i], prefix or (i shl d), d-8)
of rnLinear:
of rnLinear:
var x = cast[ptr TRadixNodeLinear](r)
for i in 0..ze(x.len)-1:
for i in 0..ze(x.len)-1:
traverse(x.vals[i], prefix or (ze(x.keys[i]) shl d), d-8)
type
@ -261,59 +261,59 @@ when false:
i.r = r
i.x = 0
i.p = 0
proc nextr(i: var TRadixIter): PRadixNode =
proc nextr(i: var TRadixIter): PRadixNode =
if i.r == nil: return nil
case i.r.kind
of rnFull:
case i.r.kind
of rnFull:
var r = cast[ptr TRadixNodeFull](i.r)
while i.x <= high(r.b):
if r.b[i.x] != nil:
if r.b[i.x] != nil:
i.p = i.x
return r.b[i.x]
inc(i.x)
of rnLinear:
of rnLinear:
var r = cast[ptr TRadixNodeLinear](i.r)
if i.x < ze(r.len):
if i.x < ze(r.len):
i.p = ze(r.keys[i.x])
result = r.vals[i.x]
inc(i.x)
else: assert(false)
proc nexti(i: var TRadixIter): int =
proc nexti(i: var TRadixIter): int =
result = -1
case i.r.kind
of rnLeafBits:
case i.r.kind
of rnLeafBits:
var r = cast[ptr TRadixNodeLeafBits](i.r)
# iterate over any bit:
for i in 0..high(r.b):
# iterate over any bit:
for i in 0..high(r.b):
if x.b[i] != 0: # test all bits for zero
for j in 0..BitsPerUnit-1:
if testBit(x.b[i], j):
for j in 0..BitsPerUnit-1:
if testBit(x.b[i], j):
visit(prefix or i*BitsPerUnit+j)
of rnLeafLinear:
of rnLeafLinear:
var r = cast[ptr TRadixNodeLeafLinear](i.r)
if i.x < ze(r.len):
if i.x < ze(r.len):
result = ze(r.keys[i.x])
inc(i.x)
iterator elements(r: PRadixNode): ByteAddress {.inline.} =
iterator elements(r: PRadixNode): ByteAddress {.inline.} =
var
a, b, c, d: TRadixIter
init(a, r)
while true:
while true:
var x = nextr(a)
if x != nil:
if x != nil:
init(b, x)
while true:
while true:
var y = nextr(b)
if y != nil:
if y != nil:
init(c, y)
while true:
var z = nextr(c)
if z != nil:
if z != nil:
init(d, z)
while true:
var q = nexti(d)
if q != -1:
if q != -1:
yield a.p shl 24 or b.p shl 16 or c.p shl 8 or q

View file

@ -3,10 +3,10 @@ discard """
line: 10
errormsg: "closing \" expected"
"""
# Test the new raw strings:
const
xxx = r"This is a raw string!"
yyy = "This not\" #ERROR
# Test the new raw strings:
const
xxx = r"This is a raw string!"
yyy = "This not\" #ERROR

View file

@ -32,7 +32,7 @@ proc RomanToDecimal(romanVal: string): int =
of 'C', 'c': val = 100
of 'D', 'd': val = 500
of 'M', 'm': val = 1000
else: raiseInvalidValue("Incorrect character in roman numeral! (" &
else: raiseInvalidValue("Incorrect character in roman numeral! (" &
$romanVal[i] & ")")
if val >= prevVal:
inc(result, val)
@ -49,7 +49,7 @@ proc DecimalToRoman(decValParam: int): string =
("M", 1000), ("CM", 900),
("D", 500), ("CD", 400), ("C", 100),
("XC", 90), ("L", 50), ("XL", 40), ("X", 10), ("IX", 9),
("V", 5), ("IV", 4), ("I", 1)]
("V", 5), ("IV", 4), ("I", 1)]
if decValParam < 1 or decValParam > 3999:
raiseInvalidValue("number not representable")
result = ""
@ -64,7 +64,7 @@ for i in 1..100:
for i in items([1238, 1777, 3830, 2401, 379, 33, 940, 3973]):
if RomanToDecimal(DecimalToRoman(i)) != i: quit "BUG"
echo "success" #OUT success

View file

@ -1,7 +1,7 @@
discard """
output: '''true'''
"""
import hashes, math
{.pragma: myShallow.}
@ -112,7 +112,7 @@ proc initTable*[A, B](initialSize=64): TTable[A, B] =
result.counter = 0
newSeq(result.data, initialSize)
proc toTable*[A, B](pairs: openarray[tuple[key: A,
proc toTable*[A, B](pairs: openarray[tuple[key: A,
val: B]]): TTable[A, B] =
## creates a new hash table that contains the given `pairs`.
result = initTable[A, B](nextPowerOfTwo(pairs.len+10))
@ -214,7 +214,7 @@ proc `$`*[A](t: TCountTable[A]): string =
## The `$` operator for count tables.
dollarImpl()
proc inc*[A](t: var TCountTable[A], key: A, val = 1) =
proc inc*[A](t: var TCountTable[A], key: A, val = 1) =
## increments `t[key]` by `val`.
var index = RawGet(t, key)
if index >= 0:

View file

@ -3,10 +3,10 @@ discard """
line: 10
errormsg: "type mismatch: got (bool) but expected \'string\'"
"""
# Test 2
# Simple type checking
var a: string
a = false #ERROR
# Test 2
# Simple type checking
var a: string
a = false #ERROR

View file

@ -1,10 +1,10 @@
# Test the sizeof proc
type
TMyRecord {.final.} = object
x, y: int
b: bool
r: float
s: string
write(stdout, sizeof(TMyRecord))
# Test the sizeof proc
type
TMyRecord {.final.} = object
x, y: int
b: bool
r: float
s: string
write(stdout, sizeof(TMyRecord))

View file

@ -37,17 +37,17 @@ proc cmpPlatforms(a, b: string): int =
else:
return system.cmp(a, b)
proc sorted[T](a: openArray[T]): bool =
proc sorted[T](a: openArray[T]): bool =
result = true
for i in 0 .. < a.high:
if cmpPlatforms(a[i], a[i+1]) > 0:
if cmpPlatforms(a[i], a[i+1]) > 0:
echo "Out of order: ", a[i], " ", a[i+1]
result = false
proc main() =
var testData = @["netbsd-x86_64", "windows-x86", "linux-x86_64", "linux-x86",
var testData = @["netbsd-x86_64", "windows-x86", "linux-x86_64", "linux-x86",
"linux-ppc64", "macosx-x86-1058", "macosx-x86-1068"]
sort(testData, cmpPlatforms)
doAssert sorted(testData)

View file

@ -1,16 +1,16 @@
# Test the new stacktraces (great for debugging!)
{.push stack_trace: on.}
proc recTest(i: int) =
# enter
if i < 10:
recTest(i+1)
else: # should printStackTrace()
var p: ptr int = nil
p[] = 12
# leave
{.pop.}
recTest(0)
# Test the new stacktraces (great for debugging!)
{.push stack_trace: on.}
proc recTest(i: int) =
# enter
if i < 10:
recTest(i+1)
else: # should printStackTrace()
var p: ptr int = nil
p[] = 12
# leave
{.pop.}
recTest(0)

View file

@ -4,23 +4,23 @@ discard """
1
2'''
"""
# test for extremely strange bug
proc ack(x: int, y: int): int =
if x != 0:
if y != 5:
return y
return x
return x+y
proc gen[T](a: T) =
write(stdout, a)
gen("hallo")
write(stdout, ack(5, 4))
#OUT hallo4
# test for extremely strange bug
proc ack(x: int, y: int): int =
if x != 0:
if y != 5:
return y
return x
return x+y
proc gen[T](a: T) =
write(stdout, a)
gen("hallo")
write(stdout, ack(5, 4))
#OUT hallo4
# bug #1442
let h=3
for x in 0.. <h.int:

View file

@ -1,14 +1,14 @@
var
x: array [0..2, int]
x = [0, 1, 2]
type
TStringDesc {.final.} = object
len, space: int # len and space without counting the terminating zero
data: array [0..0, char] # for the '\0' character
var
emptyString {.exportc: "emptyString".}: TStringDesc
var
x: array [0..2, int]
x = [0, 1, 2]
type
TStringDesc {.final.} = object
len, space: int # len and space without counting the terminating zero
data: array [0..0, char] # for the '\0' character
var
emptyString {.exportc: "emptyString".}: TStringDesc

View file

@ -9,7 +9,7 @@ Whopie
echo len([1_000_000]) #OUT 1
type
type
TArray = array[0..3, int]
TVector = distinct array[0..3, int]
proc `[]`(v: TVector; idx: int): int = TArray(v)[idx]
@ -43,6 +43,6 @@ echo value
# bug #1334
var ys = @[4.1, 5.6, 7.2, 1.7, 9.3, 4.4, 3.2]
#var x = int(ys.high / 2) #echo ys[x] # Works
var ys = @[4.1, 5.6, 7.2, 1.7, 9.3, 4.4, 3.2]
#var x = int(ys.high / 2) #echo ys[x] # Works
echo ys[int(ys.high / 2)] # Doesn't work