#lang racket/base
(require (planet neil/overeasy:2)
"html-writing.rkt"
"planet-neil-xexp.rkt")
(test-section 'html-writing
(test 'element-with-no-content
(xexp->html '(p))
"<p></p>")
(test 'element-with-single-string-content
(xexp->html '(p "CONTENT"))
"<p>CONTENT</p>")
(test 'element-with-multiple-string-content
(xexp->html '(p "A" "B" "C"))
"<p>ABC</p>")
(test 'element-with-string-and-char-content
(xexp->html '(p "A" #\B "C"))
"<p>ABC</p>")
(test 'always-empty-element
(xexp->html '(br))
"<br>")
(test 'always-empty-element-with-ignored-content
(xexp->html '(br "CONTENT"))
"<br>")
(test (xexp->html '(hr (@ (clear "all"))))
"<hr clear=\"all\">")
(test 'boolean-attribute-with-no-value-given
(xexp->html `(hr (@ (noshade))))
"<hr noshade=\"noshade\">")
(test 'boolen-attribute-with-standard-value-given
(xexp->html `(hr (@ (noshade "noshade"))))
"<hr noshade=\"noshade\">")
(test 'boolean-attribute-with-nonstandard-value-given
(xexp->html `(hr (@ (noshade "foo"))))
"<hr noshade=\"foo\">")
(test 'baseline-attribute
(xexp->html `(hr (@ (aaa "bbbccc"))))
"<hr aaa=\"bbbccc\">")
(test 'attribute-value-with-single-quote
(xexp->html `(hr (@ (aaa "bbb'ccc"))))
"<hr aaa=\"bbb'ccc\">")
(test 'attribute-value-with-double-quote
(xexp->html `(hr (@ (aaa "bbb\"ccc"))))
"<hr aaa=\"bbb"ccc\">")
(test 'attribute-value-with-double-quote-and-single-quote
(xexp->html `(hr (@ (aaa "bbb\"ccc'ddd"))))
"<hr aaa=\"bbb"ccc'ddd\">")
(test 'attribute-value-with-two-strings
(xexp->html `(hr (@ (y "a" "b"))))
"<hr y=\"ab\">")
(test 'attribute-value-with-three-strings
(xexp->html `(hr (@ (y "a" "b" "c"))))
"<hr y=\"abc\">")
(test 'attribute-value-with-printable-char
(xexp->html `(hr (@ (y "a" #\b "c"))))
"<hr y=\"abc\">")
(test 'attribute-value-with-entity-reference
(xexp->html `(hr (@ (y "a" (& copy) "c"))))
"<hr y=\"a©c\">")
(test 'attribute-value-with-special-characters
(xexp->html `(hr (@ (y "a\"b<c>d&e'f"))))
"<hr y=\"a"b<c>d&e'f\">")
(test 'character-entity-reference
(xexp->html '(& copy))
"©")
(test 'character-entity-reference-with-mixed-case
(xexp->html '(& rArr))
"⇒")
(test (xexp->html
`(*PI* xml "version=\"1.0\" encoding=\"UTF-8\""))
"<?xml version=\"1.0\" encoding=\"UTF-8\"?>")
(test (xexp->html
`(*DECL*
DOCTYPE
html
PUBLIC
"-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"))
(string-append
"<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Strict//EN\""
" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd\">"))
(define (%ff1 c o)
(if (integer? o)
(let ((name
(string-append (symbol->string c)
"-"
(number->string o))))
(case c
((attributes) (list (string->symbol name) o))
(else name)))
(error-html-writing-foreign-filter o c)))
(test 'attribute-value-foreign-filter
(parameterize ((current-html-writing-foreign-filter %ff1))
(let ((os (open-output-string)))
(write-html '(td (@ (colspan 1))) os)
(let ((str (get-output-string os)))
(close-output-port os)
str)))
"<td colspan=\"attribute-value-1\"></td>")
(test 'attribute-foreign-filter
(parameterize ((current-html-writing-foreign-filter %ff1))
(let ((os (open-output-string)))
(write-html '(x (@ 1)) os)
(let ((str (get-output-string os)))
(close-output-port os)
str)))
"<x attributes-1=\"attribute-value-1\"></x>")
(test 'content-foreign-filter
(parameterize ((current-html-writing-foreign-filter %ff1))
(let ((os (open-output-string)))
(write-html '(p 1) os)
(let ((str (get-output-string os)))
(close-output-port os)
str)))
"<p>content-1</p>")
)