Merge pull request #273 from wasamasa/r7rs-implementation
[jackhill/mal.git] / tests / step6_file.mal
index 99da170..c024e0d 100644 (file)
 (eval (read-string "(+ 2 3)"))
 ;=>5
 
-;;; TODO: fix newline matching so that this works
-;;;(slurp "../tests/test.txt")
-;;;;=>"A line of text\n"
-
+(slurp "../tests/test.txt")
+;=>"A line of text\n"
 
 ;; Testing load-file
 
 ;=>()
 
 ;;
-;; -------- Optional Functionality --------
+;; Testing atoms
+
+(def! inc3 (fn* (a) (+ 3 a)))
+
+(def! a (atom 2))
+;=>(atom 2)
+
+(atom? a)
+;=>true
+
+(atom? 1)
+;=>false
+
+(deref a)
+;=>2
+
+(reset! a 3)
+;=>3
+
+(deref a)
+;=>3
+
+(swap! a inc3)
+;=>6
+
+(deref a)
+;=>6
+
+(swap! a (fn* (a) a))
+;=>6
+
+(swap! a (fn* (a) (* 2 a)))
+;=>12
+
+(swap! a (fn* (a b) (* a b)) 10)
+;=>120
+
+(swap! a + 3)
+;=>123
+
+;; Testing swap!/closure interaction
+(def! inc-it (fn* (a) (+ 1 a)))
+(def! atm (atom 7))
+(def! f (fn* () (swap! atm inc-it)))
+(f)
+;=>8
+(f)
+;=>9
+
+;>>> deferrable=True
+;>>> optional=True
+;;
+;; -------- Deferrable/Optional Functionality --------
 
 ;; Testing comments in a file
 (load-file "../tests/incB.mal")
 mymap
 ;=>{"a" 1}
 
+;; Testing `@` reader macro (short for `deref`)
+(def! atm (atom 9))
+@atm
+;=>9
+
 ;;; TODO: really a step5 test
 ;; Testing that vector params not broken by TCO
 (def! g (fn* [] 78))