plpgsql: IO using stream table. Add keywords.
[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 ;;
98 ;; -------- 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