-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathtest-optimizer.lisp
98 lines (88 loc) · 3.81 KB
/
test-optimizer.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
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
(defpackage :markup/test-optimizer
(:use #:cl
#:fiveam)
(:import-from #:markup/markup
#:make-toplevel-node
#:make-xml-tag
#:optimize-markup)
(:import-from #:markup/optimizer
#:make-lazy-xml-tag)
(:local-nicknames (#:a #:alexandria)))
(in-package :markup/test-optimizer)
(def-suite* :markup/test-optimizer :in :markup)
(def-fixture state ()
(&body))
(test happy-path
(with-fixture state ()
(is (equal '(let nil
(make-lazy-xml-tag
()
(div)
(make-xml-tag 'div :attributes nil :children nil :unused nil)))
(optimize-markup '(make-xml-tag 'div :children nil :attributes nil :unused nil))))))
(test simple-escape
(with-fixture state ()
(is (equal '(let ((r1 (format nil "~a" car)))
(make-lazy-xml-tag
(r1)
(div)
(make-xml-tag 'div :attributes nil :children (list r1) :unused nil)))
(optimize-markup '(make-xml-tag 'div :children (list
(format nil "~a" car))
:attributes nil
:unused nil))))))
(test escaping-multiple
(with-fixture state ()
(is (equal '(let ((r1 (format nil "~a" car))
(r2 bar))
(make-lazy-xml-tag
(r1 r2)
(span)
(make-xml-tag 'span :attributes nil :children (list r1 r2) :unused nil)))
(optimize-markup '(make-xml-tag 'span :children (list
(format nil "~a" car)
bar)
:attributes nil
:unused nil))))))
(test escaping-attributes
(with-fixture state ()
(is (equal '(let ((r1 (format nil "~a" car)))
(make-lazy-xml-tag
(r1)
(input)
(make-xml-tag 'input :attributes (list (cons "car" r1)) :children nil
:unused nil)))
(optimize-markup '(make-xml-tag 'input :children nil
:attributes (list (cons "car" (format nil "~a" car)))
:unused nil))))))
(test attributes-get-the-first-register
(with-fixture state ()
(is (equal '(let ((r1 (format nil "~a" car))
(r2 bar))
(make-lazy-xml-tag
(r1 r2)
(div)
(make-xml-tag 'div :attributes (list (cons "car" r1)) :children (list r2)
:unused nil)))
(optimize-markup '(make-xml-tag 'div :children (list bar)
:attributes (list (cons "car" (format nil "~a" car)))
:unused nil))))))
(test if-the-tag-is-not-builtin-then-we-move-it-to-register
(with-fixture state ()
(is (equal '(let ((r1 (make-xml-tag 'foo :attributes nil :children nil :unused nil)))
r1)
(optimize-markup '(make-xml-tag 'foo :children nil :attributes nil :unused nil))))))
(test get-topleveled-on-children
(with-fixture state ()
(is (equal '(let ((r1 (make-xml-tag 'foo
:attributes nil
:children (list
(make-toplevel-node
"foo"))
:unused nil)))
r1)
(optimize-markup
'(make-xml-tag 'foo
:children (list "foo")
:attributes nil
:unused nil))))))