#lang racket/base
(require (planet neil/testeez:1:1)
"html-template.rkt")
(testeez
"test-html-template.rkt"
(test/equal "attributes"
(html-template-to-string (hr (@ (clear "all") (id "foo"))))
"<hr clear=\"all\" id=\"foo\" />")
(test/equal "html-template syntax as distinct from html-template-to-string"
(let ((os (open-output-string)))
(parameterize ((current-output-port os))
(html-template (p "Hi!")))
(begin0 (get-output-string os)
(close-output-port os)))
"<p>Hi!</p>")
(test/equal "simple html template"
(let ((my-title "All About Kittens & Puppies"))
(html-template-to-string
(html (head (title (%eval my-title)))
(body (h1 (%eval my-title))
(p "Kittens claw." (br) "Puppies pee.")))))
"<html><head><title>All About Kittens & Puppies</title></head><body><h1>All About Kittens & Puppies</h1><p>Kittens claw.<br />Puppies pee.</p></body></html>")
(test/equal
"simple html template debug expansion"
(html-template-debug-expand
(html (head (title (%eval my-title)))
(body (h1 (%eval my-title))
(p "Bunnies are nice." (br) "Yep."))))
'(begin (display "<html><head><title>")
(write-html my-title)
(display "</title></head><body><h1>")
(write-html my-title)
(display "</h1><p>Bunnies are nice.<br />Yep.</p></body></html>")
(void)))
(test/equal ""
(html-template-to-string (p))
"<p></p>")
(test/equal ""
(html-template-to-string (p "CONTENT"))
"<p>CONTENT</p>")
(test/equal ""
(html-template-to-string (br))
"<br />")
(test/equal ""
(html-template-to-string (hr (@ (clear "all"))))
"<hr clear=\"all\" />")
(test/equal ""
(html-template-to-string (hr (@ (noshade))))
"<hr noshade />")
(test/equal ""
(html-template-to-string (hr (@ (noshade #t))))
"<hr noshade />")
(test/equal ""
(html-template-to-string (hr (@ (noshade "noshade"))))
"<hr noshade=\"noshade\" />")
(test/equal ""
(html-template-to-string (hr (@ (aaa "bbbccc"))))
"<hr aaa=\"bbbccc\" />")
(test/equal ""
(html-template-to-string (hr (@ (aaa "bbb'ccc"))))
"<hr aaa=\"bbb'ccc\" />")
(test/equal ""
(html-template-to-string (hr (@ (aaa "bbb\"ccc"))))
"<hr aaa=\"bbb"ccc\" />")
(test/equal ""
(html-template-to-string (hr (@ (aaa "bbb\"ccc'ddd"))))
"<hr aaa=\"bbb"ccc'ddd\" />")
(test/equal ""
(html-template-to-string
(p (@ (align (%verbatim "'cen" "ter'"))) "x"))
"<p align='center'>x</p>")
(test/equal ""
(html-template-to-string
(p (@ (align (%eval/effects-only (display "'cen")
(display "ter'"))))
"x"))
"<p align='center'>x</p>")
(test/equal "" (html-template-to-string (& copy)) "©")
(test/equal "" (html-template-to-string (& rArr)) "⇒")
(test/equal "" (html-template-to-string (& 151)) "—")
(test/equal ""
(html-template-to-string
(p (@ (align "center")
(%eval/effects-only (display " x=\"1\" y=\"2\"")))))
"<p align=\"center\" x=\"1\" y=\"2\"></p>")
(test/equal "attributes %eval with multiple attributes"
(html-template-to-string
(p (@ (align "center")
(%eval '((x "1") (y "2"))))))
"<p align=\"center\" x=\"1\" y=\"2\"></p>")
(test/equal "attributes %eval with one attribute"
(html-template-to-string
(p (@ (align "center")
(%eval '(x "1")))))
"<p align=\"center\" x=\"1\"></p>")
(test/equal ""
(html-template-to-string
(*pi* xml "version=\"1.0\" encoding=\"UTF-8\""))
"<?xml version=\"1.0\" encoding=\"UTF-8\"?>")
(test/equal ""
(html-template-to-string
(*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\">"))
)