diff options
Diffstat (limited to 'tests')
-rwxr-xr-x | tests/sunset.tmpl | 1 | ||||
-rwxr-xr-x | tests/tadrdisc.nim | 16 | ||||
-rwxr-xr-x | tests/tbind1.nim | 14 | ||||
-rwxr-xr-x | tests/tbind2.nim | 10 | ||||
-rwxr-xr-x | tests/tbintre2.nim | 25 | ||||
-rwxr-xr-x | tests/tcasestm.nim | 20 | ||||
-rwxr-xr-x | tests/tcnstseq.nim | 11 | ||||
-rwxr-xr-x | tests/tcopy.nim | 2 | ||||
-rwxr-xr-x | tests/tester.nim | 2 | ||||
-rwxr-xr-x | tests/titer4.nim | 3 | ||||
-rwxr-xr-x | tests/tmultim1.nim | 23 | ||||
-rwxr-xr-x | tests/tmultim2.nim | 30 | ||||
-rwxr-xr-x | tests/tobjcov.nim | 17 | ||||
-rwxr-xr-x | tests/toverl2.nim | 21 | ||||
-rwxr-xr-x | tests/toverprc.nim | 25 | ||||
-rwxr-xr-x | tests/tposix.nim | 19 | ||||
-rwxr-xr-x | tests/treadx.nim | 12 | ||||
-rwxr-xr-x | tests/trecinca.nim | 5 | ||||
-rwxr-xr-x | tests/trecincb.nim | 6 | ||||
-rwxr-xr-x | tests/treciter.nim | 7 | ||||
-rwxr-xr-x | tests/tseqcon2.nim | 9 | ||||
-rwxr-xr-x | tests/tsidee1.nim | 11 | ||||
-rwxr-xr-x | tests/tsidee2.nim | 11 | ||||
-rwxr-xr-x | tests/tsidee3.nim | 11 | ||||
-rwxr-xr-x | tests/tsidee4.nim | 10 | ||||
-rwxr-xr-x | tests/tvartup.nim | 11 |
26 files changed, 312 insertions, 20 deletions
diff --git a/tests/sunset.tmpl b/tests/sunset.tmpl index 08fa50f56..6475bac4e 100755 --- a/tests/sunset.tmpl +++ b/tests/sunset.tmpl @@ -1,3 +1,4 @@ +#! stdtmpl #proc sunsetTemplate*(current, ticker, content: string, # tabs: openarray[array[0..1, string]]): string = # result = "" diff --git a/tests/tadrdisc.nim b/tests/tadrdisc.nim new file mode 100755 index 000000000..a7118455f --- /dev/null +++ b/tests/tadrdisc.nim @@ -0,0 +1,16 @@ +# Test that the address of a dicriminants cannot be taken + +type + TKind = enum ka, kb, kc + TA = object + case k: TKind + of ka: x, y: int + of kb: a, b: string + of kc: c, d: float + +proc setKind(k: var TKind) = + k = kc + +var a: TA +setKind(a.k) #ERROR_MSG for a 'var' type a variable needs to be passed + diff --git a/tests/tbind1.nim b/tests/tbind1.nim new file mode 100755 index 000000000..e7eed3e4f --- /dev/null +++ b/tests/tbind1.nim @@ -0,0 +1,14 @@ +# Test the new ``bind`` keyword for templates + +proc p1(x: int8, y: int): int = return x + y + +template tempBind(x, y: expr): expr = + bind p1(x, y) + +proc p1(x: int, y: int8): int = return x - y + +# This is tricky: the call to ``p1(1'i8, 2'i8)`` should not fail in line 6, +# because it is not ambiguous there. But it is ambiguous after line 8. + +echo tempBind(1'i8, 2'i8) #OUT 3 + diff --git a/tests/tbind2.nim b/tests/tbind2.nim new file mode 100755 index 000000000..41711083f --- /dev/null +++ b/tests/tbind2.nim @@ -0,0 +1,10 @@ +# Test the new ``bind`` keyword for templates + +proc p1(x: int8, y: int): int = return x + y +proc p1(x: int, y: int8): int = return x - y + +template tempBind(x, y: expr): expr = + bind p1(x, y) #ERROR_MSG ambiguous call + +echo tempBind(1'i8, 2'i8) + diff --git a/tests/tbintre2.nim b/tests/tbintre2.nim new file mode 100755 index 000000000..dedc87705 --- /dev/null +++ b/tests/tbintre2.nim @@ -0,0 +1,25 @@ +# Same test, but check module boundaries + +import tbintree + +var + root: PBinaryTree[string] + x = newNode("hallo") +add(root, x) +add(root, "world") +if find(root, "world"): + for str in items(root): + stdout.write(str) +else: + stdout.writeln("BUG") + +var + r2: PBinaryTree[int] +add(r2, newNode(110)) +add(r2, 223) +add(r2, 99) +for y in items(r2): + stdout.write(y) + +#OUT halloworld99110223 + diff --git a/tests/tcasestm.nim b/tests/tcasestm.nim index 16051ceb8..277b0bab1 100755 --- a/tests/tcasestm.nim +++ b/tests/tcasestm.nim @@ -4,29 +4,29 @@ type tenum = enum eA, eB, eC var - x: string + x: string = "yyy" y: Tenum = eA i: int case y -of eA: write(stdout, "a\n") -of eB, eC: write(stdout, "b oder c\n") +of eA: write(stdout, "a") +of eB, eC: write(stdout, "b or c") -x = readLine(stdin) case x -of "Andreas", "Rumpf": write(stdout, "Hallo Meister!\n") -of "aa", "bb": write(stdout, "Du bist nicht mein Meister\n") +of "Andreas", "Rumpf": write(stdout, "Hallo Meister!") +of "aa", "bb": write(stdout, "Du bist nicht mein Meister") of "cc", "hash", "when": nil of "will", "it", "finally", "be", "generated": nil -else: write(stdout, "das sollte nicht passieren!\N") case i -of 0..5, 8, 9: nil +of 1..5, 8, 9: nil of 6, 7: nil elif x == "Ha": nil -elif x == "Ho": - nil +elif x == "yyy": + write(stdout, x) else: nil +#OUT ayyy + diff --git a/tests/tcnstseq.nim b/tests/tcnstseq.nim new file mode 100755 index 000000000..4f389bb3b --- /dev/null +++ b/tests/tcnstseq.nim @@ -0,0 +1,11 @@ +# Test the new implicit conversion from sequences to arrays in a constant +# context. + +import strutils + +const + myWords = "Angelika Anne Anna Anka Anja".split() + +for x in items(myWords): + write(stdout, x) #OUT AngelikaAnneAnnaAnkaAnja + diff --git a/tests/tcopy.nim b/tests/tcopy.nim index 81d72c7f2..6cb2ec14c 100755 --- a/tests/tcopy.nim +++ b/tests/tcopy.nim @@ -9,7 +9,7 @@ proc main() = var a, b: string p: int - p = findSubStr("=", example) + p = find(example, "=") a = copy(example, 0, p-1) b = copy(example, p+1) writeln(stdout, a & '=' & b) diff --git a/tests/tester.nim b/tests/tester.nim index b09200aea..25a6dd428 100755 --- a/tests/tester.nim +++ b/tests/tester.nim @@ -157,7 +157,7 @@ proc main(options: string) = var comp = callCompiler(filename, options) if sameResults(filename, spec, comp): inc(passed) inc(total) - # ensure that the examples at least compiles + # ensure that the examples at least compile for filename in os.walkFiles("examples/*.nim"): var comp = callCompiler(filename, options) var shortfile = os.extractFilename(filename) diff --git a/tests/titer4.nim b/tests/titer4.nim new file mode 100755 index 000000000..376522482 --- /dev/null +++ b/tests/titer4.nim @@ -0,0 +1,3 @@ + +for x in {'a'..'z'}: #ERROR_MSG iterator within for loop context expected + nil diff --git a/tests/tmultim1.nim b/tests/tmultim1.nim new file mode 100755 index 000000000..5d807e4c9 --- /dev/null +++ b/tests/tmultim1.nim @@ -0,0 +1,23 @@ +# Test multi methods + +type + TExpr = object + TLiteral = object of TExpr + x: int + TPlusExpr = object of TExpr + a, b: ref TExpr + +method eval(e: ref TExpr): int = quit "to override!" +method eval(e: ref TLiteral): int = return e.x +method eval(e: ref TPlusExpr): int = return eval(e.a) + eval(e.b) + +proc newLit(x: int): ref TLiteral = + new(result) + result.x = x + +proc newPlus(a, b: ref TExpr): ref TPlusExpr = + new(result) + result.a = a + result.b = b + +echo eval(newPlus(newPlus(newLit(1), newLit(2)), newLit(4))) #OUT 7 diff --git a/tests/tmultim2.nim b/tests/tmultim2.nim new file mode 100755 index 000000000..bf3b5fd6e --- /dev/null +++ b/tests/tmultim2.nim @@ -0,0 +1,30 @@ +# Test multi methods + +type + TThing = object + TUnit = object of TThing + x: int + TParticle = object of TThing + a, b: int + +method collide(a, b: TThing) {.inline.} = + quit "to override!" + +method collide(a: TThing, b: TUnit) {.inline.} = + write stdout, "collide: thing, unit " + +method collide(a: TUnit, b: TThing) {.inline.} = + write stdout, "collide: unit, thing " + +proc test(a, b: TThing) {.inline.} = + collide(a, b) + +var + a: TThing + b, c: TUnit +collide(b, c) # ambiguous unit, thing or thing, unit? -> prefer unit, thing! +test(b, c) +collide(a, b) +#OUT collide: unit, thing collide: unit, thing collide: thing, unit + + diff --git a/tests/tobjcov.nim b/tests/tobjcov.nim new file mode 100755 index 000000000..da34fcb60 --- /dev/null +++ b/tests/tobjcov.nim @@ -0,0 +1,17 @@ +# Covariance is not type safe: + +type + TA = object + a: int + TB = object of TA + b: array[0..5000_000, int] + +proc ap(x: var TA) = x.a = -1 +proc bp(x: var TB) = x.b[high(x.b)] = -1 + +# in Nimrod proc (x: TB) is compatible to proc (x: TA), +# but this is not type safe: +var f: proc (x: var TA) = bp +var a: TA +f(a) # bp expects a TB, but gets a TA + diff --git a/tests/toverl2.nim b/tests/toverl2.nim new file mode 100755 index 000000000..2d1225c6f --- /dev/null +++ b/tests/toverl2.nim @@ -0,0 +1,21 @@ +# Test new overloading resolution rules + +import strutils + +proc toverl2(x: int): string = return $x +proc toverl2(x: bool): string = return $x + +iterator toverl2(x: int): int = + var res = 0 + while res < x: + yield res + inc(res) + +var + pp: proc (x: bool): string = toverl2 +stdout.write(pp(true)) +for x in toverl2(3): + stdout.write(toverl2(x)) +stdout.write("\n") +#OUT true012 + diff --git a/tests/toverprc.nim b/tests/toverprc.nim new file mode 100755 index 000000000..f35528ace --- /dev/null +++ b/tests/toverprc.nim @@ -0,0 +1,25 @@ +# Test overloading of procs when used as function pointers + +import strutils + +proc parseInt(x: float): int = nil +proc parseInt(x: bool): int = nil +proc parseInt(x: float32): int = nil +proc parseInt(x: int8): int = nil +proc parseInt(x: TFile): int = nil +proc parseInt(x: char): int = nil +proc parseInt(x: int16): int = nil + +type + TParseInt = proc (x: string): int + +var + q = TParseInt(parseInt) + p: TParseInt = parseInt + +proc takeParseInt(x: proc (y: string): int): int = + result = x("123") + +echo "Give a list of numbers (separated by spaces): " +var x = stdin.readline.split.each(parseInt).max echo x, " is the maximum!" echo "another number: ", takeParseInt(parseInt) + diff --git a/tests/tposix.nim b/tests/tposix.nim index 87ea3acaf..bf0b49586 100755 --- a/tests/tposix.nim +++ b/tests/tposix.nim @@ -1,13 +1,16 @@ # Test Posix interface -import posix +when not defined(windows): -var - u: Tutsname + import posix -discard uname(u) + var + u: Tutsname + + discard uname(u) + + writeln(stdout, u.sysname) + writeln(stdout, u.nodename) + writeln(stdout, u.release) + writeln(stdout, u.machine) -writeln(stdout, u.sysname) -writeln(stdout, u.nodename) -writeln(stdout, u.release) -writeln(stdout, u.machine) diff --git a/tests/treadx.nim b/tests/treadx.nim new file mode 100755 index 000000000..13acb0514 --- /dev/null +++ b/tests/treadx.nim @@ -0,0 +1,12 @@ +import posix + +var inp = "" +var buf: array[0..10, char] +while true: + var r = read(0, addr(buf), sizeof(buf)-1) + add inp, $buf + if r != sizeof(buf)-1: break + +echo inp +#dafkladskölklödsaf ölksdakölfölksfklwe4iojr389wr 89uweokf sdlkf jweklr jweflksdj fioewjfsdlfsd + diff --git a/tests/trecinca.nim b/tests/trecinca.nim new file mode 100755 index 000000000..d78fee233 --- /dev/null +++ b/tests/trecinca.nim @@ -0,0 +1,5 @@ +# Test recursive includes + +include trecincb #ERROR_MSG recursive dependency: 'tests/trecincb.nim' + +echo "trecina" diff --git a/tests/trecincb.nim b/tests/trecincb.nim new file mode 100755 index 000000000..6191671a1 --- /dev/null +++ b/tests/trecincb.nim @@ -0,0 +1,6 @@ +# Test recursive includes + + +include trecincb #ERROR_MSG recursive dependency: 'tests/trecincb.nim' + +echo "trecinb" diff --git a/tests/treciter.nim b/tests/treciter.nim new file mode 100755 index 000000000..662239285 --- /dev/null +++ b/tests/treciter.nim @@ -0,0 +1,7 @@ +# Test that an error message occurs for a recursive iterator + +iterator myrec(n: int): int = + for x in myrec(n-1): #ERROR_MSG recursive dependency: 'myrec' + yield x + +for x in myrec(10): echo x diff --git a/tests/tseqcon2.nim b/tests/tseqcon2.nim new file mode 100755 index 000000000..6225c3bb1 --- /dev/null +++ b/tests/tseqcon2.nim @@ -0,0 +1,9 @@ +import os + +proc rec_dir(dir: string): seq[string] = + result = @[] + for kind, path in walk_dir(dir): + if kind == pcDirectory: + add(result, rec_dir(path)) + else: + add(result, path) diff --git a/tests/tsidee1.nim b/tests/tsidee1.nim new file mode 100755 index 000000000..3bd520680 --- /dev/null +++ b/tests/tsidee1.nim @@ -0,0 +1,11 @@ + +var + global: int + +proc dontcare(x: int): int = return x + global + +proc SideEffectLyer(x, y: int): int {.noSideEffect.} = #ERROR_MSG 'SideEffectLyer' can have side effects + return x + y + dontcare(x) + +echo SideEffectLyer(1, 3) + diff --git a/tests/tsidee2.nim b/tests/tsidee2.nim new file mode 100755 index 000000000..2eaec01d7 --- /dev/null +++ b/tests/tsidee2.nim @@ -0,0 +1,11 @@ + +var + global: int + +proc dontcare(x: int): int = return x + +proc SideEffectLyer(x, y: int): int {.noSideEffect.} = + return x + y + dontcare(x) + +echo SideEffectLyer(1, 3) #OUT 5 + diff --git a/tests/tsidee3.nim b/tests/tsidee3.nim new file mode 100755 index 000000000..be94192e7 --- /dev/null +++ b/tests/tsidee3.nim @@ -0,0 +1,11 @@ + +var + global: int + +proc dontcare(x: int): int {.noSideEffect.} = return x + +proc noSideEffect(x, y: int, p: proc (a: int): int {.noSideEffect.}): int {.noSideEffect.} = + return x + y + dontcare(x) + +echo noSideEffect(1, 3, dontcare) #OUT 5 + diff --git a/tests/tsidee4.nim b/tests/tsidee4.nim new file mode 100755 index 000000000..55c474d10 --- /dev/null +++ b/tests/tsidee4.nim @@ -0,0 +1,10 @@ + +var + global: int + +proc dontcare(x: int): int = return x + +proc noSideEffect(x, y: int, p: proc (a: int): int {.noSideEffect.}): int {.noSideEffect.} = + return x + y + dontcare(x) + +echo noSideEffect(1, 3, dontcare) #ERROR_MSG type mismatch diff --git a/tests/tvartup.nim b/tests/tvartup.nim new file mode 100755 index 000000000..05b00b207 --- /dev/null +++ b/tests/tvartup.nim @@ -0,0 +1,11 @@ +# Test the new tuple unpacking + +proc divmod(a, b: int): tuple[di, mo: int] = + return (a div b, a mod b) + +var (x, y) = divmod(15, 6) +stdout.write(x) +stdout.write(" ") +stdout.write(y) + +#OUT 2 3 |