aboutsummaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorJoel Martin <github@martintribe.org>2014-12-18 20:33:49 -0600
committerJoel Martin <github@martintribe.org>2015-01-09 16:16:50 -0600
commitb8ee29b22fbaa7a01f2754b4d6dd9af52e02017c (patch)
treef4d977ed220e9a3f665cfbf4f68770a81e4c2095 /tests
parentaaba249304b184e12e2445ab22d66df1f39a51a5 (diff)
downloadmal-b8ee29b22fbaa7a01f2754b4d6dd9af52e02017c.tar.gz
mal-b8ee29b22fbaa7a01f2754b4d6dd9af52e02017c.zip
All: add keywords.
Also, fix nth and count to match cloure.
Diffstat (limited to 'tests')
-rw-r--r--tests/step1_read_print.mal7
-rw-r--r--tests/step2_eval.mal3
-rw-r--r--tests/step4_if_fn_do.mal12
-rw-r--r--tests/step8_macros.mal16
-rw-r--r--tests/step9_try.mal46
-rw-r--r--tests/test.txt1
6 files changed, 77 insertions, 8 deletions
diff --git a/tests/step1_read_print.mal b/tests/step1_read_print.mal
index 3dc4023..57b2e34 100644
--- a/tests/step1_read_print.mal
+++ b/tests/step1_read_print.mal
@@ -73,6 +73,12 @@ abc-def
;;
;; -------- Optional Functionality --------
+;; Testing keywords
+:kw
+;=>:kw
+(:kw1 :kw2 :kw3)
+;=>(:kw1 :kw2 :kw3)
+
;; Testing read of vectors
[+ 1 2]
;=>[+ 1 2]
@@ -92,6 +98,7 @@ abc-def
;=>{"a" {"b" {"c" 3}}}
{ "a" {"b" { "cde" 3 } }}
;=>{"a" {"b" {"cde" 3}}}
+;=>{:a {:b {:cde 3}}}
;; Testing read of comments
;; whole line comment (not an exception)
diff --git a/tests/step2_eval.mal b/tests/step2_eval.mal
index eb35592..2f48c73 100644
--- a/tests/step2_eval.mal
+++ b/tests/step2_eval.mal
@@ -23,3 +23,6 @@
{"a" (+ 7 8)}
;=>{"a" 15}
+
+{:a (+ 7 8)}
+;=>{:a 15}
diff --git a/tests/step4_if_fn_do.mal b/tests/step4_if_fn_do.mal
index ee30ea3..46efeae 100644
--- a/tests/step4_if_fn_do.mal
+++ b/tests/step4_if_fn_do.mal
@@ -14,6 +14,10 @@
;=>(1 2 3)
(count (list 1 2 3))
;=>3
+(count (list))
+;=>0
+(count nil)
+;=>0
(if (> (count (list 1 2 3)) 3) "yes" "no")
;=>"no"
(if (>= (count (list 1 2 3)) 3) "yes" "no")
@@ -335,6 +339,14 @@ a
;;
;; -------- Optional Functionality --------
+;; Testing keywords
+(= :abc :abc)
+;=>true
+(= :abc :def)
+;=>false
+(= :abc ":abc")
+;=>false
+
;; Testing vector truthiness
(if [] 7 8)
;=>7
diff --git a/tests/step8_macros.mal b/tests/step8_macros.mal
index 8773ba8..cf8f5d1 100644
--- a/tests/step8_macros.mal
+++ b/tests/step8_macros.mal
@@ -1,13 +1,13 @@
;; Testing nth, first and rest functions
-(nth '() 0)
-;=>nil
(nth '(1) 0)
;=>1
(nth '(1 2) 1)
;=>2
-(nth '(1 2) 2)
-;=>nil
+(def! x "x")
+(def! x (nth '(1 2) 2))
+x
+;=>"x"
(first '())
;=>nil
@@ -132,14 +132,14 @@
;; Testing nth, first, rest with vectors
-(nth [] 0)
-;=>nil
(nth [1] 0)
;=>1
(nth [1 2] 1)
;=>2
-(nth [1 2] 2)
-;=>nil
+(def! x "x")
+(def! x (nth [1 2] 2))
+x
+;=>"x"
(first [])
;=>nil
diff --git a/tests/step9_try.mal b/tests/step9_try.mal
index aee7908..3781e4d 100644
--- a/tests/step9_try.mal
+++ b/tests/step9_try.mal
@@ -88,6 +88,24 @@
;;
;; -------- Optional Functionality --------
+;; Testing symbol and keyword functions
+(symbol? :abc)
+;=>false
+(symbol? 'abc)
+;=>true
+(symbol? "abc")
+;=>false
+(symbol? (symbol "abc"))
+;=>true
+(keyword? :abc)
+;=>true
+(keyword? 'abc)
+;=>false
+(keyword? "abc")
+;=>false
+(keyword? (keyword "abc"))
+;=>true
+
;; Testing sequential? function
(sequential? (list 1 2 3))
@@ -110,8 +128,16 @@
(vector 3 4 5)
;=>[3 4 5]
+(map? {})
+;=>true
+(map? '())
+;=>false
(map? [])
;=>false
+(map? 'abc)
+;=>false
+(map? :abc)
+;=>false
;;
;; Testing hash-maps
@@ -194,6 +220,26 @@
(count (keys hm3))
;=>2
+;; Testing keywords as hash-map keys
+(get {:abc 123} :abc)
+;=>123
+(contains? {:abc 123} :abc)
+;=>true
+(contains? {:abcd 123} :abc)
+;=>false
+(assoc {} :bcd 234)
+;=>{:bcd 234}
+(dissoc {:cde 345 :fgh 456} :cde)
+;=>{:fgh 456}
+(keyword? (nth (keys {:abc 123 :def 456}) 0))
+;=>true
+;;; TODO: support : in strings in make impl
+;;;(keyword? (nth (keys {":abc" 123 ":def" 456}) 0))
+;;;;=>false
+(keyword? (nth (vals {"a" :abc "b" :def}) 0))
+;=>true
+
+
;;
;; Testing conj function
diff --git a/tests/test.txt b/tests/test.txt
new file mode 100644
index 0000000..0f24bc0
--- /dev/null
+++ b/tests/test.txt
@@ -0,0 +1 @@
+A line of text