diff options
author | Bad Diode <bd@badd10de.dev> | 2024-06-17 18:38:50 +0200 |
---|---|---|
committer | Bad Diode <bd@badd10de.dev> | 2024-06-17 18:38:50 +0200 |
commit | c581804c6ffa5824a9b762097a990425007e49cf (patch) | |
tree | 516e314a60d537d8e1617f945afc8a12b3e0d61f /tests | |
parent | 7fee0fc28809042a2ecbc03f2e1b5b569073982b (diff) | |
download | bdl-c581804c6ffa5824a9b762097a990425007e49cf.tar.gz bdl-c581804c6ffa5824a9b762097a990425007e49cf.zip |
Add let/set/struct parsing
Diffstat (limited to 'tests')
-rw-r--r-- | tests/arithmetic_expected.txt | 13 | ||||
-rw-r--r-- | tests/booleans_expected.txt | 53 | ||||
-rw-r--r-- | tests/constants/numbers.bdl | 41 | ||||
-rw-r--r-- | tests/constants/strings.bdl | 5 | ||||
-rw-r--r-- | tests/lists_expected.txt | 15 | ||||
-rw-r--r-- | tests/types_expected.txt | 55 | ||||
-rw-r--r-- | tests/variables.bad | 57 | ||||
-rw-r--r-- | tests/variables_expected.txt | 23 |
8 files changed, 57 insertions, 205 deletions
diff --git a/tests/arithmetic_expected.txt b/tests/arithmetic_expected.txt deleted file mode 100644 index a2a5a83..0000000 --- a/tests/arithmetic_expected.txt +++ /dev/null | |||
@@ -1,13 +0,0 @@ | |||
1 | (+ 10 100) -> 110 | ||
2 | (+ 1 -2 3 4) -> 6 | ||
3 | (- 100 75) -> 25 | ||
4 | (- 10 20 30) -> -40 | ||
5 | (* 10 7) -> 70 | ||
6 | (* -1 66) -> -66 | ||
7 | (/ 45 5) -> 9 | ||
8 | (/ 10 5 2) -> 1 | ||
9 | (% 45 5) -> 0 | ||
10 | (% 45 7) -> 3 | ||
11 | (% 120 45) -> 30 | ||
12 | (% 120 45 8) -> 6 | ||
13 | (* 20 (+ 100 (- 50 30) (/ 300 3)) 10) -> 44000 | ||
diff --git a/tests/booleans_expected.txt b/tests/booleans_expected.txt deleted file mode 100644 index 43f67e5..0000000 --- a/tests/booleans_expected.txt +++ /dev/null | |||
@@ -1,53 +0,0 @@ | |||
1 | (not true) -> false | ||
2 | (not false) -> true | ||
3 | (not (not true)) -> true | ||
4 | (not (not false)) -> false | ||
5 | (not 1) -> false | ||
6 | (not (not 1)) -> true | ||
7 | (not "string") -> false | ||
8 | (not (not "string")) -> true | ||
9 | (and 1 "string" 4 true) -> true | ||
10 | (and true true true) -> true | ||
11 | (and (+ 1 2 3)) -> true | ||
12 | (and false false false) -> false | ||
13 | (and true false false) -> false | ||
14 | (and false true false) -> false | ||
15 | (and false true true) -> false | ||
16 | (and (not false) true true) -> true | ||
17 | (or 1 "string" 4 true) -> true | ||
18 | (or false 1) -> true | ||
19 | (or false "string") -> true | ||
20 | (or false) -> false | ||
21 | (or true true true) -> true | ||
22 | (or false false false) -> false | ||
23 | (or true false false) -> true | ||
24 | (or false true false) -> true | ||
25 | (or false true true) -> true | ||
26 | (or (not false) true true) -> true | ||
27 | (or (not true) false) -> false | ||
28 | (if true true false) -> true | ||
29 | (if false true false) -> false | ||
30 | (if true (+ 1 2 3) 0) -> 6 | ||
31 | (if false (+ 1 2 3) 0) -> 0 | ||
32 | (if (or true false) (+ 1 2 3) (+ 7 8 9)) -> 6 | ||
33 | (if (or false false) (+ 1 2 3) (+ 7 8 9)) -> 24 | ||
34 | (if (or (+ 1 2 3) false) (+ 1 2 3) (+ 7 8 9)) -> 6 | ||
35 | (if true 7) -> 7 | ||
36 | (if false 7) -> | ||
37 | (cond ((and true true true) 1) ((or true true false) 2) (else 3)) -> 1 | ||
38 | (cond ((and true true false) 1) ((or true true false) 2) (else 3)) -> 2 | ||
39 | (cond ((and true true false) 1) ((or false false false) 2) (else 3)) -> 3 | ||
40 | (cond ((and true true true) 1) ((or true true false) 2)) -> | ||
41 | (cond ((and true true true) (+ 1 2 3)) ((or true true false) 2) (else 3)) -> 6 | ||
42 | (< 1 2 3) -> true | ||
43 | (< 3 2 1) -> false | ||
44 | (> 1 2 3) -> false | ||
45 | (> 3 2 1) -> true | ||
46 | (= 1 2 3) -> false | ||
47 | (= 3 2 1) -> false | ||
48 | (= 3 3 3) -> true | ||
49 | (= (+ 1 2) 3 (- 6 3)) -> true | ||
50 | (< 1 1 3) -> false | ||
51 | (<= 1 1 3) -> true | ||
52 | (> 3 3 1) -> false | ||
53 | (>= 3 3 1) -> true | ||
diff --git a/tests/constants/numbers.bdl b/tests/constants/numbers.bdl deleted file mode 100644 index 136b5fb..0000000 --- a/tests/constants/numbers.bdl +++ /dev/null | |||
@@ -1,41 +0,0 @@ | |||
1 | ; Signed integers. | ||
2 | (print 1:s8) | ||
3 | (print 52:s8) | ||
4 | (print -1:s8) | ||
5 | (print 0:s8) | ||
6 | (print 1:s16) | ||
7 | (print 52:s16) | ||
8 | (print -1:s16) | ||
9 | (print 0:s16) | ||
10 | (print 1:s32) | ||
11 | (print 52:s32) | ||
12 | (print -1:s32) | ||
13 | (print 0:s32) | ||
14 | (print 1:s64) | ||
15 | (print 52:s64) | ||
16 | (print -1:s64) | ||
17 | (print 0:s64) | ||
18 | |||
19 | ; Unsigned integers. | ||
20 | (print 1:u8) | ||
21 | (print 52:u8) | ||
22 | (print -1:u8) | ||
23 | (print 0:u8) | ||
24 | (print 1:u16) | ||
25 | (print 52:u16) | ||
26 | (print -1:u16) | ||
27 | (print 0:u16) | ||
28 | (print 1:u32) | ||
29 | (print 52:u32) | ||
30 | (print -1:u32) | ||
31 | (print 0:u32) | ||
32 | (print 1:u64) | ||
33 | (print 52:u64) | ||
34 | (print -1:u64) | ||
35 | (print 0:u64) | ||
36 | |||
37 | ; Type inference. | ||
38 | (print 1) | ||
39 | (print 52) | ||
40 | (print -1) | ||
41 | (print 0) | ||
diff --git a/tests/constants/strings.bdl b/tests/constants/strings.bdl deleted file mode 100644 index 9b1d687..0000000 --- a/tests/constants/strings.bdl +++ /dev/null | |||
@@ -1,5 +0,0 @@ | |||
1 | (print "abc") | ||
2 | (print "test this longer string") | ||
3 | (print "escape\na\nnewline") | ||
4 | (print "escape\ttab\tcharacters") | ||
5 | (print "with type :str":str) | ||
diff --git a/tests/lists_expected.txt b/tests/lists_expected.txt deleted file mode 100644 index 6ddb71b..0000000 --- a/tests/lists_expected.txt +++ /dev/null | |||
@@ -1,15 +0,0 @@ | |||
1 | (list) -> | ||
2 | (list 1) -> (1) | ||
3 | (list 1 2) -> (1 2) | ||
4 | (list 1 2 3) -> (1 2 3) | ||
5 | (list 4 5 (+ 1 2 3)) -> (4 5 6) | ||
6 | (car (list 1 2 3)) -> 1 | ||
7 | (cdr (list 1 2 3)) -> (2 3) | ||
8 | (car (list (* 10 20) (+ 1 2 3) 50 60)) -> 200 | ||
9 | (cdr (list (* 10 20) (+ 1 2 3) 50 60)) -> (6 50 60) | ||
10 | (car (cdr (list (* 10 20) (+ 1 2 3) 50 60))) -> 6 | ||
11 | (cons 1 2) -> (1 . 2) | ||
12 | (cons "a" "b") -> ("a" . "b") | ||
13 | (cons "a" (cons "c" ())) -> ("a" "c") | ||
14 | (cons 1 (cons 2 (cons (+ 1 2) ()))) -> (1 2 3) | ||
15 | (cons 1 (cons 2 (cons (+ 1 2) 4))) -> (1 2 3 . 4) | ||
diff --git a/tests/types_expected.txt b/tests/types_expected.txt deleted file mode 100644 index 58eaa7f..0000000 --- a/tests/types_expected.txt +++ /dev/null | |||
@@ -1,55 +0,0 @@ | |||
1 | (boolean? true) -> true | ||
2 | (boolean? false) -> true | ||
3 | (boolean? 1) -> false | ||
4 | (boolean? 5) -> false | ||
5 | (boolean? "string") -> false | ||
6 | (boolean? (+ 1 2 3)) -> false | ||
7 | (boolean? (not 1)) -> true | ||
8 | (nil? true) -> false | ||
9 | (nil? false) -> false | ||
10 | (nil? 1) -> false | ||
11 | (nil? 5) -> false | ||
12 | (nil? "string") -> false | ||
13 | (nil? (+ 1 2 3)) -> false | ||
14 | (nil? (not 1)) -> false | ||
15 | (nil? ()) -> true | ||
16 | (string? true) -> false | ||
17 | (string? false) -> false | ||
18 | (string? 1) -> false | ||
19 | (string? 5) -> false | ||
20 | (string? "string") -> true | ||
21 | (string? (+ 1 2 3)) -> false | ||
22 | (string? (not 1)) -> false | ||
23 | (fixnum? true) -> false | ||
24 | (fixnum? false) -> false | ||
25 | (fixnum? 1) -> true | ||
26 | (fixnum? 5) -> true | ||
27 | (fixnum? "string") -> false | ||
28 | (fixnum? (+ 1 2 3)) -> true | ||
29 | (fixnum? (not 1)) -> false | ||
30 | (symbol? true) -> false | ||
31 | (symbol? false) -> false | ||
32 | (symbol? 1) -> false | ||
33 | (symbol? +) -> false | ||
34 | (symbol? "string") -> false | ||
35 | (symbol? (+ 1 2 3)) -> false | ||
36 | (symbol? (not 1)) -> false | ||
37 | (symbol? 'a) -> true | ||
38 | (symbol? 'c) -> true | ||
39 | (pair? false) -> false | ||
40 | (pair? 1) -> false | ||
41 | (pair? 5) -> false | ||
42 | (pair? "string") -> false | ||
43 | (pair? (+ 1 2 3)) -> false | ||
44 | (pair? (not 1)) -> false | ||
45 | (pair? (cons 1 2)) -> true | ||
46 | (pair? (list 1 2 3)) -> true | ||
47 | (procedure? false) -> false | ||
48 | (procedure? 1) -> false | ||
49 | (procedure? 5) -> false | ||
50 | (procedure? "string") -> false | ||
51 | (procedure? (+ 1 2 3)) -> false | ||
52 | (procedure? (not 1)) -> false | ||
53 | (procedure? +) -> true | ||
54 | (procedure? -) -> true | ||
55 | (procedure? procedure?) -> true | ||
diff --git a/tests/variables.bad b/tests/variables.bad new file mode 100644 index 0000000..a6f9900 --- /dev/null +++ b/tests/variables.bad | |||
@@ -0,0 +1,57 @@ | |||
1 | ; Basic variable declaration with and without default values. The type could be | ||
2 | ; inferred, but can also be manually specified. | ||
3 | let a | ||
4 | let b: f64 | ||
5 | let c = 10 | ||
6 | let d:u64 = 20 | ||
7 | |||
8 | ; No infix '=', instead we use `set` to bind values. | ||
9 | set a = "hello" | ||
10 | set b = 1.2 | ||
11 | set c = 30 | ||
12 | set d = (1 + 2 - 3) | ||
13 | |||
14 | ; Struct definitions. | ||
15 | struct vec { | ||
16 | x: f32 | ||
17 | y: f32 | ||
18 | z: f32 | ||
19 | } | ||
20 | |||
21 | ; Default values are allowed, including const expressions. | ||
22 | struct person { | ||
23 | name: str = "joe" | ||
24 | age: int = 18 * 2 | ||
25 | } | ||
26 | |||
27 | ; We can use the dot operator to access fields. | ||
28 | let player_a: person | ||
29 | set player_a.name = "alex" | ||
30 | set player_a.age = 32 | ||
31 | let player_b = player_a | ||
32 | |||
33 | ; Anonymous structs can also be declared inline. | ||
34 | let user: { id: u64 name: str } | ||
35 | set user.id = 10 | ||
36 | set user.name = "haxor" | ||
37 | |||
38 | ; We can have anonymous struct fields. | ||
39 | struct entity { | ||
40 | pos: vec | ||
41 | vel: vec | ||
42 | attr: { | ||
43 | id: u64 | ||
44 | name: str | ||
45 | } | ||
46 | } | ||
47 | |||
48 | ; Symbols followed by curly braces output struct literals. | ||
49 | ; let particle = entity { | ||
50 | ; ; Two ways of initializing inner fields. | ||
51 | ; pos = { 1 2 } | ||
52 | ; attr.id = 1 | ||
53 | ; attr.name = "particle" | ||
54 | |||
55 | ; ; Missing initialization fields default to zero. | ||
56 | ; vel = { -3 } | ||
57 | ; } | ||
diff --git a/tests/variables_expected.txt b/tests/variables_expected.txt deleted file mode 100644 index 02a5f7a..0000000 --- a/tests/variables_expected.txt +++ /dev/null | |||
@@ -1,23 +0,0 @@ | |||
1 | (def a 20) | ||
2 | ((lambda (a b) (+ 10 a b)) 1 2) -> 13 | ||
3 | ((lambda (a b) (+ 10 a b)) a 3) -> 33 | ||
4 | (def myfun (lambda (a b) (+ a b))) (myfun 6 9) -> 15 | ||
5 | (fun myfun (a b) (+ a b)) (myfun 6 9) -> 15 | ||
6 | (+ 1 (myfun 10 (myfun a a)) 30) -> 81 | ||
7 | (myfun 10 (myfun 5 0)) -> 15 | ||
8 | (fun make-counter () (def value 0) (def counter (lambda () (set! value (+ value 1)) value)) counter) | ||
9 | (def counter-a (make-counter)) | ||
10 | (def counter-b (make-counter)) | ||
11 | (counter-a) -> 1 | ||
12 | (counter-b) -> 1 | ||
13 | (counter-a) -> 2 | ||
14 | (counter-a) -> 3 | ||
15 | (counter-a) -> 4 | ||
16 | (counter-b) -> 2 | ||
17 | (counter-b) -> 3 | ||
18 | (counter-b) -> 4 | ||
19 | (fun fib (n) (if (<= n 2) 1 (+ (fib (- n 1)) (fib (- n 2))))) | ||
20 | (fib 15) -> 610 | ||
21 | (fun b () (display a) (print " --- ") (def a 42) (display a) (newline)) | ||
22 | (b) -> 20 --- 42 | ||
23 | (b) -> 20 --- 42 | ||