Commit | Line | Data |
---|---|---|
9d8f0299 JM |
1 | ;;; TODO: really a step5 test |
2 | ;; | |
3 | ;; Testing that (do (do)) not broken by TCO | |
4 | (do (do 1 2)) | |
5 | ;=>2 | |
6 | ||
dbac60df | 7 | ;; |
89bd4de1 | 8 | ;; Testing read-string, eval and slurp |
dbac60df JM |
9 | (read-string "(1 2 (3 4) nil)") |
10 | ;=>(1 2 (3 4) nil) | |
89bd4de1 | 11 | |
d98d5c3b BH |
12 | (= nil (read-string "nil")) |
13 | ;=>true | |
14 | ||
89bd4de1 JM |
15 | (read-string "(+ 2 3)") |
16 | ;=>(+ 2 3) | |
17 | ||
0d17edb4 BH |
18 | (read-string "\"\n\"") |
19 | ;=>"\n" | |
20 | ||
dbac60df JM |
21 | (read-string "7 ;; comment") |
22 | ;=>7 | |
23 | ||
24 | ;;; Differing output, but make sure no fatal error | |
25 | (read-string ";; comment") | |
26 | ||
27 | ||
89bd4de1 JM |
28 | (eval (read-string "(+ 2 3)")) |
29 | ;=>5 | |
30 | ||
2cd015e5 DM |
31 | (slurp "../tests/test.txt") |
32 | ;=>"A line of text\n" | |
89bd4de1 | 33 | |
82bc78eb NB |
34 | ;;; Load the same file twice. |
35 | (slurp "../tests/test.txt") | |
36 | ;=>"A line of text\n" | |
37 | ||
31690700 JM |
38 | ;; Testing load-file |
39 | ||
40 | (load-file "../tests/inc.mal") | |
e6d41de4 | 41 | ;=>nil |
31690700 JM |
42 | (inc1 7) |
43 | ;=>8 | |
44 | (inc2 7) | |
45 | ;=>9 | |
46 | (inc3 9) | |
47 | ;=>12 | |
48 | ||
9af8aee6 | 49 | ;; |
627bd6f7 DM |
50 | ;; Testing atoms |
51 | ||
52 | (def! inc3 (fn* (a) (+ 3 a))) | |
53 | ||
54 | (def! a (atom 2)) | |
55 | ;=>(atom 2) | |
56 | ||
57 | (atom? a) | |
58 | ;=>true | |
59 | ||
60 | (atom? 1) | |
61 | ;=>false | |
62 | ||
63 | (deref a) | |
64 | ;=>2 | |
65 | ||
66 | (reset! a 3) | |
67 | ;=>3 | |
68 | ||
69 | (deref a) | |
70 | ;=>3 | |
71 | ||
72 | (swap! a inc3) | |
73 | ;=>6 | |
74 | ||
75 | (deref a) | |
76 | ;=>6 | |
77 | ||
78 | (swap! a (fn* (a) a)) | |
79 | ;=>6 | |
80 | ||
81 | (swap! a (fn* (a) (* 2 a))) | |
82 | ;=>12 | |
83 | ||
84 | (swap! a (fn* (a b) (* a b)) 10) | |
85 | ;=>120 | |
86 | ||
87 | (swap! a + 3) | |
88 | ;=>123 | |
89 | ||
90 | ;; Testing swap!/closure interaction | |
91 | (def! inc-it (fn* (a) (+ 1 a))) | |
92 | (def! atm (atom 7)) | |
0067158f | 93 | (def! f (fn* () (swap! atm inc-it))) |
627bd6f7 DM |
94 | (f) |
95 | ;=>8 | |
96 | (f) | |
97 | ;=>9 | |
98 | ||
306ba5eb AMP |
99 | ;; Testing whether closures can retain atoms |
100 | (def! g (let* (atm (atom 0)) (fn* () (deref atm)))) | |
101 | (def! atm (atom 1)) | |
102 | (g) | |
103 | ;=>0 | |
104 | ||
a1eb30fc | 105 | ;>>> deferrable=True |
7df7eeec BH |
106 | ;; |
107 | ;; -------- Deferrable Functionality -------- | |
108 | ||
109 | ;; Testing reading of large files | |
110 | (load-file "../tests/computations.mal") | |
111 | ;=>nil | |
112 | (sumdown 2) | |
113 | ;=>3 | |
114 | (fib 2) | |
115 | ;=>1 | |
116 | ||
77fd710c JM |
117 | ;; Testing `@` reader macro (short for `deref`) |
118 | (def! atm (atom 9)) | |
119 | @atm | |
120 | ;=>9 | |
121 | ||
122 | ;;; TODO: really a step5 test | |
123 | ;; Testing that vector params not broken by TCO | |
124 | (def! g (fn* [] 78)) | |
125 | (g) | |
126 | ;=>78 | |
127 | (def! g (fn* [a] (+ a 78))) | |
128 | (g 3) | |
129 | ;=>81 | |
130 | ||
131 | ;; | |
132 | ;; Testing that *ARGV* exists and is an empty list | |
133 | (list? *ARGV*) | |
134 | ;=>true | |
135 | *ARGV* | |
136 | ;=>() | |
137 | ||
a124b322 AW |
138 | ;; |
139 | ;; Testing that eval sets aa in root scope, and that it is found in nested scope | |
140 | (let* (b 12) (do (eval (read-string "(def! aa 7)")) aa )) | |
141 | ;=>7 | |
142 | ||
77fd710c | 143 | ;>>> soft=True |
46e25689 | 144 | ;>>> optional=True |
0067158f | 145 | ;; |
7df7eeec | 146 | ;; -------- Optional Functionality -------- |
9af8aee6 | 147 | |
c150ec41 | 148 | ;; Testing comments in a file |
31690700 | 149 | (load-file "../tests/incB.mal") |
e6d41de4 | 150 | ;=>nil |
31690700 JM |
151 | (inc4 7) |
152 | ;=>11 | |
153 | (inc5 7) | |
154 | ;=>12 | |
c150ec41 | 155 | |
f5223195 JM |
156 | ;; Testing map literal across multiple lines in a file |
157 | (load-file "../tests/incC.mal") | |
e6d41de4 | 158 | ;=>nil |
f5223195 JM |
159 | mymap |
160 | ;=>{"a" 1} | |
161 | ||
fc7f8a4b NB |
162 | ;; Checking that eval does not use local environments. |
163 | (def! a 1) | |
164 | ;=>1 | |
165 | (let* (a 2) (eval (read-string "a"))) | |
166 | ;=>1 | |
e7f9404b | 167 | |
3b797cd5 NB |
168 | ;; Non alphanumeric characters in comments in read-string |
169 | (read-string "1;!") | |
170 | ;=>1 | |
171 | (read-string "1;\"") | |
172 | ;=>1 | |
173 | (read-string "1;#") | |
174 | ;=>1 | |
175 | (read-string "1;$") | |
176 | ;=>1 | |
177 | (read-string "1;%") | |
178 | ;=>1 | |
179 | (read-string "1;'") | |
180 | ;=>1 | |
181 | (read-string "1;\\") | |
182 | ;=>1 | |
183 | (read-string "1;\\\\") | |
184 | ;=>1 | |
185 | (read-string "1;\\\\\\") | |
186 | ;=>1 | |
187 | (read-string "1;`") | |
188 | ;=>1 | |
189 | ;;; Hopefully less problematic characters can be checked together | |
190 | (read-string "1; &()*+,-./:;<=>?@[]^_{|}~") | |
191 | ;=>1 | |
a124b322 | 192 |