forked from sellout/YACC-is-dead
-
Notifications
You must be signed in to change notification settings - Fork 0
/
api-tests.lisp
39 lines (30 loc) · 1.58 KB
/
api-tests.lisp
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
(in-package #:yacc-is-dead-tests)
(def-suite api-tests
:description "Test the external API, like unit tests are supposed to."
:in yacc-is-dead-tests)
(in-suite api-tests)
(def-test should-treat-literal-as-eq-parser ()
(is (equal '(x) (parse 'x '(x)))))
(def-test should-reduce-across-types ()
(is (equal '("X") (parse (==> 'x #'symbol-name) '(x)))))
(def-test should-match-based-on-predicate ()
(is (equal '(#\x) (parse (token #'characterp) '(#\x))))
(is (equal '() (parse (token #'characterp) '(12)))))
(def-test should-survive-right-recursion ()
(lazy-let ((right-recurse (choice (~ 'x right-recurse) *epsilon*)))
(is (equal '((x x x x x x x)) (parse right-recurse '(x x x x x x x))))))
(def-test should-survive-left-recursion ()
(lazy-let ((left-recurse (choice (~ left-recurse 'x) *epsilon*)))
(is (equal '((((((((NIL . X) . X) . X) . X) . X) . X) . X))
(parse left-recurse '(x x x x x x x))))))
(def-test should-normalize-left-recursion ()
(lazy-let ((left-recurse (choice (==> (~ left-recurse 'x)
(lambda (parse)
(append (car parse)
(list (cdr parse)))))
*epsilon*)))
(is (equal '((x x x x x x x)) (parse left-recurse '(x x x x x x x))))))
(def-test should-survive-bidi-recursion ()
(lazy-let ((bidi (choice (~ bidi '+ bidi) (==> 'x #'list))))
(is (equal '(((X) + (X) + (X) + (X) + (X) + (X) + (X) + X) + X)
(car (parse bidi '(x + x + x + x + x + x + x + x + x)))))))