diff options
| author | Joel Martin <github@martintribe.org> | 2015-01-02 23:20:00 -0600 |
|---|---|---|
| committer | Joel Martin <github@martintribe.org> | 2015-01-09 16:16:55 -0600 |
| commit | f522319598c701efde91a78b07110d7039a8c906 (patch) | |
| tree | c903469df13f81ffb7d706680c5eaafadbb90471 /tests | |
| parent | 5400d4bf5e7fe7f968a4553f55101de962a39ef7 (diff) | |
| download | mal-f522319598c701efde91a78b07110d7039a8c906.tar.gz mal-f522319598c701efde91a78b07110d7039a8c906.zip | |
Racket: add steps0-A. Self-hosting.
- Some additioanl tests.
- Split step9 tests into optional but self-hosting requirements
(metadata on functions) and other optional (conj, metadata on
collections).
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/incB.mal | 4 | ||||
| -rw-r--r-- | tests/incC.mal | 6 | ||||
| -rw-r--r-- | tests/step1_read_print.mal | 33 | ||||
| -rw-r--r-- | tests/step3_env.mal | 6 | ||||
| -rw-r--r-- | tests/step6_file.mal | 5 | ||||
| -rw-r--r-- | tests/step9_try.mal | 151 |
6 files changed, 127 insertions, 78 deletions
diff --git a/tests/incB.mal b/tests/incB.mal index 1c68810..519bdf4 100644 --- a/tests/incB.mal +++ b/tests/incB.mal @@ -3,10 +3,6 @@ (def! inc5 (fn* (a) ;; a comment after code (+ 5 a))) -;; Test map split across lines -(def! mymap {"a" - 1}) - (prn "incB.mal finished") "incB.mal return string" diff --git a/tests/incC.mal b/tests/incC.mal new file mode 100644 index 0000000..e6f5041 --- /dev/null +++ b/tests/incC.mal @@ -0,0 +1,6 @@ +(def! mymap {"a" + 1}) + +(prn "incC.mal finished") +"incC.mal return string" + diff --git a/tests/step1_read_print.mal b/tests/step1_read_print.mal index 57b2e34..4ac08cb 100644 --- a/tests/step1_read_print.mal +++ b/tests/step1_read_print.mal @@ -60,6 +60,22 @@ abc-def (1 2, 3,,,,),, ;=>(1 2 3) +;; Testing read of quoting +'1 +;=>(quote 1) +'(1 2 3) +;=>(quote (1 2 3)) +`1 +;=>(quasiquote 1) +`(1 2 3) +;=>(quasiquote (1 2 3)) +~1 +;=>(unquote 1) +~(1 2 3) +;=>(unquote (1 2 3)) +~@(1 2 3) +;=>(splice-unquote (1 2 3)) + ;; ;; Testing reader errors ;;; TODO: fix these so they fail correctly @@ -107,23 +123,6 @@ abc-def 1; comment after expression ;=>1 -;; Testing read of quoting -'1 -;=>(quote 1) -'(1 2 3) -;=>(quote (1 2 3)) -`1 -;=>(quasiquote 1) -`(1 2 3) -;=>(quasiquote (1 2 3)) -~1 -;=>(unquote 1) -~(1 2 3) -;=>(unquote (1 2 3)) -~@(1 2 3) -;=>(splice-unquote (1 2 3)) - - ;; Testing read of ^/metadata ^{"a" 1} [1 2 3] ;=>(with-meta [1 2 3] {"a" 1}) diff --git a/tests/step3_env.mal b/tests/step3_env.mal index 26372e6..8fb4c42 100644 --- a/tests/step3_env.mal +++ b/tests/step3_env.mal @@ -35,6 +35,12 @@ x ;; ;; -------- Optional Functionality -------- +;; Testing let* with vector bindings +(let* [z 9] z) +;=>9 +(let* [p (+ 2 3) q (+ 2 p)] (+ p q)) +;=>12 + ;; Testing vector evaluation (let* (a 5 b 6) [3 4 a [b 7] 8]) ;=>[3 4 5 [6 7] 8] diff --git a/tests/step6_file.mal b/tests/step6_file.mal index d681532..5c7e32f 100644 --- a/tests/step6_file.mal +++ b/tests/step6_file.mal @@ -46,6 +46,11 @@ (inc5 7) ;=>12 +;; Testing map literal across multiple lines in a file +(load-file "../tests/incC.mal") +mymap +;=>{"a" 1} + ;;; TODO: really a step5 test ;; Testing that vector params not broken by TCO (def! g (fn* [] 78)) diff --git a/tests/step9_try.mal b/tests/step9_try.mal index 3781e4d..4093e7d 100644 --- a/tests/step9_try.mal +++ b/tests/step9_try.mal @@ -1,6 +1,9 @@ ;; ;; Testing try*/catch* +(try* 123 (catch* e 456)) +;=>123 + (try* (abc 1 2) (catch* exc (prn "exc is:" exc)))) ; "exc is:" "'abc' not found" ;=>nil @@ -10,8 +13,8 @@ ;;;; "exc is:" ["data" "foo"] ;;;;=>7 ;;;;=>7 -(try* (throw ["data" "foo"]) (catch* exc (do (prn "err:" exc) 7))) -; "err:" ["data" "foo"] +(try* (throw (list "data" "foo")) (catch* exc (do (prn "err:" exc) 7))) +; "err:" ("data" "foo") ;=>7 (try* (throw "my exception") (catch* exc (do (prn "exc:" exc) 7))) @@ -61,7 +64,7 @@ ;=>6 (map double nums) ;=>(2 4 6) -(map (fn* [x] (symbol? x)) (list 1 (symbol "two") "three")) +(map (fn* (x) (symbol? x)) (list 1 (symbol "two") "three")) ;=>(false true false) ;; @@ -86,7 +89,8 @@ ;=>"\"hello\"" ;; -;; -------- Optional Functionality -------- +;; ------- Optional Functionality ---------- +;; ------- (Needed for self-hosting) ------- ;; Testing symbol and keyword functions (symbol? :abc) @@ -119,6 +123,11 @@ (sequential? "abc") ;=>false + +;; Testing map function with vectors +(map (fn* (a) (* 2 a)) [1 2 3]) +;=>(2 4 6) + ;; Testing vector functions (vector? [10 11]) @@ -242,58 +251,21 @@ ;; -;; Testing conj function -(conj (list) 1) -;=>(1) -(conj (list 1) 2) -;=>(2 1) -(conj (list 2 3) 4) -;=>(4 2 3) -(conj (list 2 3) 4 5 6) -;=>(6 5 4 2 3) -(conj (list 1) (list 2 3)) -;=>((2 3) 1) - -(conj [] 1) -;=>[1] -(conj [1] 2) -;=>[1 2] -(conj [2 3] 4) -;=>[2 3 4] -(conj [2 3] 4 5 6) -;=>[2 3 4 5 6] -(conj [1] [2 3]) -;=>[1 [2 3]] +;; Testing metadata on functions ;; -;; Testing metadata -(meta [1 2 3]) -;=>nil +;; Testing metadata on mal functions (meta (fn* (a) a)) ;=>nil -(with-meta [1 2 3] {"a" 1}) -;=>[1 2 3] +(meta (with-meta (fn* (a) a) {"b" 1})) +;=>{"b" 1} -(meta (with-meta [1 2 3] {"a" 1})) -;=>{"a" 1} - -(meta (with-meta [1 2 3] "abc")) +(meta (with-meta (fn* (a) a) "abc")) ;=>"abc" -(meta (with-meta (list 1 2 3) {"a" 1})) -;=>{"a" 1} - -(meta (with-meta {"abc" 123} {"a" 1})) -;=>{"a" 1} - -;;; Not actually supported by Clojure -;;;(meta (with-meta (atom 7) {"a" 1})) -;;;;=>{"a" 1} - -(def! l-wm (with-meta [4 5 6] {"b" 2})) -;=>[4 5 6] +(def! l-wm (with-meta (fn* (a) a) {"b" 2})) (meta l-wm) ;=>{"b" 2} @@ -312,20 +284,10 @@ (meta f-wm) ;=>{"abc" 1} - (def! f-wm2 ^{"abc" 1} (fn* [a] (+ 1 a))) (meta f-wm2) ;=>{"abc" 1} -;; Testing metadata on builtin functions -(meta +) -;=>nil -(def! f-wm3 ^{"def" 2} +) -(meta f-wm3) -;=>{"def" 2} -(meta +) -;=>nil - ;; ;; Make sure closures and metadata co-exist (def! gen-plusX (fn* (x) (with-meta (fn* (b) (+ x b)) {"meta" 1}))) @@ -393,3 +355,78 @@ (f) ;=>9 + +;; +;; ------- Optional Functionality -------------- +;; ------- (Not needed for self-hosting) ------- + +;; +;; Testing conj function +(conj (list) 1) +;=>(1) +(conj (list 1) 2) +;=>(2 1) +(conj (list 2 3) 4) +;=>(4 2 3) +(conj (list 2 3) 4 5 6) +;=>(6 5 4 2 3) +(conj (list 1) (list 2 3)) +;=>((2 3) 1) + +(conj [] 1) +;=>[1] +(conj [1] 2) +;=>[1 2] +(conj [2 3] 4) +;=>[2 3 4] +(conj [2 3] 4 5 6) +;=>[2 3 4 5 6] +(conj [1] [2 3]) +;=>[1 [2 3]] + + +;; +;; Testing metadata on collections + +(meta [1 2 3]) +;=>nil + +(with-meta [1 2 3] {"a" 1}) +;=>[1 2 3] + +(meta (with-meta [1 2 3] {"a" 1})) +;=>{"a" 1} + +(meta (with-meta [1 2 3] "abc")) +;=>"abc" + +(meta (with-meta (list 1 2 3) {"a" 1})) +;=>{"a" 1} + +(meta (with-meta {"abc" 123} {"a" 1})) +;=>{"a" 1} + +;;; Not actually supported by Clojure +;;;(meta (with-meta (atom 7) {"a" 1})) +;;;;=>{"a" 1} + +(def! l-wm (with-meta [4 5 6] {"b" 2})) +;=>[4 5 6] +(meta l-wm) +;=>{"b" 2} + +(meta (with-meta l-wm {"new_meta" 123})) +;=>{"new_meta" 123} +(meta l-wm) +;=>{"b" 2} + +;; +;; Testing metadata on builtin functions +(meta +) +;=>nil +(def! f-wm3 ^{"def" 2} +) +(meta f-wm3) +;=>{"def" 2} +(meta +) +;=>nil + |
