-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.zp
98 lines (85 loc) · 3.73 KB
/
test.zp
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
(load "html/html")
(load "minitest/minitest")
(define html:build (import "html:build"))
(define html:parse (import "html:parse"))
(define html:with-skeleton (import "html:with-skeleton"))
(define minitest:assert-equal (import "minitest:assert-equal"))
((import "minitest:colorize") #t)
((import "minitest:verbose") #t)
(minitest:assert-equal
"<html><body onclick=\"foo()\" style=\"color: purple\"><h1>title</h1><span>i am some text!</span></body></html>"
(html:build
#{:tags (#{:name "html"
:tags (#{:name "body"
:attributes #{"style" "color: purple" "onclick" "foo()"}
:tags (#{:name "h1" :text "title"}
#{:name "span" :text "i am some text!"})})})})
"build html")
(minitest:assert-equal
"<html><head><script type=\"text/javascript\">alert(\"yay\");</script></head><body><p>notifications are annoying</p></body></html>"
(html:build
(html:with-skeleton
#{:head #{:tags (#{:name "script"
:attributes #{"type" "text/javascript"}
:text "alert(\"yay\");"})}
:body #{:tags (#{:name "p"
:text "notifications are annoying"})}}))
"build html with skeleton")
(minitest:assert-equal
#{:tags () :text "just text"}
(html:parse "just text")
"test that dangling text is preserved")
(minitest:assert-equal
:err-unclosed-tag
(html:parse "<invalid")
"test that invalid html is not parsed (mismatched brackets)")
(minitest:assert-equal
#{:tags () :text ""}
(html:parse "")
"test that empty html yields empty accumulator")
(minitest:assert-equal
#{:tags (#{:name "br" :attributes #{} :text "" :tags ()}) :text "{0}"}
(html:parse "<br/>")
"test that self-closing tags are parsed correctly")
(minitest:assert-equal
#{:tags (#{:name "br" :attributes #{"style" "padding-bottom: 1em"} :text "" :tags ()}) :text "{0}"}
(html:parse "<br style=\"padding-bottom: 1em\"/>")
"test that the attributes of self-closing tags are parsed correctly")
(minitest:assert-equal
#{:tags (#{:name "br" :attributes #{} :text "" :tags ()}
#{:name "br" :attributes #{} :text "" :tags ()})
:text "{0}{1}"}
(html:parse "<br/><br/>")
"test that multiple self-closing tags are parsed correctly")
(minitest:assert-equal
#{:tags (#{:name "p" :text "yes, that is me" :attributes #{} :tags ()}) :text "{0}"}
(html:parse "<p>yes, that is me</p>")
"test that regular tags are parsed correctly")
(minitest:assert-equal
#{:tags (#{:name "p"
:attributes #{"style" "font-family: monospace;"}
:text "yes, that is me"
:tags ()})
:text "{0}"}
(html:parse "<p style=\"font-family: monospace;\">yes, that is me</p>")
"test that the attributes of regular tags are parsed correctly")
(minitest:assert-equal
#{:tags (#{:name "html"
:attributes #{}
:text "{0}"
:tags (#{:name "body"
:attributes #{"style" "color: purple"
"onclick" "foo()"}
:text "{0}{1}"
:tags (#{:name "h1" :attributes #{} :text "title" :tags ()}
#{:name "span" :attributes #{} :text "i am some text!" :tags ()})})})
:text "{0}"}
(html:parse
"<html><body onclick=\"foo()\" style=\"color: purple\"><h1>title</h1><span>i am some text!</span></body></html>")
"parse html (complex example)")
(define fixture "<html><head><meta attr=\"noop\"></meta></head><body onclick=\"foo()\" style=\"color: purple\"><h1>title</h1><span>i am some text!</span></body></html>")
(minitest:assert-equal
fixture
(html:build (html:parse fixture))
"test that parsing & building html results in equivalent HTML")
((import "minitest:results"))