tests: make macro result evaluation mandatory.
[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 ;;; TODO: fix newline matching so that this works
26 ;;;(slurp "../tests/test.txt")
27 ;;;;=>"A line of text\n"
28
29
30 ;; Testing load-file
31
32 (load-file "../tests/inc.mal")
33 (inc1 7)
34 ;=>8
35 (inc2 7)
36 ;=>9
37 (inc3 9)
38 ;=>12
39
40 ;;
41 ;; Testing that *ARGV* exists and is an empty list
42 (list? *ARGV*)
43 ;=>true
44 *ARGV*
45 ;=>()
46
47 ;;
48 ;; Testing atoms
49
50 (def! inc3 (fn* (a) (+ 3 a)))
51
52 (def! a (atom 2))
53 ;=>(atom 2)
54
55 (atom? a)
56 ;=>true
57
58 (atom? 1)
59 ;=>false
60
61 (deref a)
62 ;=>2
63
64 (reset! a 3)
65 ;=>3
66
67 (deref a)
68 ;=>3
69
70 (swap! a inc3)
71 ;=>6
72
73 (deref a)
74 ;=>6
75
76 (swap! a (fn* (a) a))
77 ;=>6
78
79 (swap! a (fn* (a) (* 2 a)))
80 ;=>12
81
82 (swap! a (fn* (a b) (* a b)) 10)
83 ;=>120
84
85 (swap! a + 3)
86 ;=>123
87
88 ;; Testing swap!/closure interaction
89 (def! inc-it (fn* (a) (+ 1 a)))
90 (def! atm (atom 7))
91 (def! f (fn* [] (swap! atm inc-it)))
92 (f)
93 ;=>8
94 (f)
95 ;=>9
96
97 ;; -------- Optional Functionality --------
98
99 ;; Testing comments in a file
100 (load-file "../tests/incB.mal")
101 ; "incB.mal finished"
102 ;=>"incB.mal return string"
103 (inc4 7)
104 ;=>11
105 (inc5 7)
106 ;=>12
107
108 ;; Testing map literal across multiple lines in a file
109 (load-file "../tests/incC.mal")
110 mymap
111 ;=>{"a" 1}
112
113 ;; Testing `@` reader macro (short for `deref`)
114 (def! atm (atom 9))
115 @atm
116 ;=>9
117
118 ;;; TODO: really a step5 test
119 ;; Testing that vector params not broken by TCO
120 (def! g (fn* [] 78))
121 (g)
122 ;=>78
123 (def! g (fn* [a] (+ a 78)))
124 (g 3)
125 ;=>81
126