(require-extension testeez htmlprag)
(testeez
"HtmlPrag"
(test-define "" lf "\n")
(test/equal "" (html->shtml ">") `(,shtml-top-symbol (a ">")))
(test/equal "" (html->shtml "") `(,shtml-top-symbol (a "<" ">")))
(test/equal "" (html->shtml "<>") `(,shtml-top-symbol "<" ">"))
(test/equal "" (html->shtml "< >") `(,shtml-top-symbol "<" ">"))
(test/equal "" (html->shtml "< a>") `(,shtml-top-symbol (a)))
(test/equal "" (html->shtml "< a / >") `(,shtml-top-symbol (a)))
(test/equal "" (html->shtml "shtml "shtml ">") `(,shtml-top-symbol ">" (a)))
(test/equal "" (html->shtml ">") `(,shtml-top-symbol))
(test/equal "" (html->shtml "<\">") `(,shtml-top-symbol "<" "\"" ">"))
(test/equal ""
(html->shtml (string-append "xxxaaa" lf
"bbb" lf
"cshtml "aaabbb")
`(,shtml-top-symbol
"aaa" (,shtml-comment-symbol " xxx ") "bbb"))
(test/equal ""
(html->shtml "aaabbb")
`(,shtml-top-symbol
"aaa" (,shtml-comment-symbol " xxx ") "bbb"))
(test/equal ""
(html->shtml "aaabbb")
`(,shtml-top-symbol
"aaa" (,shtml-comment-symbol " xxx -") "bbb"))
(test/equal ""
(html->shtml "aaabbb")
`(,shtml-top-symbol
"aaa" (,shtml-comment-symbol " xxx --") "bbb"))
(test/equal ""
(html->shtml "aaabbb")
`(,shtml-top-symbol
"aaa" (,shtml-comment-symbol " xxx -y") "bbb"))
(test/equal ""
(html->shtml "aaabbb")
`(,shtml-top-symbol
"aaa" (,shtml-comment-symbol "-") "bbb"))
(test/equal ""
(html->shtml "aaabbb")
`(,shtml-top-symbol
"aaa" (,shtml-comment-symbol "") "bbb"))
(test/equal ""
(html->shtml "aaabbb")
`(,shtml-top-symbol "aaa" (,shtml-comment-symbol "->bbb")))
(test/equal "" (html->shtml "
") `(,shtml-top-symbol (hr)))
(test/equal "" (html->shtml "
") `(,shtml-top-symbol (hr)))
(test/equal "" (html->shtml "
") `(,shtml-top-symbol (hr)))
(test/equal ""
(html->shtml "
")
`(,shtml-top-symbol (hr (@ (noshade)))))
(test/equal ""
(html->shtml "
")
`(,shtml-top-symbol (hr (@ (noshade)))))
(test/equal ""
(html->shtml "
")
`(,shtml-top-symbol (hr (@ (noshade)))))
(test/equal ""
(html->shtml "
")
`(,shtml-top-symbol (hr (@ (noshade)))))
(test/equal ""
(html->shtml "
")
`(,shtml-top-symbol (hr (@ (noshade "1")))))
(test/equal ""
(html->shtml "
")
`(,shtml-top-symbol (hr (@ (noshade "1/")))))
(test/equal ""
(html->shtml "aaabbb
ccc
ddd")
`(,shtml-top-symbol (q "aaa" (p) "bbb") "ccc" "ddd"))
(test/equal "" (html->shtml "<") `(,shtml-top-symbol "<"))
(test/equal "" (html->shtml ">") `(,shtml-top-symbol ">"))
(test/equal ""
(html->shtml "Gilbert & Sullivan")
`(,shtml-top-symbol "Gilbert & Sullivan"))
(test/equal ""
(html->shtml "Gilbert & Sullivan")
`(,shtml-top-symbol "Gilbert & Sullivan"))
(test/equal ""
(html->shtml "Gilbert & Sullivan")
`(,shtml-top-symbol "Gilbert & Sullivan"))
(test/equal ""
(html->shtml "Copyright © Foo")
`(,shtml-top-symbol "Copyright "
(& ,(string->symbol "copy"))
" Foo"))
(test/equal ""
(html->shtml "aaa©bbb")
`(,shtml-top-symbol
"aaa" (& ,(string->symbol "copy")) "bbb"))
(test/equal ""
(html->shtml "aaa©")
`(,shtml-top-symbol
"aaa" (& ,(string->symbol "copy"))))
(test/equal "" (html->shtml "*") `(,shtml-top-symbol "*"))
(test/equal "" (html->shtml "*") `(,shtml-top-symbol "*"))
(test/equal "" (html->shtml "*x") `(,shtml-top-symbol "*x"))
(test/equal "" (html->shtml "") `(,shtml-top-symbol
(& 151)
;; ,(string (%htmlprag:a2c 151))
))
(test/equal "" (html->shtml "Ϩ") `(,shtml-top-symbol (& 1000)))
(test/equal "" (html->shtml "B") `(,shtml-top-symbol "B"))
(test/equal "" (html->shtml "¢") `(,shtml-top-symbol
(& 162)
;; ,(string (%htmlprag:a2c 162))
))
(test/equal "" (html->shtml "ÿ") `(,shtml-top-symbol
(& 255)
;; ,(string (%htmlprag:a2c 255))
))
(test/equal "" (html->shtml "Ā") `(,shtml-top-symbol (& 256)))
(test/equal "" (html->shtml "B") `(,shtml-top-symbol "B"))
(test/equal "" (html->shtml "&42;") `(,shtml-top-symbol "&42;"))
(test/equal ""
(html->shtml (string-append "aaa©bbb&ccc<ddd&>"
"eee*fffϨgggZhhh"))
`(,shtml-top-symbol
"aaa"
(& ,(string->symbol "copy"))
"bbb&ccceee*fff"
(& 1000)
"gggZhhh"))
(test/equal ""
(html->shtml
(string-append
"2"))
`(,shtml-top-symbol
(img (@
(src
"http://e.e/aw/pics/listings/ebayLogo_38x16.gif")
(border "0") (width "38") (height "16")
(hspace "5") (vspace "0")))
"2"))
(test/equal ""
(html->shtml "eee")
`(,shtml-top-symbol (aaa (@ (bbb "ccc") (ddd)) "eee")))
(test/equal ""
(html->shtml "eee")
`(,shtml-top-symbol (aaa (@ (bbb "ccc") (ddd)) "eee")))
(test/equal ""
(html->shtml
(string-append
"My Title"
""
"This is a bold-italic test of "
"broken HTML.
Yes it is."))
`(,shtml-top-symbol
(html (head (title "My Title"))
(body (@ (bgcolor "white") (foo "42"))
"This is a "
(b (i "bold-italic"))
" test of "
"broken HTML."
(br)
"Yes it is."))))
(test/equal ""
(html->shtml
(string-append
""))
`(,shtml-top-symbol
(,shtml-decl-symbol
,(string->symbol "DOCTYPE")
html
,(string->symbol "PUBLIC")
"-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd")))
(test/equal ""
(html->shtml
(string-append
""))
`(,shtml-top-symbol
(html (@ (xmlns "http://www.w3.org/1999/xhtml")
(xml:lang "en") (lang "en")))))
(test/equal
""
(html->shtml
(string-append
""
"Frobnostication"
"Moved to "
"here."))
`(,shtml-top-symbol
(html (@ (xmlns:html "http://www.w3.org/TR/REC-html40"))
(head (title "Frobnostication"))
(body (p "Moved to "
(a (@ (href "http://frob.com"))
"here."))))))
(test/equal ""
(html->shtml
(string-append
""
"Layman, A"
"33B"
"Check Status"
"1997-05-24T07:55:00+1"))
`(,shtml-top-symbol
(reservation (@ (,(string->symbol "xmlns:HTML")
"http://www.w3.org/TR/REC-html40"))
(name (@ (class "largeSansSerif"))
"Layman, A")
(seat (@ (class "Y") (class "largeMonotype"))
"33B")
(a (@ (href "/cgi-bin/ResStatus"))
"Check Status")
(departure "1997-05-24T07:55:00+1"))))
(test/equal
""
(html->shtml
(string-append
"whatever"
"link"
"BLah italic bold ened "
" still < bold
But not done yet..."))
`(,shtml-top-symbol
(html (head (title) (title "whatever"))
(body (a (@ (href "url")) "link")
(p (@ (align "center"))
(ul (@ (compact) (style "aa"))))
(p "BLah"
(,shtml-comment-symbol " comment ")
" "
(i " italic " (b " bold " (tt " ened ")))
" still < bold "))
(p " But not done yet..."))))
(test/equal ""
(html->shtml "")
`(,shtml-top-symbol
(,shtml-pi-symbol xml "version=\"1.0\" encoding=\"UTF-8\"")))
(test/equal ""
(html->shtml "")
`(,shtml-top-symbol (,shtml-pi-symbol php "php_info(); ")))
(test/equal ""
(html->shtml "shtml "shtml " blort ?>")
`(,shtml-top-symbol
(,shtml-pi-symbol foo "bar ? baz > blort ")))
(test/equal ""
(html->shtml "x")
`(,shtml-top-symbol (,shtml-pi-symbol foo "b") "x"))
(test/equal ""
(html->shtml "x")
`(,shtml-top-symbol (,shtml-pi-symbol foo "") "x"))
(test/equal ""
(html->shtml "x")
`(,shtml-top-symbol (,shtml-pi-symbol foo "") "x"))
(test/equal ""
(html->shtml "x")
`(,shtml-top-symbol (,shtml-pi-symbol foo "") "x"))
(test/equal ""
(html->shtml "x")
`(,shtml-top-symbol (,shtml-pi-symbol f "") "x"))
(test/equal ""
(html->shtml "?>x")
`(,shtml-top-symbol (,shtml-pi-symbol #f "") "x"))
(test/equal ""
(html->shtml ">x")
`(,shtml-top-symbol (,shtml-pi-symbol #f ">x")))
(test/equal ""
(html->shtml "blort")
`(,shtml-top-symbol (foo (@ (bar "baz")) "blort")))
(test/equal ""
(html->shtml "blort")
`(,shtml-top-symbol (foo (@ (bar "baz")) "blort")))
(test/equal ""
(html->shtml "blort")
`(,shtml-top-symbol (foo (@ (bar "baz'>blort")))))
(test/equal ""
(html->shtml "
")
(test/equal ""
(shtml->html '(p "CONTENT")) "CONTENT
")
(test/equal ""
(shtml->html '(br)) "
")
(test/equal ""
(shtml->html '(br "CONTENT")) "
")
(test/equal ""
(shtml->html `(hr (@ (clear "all"))))
"
")
(test/equal ""
(shtml->html `(hr (@ (noshade))))
"
")
(test/equal ""
(shtml->html `(hr (@ (noshade #t))))
"
") ;; TODO: Maybe lose this test.
(test/equal ""
(shtml->html `(hr (@ (noshade "noshade"))))
"
")
(test/equal ""
(shtml->html `(hr (@ (aaa "bbbccc"))))
"
")
(test/equal ""
(shtml->html `(hr (@ (aaa "bbb'ccc"))))
"
")
(test/equal ""
(shtml->html `(hr (@ (aaa "bbb\"ccc"))))
"
")
(test/equal ""
(shtml->html `(hr (@ (aaa "bbb\"ccc'ddd"))))
"
")
(test/equal "" (shtml->html '(& "copy")) "©")
(test/equal "" (shtml->html '(& "rArr")) "⇒")
(test/equal "" (shtml->html `(& ,(string->symbol "rArr"))) "⇒")
(test/equal "" (shtml->html '(& 151)) "")
(test/equal ""
(html->shtml "©")
`(,shtml-top-symbol (& ,(string->symbol "copy"))))
(test/equal ""
(html->shtml "⇒")
`(,shtml-top-symbol (& ,(string->symbol "rArr"))))
(test/equal ""
(html->shtml "")
`(,shtml-top-symbol
(& 151)
;; ,(string (%htmlprag:a2c 151))
))
(test/equal ""
(html->shtml "ϧ")
`(,shtml-top-symbol (& 999)))
(test/equal ""
(shtml->html
`(,shtml-pi-symbol xml "version=\"1.0\" encoding=\"UTF-8\""))
"")
(test/equal ""
(shtml->html
`(,shtml-decl-symbol
,(string->symbol "DOCTYPE")
html
,(string->symbol "PUBLIC")
"-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"))
(string-append
""))
(test/equal ""
(shtml-entity-value '(*ENTITY* "shtml-named-char" "rArr"))
(string->symbol "rArr"))
(test/equal ""
(shtml-entity-value '(& "rArr"))
(string->symbol "rArr"))
(test/equal ""
(shtml-entity-value `(& ,(string->symbol "rArr")))
(string->symbol "rArr"))
(test/equal ""
(html->shtml "xxxyyy")
`(,shtml-top-symbol "xxx" "abc" "yyy"))
(test/equal ""
(html->shtml "xxxyyy")
`(,shtml-top-symbol "xxx" "ab]c" "yyy"))
(test/equal ""
(html->shtml "xxxyyy")
`(,shtml-top-symbol "xxx" "ab]]c" "yyy"))
(test/equal ""
(html->shtml "xxxyyy")
`(,shtml-top-symbol "xxx" "]" "yyy"))
(test/equal ""
(html->shtml "xxxshtml "P3
")
`(,shtml-top-symbol (html (div (p "P1")
(p "P2"))
(p "P3"))))
(test/equal "we no longer convert character references above 126 to string"
(html->shtml "")
`(,shtml-top-symbol (& 151)))
;; TODO: Write more test cases for HTML encoding.
;; TODO: Write test cases for foreign-filter of HTML writing.
;; TODO: Write test cases for attribute values that aren't simple strings.
;; TODO: Document this.
;;
;; (define html-1 "")
;; (define shtml (html->shtml html-1))
;; shtml
;; (define html-2 (shtml->html shtml))
;; html-2
)