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/step9_try.mal | |
| 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/step9_try.mal')
| -rw-r--r-- | tests/step9_try.mal | 151 |
1 files changed, 94 insertions, 57 deletions
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 + |
