diff options
author | Bad Diode <bd@badd10de.dev> | 2024-06-21 11:40:31 +0200 |
---|---|---|
committer | Bad Diode <bd@badd10de.dev> | 2024-06-21 11:40:31 +0200 |
commit | 4646adb64119d9bd761447024a2f35cc0c9c2115 (patch) | |
tree | 116dfd0f2ad27933639188e6d29eec42305124d7 /tests | |
parent | c10fe9d48d40e3fa2a20ee61b79518dfbaeb4db9 (diff) | |
download | bdl-4646adb64119d9bd761447024a2f35cc0c9c2115.tar.gz bdl-4646adb64119d9bd761447024a2f35cc0c9c2115.zip |
Add a basic symbol checker
Diffstat (limited to 'tests')
-rw-r--r-- | tests/functions.bad | 2 | ||||
-rw-r--r-- | tests/literals.bad | 6 | ||||
-rw-r--r-- | tests/loops.bad | 5 | ||||
-rw-r--r-- | tests/semantics.bad | 59 |
4 files changed, 66 insertions, 6 deletions
diff --git a/tests/functions.bad b/tests/functions.bad index fa28d75..3149a24 100644 --- a/tests/functions.bad +++ b/tests/functions.bad | |||
@@ -9,7 +9,7 @@ fun add_three(a: int, b: int, c: int): int { | |||
9 | ; Functions that don't return anything must explicitly state it as returning | 9 | ; Functions that don't return anything must explicitly state it as returning |
10 | ; nil. | 10 | ; nil. |
11 | fun foo(): nil { | 11 | fun foo(): nil { |
12 | write("hello buddy") | 12 | println("hello buddy") |
13 | } | 13 | } |
14 | 14 | ||
15 | ; An alternate form for empty return values. | 15 | ; An alternate form for empty return values. |
diff --git a/tests/literals.bad b/tests/literals.bad index 78750c2..a53853d 100644 --- a/tests/literals.bad +++ b/tests/literals.bad | |||
@@ -31,6 +31,6 @@ false | |||
31 | ; Nil. | 31 | ; Nil. |
32 | nil | 32 | nil |
33 | 33 | ||
34 | ; Symbols. | 34 | ; Unicode is supported also in symbols. |
35 | symbols_support | 35 | let 💩 = "poo" |
36 | 🥰_💩_symbols | 36 | let 🥰 = 💩 |
diff --git a/tests/loops.bad b/tests/loops.bad index 45c9712..d42716f 100644 --- a/tests/loops.bad +++ b/tests/loops.bad | |||
@@ -1,11 +1,12 @@ | |||
1 | ; The most basic loop is the while loop. | 1 | ; The most basic loop is the while loop. |
2 | while (abc) "heelo" | 2 | while (true) "heelo" |
3 | 3 | ||
4 | while (1 + 2 == 3) { | 4 | while (1 + 2 == 3) { |
5 | "hello" | 5 | "hello" |
6 | } | 6 | } |
7 | 7 | ||
8 | while (symbol) { | 8 | let a = true |
9 | while (a) { | ||
9 | "hello" | 10 | "hello" |
10 | } | 11 | } |
11 | 12 | ||
diff --git a/tests/semantics.bad b/tests/semantics.bad new file mode 100644 index 0000000..4ce40b9 --- /dev/null +++ b/tests/semantics.bad | |||
@@ -0,0 +1,59 @@ | |||
1 | fun foo(): nil { | ||
2 | bar() | ||
3 | } | ||
4 | |||
5 | fun bar(): nil { | ||
6 | foo() | ||
7 | } | ||
8 | |||
9 | ; There are some builtint functions. | ||
10 | println("hello world") | ||
11 | |||
12 | ; Let/set. | ||
13 | let num = 1 | ||
14 | set num = 2 | ||
15 | set num = 0 + num | ||
16 | |||
17 | ; Loops and conditionals. | ||
18 | if (num) 3 else 1 | ||
19 | let val = if (2 + num == 4) num else num | ||
20 | if (true) { | ||
21 | let c = 1 | ||
22 | 1 + 1 + c | ||
23 | } | ||
24 | |||
25 | match (num) { | ||
26 | case 1 = 23 | ||
27 | case 2 = num | ||
28 | else = num | ||
29 | } | ||
30 | |||
31 | cond { | ||
32 | case 1 == 1 = 23 | ||
33 | case 2 != 1 = num | ||
34 | else = num | ||
35 | } | ||
36 | |||
37 | while (num == 1) num | ||
38 | while (true) { | ||
39 | let c = 1 | ||
40 | 1 + 1 + c | ||
41 | } | ||
42 | |||
43 | fun nested(): u32 { | ||
44 | fun adder(a: u32, b: u32): u32 a + b | ||
45 | adder(1,2) | ||
46 | } | ||
47 | |||
48 | ; This should err. | ||
49 | ; fun foo(): nil { | ||
50 | ; 1 | ||
51 | ; } | ||
52 | ; let b = a | ||
53 | ; let a = a | ||
54 | ; set a = 10 | ||
55 | ; set num = 1 << a | ||
56 | ; baz() | ||
57 | ; if (a) 1 | ||
58 | ; if (num == 1) a | ||
59 | ; if (num == 1) 1 else a | ||