bash: fix negative nums, more complex test.
[jackhill/mal.git] / tests / step7_quote.mal
1 ;; Testing cons function
2 (cons 1 (list))
3 ;=>(1)
4 (cons 1 (list 2))
5 ;=>(1 2)
6 (cons 1 (list 2 3))
7 ;=>(1 2 3)
8 (cons (list 1) (list 2 3))
9 ;=>((1) 2 3)
10
11 ;; Testing concat function
12 (concat)
13 ;=>()
14 (concat (list 1 2))
15 ;=>(1 2)
16 (concat (list 1 2) (list 3 4))
17 ;=>(1 2 3 4)
18 (concat (list 1 2) (list 3 4) (list 5 6))
19 ;=>(1 2 3 4 5 6)
20 (concat (concat))
21 ;=>()
22
23
24 ;; Testing regular quote
25 (quote 7)
26 ;=>7
27 '7
28 ;=>7
29 (quote (1 2 3))
30 ;=>(1 2 3)
31 '(1 2 3)
32 ;=>(1 2 3)
33 (quote (1 2 (3 4)))
34 ;=>(1 2 (3 4))
35 '(1 2 (3 4))
36 ;=>(1 2 (3 4))
37
38
39 ;; Testing simple quasiquote
40 (quasiquote 7)
41 ;=>7
42 `7
43 ;=>7
44 (quasiquote (1 2 3))
45 ;=>(1 2 3)
46 `(1 2 3)
47 ;=>(1 2 3)
48 (quasiquote (1 2 (3 4)))
49 ;=>(1 2 (3 4))
50 `(1 2 (3 4))
51 ;=>(1 2 (3 4))
52 (quasiquote (nil))
53 ;=>(nil)
54 `(nil)
55 ;=>(nil)
56
57
58 ;; Testing unquote
59 `~7
60 ;=>7
61 (def! a 8)
62 ;=>8
63 `a
64 ;=>a
65 `~a
66 ;=>8
67 `(1 a 3)
68 ;=>(1 a 3)
69 `(1 ~a 3)
70 ;=>(1 8 3)
71 (def! b '(1 "b" "d"))
72 ;=>(1 "b" "d")
73 `(1 b 3)
74 ;=>(1 b 3)
75 `(1 ~b 3)
76 ;=>(1 (1 "b" "d") 3)
77
78
79 ;; Testing splice-unquote
80 (def! c '(1 "b" "d"))
81 ;=>(1 "b" "d")
82 `(1 c 3)
83 ;=>(1 c 3)
84 `(1 ~@c 3)
85 ;=>(1 1 "b" "d" 3)
86
87
88 ;; Testing symbol equality
89 (= 'abc 'abc)
90 ;=>true
91 (= 'abc 'abcd)
92 ;=>false
93 (= 'abc "abc")
94 ;=>false
95 (= "abc" 'abc)
96 ;=>false
97 (= "abc" (str 'abc))
98 ;=>true
99 (= 'abc nil)
100 ;=>false
101 (= nil 'abc)
102 ;=>false
103
104 ;;;;; Test quine
105 ;;; TODO: needs expect line length fix
106 ;;;((fn* [q] (quasiquote ((unquote q) (quote (unquote q))))) (quote (fn* [q] (quasiquote ((unquote q) (quote (unquote q)))))))
107 ;;;=>((fn* [q] (quasiquote ((unquote q) (quote (unquote q))))) (quote (fn* [q] (quasiquote ((unquote q) (quote (unquote q)))))))
108
109 ;;
110 ;; -------- Optional Functionality --------
111
112 ;; Testing cons, concat, first, rest with vectors
113
114 (cons [1] [2 3])
115 ;=>([1] 2 3)
116 (cons 1 [2 3])
117 ;=>(1 2 3)
118 (concat [1 2] (list 3 4) [5 6])
119 ;=>(1 2 3 4 5 6)
120
121 ;; Testing unquote with vectors
122 (def! a 8)
123 ;=>8
124 `[1 a 3]
125 ;=>(1 a 3)
126 ;;; TODO: fix this
127 ;;;;=>[1 a 3]
128
129 ;; Testing splice-unquote with vectors
130 (def! c '(1 "b" "d"))
131 ;=>(1 "b" "d")
132 `[1 ~@c 3]
133 ;=>(1 1 "b" "d" 3)
134 ;;; TODO: fix this
135 ;;;;=>[1 1 "b" "d" 3]
136