Merge pull request #339 from asarhaddon/master
[jackhill/mal.git] / 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 (read-string "(+ 2 3)")
13 ;=>(+ 2 3)
14
15 (read-string "7 ;; comment")
16 ;=>7
17
18 ;;; Differing output, but make sure no fatal error
19 (read-string ";; comment")
20
21
22 (eval (read-string "(+ 2 3)"))
23 ;=>5
24
25 (slurp "../tests/test.txt")
26 ;=>"A line of text\n"
27
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
38 ;;
39 ;; Testing that *ARGV* exists and is an empty list
40 (list? *ARGV*)
41 ;=>true
42 *ARGV*
43 ;=>()
44
45 ;;
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))
89 (def! f (fn* () (swap! atm inc-it)))
90 (f)
91 ;=>8
92 (f)
93 ;=>9
94
95 ;>>> deferrable=True
96 ;>>> optional=True
97 ;;
98 ;; -------- Deferrable/Optional Functionality --------
99
100 ;; Testing comments in a file
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
108
109 ;; Testing map literal across multiple lines in a file
110 (load-file "../tests/incC.mal")
111 mymap
112 ;=>{"a" 1}
113
114 ;; Testing `@` reader macro (short for `deref`)
115 (def! atm (atom 9))
116 @atm
117 ;=>9
118
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
128 ;; Checking that eval does not use local environments.
129 (def! a 1)
130 ;=>1
131 (let* (a 2) (eval (read-string "a")))
132 ;=>1