Travis: split build and test into separate scripts.
[jackhill/mal.git] / tests / step8_macros.mal
index 351e0ca..a345190 100644 (file)
@@ -1,3 +1,11 @@
+;; Testing non-macro function
+(not (= 1 1))
+;=>false
+;;; This should fail if it is a macro
+(not (= 1 2))
+;=>true
+
+
 ;; Testing trivial macros
 (defmacro! one (fn* () 1))
 (one)
 (macroexpand (unless2 2 3 4))
 ;=>(if (not 2) 3 4)
 
-;;
-;; Loading core.mal
-(load-file "../core.mal")
 
-;; Testing and macro
-(and)
-;=>true
-(and 1)
+;; Testing nth, first and rest functions
+
+(nth '(1) 0)
 ;=>1
-(and 1 2)
+(nth '(1 2) 1)
 ;=>2
-(and 1 2 3)
-;=>3
-(and 1 2 3 4)
-;=>4
-(and 1 2 3 4 false)
-;=>false
-(and 1 2 3 4 false 5)
-;=>false
+(def! x "x")
+(def! x (nth '(1 2) 2))
+x
+;=>"x"
+
+(first '())
+;=>nil
+(first '(6))
+;=>6
+(first '(7 8 9))
+;=>7
+
+(rest '())
+;=>()
+(rest '(6))
+;=>()
+(rest '(7 8 9))
+;=>(8 9)
+
 
 ;; Testing or macro
 (or)
 ;=>4
 (or false nil 3 false nil 4)
 ;=>3
-
-;; Testing -> macro
-
-(-> 7)
-;=>7
-(-> (list 7 8 9) first)
-;=>7
-(-> (list 7 8 9) (first))
-;=>7
-(-> (list 7 8 9) first (+ 7))
-;=>14
-(-> (list 7 8 9) rest (rest) first (+ 7))
-;=>16
+(or (or false 4))
+;=>4
 
 ;; Testing cond macro
 
 (cond false 7 false 8 false 9)
 ;=>nil
 
-;Testing all EVAL of non-default locations
+;;
+;; Loading core.mal
+(load-file "../core.mal")
+
+;; Testing and macro
+(and)
+;=>true
+(and 1)
+;=>1
+(and 1 2)
+;=>2
+(and 1 2 3)
+;=>3
+(and 1 2 3 4)
+;=>4
+(and 1 2 3 4 false)
+;=>false
+(and 1 2 3 4 false 5)
+;=>false
+
+;; Testing -> macro
+
+(-> 7)
+;=>7
+(-> (list 7 8 9) first)
+;=>7
+(-> (list 7 8 9) (first))
+;=>7
+(-> (list 7 8 9) first (+ 7))
+;=>14
+(-> (list 7 8 9) rest (rest) first (+ 7))
+;=>16
+
+;; Testing EVAL in let*
+
+(let* (x (or nil "yes")) x)
+;=>"yes"
+
+;;
+;; -------- Optional Functionality --------
+
+;; Testing nth, first, rest with vectors
+
+(nth [1] 0)
+;=>1
+(nth [1 2] 1)
+;=>2
+(def! x "x")
+(def! x (nth [1 2] 2))
+x
+;=>"x"
+
+(first [])
+;=>nil
+(first [10])
+;=>10
+(first [10 11 12])
+;=>10
+(rest [])
+;=>()
+(rest [10])
+;=>()
+(rest [10 11 12])
+;=>(11 12)
+
+;; Testing EVAL in vector let*
+
 (let* [x (or nil "yes")] x)
 ;=>"yes"