aboutsummaryrefslogtreecommitdiffstats
path: root/tests/conditionals.bad
diff options
context:
space:
mode:
Diffstat (limited to 'tests/conditionals.bad')
-rw-r--r--tests/conditionals.bad62
1 files changed, 42 insertions, 20 deletions
diff --git a/tests/conditionals.bad b/tests/conditionals.bad
index b1c6a89..44467a8 100644
--- a/tests/conditionals.bad
+++ b/tests/conditionals.bad
@@ -1,28 +1,50 @@
1; Basic if expressions. 1; ; Basic if expressions.
2if true "hello" 2; if true "hello"
3 3
4; These can produce values and the result bound to a name. 4; ; These can produce values and the result bound to a name.
5let a = if (2 + 2 >= 4) 42 5; let a = if (2 + 2 >= 4) 42
6 6
7; We support a single if expression. 7; ; We support a single if expression.
8let b = if 0xff == 255 "hello" else "world" 8; let b = if 0xff == 255 "hello" else "world"
9 9
10; ... but these can compound on each other 10; ; ... but these can compound on each other
11if 1 < 2 6 11; if 1 < 2 6
12else if 1 > 2 7 12; else if 1 > 2 7
13else 8 13; else 8
14 14
15; A block is an expression, and if raise the scope level regardless if a block 15; ; A block is an expression, and if raise the scope level regardless if a block
16; is used or not. 16; ; is used or not.
17if true != false { 17; if true != false {
18 let a = "yo" 18; let a = "yo"
19; }
20
21; ; Match cases should only apply to literal values, for example `case 1 + 2`
22; ; isn't allowed. They should generally convert to a lookup table.
23; match a = {
24; case 8 = "hello"
25; case 9 = "world"
26; else = "what"
27; }
28
29; cond {
30; case a == b = "hello"
31; case a != c = "world"
32; else = "what"
33; }
34
35; Enums are integers with values that increase automatically or that can be set
36; with a constexpr.
37enum flags {
38 node_add = 1 << 0
39 node_sub = 1 << 1
40 node_div = 1 << 2
41 node_mul
19} 42}
43let a:flags = flags.node_add
20 44
21; Match cases should only apply to literal values, for example `case 1 + 2` 45; No need to qualify enum fields inside match-case.
22; isn't allowed. They should generally convert to a lookup table.
23match a = { 46match a = {
24 case 8 = "hello" 47 case node_add = "adding something..."
25 case 9 = "world" 48 case node_add = "subbing something..."
26 else = "what" 49 else = "default case"
27} 50}
28