summary refs log tree commit diff stats
path: root/tests/parser
diff options
context:
space:
mode:
Diffstat (limited to 'tests/parser')
-rw-r--r--tests/parser/tcommand_as_expr.nim1
-rw-r--r--tests/parser/tdomulttest.nim2
-rw-r--r--tests/parser/tinvcolonlocation1.nim12
-rw-r--r--tests/parser/tinvcolonlocation2.nim15
-rw-r--r--tests/parser/tinvcolonlocation3.nim12
-rw-r--r--tests/parser/tinvwhen.nim16
-rw-r--r--tests/parser/toprprec.nim8
-rw-r--r--tests/parser/tstrongspaces.nim35
-rw-r--r--tests/parser/ttupleunpack.nim35
9 files changed, 121 insertions, 15 deletions
diff --git a/tests/parser/tcommand_as_expr.nim b/tests/parser/tcommand_as_expr.nim
index 730e9cbb7..a244c8767 100644
--- a/tests/parser/tcommand_as_expr.nim
+++ b/tests/parser/tcommand_as_expr.nim
@@ -5,6 +5,7 @@ discard """
 77'''
 """
 #import math
+import sequtils
 
 proc optarg(x:int, y:int = 0):int = x + 3 * y
 proc singlearg(x:int):int = 20*x
diff --git a/tests/parser/tdomulttest.nim b/tests/parser/tdomulttest.nim
index 4ee6de128..418192ac8 100644
--- a/tests/parser/tdomulttest.nim
+++ b/tests/parser/tdomulttest.nim
@@ -14,4 +14,4 @@ do (x: int) -> int:
   echo("multi lines")
   return x
 
-echo("end")
\ No newline at end of file
+echo("end")
diff --git a/tests/parser/tinvcolonlocation1.nim b/tests/parser/tinvcolonlocation1.nim
new file mode 100644
index 000000000..cacde48bd
--- /dev/null
+++ b/tests/parser/tinvcolonlocation1.nim
@@ -0,0 +1,12 @@
+discard """
+  file: "tinvcolonlocation1.nim"
+  line: 8
+  column: 3
+  errormsg: "':' expected"
+"""
+try #<- missing ':'
+  echo "try"
+except:
+  echo "except"
+finally:
+  echo "finally"
diff --git a/tests/parser/tinvcolonlocation2.nim b/tests/parser/tinvcolonlocation2.nim
new file mode 100644
index 000000000..2b6a92b9d
--- /dev/null
+++ b/tests/parser/tinvcolonlocation2.nim
@@ -0,0 +1,15 @@
+discard """
+  file: "tinvcolonlocation2.nim"
+  line: 11
+  column: 1
+  errormsg: "':' expected"
+"""
+try:
+  echo "try"
+except #<- missing ':'
+  echo "except"
+finally:
+#<-- error will be here above, at the beginning of finally,
+#    since compiler tries to consome echo and part of except
+#    expression
+  echo "finally"
diff --git a/tests/parser/tinvcolonlocation3.nim b/tests/parser/tinvcolonlocation3.nim
new file mode 100644
index 000000000..2b30b1dbe
--- /dev/null
+++ b/tests/parser/tinvcolonlocation3.nim
@@ -0,0 +1,12 @@
+discard """
+  file: "tinvcolonlocation3.nim"
+  line: 12
+  column: 3
+  errormsg: "':' expected"
+"""
+try:
+  echo "try"
+except:
+  echo "except"
+finally #<- missing ':'
+  echo "finally"
diff --git a/tests/parser/tinvwhen.nim b/tests/parser/tinvwhen.nim
index 5ff94cc6c..99701bdf5 100644
--- a/tests/parser/tinvwhen.nim
+++ b/tests/parser/tinvwhen.nim
@@ -3,13 +3,13 @@ discard """
   line: 11
   errormsg: "invalid indentation"
 """
-# This was parsed even though it should not!

-

-proc chdir(path: cstring): cint {.importc: "chdir", header: "dirHeader".}

-

-proc getcwd(buf: cstring, buflen: cint): cstring

-    when defined(unix): {.importc: "getcwd", header: "<unistd.h>".} #ERROR_MSG invalid indentation

-    elif defined(windows): {.importc: "getcwd", header: "<direct.h>"}

-    else: {.error: "os library not ported to your OS. Please help!".}

+# This was parsed even though it should not!
+
+proc chdir(path: cstring): cint {.importc: "chdir", header: "dirHeader".}
+
+proc getcwd(buf: cstring, buflen: cint): cstring
+    when defined(unix): {.importc: "getcwd", header: "<unistd.h>".} #ERROR_MSG invalid indentation
+    elif defined(windows): {.importc: "getcwd", header: "<direct.h>"}
+    else: {.error: "os library not ported to your OS. Please help!".}
 
 
diff --git a/tests/parser/toprprec.nim b/tests/parser/toprprec.nim
index ce33934b5..2c22f5b80 100644
--- a/tests/parser/toprprec.nim
+++ b/tests/parser/toprprec.nim
@@ -2,7 +2,7 @@ discard """
   file: "toprprec.nim"
   output: "done"
 """
-# Test operator precedence: 
+# Test operator precedence:
 
 template `@` (x: expr): expr {.immediate.} = self.x
 template `@!` (x: expr): expr {.immediate.} = x
@@ -12,7 +12,7 @@ type
   TO = object
     x: int
   TA = tuple[a, b: int, obj: TO]
-  
+
 proc init(self: var TA): string =
   @a = 3
   === @b = 4
@@ -22,10 +22,10 @@ proc init(self: var TA): string =
 
 assert 3+5*5-2 == 28- -26-28
 
-proc `^-` (x, y: int): int =  
+proc `^-` (x, y: int): int =
   # now right-associative!
   result = x - y
-  
+
 assert 34 ^- 6 ^- 2 == 30
 assert 34 - 6 - 2 == 26
 
diff --git a/tests/parser/tstrongspaces.nim b/tests/parser/tstrongspaces.nim
index 91506daf0..cb0219976 100644
--- a/tests/parser/tstrongspaces.nim
+++ b/tests/parser/tstrongspaces.nim
@@ -1,7 +1,13 @@
-#! strongSpaces
+#? strongSpaces
 
 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/ttupleunpack.nim b/tests/parser/ttupleunpack.nim
new file mode 100644
index 000000000..aaa06f9f4
--- /dev/null
+++ b/tests/parser/ttupleunpack.nim
@@ -0,0 +1,35 @@
+discard """
+  file: "ttupleunpack.nim"
+  output: ""
+  exitcode: 0
+"""
+
+proc returnsTuple(): (int, int, int) = (4, 2, 3)
+
+proc main2 =
+  let (x, _, z) = returnsTuple()
+
+proc main() =
+
+  proc foo(): tuple[x, y, z: int] =
+    return (4, 2, 3)
+
+  var (x, _, y) = foo()
+  doAssert x == 4
+  doAssert y == 3
+
+  var (a, _, _) = foo()
+  doAssert a == 4
+
+  var (aa, _, _) = foo()
+  doAssert aa == 4
+
+  iterator bar(): tuple[x, y, z: int] =
+    yield (1,2,3)
+
+  for x, y, _ in bar():
+    doAssert x == 1
+    doAssert y == 2
+
+main()
+main2()