on master help sign in
Improve the test driver
b17e7ebNeil Mitchell
src/Main.hs+3−1
@@ -14,6 +14,8 @@ examples =
14 [(True, "<test id=bob>here<extra/>there</test>")
14 [(True, "<test id=bob>here<extra/>there</test>")
15 ,(True, "<test /><close />")
15 ,(True, "<test /><close />")
16 ,(True, "<test id=\"bob value\" another-attr=\"test with <\">here </test> more text at the end<close />")
16 ,(True, "<test id=\"bob value\" another-attr=\"test with <\">here </test> more text at the end<close />")
17+ ,(False, "<test></more>")
18+ ,(False, "<test")
17 ]
19 ]
18
20
19main :: IO ()
21main :: IO ()
@@ -41,7 +43,7 @@ rerender = contents . documentNode
41 "</" <> nodeName x <> ">"
43 "</" <> nodeName x <> ">"
42 attr (Attribute a b) = validName a <> "=\"" <> validAttr b <> "\""
44 attr (Attribute a b) = validName a <> "=\"" <> validAttr b <> "\""
43
45
44− validName x | BS.all (\x -> isAlpha x) x = x
46+ validName x | BS.all (\x -> isAlphaNum x || x `elem` ("-:_" :: String)) x = x
45 | otherwise = error "Invalid name"
47 | otherwise = error "Invalid name"
46 validAttr x | BS.notElem '\"' x = x
48 validAttr x | BS.notElem '\"' x = x
47 | otherwise = error "Invalid attribute"
49 | otherwise = error "Invalid attribute"