Skip to content

Commit

Permalink
Fixed bug in preprocessing that caused doctypes to be processed incor…
Browse files Browse the repository at this point in the history
…rectly
  • Loading branch information
mightybyte committed Dec 20, 2012
1 parent 9cc1188 commit 70e0cf5
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 42 deletions.
4 changes: 2 additions & 2 deletions src/Heist.hs
Original file line number Diff line number Diff line change
Expand Up @@ -178,8 +178,8 @@ initHeist (HeistConfig i lt c a rawTemplates) = do
hs0 = empty { _spliceMap = Map.fromList lt
, _templateMap = rawTemplates
, _preprocessingMode = True }
tPairs <- lift $ evalHeistT
(mapM preprocess $ Map.toList rawTemplates) (X.TextNode "") hs0
eval a = evalHeistT a (X.TextNode "") hs0
tPairs <- lift $ mapM (eval . preprocess) $ Map.toList rawTemplates
let bad = lefts tPairs
tmap = Map.fromList $ rights tPairs
hs1 = empty { _spliceMap = Map.fromList i
Expand Down
45 changes: 13 additions & 32 deletions test/suite/Heist/Interpreted/Tests.hs
Original file line number Diff line number Diff line change
Expand Up @@ -201,14 +201,12 @@ attrSubstTest = do
H.assertEqual str expected $ toByteString $ resDoc

out1 = B.unlines
[doctype
,"<mytag flag>Empty attribute</mytag>"
["<mytag flag>Empty attribute</mytag>"
,"<mytag flag='abc${foo}'>No ident capture</mytag>"
,"<div id='pre_meaning_of_everything_post'></div>"
]
out2 = B.unlines
[doctype
,"<mytag flag>Empty attribute</mytag>"
["<mytag flag>Empty attribute</mytag>"
,"<mytag flag='abc${foo}'>No ident capture</mytag>"
,"<div id='pre__post'></div>"
]
Expand All @@ -232,10 +230,8 @@ bindAttrTest = do

------------------------------------------------------------------------------
markdownHtmlExpected :: ByteString
markdownHtmlExpected = B.concat
[ doctype
, "<div class='markdown'><p>This <em>is</em> a test.</p></div>"
]
markdownHtmlExpected =
"<div class='markdown'><p>This <em>is</em> a test.</p></div>"

------------------------------------------------------------------------------
-- | Markdown test on a file
Expand All @@ -250,11 +246,9 @@ jsonValueTest = do
renderTest "json_snippet" jsonExpected2

where
jsonExpected1 = B.concat [ doctype
, "<i>&lt;b&gt;ok&lt;/b&gt;</i><i>1</i>"
jsonExpected1 = B.concat [ "<i>&lt;b&gt;ok&lt;/b&gt;</i><i>1</i>"
, "<i></i><i>false</i><i>foo</i>" ]
jsonExpected2 = B.concat
[doctype, "<i><b>ok</b></i><i>1</i><i></i><i>false</i><i>foo</i>"]
jsonExpected2 = "<i><b>ok</b></i><i>1</i><i></i><i>false</i><i>foo</i>"



Expand All @@ -263,9 +257,7 @@ jsonObjectTest :: H.Assertion
jsonObjectTest = do
renderTest "json_object" jsonExpected
where
jsonExpected = B.concat
[ doctype
, "<i>1</i><i><b>ok</b></i>12quuxquux1<b>ok</b>" ]
jsonExpected = "<i>1</i><i><b>ok</b></i>12quuxquux1<b>ok</b>"


------------------------------------------------------------------------------
Expand Down Expand Up @@ -305,10 +297,7 @@ renderTest templateName expectedResult = do
titleExpansion :: H.Assertion
titleExpansion = renderTest "title_expansion" expected
where
expected = B.concat
[ doctype
, "<title>foo</title>"
]
expected = "<title>foo</title>"


------------------------------------------------------------------------------
Expand All @@ -325,24 +314,20 @@ textareaExpansion = renderTest "textarea_expansion" expected
divExpansion :: H.Assertion
divExpansion = renderTest "div_expansion" expected
where
expected = B.concat
[ doctype
, "<div>foo</div>"
]
expected = "<div>foo</div>"


------------------------------------------------------------------------------
-- | Handling of <content> and bound parameters in a bound tag.
bindParam :: H.Assertion
bindParam = renderTest "bind_param" $
B.concat [doctype, "<li>Hi there world</li>"]
bindParam = renderTest "bind_param" "<li>Hi there world</li>"


------------------------------------------------------------------------------
-- | Handling of <content> and bound parameters in a bound tag.
attrSpliceContext :: H.Assertion
attrSpliceContext = renderTest "attrsubtest2" $
B.append doctype "<a href='asdf'>link</a><a href='before$after'>foo</a>"
attrSpliceContext = renderTest "attrsubtest2"
"<a href='asdf'>link</a><a href='before$after'>foo</a>"


------------------------------------------------------------------------------
Expand All @@ -355,11 +340,7 @@ markdownTextTest = do
hs
H.assertEqual "Markdown text" markdownHtmlExpected
(B.filter (/= '\n') $ toByteString $
X.render (X.HtmlDocument X.UTF8 (Just dt) result))
where
dt = X.DocType "html" (X.Public "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd")
X.NoInternalSubset
X.render (X.HtmlDocument X.UTF8 Nothing result))


------------------------------------------------------------------------------
Expand Down
12 changes: 4 additions & 8 deletions test/suite/Heist/Tests.hs
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,8 @@ attrSpliceTest = do
H.assertEqual "compiled bar" expected4
(toByteString builder2)
where
expected1 = doctype `B.append` "\n<input type='checkbox' value='foo' checked />\n<input type='checkbox' value='bar' />\n"
expected2 = doctype `B.append` "\n<input type='checkbox' value='foo' />\n<input type='checkbox' value='bar' checked />\n"
expected1 = "<input type='checkbox' value='foo' checked />\n<input type='checkbox' value='bar' />\n"
expected2 = "<input type='checkbox' value='foo' />\n<input type='checkbox' value='bar' checked />\n"
expected3 = "<input type=\"checkbox\" value=\"foo\" checked />&#10;<input type=\"checkbox\" value=\"bar\" />&#10;"
expected4 = "<input type=\"checkbox\" value=\"foo\" />&#10;<input type=\"checkbox\" value=\"bar\" checked />&#10;"

Expand Down Expand Up @@ -171,8 +171,7 @@ bindApplyInteractionTest = do
,"&#10;"
]
iExpected = B.unlines
[doctype
,"&#10;This is a test."
["&#10;This is a test."
,"===bind content==="
,"Another test line."
,"apply content"
Expand All @@ -193,8 +192,5 @@ backslashHandlingTest = do
H.assertEqual "interpreted failure" iExpected iOut
where
cExpected = "<foo regex='d+\\d'></foo>&#10;"
iExpected = B.unlines
[doctype
,"<foo regex='d+\\d'></foo>"
]
iExpected = "<foo regex='d+\\d'></foo>\n"

0 comments on commit 70e0cf5

Please sign in to comment.