(import test)
(import html-parser)
(test-begin "html-parser")
(define (string-scan str pat)
(string-length ((make-string-reader/ci pat) (open-input-string str))))
(test-group "utilities"
(test "string-scan (basic)" 3 (string-scan "abcdefghi" "def"))
(test "string-scan (case-insensitive)" 3 (string-scan "abcdEfghi" "deF"))
(test "string-scan (single char)" 4 (string-scan "abcdefghi" "e"))
(test "string-scan (overlap)" 12
(string-scan "salkabcdabghabcdabdef" "abcdabd"))
(test "string-scan (boyer-moore)" 216
(string-scan "abracadababrabrabrabracadababrabrabrabracadababrabrabrabracadababrabrabrabracadababrabrabrabracadababrabrabrabracadababrabrabrabracadababrabrabrabracadababrabrabrabracadababrabrabrabracadababrabrabrabracadababrabrabrabracadabrabracadababrabrabrabracadababrabrabrabracadababrabrabrabracadababrabrabrabracadababrabrabrabracadababrabrabrabracadababrabrabrabracadababrabrabr"
"abracadabra"))
(test "string-scan (empty pattern)" 0
(string-scan "abakjrgaker" ""))
)
(test-group "parsing"
(test '(*TOP* (a (@ (href "http://foo.scm/")) "foo"))
(html->sxml "foo"))
(test '(*TOP* (a "a" (b "ab") "a" (c "ac")) "x")
(html->sxml "aaba
p1
p2
p3"))
(test '(*TOP* (i "italic" (b "bold italic")) (b "bold"))
(html->sxml "italicbold italicbold"))
(test '(*TOP* (*PI* xml "blah blah"))
(html->sxml ""))
(test '(*TOP* (*DECL* DOCTYPE HTML PUBLIC "-//W3C//DTD HTML&4.0//EN"))
(html->sxml ""))
(test '(*TOP* "abc" (*COMMENT* "def") "ghi")
(html->sxml "abcghi"))
(test '(*TOP* (pre "&"))
(html->sxml "&]]>
"))
(test '(*TOP* (xmp "&"))
(html->sxml "