source: project/release/4/html-parser/tags/0.5.7/test.scm @ 33366

Last change on this file since 33366 was 33366, checked in by Alex Shinn, 5 years ago

fixing bug in unterminated attributes (reported by alaric)

File size: 2.5 KB
Line 
1
2(use test)
3(load "html-parser.scm")
4(import html-parser)
5
6(test-begin "html-parser")
7
8(define (string-scan str pat)
9  (string-length ((make-string-reader/ci pat) (open-input-string str))))
10
11(test-group "utilities"
12
13(test "string-scan (basic)" 3 (string-scan "abcdefghi" "def"))
14
15(test "string-scan (case-insensitive)" 3 (string-scan "abcdEfghi" "deF"))
16
17(test "string-scan (single char)" 4 (string-scan "abcdefghi" "e"))
18
19(test "string-scan (overlap)" 12
20  (string-scan "salkabcdabghabcdabdef" "abcdabd"))
21
22(test "string-scan (boyer-moore)" 216
23       (string-scan "abracadababrabrabrabracadababrabrabrabracadababrabrabrabracadababrabrabrabracadababrabrabrabracadababrabrabrabracadababrabrabrabracadababrabrabrabracadababrabrabrabracadababrabrabrabracadababrabrabrabracadababrabrabrabracadabrabracadababrabrabrabracadababrabrabrabracadababrabrabrabracadababrabrabrabracadababrabrabrabracadababrabrabrabracadababrabrabrabracadababrabrabr"
24                    "abracadabra"))
25
26(test "string-scan (empty pattern)" 0
27       (string-scan "abakjrgaker" ""))
28
29)
30
31(test-group "parsing"
32
33(test '(*TOP* (a (@ (href "http://foo.scm/")) "foo"))
34    (html->sxml "<a href=\"http://foo.scm/\">foo</a>"))
35
36(test '(*TOP* (a "a" (b "ab") "a" (c "ac")) "x")
37    (html->sxml "<a>a<b>ab</b>a<c>ac</c></a>x"))
38
39(test '(*TOP* (p "p1") (p "p2") (p "p3"))
40    (html->sxml "<p>p1<p>p2</p><p>p3"))
41
42(test '(*TOP* (i "italic" (b "bold italic")) (b "bold"))
43    (html->sxml "<i>italic<b>bold italic</i>bold</b>"))
44
45(test '(*TOP* (*PI* xml "blah blah"))
46    (html->sxml "<?xml blah blah?>"))
47
48(test '(*TOP* (*DECL* DOCTYPE HTML PUBLIC "-//W3C//DTD HTML&4.0//EN"))
49    (html->sxml "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML&amp;4.0//EN\"!>"))
50
51(test '(*TOP* "abc" (*COMMENT* "def") "ghi")
52    (html->sxml "abc<!--def-->ghi"))
53
54(test '(*TOP* (pre "<a>&amp;<!--foo-->"))
55    (html->sxml "<pre><![CDATA[<a>&amp;<!--foo-->]]></pre>"))
56
57(test '(*TOP* (xmp "<a>&amp;<!--foo--><![CDATA[...]]></a>"))
58    (html->sxml "<xmp><a>&amp;<!--foo--><![CDATA[...]]></a></xmp>"))
59
60(test '(*TOP* (b (@ (id "&")) "&"))
61    (html->sxml "<b id=\"&amp;\">&amp;</b>"))
62
63(test '(*TOP* (foo (@ (bar "&x"))))
64    (html->sxml "<foo bar=\"&x\" />"))
65
66(test '(*TOP* (foo (@ (bar))))
67    (html->sxml "<foo bar></foo>"))
68
69(test '(*TOP* (div (@ (data "")) "empty"))
70    (html->sxml "<div data=\"\">empty</div>"))
71
72(test '(*TOP* (br) "\r\n" (br) "\r\n" (div (@ (data "(sxml (@ (attr \"12345\")) body)")) "div body"))
73    (html->sxml "<br>\r\n<br>\r\n<div data=\"(sxml (@ (attr &quot;12345&quot;)) body)\">div body</div>"))
74
75)
76
77(test-end)
Note: See TracBrowser for help on using the repository browser.