| 1 |
;; |
| 2 |
;; test sxml tools |
| 3 |
;; |
| 4 |
|
| 5 |
;; ssax test is derived from the original SSAX source. |
| 6 |
;; We use 'load' instead of 'include'. ssax-test.scm is a generated file |
| 7 |
;; and in case of out-of-tree build it resides in a build directory while |
| 8 |
;; this file (test.scm) is in a source directory, so 'include' can't |
| 9 |
;; find ssax-test.scm with a relative pathname. OTOH, 'load' uses current |
| 10 |
;; directory for files starting with "./". |
| 11 |
(load "./ssax-test.scm") |
| 12 |
|
| 13 |
;(load "./tree-trans-test.scm") |
| 14 |
;(load "./to-html-test.scm") |
| 15 |
|
| 16 |
;; module consistency. |
| 17 |
|
| 18 |
(use gauche.test) |
| 19 |
|
| 20 |
(test-start "SXML auxiliary utilities") |
| 21 |
|
| 22 |
(test-section "sxml.tools") |
| 23 |
(use sxml.tools) |
| 24 |
(test-module 'sxml.tools) |
| 25 |
(use text.tree) |
| 26 |
|
| 27 |
(define (test-xml-html msg sxml xml-expect html-expect) |
| 28 |
(test* #"sxml:sxml->xml ~msg" xml-expect |
| 29 |
(tree->string (sxml:sxml->xml sxml))) |
| 30 |
(test* #"sxml:sxml->html ~msg" html-expect |
| 31 |
(tree->string (sxml:sxml->html sxml)))) |
| 32 |
|
| 33 |
;; Check rendering quirks |
| 34 |
;; https://github.com/shirok/Gauche-makiki/issues/11 |
| 35 |
(test-xml-html |
| 36 |
"attrs" |
| 37 |
'(body (div (@ (foo "") (bar "abc\"def") (baz:quux xyzzy)))) |
| 38 |
"<body><div foo=\"\" bar=\"abc"def\" baz:quux=\"xyzzy\"/></body>" |
| 39 |
"<body><div foo bar=\"abc"def\" baz:quux=\"xyzzy\"></div></body>") |
| 40 |
|
| 41 |
;; HTML void elements |
| 42 |
(test-xml-html |
| 43 |
"html void elements" |
| 44 |
'(div (img (@ (src "abc"))) (br) (hr)) |
| 45 |
"<div><img src=\"abc\"/><br/><hr/></div>" |
| 46 |
"<div><img src=\"abc\"><br><hr></div>") |
| 47 |
|
| 48 |
;; Check namespace prefix reassignment |
| 49 |
(test* "sxml:sxml->xml namespace" |
| 50 |
"<z:Item xmlns:z=\"https://example.com/defs\">\ |
| 51 |
<z:Serial>1234</z:Serial>\ |
| 52 |
<z:Serial>5678</z:Serial>\ |
| 53 |
</z:Item>" |
| 54 |
($ tree->string $ sxml:sxml->xml |
| 55 |
'(https://example.com/defs:Item |
| 56 |
(https://example.com/defs:Serial "1234") |
| 57 |
(https://example.com/defs:Serial "5678")) |
| 58 |
'((z . "https://example.com/defs")))) |
| 59 |
|
| 60 |
(test-section "sxml.sxpath") |
| 61 |
(use sxml.sxpath) |
| 62 |
(test-module 'sxml.sxpath) |
| 63 |
|
| 64 |
;; regression test for sxpath bug fix |
| 65 |
(let ((sxml '(*TOP* (rss:title "foo"))) |
| 66 |
(ns-alist '((my . "rss")))) |
| 67 |
(test* "ns-trans" '((rss:title "foo")) |
| 68 |
((sxpath "//my:title" ns-alist) sxml))) |
| 69 |
|
| 70 |
|
| 71 |
;; sxml.serializer test |
| 72 |
|
| 73 |
(test-section "sxml.serializer") |
| 74 |
(use sxml.serializer) |
| 75 |
(test-module 'sxml.serializer) |
| 76 |
|
| 77 |
(let ((testdata '(foo (@ (a "b") (c "d\"e'f")) (g "h" (i "j" (k)))))) |
| 78 |
(let-syntax |
| 79 |
((t (syntax-rules () ((t p r) (test* 'p r (p testdata)))))) |
| 80 |
(t srl:sxml->xml |
| 81 |
"<foo a=\"b\" c=\"d"e'f\">\n <g>h<i>j<k/></i></g>\n</foo>") |
| 82 |
(t srl:sxml->xml-noindent |
| 83 |
"<foo a=\"b\" c=\"d"e'f\"><g>h<i>j<k/></i></g></foo>") |
| 84 |
(t srl:sxml->html |
| 85 |
"<foo a=\"b\" c=\"d"e'f\">\n <g>h<i>j<k></k></i></g>\n</foo>") |
| 86 |
(t srl:sxml->html-noindent |
| 87 |
"<foo a=\"b\" c=\"d"e'f\"><g>h<i>j<k></k></i></g></foo>") |
| 88 |
)) |
| 89 |
|
| 90 |
(test-end) |