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 | 3 | ||||
-rw-r--r-- | tests/let/tlet2.nim | 3 |
5 files changed, 61 insertions, 4 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 index 6703ba254..25d7b9bf7 100644 --- a/tests/let/tlet.nim +++ b/tests/let/tlet.nim @@ -1,6 +1,6 @@ discard """ - line: "10" errormsg: "'name' cannot be assigned to" + line: "10" """ echo("What's your name? ") @@ -8,4 +8,3 @@ 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 index 66dd5a55b..63e7d6128 100644 --- a/tests/let/tlet2.nim +++ b/tests/let/tlet2.nim @@ -1,6 +1,6 @@ discard """ + errormsg: "type mismatch: got <int literal(8), int literal(5), int, int>" line: "13" - errormsg: "type mismatch: got (int literal(8), int literal(5), int, int)" """ proc divmod(a, b: int, res, remainder: var int) = @@ -13,4 +13,3 @@ let divmod(8, 5, x, y) # modifies x and y echo(x) echo(y) - |