aboutsummaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorBad Diode <bd@badd10de.dev>2024-06-18 19:54:56 +0200
committerBad Diode <bd@badd10de.dev>2024-06-18 19:54:56 +0200
commit3d88e46dd0d1b54bc0a414b5db42ed76ddc08363 (patch)
tree5eed2d95bdc017ef28d603ff1f49b96640929013 /tests
parentf9d0fe5ad641e453724dabc2b17634a44e198ce0 (diff)
downloadbdl-3d88e46dd0d1b54bc0a414b5db42ed76ddc08363.tar.gz
bdl-3d88e46dd0d1b54bc0a414b5db42ed76ddc08363.zip
Add `cond` conditionals
Diffstat (limited to 'tests')
-rw-r--r--tests/conditionals.bad68
1 files changed, 35 insertions, 33 deletions
diff --git a/tests/conditionals.bad b/tests/conditionals.bad
index 44467a8..856ac8a 100644
--- a/tests/conditionals.bad
+++ b/tests/conditionals.bad
@@ -1,36 +1,30 @@
1; ; Basic if expressions. 1; Basic if expressions.
2; if true "hello" 2if 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.
5; let a = if (2 + 2 >= 4) 42 5let a = if (2 + 2 >= 4) 42
6 6
7; ; We support a single if expression. 7; We support a single if expression.
8; let b = if 0xff == 255 "hello" else "world" 8let 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
11; if 1 < 2 6 11if 1 < 2 6
12; else if 1 > 2 7 12else if 1 > 2 7
13; else 8 13else 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.
17; if true != false { 17if true != false {
18; let a = "yo" 18 let a = "yo"
19; } 19}
20 20
21; ; Match cases should only apply to literal values, for example `case 1 + 2` 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. 22; isn't allowed. They should generally convert to a lookup table.
23; match a = { 23match a = {
24; case 8 = "hello" 24 case 8 = "hello"
25; case 9 = "world" 25 case 9 = "world"
26; else = "what" 26 else = "what"
27; } 27}
28
29; cond {
30; case a == b = "hello"
31; case a != c = "world"
32; else = "what"
33; }
34 28
35; Enums are integers with values that increase automatically or that can be set 29; Enums are integers with values that increase automatically or that can be set
36; with a constexpr. 30; with a constexpr.
@@ -48,3 +42,11 @@ match a = {
48 case node_add = "subbing something..." 42 case node_add = "subbing something..."
49 else = "default case" 43 else = "default case"
50} 44}
45
46; Conditional `cond` statements are syntactic sugar for a chain of if-else
47; statements.
48let msg:str = cond {
49 case a == b = "hello"
50 case a != c = "world"
51 else = "what"
52}