aboutsummaryrefslogtreecommitdiff
path: root/make/tests/reader.mk
blob: 672d27b2f0ccef40f6a595b5b674be4f5c5874d6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
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"