diff options
author | cooldome <cdome@bk.ru> | 2017-12-25 00:22:03 +0300 |
---|---|---|
committer | Andreas Rumpf <rumpf_a@web.de> | 2017-12-24 22:22:03 +0100 |
commit | 2b3ec0a7c66d2246371ed51348aaa87d4c3cf0f9 (patch) | |
tree | 2e193077ee1d8811a37d0bc6166a0008200f6800 /tests/casestmt/tcasestm.nim | |
parent | 6bd3a2826fb559d4e88cd2fa5ba89be995553700 (diff) | |
download | Nim-2b3ec0a7c66d2246371ed51348aaa87d4c3cf0f9.tar.gz |
Implement language feature #6885 (#6954)
Diffstat (limited to 'tests/casestmt/tcasestm.nim')
-rw-r--r-- | tests/casestmt/tcasestm.nim | 59 |
1 files changed, 59 insertions, 0 deletions
diff --git a/tests/casestmt/tcasestm.nim b/tests/casestmt/tcasestm.nim index 7ac20bf2f..b005d8120 100644 --- a/tests/casestmt/tcasestm.nim +++ b/tests/casestmt/tcasestm.nim @@ -36,5 +36,64 @@ var z = case i echo z #OUT ayyy +let str1 = "Y" +let str2 = "NN" +let a = case str1: + of "Y": true + of "N": false + else: + echo "no good" + quit("quiting") +let b = case str2: + of nil, "": raise newException(ValueError, "Invalid boolean") + elif str2[0] == 'Y': true + elif str2[0] == 'N': false + else: "error".quit(2) +doAssert(a == true) +doAssert(b == false) + +var bb: bool +doassert(not compiles( + bb = case str2: + of nil, "": raise newException(ValueError, "Invalid boolean") + elif str.startsWith("Y"): true + elif str.startsWith("N"): false +)) + +doassert(not compiles( + bb = case str2: + of "Y": true + of "N": false +)) + +doassert(not compiles( + bb = case str2: + of "Y": true + of "N": raise newException(ValueError, "N not allowed") +)) + +doassert(not compiles( + bb = case str2: + of "Y": raise newException(ValueError, "Invalid Y") + else: raise newException(ValueError, "Invalid N") +)) + + +doassert(not compiles( + bb = case str2: + of "Y": + raise newException(ValueError, "Invalid Y") + true + else: raise newException(ValueError, "Invalid") +)) + + +doassert(not compiles( + bb = case str2: + of "Y": + "invalid Y".quit(3) + true + else: raise newException(ValueError, "Invalid") +)) \ No newline at end of file |