-
Notifications
You must be signed in to change notification settings - Fork 13
/
test-by-example.t
175 lines (132 loc) · 3.26 KB
/
test-by-example.t
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
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
(use test-by-example test)
(let in (instring "abcde")
(testis (re-match "ab?" in) '("ab"))
(testis (readc in) #\c))
(let in (instring "acxy")
(testis (re-match "ab?" in) '("a"))
(testis (readc in) #\c))
(let in (instring "bcde")
(testis (re-match "ab?" in) nil)
(testis (readc in) #\b))
(let in (instring "abcd")
(testis (re-match "a(b)" in) '("ab" "b"))
(testis (readc in) #\c))
(let in (instring "abcde")
(testis (re-looking-at "ab?" in) t)
(testis (readc in) #\a))
(let in (instring "acxy")
(testis (re-looking-at "ab?" in) t)
(testis (readc in) #\a))
(let in (instring "bcde")
(testis (re-looking-at "ab?" in) nil)
(testis (readc in) #\b))
(let in (instring "ABC")
(skip-newlines in)
(testis (readc in) #\A))
(let in (instring " ABC")
(skip-newlines in)
(testis (readc in) #\space))
(let in (instring "\nABC")
(skip-newlines in)
(testis (readc in) #\A))
(let in (instring " \n \n\n \nABC")
(skip-newlines in)
(testis (readc in) #\A))
(fromstring "\nabc"
(testis (read-upto-empty-line) "")
(testis (readline) "abc"))
(fromstring "abc"
(testis (read-upto-empty-line) "abc\n")
(testis (readline) nil))
(fromstring "abc\n\ndef"
(testis (read-upto-empty-line) "abc\n")
(testis (readline) "def"))
(fromstring "abc\ndef\n\nghi"
(testis (read-upto-empty-line) "abc\ndef\n")
(testis (readline) "ghi"))
(fromstring "" (testis (parse-test-result) nil))
(fromstring "(a b c\n d e f)\n"
(testis (parse-test-result) '((val "(a b c\n d e f)\n"))))
(fromstring "prints: abc\n"
(testis (parse-test-result) '((prints "abc"))))
(fromstring "err: foo\n"
(testis (parse-test-result) '((err "foo"))))
(fromstring "stderr: abc\nprints: foo\n(123\n 456)\n"
(testis (parse-test-result)
'((errout "abc") (prints "foo") (val "(123\n 456)\n"))))
(fromstring #<<.
> (+ 3 4)
.
(testis (parse-one-test-spec)
'((expr "(+ 3 4)\n"))))
(fromstring #<<.
> (+ 3
4)
.
(testis (parse-one-test-spec)
'((expr "(+ 3\n 4)\n"))))
(fromstring #<<.
> (+ '(a b c d) '(e f))
(a b c
d e f)
.
(testis (parse-one-test-spec)
'((expr "(+ '(a b c d) '(e f))\n")
(val "(a b c\n d e f)\n"))))
(fromstring #<<.
> (just-for-side-effect)
.
(testis (parse-one-test-spec)
'((expr "(just-for-side-effect)\n"))))
(fromstring "" (testis (parse-test-specs) nil))
(fromstring #<<.
> (abc)
> (def)
.
(testis (parse-test-specs)
'(((expr "(abc)\n")) ((expr "(def)\n")))))
(fromstring #<<.
> (prn "hi")
prints: hi\n
.
(testis (parse-test-specs)
'(((expr "(prn \"hi\")\n") (prints "hi\n")))))
(let spec (fromstring #<<.
> (+ 3 5)
8
.
(car (parse-test-specs)))
(testis (eval-test runtime* spec)
'((val "8"))))
(let spec (fromstring #<<.
> (+ 3 5)
4
.
(car (parse-test-specs)))
(testis (check-test-result runtime* spec
(eval-test runtime* spec))
"expected val \"4\\n\", actual ((val \"8\"))"))
(example-test (runtime '(foobit-example)) #<<.
> foobit
6673
.
)
(example-test runtime* #<<.
> +
#<fn:+>
.
)
(example-test runtime* #<<.
> (pr "foo")
prints: foo
.
)
(pr "expected (not a real failure): ")
(testis
(catcherr
(example-test runtime* #<<.
> (err "foo")
err: bar
.
))
(makeerr "test failed"))