diff options
Diffstat (limited to 'tests/parser')
-rw-r--r-- | tests/parser/tcommand_as_expr.nim | 9 | ||||
-rw-r--r-- | tests/parser/tproctype_pragmas.nim | 19 | ||||
-rw-r--r-- | tests/parser/tstrongspaces.nim | 33 | ||||
-rw-r--r-- | tests/parser/ttypeof.nim | 26 |
4 files changed, 83 insertions, 4 deletions
diff --git a/tests/parser/tcommand_as_expr.nim b/tests/parser/tcommand_as_expr.nim index 22c49ab3f..730e9cbb7 100644 --- a/tests/parser/tcommand_as_expr.nim +++ b/tests/parser/tcommand_as_expr.nim @@ -1,7 +1,8 @@ discard """ output: '''140 5-120-120 -359''' +359 +77''' """ #import math @@ -16,8 +17,10 @@ proc foo(x, y: int): int = x-y let x = optarg foo 7.foo let y = singlearg foo(1, foo 8) let z = singlearg 1.foo foo 8 - + echo x, y, z let a = [2,4,8].map do (d:int) -> int: d + 1 -echo a[0], a[1], a[2] \ No newline at end of file +echo a[0], a[1], a[2] + +echo(foo 8, foo 8) diff --git a/tests/parser/tproctype_pragmas.nim b/tests/parser/tproctype_pragmas.nim new file mode 100644 index 000000000..8c7acd0cf --- /dev/null +++ b/tests/parser/tproctype_pragmas.nim @@ -0,0 +1,19 @@ +discard """ + output: '''39 +40''' +""" + +# bug 1802 +# Ensure proc pragmas are attached properly: + +proc makeStdcall(s: string): (proc(i: int) {.stdcall.}) = + (proc (x: int) {.stdcall.} = echo x) + +proc makeNimcall(s: string): (proc(i: int)) {.stdcall.} = + (proc (x: int) {.nimcall.} = echo x) + +let stdc: proc (y: int) {.stdcall.} = makeStdcall("bu") +let nimc: proc (y: int) {.closure.} = makeNimcall("ba") + +stdc(39) +nimc(40) diff --git a/tests/parser/tstrongspaces.nim b/tests/parser/tstrongspaces.nim index 91506daf0..e70b91988 100644 --- a/tests/parser/tstrongspaces.nim +++ b/tests/parser/tstrongspaces.nim @@ -2,6 +2,12 @@ discard """ output: '''35 +true +true +4 +true +1 +false 77 (Field0: 1, Field1: 2, Field2: 2) ha @@ -9,11 +15,26 @@ true tester args all all args +19 +-3 +false +-2 ''' """ echo 2+5 * 5 +# Keyword operators +echo 1 + 16 shl 1 == 1 + (16 shl 1) +echo 2 and 1 in {0, 30} +echo 2+2 * 2 shr 1 +echo false or 2 and 1 in {0, 30} + +proc `^`(a, b: int): int = a + b div 2 +echo 19 mod 16 ^ 4 + 2 and 1 +echo 18 mod 16 ^ 4 > 0 + +# echo $foo gotcha let foo = 77 echo $foo @@ -27,7 +48,7 @@ when true: let b = 66 let c = 90 let bar = 8000 - if foo+4 * 4 == 8 and b&c | 9 ++ + if foo+4 * 4 == 8 and b&c | 9 ++ bar: echo "ho" else: @@ -50,3 +71,13 @@ const echo tester & " " & args|"all" echo "all" | tester & " " & args echo "all"|tester & " " & args + +# Test arrow like operators. See also tests/macros/tclosuremacro.nim +proc `+->`(a, b: int): int = a + b*4 +template `===>`(a, b: int): expr = a - b shr 1 + +echo 3 +-> 2 + 2 and 4 +var arrowed = 3+->2 + 2 and 4 # arrowed = 4 +echo arrowed ===> 15 +echo (2 * 3+->2) == (2*3 +-> 2) +echo arrowed ===> 2 + 3+->2 diff --git a/tests/parser/ttypeof.nim b/tests/parser/ttypeof.nim new file mode 100644 index 000000000..24f98059e --- /dev/null +++ b/tests/parser/ttypeof.nim @@ -0,0 +1,26 @@ +discard """ + output: '''12 +int +int +int''' +""" + +import typetraits + +# bug #1805 + +proc foob(x: int): string = "foo" +proc barb(x: string): int = 12 + +echo(foob(10).barb()) # works +echo(type(10).name()) # doesn't work + +echo(name(type(10))) # works +echo((type(10)).name()) # works + + +# test that 'addr' still works +proc poo(x, y: ptr int) = discard + +var someInt: int +poo(addr someInt, addr someInt) |