diff options
Diffstat (limited to 'tests/let')
-rw-r--r-- | tests/let/t7936.nim | 27 | ||||
-rw-r--r-- | tests/let/timportc.nim | 24 | ||||
-rw-r--r-- | tests/let/timportc2.nim | 8 | ||||
-rw-r--r-- | tests/let/tlet.nim | 10 | ||||
-rw-r--r-- | tests/let/tlet2.nim | 15 |
5 files changed, 84 insertions, 0 deletions
diff --git a/tests/let/t7936.nim b/tests/let/t7936.nim new file mode 100644 index 000000000..3819dfc02 --- /dev/null +++ b/tests/let/t7936.nim @@ -0,0 +1,27 @@ +discard """ + action: "run" +""" + +import + tables, deques, sequtils + +const + lookupTable = {'(': ')', '{': '}', '[': ']'}.toTable + +proc isPaired*(value: string): bool = + var stack = initDeque[char]() + + for item in value: + # echo "Looking at " & item + if item in lookupTable: + stack.addLast(item) + if item in toSeq(lookupTable.values): + if stack.len == 0: + return false + if lookupTable[stack.popLast()] != item: + return false + + return stack.len == 0 + +doAssert isPaired("{[()]}") == true +doAssert isPaired("a)b(c") == false diff --git a/tests/let/timportc.nim b/tests/let/timportc.nim new file mode 100644 index 000000000..85244da9f --- /dev/null +++ b/tests/let/timportc.nim @@ -0,0 +1,24 @@ +discard """ +targets: "c cpp js" +""" + +when defined(c) or defined(cpp): + {.emit:""" + const int TEST1 = 123; + #define TEST2 321 + """.} + +when defined(js): + {.emit:""" + const TEST1 = 123; + const TEST2 = 321; // JS doesn't have macros, so we just duplicate + """.} + +let + TEST0 = 1 + TEST1 {.importc, nodecl.}: cint + TEST2 {.importc, nodecl.}: cint + +doAssert TEST0 == 1 +doAssert TEST1 == 123 +doAssert TEST2 == 321 diff --git a/tests/let/timportc2.nim b/tests/let/timportc2.nim new file mode 100644 index 000000000..964305923 --- /dev/null +++ b/tests/let/timportc2.nim @@ -0,0 +1,8 @@ +discard """ + errormsg: "'let' symbol requires an initialization" + line: "7" +""" + +# Test that this still works when not annotated with importc +let test: cint +echo test diff --git a/tests/let/tlet.nim b/tests/let/tlet.nim new file mode 100644 index 000000000..25d7b9bf7 --- /dev/null +++ b/tests/let/tlet.nim @@ -0,0 +1,10 @@ +discard """ + errormsg: "'name' cannot be assigned to" + line: "10" +""" + +echo("What's your name? ") +let name = readLine(stdin) +while name == "": + echo("Please tell me your name: ") + name = readLine(stdin) diff --git a/tests/let/tlet2.nim b/tests/let/tlet2.nim new file mode 100644 index 000000000..63e7d6128 --- /dev/null +++ b/tests/let/tlet2.nim @@ -0,0 +1,15 @@ +discard """ + errormsg: "type mismatch: got <int literal(8), int literal(5), int, int>" + line: "13" +""" + +proc divmod(a, b: int, res, remainder: var int) = + res = a div b # integer division + remainder = a mod b # integer modulo operation + +let + x = 9 + y = 3 +divmod(8, 5, x, y) # modifies x and y +echo(x) +echo(y) |