-
Notifications
You must be signed in to change notification settings - Fork 0
/
testcases.scm
136 lines (101 loc) · 3.29 KB
/
testcases.scm
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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
;;;; Test Cases for the new non-REPL version
;Match-let testing
(match-let '((? a) (? b)) '(1 2) (+ a b))
(let ((vars '(seq (? x) (?? xs)))
(vals '(seq 1 2 3 4 5)))
(match-let vars vals (cons x xs)))
(let ((vars '(seq (? x) (?? xs)))
(vals '(seq 1 2 3 4 5)))
(match-let vars vals (cons x xs) (pp `(,x and ,xs have been set))))
;;;Match-case testing
(match-case '(harold 4 5 3333 33 3333)
('(harold (? a) `(? b ,number?) (?? c)) (pp `(harold is ,a ,b ,c)))
('(cora `(? a ,number?) (? b) (?? c)) (pp "cora"))
(((?? c) chesterworth (? d)) (pp "chesterworth")))
(match-case '(harold 4 5 3333 33 3333)
('(harold (? a) `(? b ,number?) (?? c)) (pp `(harold is ,a
,b
,c)))
(((?:choice a (? b)) 100 (?:choice buffalos buffaloes) (??
b))
(pp b)))
(match-case '(1 2 3)
('(2 3 (? a)) (+ 2 3 a))
('(1 2 3) (+ 1 2 3)))
(match-case '(2 3 557)
('(2 3 (? a)) (+ 2 3 a))
('(1 2 3) (+ 1 2 3)))
(match-case '(1 #t 3)
('(2 3 (? a)) (+ 2 3 a))
('(1 2 3) (+ 1 2 3))
('(1 `(? a ,boolean?) 3) a))
(define (parse-token token)
(match-case token
('(bin-op (? op) (? a1) (? a2)) (op a1 a2))
('(un-op (? op) (? a)) (op a))
('(?? a) (pp a) (pp "no match"))))
(parse-token '(bin-op + 1 3))
(parse-token '(un-op - 4))
(parse-token '(+ 1 2))
(parse-token '(goto 0x3453))
(parse-token '(2 3 4 5))
;;;Match-define testing
(match-define '(? x) 1)
(match-define '((? x) (?? xs)) '(1 2 3 4 5))
(match-define '(?? xs) (list (list cos sin) '2 '3 '4))
(match-define '((? x) ((? y) (? z))) '(p (-3 4)))
;;;; Segment Variable Testing
((matcher '((? x) (?? a))) '(1 2 3 4 5))
((matcher '(?? a)) '(2 3 4 5))
(quote ((2 3 4 5)))
(quote 1)
(quote a)
;;;Testing multi-line body
(let ((vars '(seq (? x) (?? xs)))
(vals '(seq 1 2 3 4 5)))
(match-let vars vals (begin (cons x xs) (pp 'herewego)
(pp 'lotsoflines)
(pp x) (pp xs))))
(let ((vars '(seq (? x) (?? xs)))
(vals '(seq 1 2 3 4 5)))
(match-let vars vals (pp (cons x xs)) (pp 'herewego) (pp x) (pp xs)))
;;;Testing predicates
((matcher '(a ((? b) 2 3) (? b) c))
'(a (1 2 3) 1 c))
((matcher '((? b)))
'(4))
((matcher `((? b ,number?)))
'(4))
((matcher `((? b ,number?)))
'(4))
(matcher `((?? b ,number?)))
;undefined behavior--segments shouldn't work with predicates
(define (parse-token token)
(match-case token
('(bool-lit `(? a ,boolean?)) (pp a))
('(stringy `(? a ,string?)) (pp a))
('(?? a) (pp a) (pp 'extra))))
(parse-token '(goto 0x3453))
(parse-token '(bool-lit #t))
(parse-token '(stringy "Macros are hard"))
;;Very simple demo
(define (parse-token token)
(match-case token
('(bin-op (? op) (? a1) (? a2)) (op a1 a2))
('(un-op (? op) (? a)) (op a))
('(bool `(? val ,boolean?)) val)
('(stringy `(? a ,string?)) (pp a))
('(num `(? a ,number?)) (pp `(number is ,a)))
('(?? a) (pp a))))
(parse-token '(goto 0x3453))
(parse-token '(bool #t))
(parse-token '(stringy "Macros are hard"))
(parse-token '(bin-op (+ 4 5)))
(parse-token '(un-op (- 4)))
(parse-token '(num 4))
(let ((vals '(1 2 3 4 5)))
(match-let vals `((? x ,number?) (?? xs)) (pp `(x is ,x and xs
is ,xs)) (cons x
xs)))
; (x is 1 and xs is (2 3 4 5))
;Value 124: (1 2 3 4 5)