Skip to content

Loading…

some failing test cases #9

Merged
3 commits merged into from

2 participants

@sol

Starting with heist 0.5 it is no longer possible to use bound names in title- or textarea-tags. I guess this is due to the usage of parseHTML (from xmlhtml), which (according to src/Text/XmlHtml/HTML/Parse.hs:50) treats the content of title- and textarea-tags differently.

The attached code explains in detail what I mean.

Is this considered a bug? And if no, how would you deal with page titles or content of text areas that are determined at runtime?

sol added some commits
@sol sol Factor out reusable code from markdownTest
With this it is easy to add more tests of that kind.
90d20a6
@sol sol Add a failing test case
It shows that expansion of bound names inside a title-tag does not work.
067dede
@sol sol Add a failing test case
It shows that expansion of bound names inside a textarea-tag does not
work.
ea39123
@mightybyte
Snap Framework member

I pulled and applied this. Sorry for the delay. Thanks for the contribution.

This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Feb 13, 2011
  1. @sol

    Factor out reusable code from markdownTest

    sol committed
    With this it is easy to add more tests of that kind.
  2. @sol

    Add a failing test case

    sol committed
    It shows that expansion of bound names inside a title-tag does not work.
  3. @sol

    Add a failing test case

    sol committed
    It shows that expansion of bound names inside a textarea-tag does not
    work.
This page is out of date. Refresh to see the latest.
View
29 test/suite/Text/Templating/Heist/Tests.hs
@@ -55,6 +55,8 @@ tests = [ testProperty "heist/simpleBind" simpleBindTest
, testCase "heist/attributeSubstitution" attrSubstTest
, testCase "heist/bindAttribute" bindAttrTest
, testCase "heist/markdown" markdownTest
+ , testCase "heist/title_expansion" titleExpansion
+ , testCase "heist/textarea_expansion" textareaExpansion
, testCase "heist/markdownText" markdownTextTest
, testCase "heist/apply" applyTest
, testCase "heist/ignore" ignoreTest
@@ -131,7 +133,7 @@ loadTest = do
ets <- loadT "templates"
either (error "Error loading templates")
(\ts -> do let tm = _templateMap ts
- H.assertBool "loadTest size" $ Map.size tm == 17
+ H.assertBool "loadTest size" $ Map.size tm == 19
) ets
@@ -218,20 +220,39 @@ htmlExpected = "<div class=\'markdown\'><p>This <em>is</em> a test.</p></div>"
------------------------------------------------------------------------------
-- | Markdown test on a file
markdownTest :: H.Assertion
-markdownTest = do
+markdownTest = renderTest "markdown" htmlExpected
+
+
+-- | Render a template and assert that it matches an expected result
+renderTest :: ByteString -- ^ template name
+ -> ByteString -- ^ expected result
+ -> H.Assertion
+renderTest templateName expectedResult = do
ets <- loadT "templates"
let ts = either (error "Error loading templates") id ets
- check ts htmlExpected
+ check ts expectedResult
where
check ts str = do
- Just (doc, mime) <- renderTemplate ts "markdown"
+ Just (doc, _) <- renderTemplate ts templateName
let result = B.filter (/= '\n') (toByteString doc)
H.assertEqual ("Should match " ++ (show str)) str result
------------------------------------------------------------------------------
+-- | Expansion of a bound name inside a title-tag
+titleExpansion :: H.Assertion
+titleExpansion = renderTest "title_expansion" "<title>foo</title>"
+
+
+------------------------------------------------------------------------------
+-- | Expansion of a bound name inside a textarea-tag
+textareaExpansion :: H.Assertion
+textareaExpansion = renderTest "textarea_expansion" "<textarea>foo</textarea>"
+
+
+------------------------------------------------------------------------------
-- | Markdown test on supplied text
markdownTextTest :: H.Assertion
markdownTextTest = do
View
1 test/templates/textarea_expansion.tpl
@@ -0,0 +1 @@
+<bind tag="mytext">foo</bind><textarea><mytext/></textarea>
View
1 test/templates/title_expansion.tpl
@@ -0,0 +1 @@
+<bind tag="mytext">foo</bind><title><mytext/></title>
Something went wrong with that request. Please try again.