Merge pull request #323 from jig/master
[jackhill/mal.git] / tests / step6_file.mal
CommitLineData
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
JM
11
12(read-string "(+ 2 3)")
13;=>(+ 2 3)
14
dbac60df
JM
15(read-string "7 ;; comment")
16;=>7
17
18;;; Differing output, but make sure no fatal error
19(read-string ";; comment")
20
21
89bd4de1
JM
22(eval (read-string "(+ 2 3)"))
23;=>5
24
2cd015e5
DM
25(slurp "../tests/test.txt")
26;=>"A line of text\n"
89bd4de1 27
31690700
JM
28;; Testing load-file
29
30(load-file "../tests/inc.mal")
31(inc1 7)
32;=>8
33(inc2 7)
34;=>9
35(inc3 9)
36;=>12
37
a816262a
JM
38;;
39;; Testing that *ARGV* exists and is an empty list
40(list? *ARGV*)
41;=>true
42*ARGV*
43;=>()
44
9af8aee6 45;;
627bd6f7
DM
46;; Testing atoms
47
48(def! inc3 (fn* (a) (+ 3 a)))
49
50(def! a (atom 2))
51;=>(atom 2)
52
53(atom? a)
54;=>true
55
56(atom? 1)
57;=>false
58
59(deref a)
60;=>2
61
62(reset! a 3)
63;=>3
64
65(deref a)
66;=>3
67
68(swap! a inc3)
69;=>6
70
71(deref a)
72;=>6
73
74(swap! a (fn* (a) a))
75;=>6
76
77(swap! a (fn* (a) (* 2 a)))
78;=>12
79
80(swap! a (fn* (a b) (* a b)) 10)
81;=>120
82
83(swap! a + 3)
84;=>123
85
86;; Testing swap!/closure interaction
87(def! inc-it (fn* (a) (+ 1 a)))
88(def! atm (atom 7))
0067158f 89(def! f (fn* () (swap! atm inc-it)))
627bd6f7
DM
90(f)
91;=>8
92(f)
93;=>9
94
a1eb30fc 95;>>> deferrable=True
46e25689 96;>>> optional=True
0067158f 97;;
a1eb30fc 98;; -------- Deferrable/Optional Functionality --------
9af8aee6 99
c150ec41 100;; Testing comments in a file
31690700
JM
101(load-file "../tests/incB.mal")
102; "incB.mal finished"
103;=>"incB.mal return string"
104(inc4 7)
105;=>11
106(inc5 7)
107;=>12
c150ec41 108
f5223195
JM
109;; Testing map literal across multiple lines in a file
110(load-file "../tests/incC.mal")
111mymap
112;=>{"a" 1}
113
627bd6f7
DM
114;; Testing `@` reader macro (short for `deref`)
115(def! atm (atom 9))
116@atm
117;=>9
118
c150ec41
JM
119;;; TODO: really a step5 test
120;; Testing that vector params not broken by TCO
121(def! g (fn* [] 78))
122(g)
123;=>78
124(def! g (fn* [a] (+ a 78)))
125(g 3)
126;=>81
127