aboutsummaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorBad Diode <bd@badd10de.dev>2024-06-21 11:40:31 +0200
committerBad Diode <bd@badd10de.dev>2024-06-21 11:40:31 +0200
commit4646adb64119d9bd761447024a2f35cc0c9c2115 (patch)
tree116dfd0f2ad27933639188e6d29eec42305124d7 /tests
parentc10fe9d48d40e3fa2a20ee61b79518dfbaeb4db9 (diff)
downloadbdl-4646adb64119d9bd761447024a2f35cc0c9c2115.tar.gz
bdl-4646adb64119d9bd761447024a2f35cc0c9c2115.zip
Add a basic symbol checker
Diffstat (limited to 'tests')
-rw-r--r--tests/functions.bad2
-rw-r--r--tests/literals.bad6
-rw-r--r--tests/loops.bad5
-rw-r--r--tests/semantics.bad59
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.
11fun foo(): nil { 11fun 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.
32nil 32nil
33 33
34; Symbols. 34; Unicode is supported also in symbols.
35symbols_support 35let 💩 = "poo"
36🥰_💩_symbols 36let 🥰 = 💩
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.
2while (abc) "heelo" 2while (true) "heelo"
3 3
4while (1 + 2 == 3) { 4while (1 + 2 == 3) {
5 "hello" 5 "hello"
6} 6}
7 7
8while (symbol) { 8let a = true
9while (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 @@
1fun foo(): nil {
2 bar()
3}
4
5fun bar(): nil {
6 foo()
7}
8
9; There are some builtint functions.
10println("hello world")
11
12; Let/set.
13let num = 1
14set num = 2
15set num = 0 + num
16
17; Loops and conditionals.
18if (num) 3 else 1
19let val = if (2 + num == 4) num else num
20if (true) {
21 let c = 1
22 1 + 1 + c
23}
24
25match (num) {
26 case 1 = 23
27 case 2 = num
28 else = num
29}
30
31cond {
32 case 1 == 1 = 23
33 case 2 != 1 = num
34 else = num
35}
36
37while (num == 1) num
38while (true) {
39 let c = 1
40 1 + 1 + c
41}
42
43fun 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