generate perf analysis
[jackhill/mal.git] / impls / tests / step6_file.mal
1 ;;; TODO: really a step5 test
2 ;;
3 ;; Testing that (do (do)) not broken by TCO
4 (do (do 1 2))
5 ;=>2
6
7 ;;
8 ;; Testing read-string, eval and slurp
9 (read-string "(1 2 (3 4) nil)")
10 ;=>(1 2 (3 4) nil)
11
12 (= nil (read-string "nil"))
13 ;=>true
14
15 (read-string "(+ 2 3)")
16 ;=>(+ 2 3)
17
18 (read-string "\"\n\"")
19 ;=>"\n"
20
21 (read-string "7 ;; comment")
22 ;=>7
23
24 ;;; Differing output, but make sure no fatal error
25 (read-string ";; comment")
26
27
28 (eval (read-string "(+ 2 3)"))
29 ;=>5
30
31 (slurp "../tests/test.txt")
32 ;=>"A line of text\n"
33
34 ;;; Load the same file twice.
35 (slurp "../tests/test.txt")
36 ;=>"A line of text\n"
37
38 ;; Testing load-file
39
40 (load-file "../tests/inc.mal")
41 ;=>nil
42 (inc1 7)
43 ;=>8
44 (inc2 7)
45 ;=>9
46 (inc3 9)
47 ;=>12
48
49 ;;
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))
93 (def! f (fn* () (swap! atm inc-it)))
94 (f)
95 ;=>8
96 (f)
97 ;=>9
98
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
105 ;>>> deferrable=True
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
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
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
143 ;>>> soft=True
144 ;>>> optional=True
145 ;;
146 ;; -------- Optional Functionality --------
147
148 ;; Testing comments in a file
149 (load-file "../tests/incB.mal")
150 ;=>nil
151 (inc4 7)
152 ;=>11
153 (inc5 7)
154 ;=>12
155
156 ;; Testing map literal across multiple lines in a file
157 (load-file "../tests/incC.mal")
158 ;=>nil
159 mymap
160 ;=>{"a" 1}
161
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
167
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
192