diff options
author | Zahary Karadjov <zahary@gmail.com> | 2012-10-01 23:48:37 +0300 |
---|---|---|
committer | Zahary Karadjov <zahary@gmail.com> | 2012-10-03 01:59:49 +0300 |
commit | 770d4a997eab25a04cdfd83b325491a2e63bea08 (patch) | |
tree | 54f7302645b240942ed43428586489d7df36377c /tests | |
parent | 92f70b08f9c4d6108f61f37c29c1b001c6173a19 (diff) | |
download | Nim-770d4a997eab25a04cdfd83b325491a2e63bea08.tar.gz |
implemented case expressions
Diffstat (limited to 'tests')
-rw-r--r-- | tests/reject/tcaseexpr1.nim | 30 | ||||
-rwxr-xr-x | tests/run/tcasestm.nim | 24 |
2 files changed, 43 insertions, 11 deletions
diff --git a/tests/reject/tcaseexpr1.nim b/tests/reject/tcaseexpr1.nim new file mode 100644 index 000000000..0c2e7c452 --- /dev/null +++ b/tests/reject/tcaseexpr1.nim @@ -0,0 +1,30 @@ +discard """ + file: "tcaseexpr1.nim" + + line: 23 + errormsg: "not all cases are covered" + + line: 29 + errormsg: "type mismatch: got (string) but expected 'int'" +""" + +type + E = enum A, B, C + +proc foo(x): auto = + return case x + of 1..9: "digit" + else: "number" + +var r = foo(10) + +var x = C + +var t1 = case x: + of A: "a" + of B: "b" + +var t2 = case x: + of A: 10 + of B, C: "23" + diff --git a/tests/run/tcasestm.nim b/tests/run/tcasestm.nim index cb63e0c51..003ec6e50 100755 --- a/tests/run/tcasestm.nim +++ b/tests/run/tcasestm.nim @@ -1,6 +1,6 @@ discard """ file: "tcasestm.nim" - output: "ayyy" + output: "ayyydd" """ # Test the case statement @@ -22,16 +22,18 @@ of "aa", "bb": write(stdout, "Du bist nicht mein Meister") of "cc", "hash", "when": nil of "will", "it", "finally", "be", "generated": nil -case i -of 1..5, 8, 9: nil -of 6, 7: nil -elif x == "Ha": - nil -elif x == "yyy": - write(stdout, x) -else: - nil - +var z = case i + of 1..5, 8, 9: "aa" + of 6, 7: "bb" + elif x == "Ha": + "cc" + elif x == "yyy": + write(stdout, x) + "dd" + else: + "zz" + +echo z #OUT ayyy |