aboutsummaryrefslogtreecommitdiff
path: root/make/tests/reader.mk
diff options
context:
space:
mode:
authorJoel Martin <github@martintribe.org>2014-03-24 16:32:24 -0500
committerJoel Martin <github@martintribe.org>2014-03-24 16:32:24 -0500
commit3169070063b2cb877200117ebb384269d73bcb93 (patch)
tree23de3db1ea5c37afd21a45b6ed7771f56a08c0c4 /make/tests/reader.mk
downloadmal-3169070063b2cb877200117ebb384269d73bcb93.tar.gz
mal-3169070063b2cb877200117ebb384269d73bcb93.zip
Current state of mal for Clojure West lighting talk.
Diffstat (limited to 'make/tests/reader.mk')
-rw-r--r--make/tests/reader.mk76
1 files changed, 76 insertions, 0 deletions
diff --git a/make/tests/reader.mk b/make/tests/reader.mk
new file mode 100644
index 0000000..672d27b
--- /dev/null
+++ b/make/tests/reader.mk
@@ -0,0 +1,76 @@
+INTERACTIVE = no
+
+include tests/common.mk
+include reader.mk
+
+_tonum = $(call int_decode,$($(1)_value))
+
+$(info Testing READ_STR of numbers)
+$(call assert_eq,2,$(call _tonum,$(call READ_STR,2)))
+$(call assert_eq,12345,$(call _tonum,$(call READ_STR,12345)))
+$(call assert_eq,12345,$(call _tonum,$(call READ_STR,12345 "abc")))
+$(call assert_eq,12345,$(call _tonum,$(call READ_STR,12345"abc")))
+$(call assert_eq,12345,$(call _tonum,$(call READ_STR,12345(1))))
+
+$(info Testing READ_STR of symbols)
+$(call assert_eq,abc,$($(call READ_STR,abc)_value))
+$(call assert_eq,abc,$($(call READ_STR,abc )_value))
+$(call assert_eq,abc,$($(call READ_STR,abc"a str")_value))
+$(call assert_eq,abc,$($(call READ_STR,abc(2 3))_value))
+
+$(info Testing READ_STR of strings)
+$(call assert_eq,a string,$(call str_decode,$($(call READ_STR,"a string")_value)))
+$(call assert_eq,a string (with parens),$(call str_decode,$($(call READ_STR,"a string (with parens)")_value)))
+$(call assert_eq,a string,$(call str_decode,$($(call READ_STR,"a string"())_value)))
+$(call assert_eq,a string,$(call str_decode,$($(call READ_STR,"a string"123)_value)))
+$(call assert_eq,a string,$(call str_decode,$($(call READ_STR,"a string"abc)_value)))
+$(call assert_eq,,$(call str_decode,$($(call READ_STR,"")_value)))
+$(call assert_eq,abc ,$(call str_decode,$($(call READ_STR,"abc ")_value)))
+$(call assert_eq, abc,$(call str_decode,$($(call READ_STR," abc")_value)))
+$(call assert_eq,$$abc,$(call str_decode,$($(call READ_STR,"$$abc")_value)))
+$(call assert_eq,abc$$(),$(call str_decode,$($(call READ_STR,"abc$$()")_value)))
+$(call assert_eq,"xyz",$(call str_decode,$($(call READ_STR,"\"xyz\"")_value)))
+
+$(info Testing READ_STR of lists)
+$(call assert_eq,2,$(call _count,$(call READ_STR,(2 3))))
+$(call assert_eq,2,$(call _tonum,$(call sfirst,$(call READ_STR,(2 3)))))
+$(call assert_eq,3,$(call _tonum,$(call sfirst,$(call srest,$(call READ_STR,(2 3))))))
+L := $(strip $(call READ_STR,(+ 1 2 "str1" "string (with parens) and 'single quotes'")))
+$(call assert_eq,5,$(call _count,$(L)))
+$(call assert_eq,str1,$(call str_decode,$($(call _nth,$(L),3)_value)))
+$(call assert_eq,string (with parens) and 'single quotes',$(call str_decode,$($(call _nth,$(L),4)_value)))
+
+$(info Testing READ_STR of vectors)
+$(call assert_eq,2,$(call _count,$(call READ_STR,[2 3])))
+$(call assert_eq,2,$(call _tonum,$(call sfirst,$(call READ_STR,[2 3]))))
+$(call assert_eq,3,$(call _tonum,$(call sfirst,$(call srest,$(call READ_STR,[2 3])))))
+L := $(strip $(call READ_STR,[+ 1 2 "str1" "string (with parens) and 'single quotes'"]))
+$(call assert_eq,5,$(call _count,$(L)))
+$(call assert_eq,str1,$(call str_decode,$($(call _nth,$(L),3)_value)))
+$(call assert_eq,string (with parens) and 'single quotes',$(call str_decode,$($(call _nth,$(L),4)_value)))
+
+$(info Testing READ_STR of quote/quasiquote)
+$(call assert_eq,quote,$($(call _nth,$(call READ_STR,'1),0)_value)) #'
+$(call assert_eq,1,$(call _tonum,$(call _nth,$(call READ_STR,'1),1))) #'
+$(call assert_eq,quote,$($(call _nth,$(call READ_STR,'(1 2 3)),0)_value)) #'
+$(call assert_eq,3,$(call _tonum,$(call _nth,$(call _nth,$(call READ_STR,'(1 2 3)),1),2))) #'
+
+$(call assert_eq,quasiquote,$($(call _nth,$(call READ_STR,`1),0)_value))
+$(call assert_eq,1,$(call _tonum,$(call _nth,$(call READ_STR,`1),1)))
+$(call assert_eq,quasiquote,$($(call _nth,$(call READ_STR,`(1 2 3)),0)_value))
+$(call assert_eq,3,$(call _tonum,$(call _nth,$(call _nth,$(call READ_STR,`(1 2 3)),1),2)))
+
+$(call assert_eq,unquote,$($(call _nth,$(call READ_STR,~1),0)_value))
+$(call assert_eq,1,$(call _tonum,$(call _nth,$(call READ_STR,~1),1)))
+$(call assert_eq,unquote,$($(call _nth,$(call READ_STR,~(1 2 3)),0)_value))
+$(call assert_eq,3,$(call _tonum,$(call _nth,$(call _nth,$(call READ_STR,~(1 2 3)),1),2)))
+
+$(call assert_eq,splice-unquote,$($(call _nth,$(call READ_STR,~@1),0)_value))
+$(call assert_eq,1,$(call _tonum,$(call _nth,$(call READ_STR,~@1),1)))
+$(call assert_eq,splice-unquote,$($(call _nth,$(call READ_STR,~@(1 2 3)),0)_value))
+$(call assert_eq,3,$(call _tonum,$(call _nth,$(call _nth,$(call READ_STR,~@(1 2 3)),1),2)))
+
+
+.PHONY: all
+all:
+ @echo "All tests completed"