Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Testfix #4

Closed
wants to merge 3 commits into from

1 participant

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
This page is out of date. Refresh to see the latest.
Showing with 32 additions and 8 deletions.
  1. +32 −8 test/suite/Text/Templating/Heist/Tests.hs
View
40 test/suite/Text/Templating/Heist/Tests.hs
@@ -30,6 +30,7 @@ import Text.Templating.Heist
import Text.Templating.Heist.Internal
import Text.Templating.Heist.Types
import Text.Templating.Heist.Splices.Apply
+import Text.Templating.Heist.Splices.Ignore
import Text.XML.Expat.Cursor
import Text.XML.Expat.Format
import qualified Text.XML.Expat.Tree as X
@@ -41,6 +42,7 @@ tests = [ testProperty "heist/simpleBind" simpleBindTest
, testProperty "heist/simpleApply" simpleApplyTest
, testCase "heist/stateMonoid" monoidTest
, testCase "heist/templateAdd" addTest
+ , testCase "heist/hasTemplate" hasTemplateTest
, testCase "heist/getDoc" getDocTest
, testCase "heist/load" loadTest
, testCase "heist/fsLoad" fsLoadTest
@@ -50,6 +52,7 @@ tests = [ testProperty "heist/simpleBind" simpleBindTest
, testCase "heist/bindAttribute" bindAttrTest
, testCase "heist/markdown" markdownTest
, testCase "heist/apply" applyTest
+ , testCase "heist/ignore" ignoreTest
]
@@ -100,6 +103,15 @@ addTest = do
------------------------------------------------------------------------------
+hasTemplateTest :: H.Assertion
+hasTemplateTest = do
+ ets <- loadT "templates"
+ let tm = either (error "Error loading templates") _templateMap ets
+ let ts = setTemplates tm emptyTemplateState :: TemplateState IO
+ H.assertBool "hasTemplate ts" (hasTemplate "index" ts)
+
+
+------------------------------------------------------------------------------
getDocTest :: H.Assertion
getDocTest = do
d <- getDoc "bkteoar"
@@ -180,6 +192,7 @@ bindAttrTest = do
ets <- loadT "templates"
let ts = either (error "Error loading templates") id ets
check ts "<div id=\"zzzzz\""
+
where
check ts str = do
res <- renderTemplate ts "bind-attrs"
@@ -188,13 +201,13 @@ bindAttrTest = do
H.assertBool ("attr subst bar") $
B.null $ snd $ B.breakSubstring "$(bar)" $ fromJust res
-
+
------------------------------------------------------------------------------
markdownTest :: H.Assertion
markdownTest = do
ets <- loadT "templates"
let ts = either (error "Error loading templates") id ets
-
+
check ts "<div class=\"markdown\"><p>This <em>is</em> a test.</p></div>"
where
@@ -210,8 +223,18 @@ applyTest = do
let es = emptyTemplateState :: TemplateState IO
res <- evalTemplateMonad applyImpl
(X.Element "apply" [("template", "nonexistant")] []) es
- H.assertEqual "apply nothing" res []
-
+ H.assertEqual "apply nothing" [] res
+
+
+------------------------------------------------------------------------------
+ignoreTest :: H.Assertion
+ignoreTest = do
+ let es = emptyTemplateState :: TemplateState IO
+ res <- evalTemplateMonad ignoreImpl
+ (X.Element "ignore" [("tag", "ignorable")]
+ [X.Text "This should be ignored"]) es
+ H.assertEqual "<ignore> tag" [] res
+
------------------------------------------------------------------------------
-- Utility functions
@@ -279,7 +302,7 @@ insertAt elems n list = maybe [] (toForest . root) $
------------------------------------------------------------------------------
move :: Insert ()
-move = modify (\x -> x-1)
+move = modify (\x -> x - 1)
------------------------------------------------------------------------------
@@ -360,8 +383,8 @@ instance Arbitrary Bind where
kids <- liftM (take 3) arbitrary
doc <- liftM (take 5) arbitrary
let s = insSize doc
- loc <- choose (0, s-1)
- loc2 <- choose (0, s-loc-1)
+ loc <- choose (0, s - 1)
+ loc2 <- choose (0, s - loc - 1)
return $ Bind name kids doc loc loc2
shrink (Bind e [c] (_:ds) p r) = [Bind e [c] ds p r]
shrink (Bind e (_:cs) d p r) = [Bind e cs d p r]
@@ -438,7 +461,7 @@ instance Arbitrary Apply where
caller <- liftM (take 5) arbitrary
callee <- liftM (take 1) $ listOf $ limitedDepth 3
let s = insSize caller
- loc <- choose (0, s-1)
+ loc <- choose (0, s - 1)
return $ Apply name caller callee kids loc
@@ -458,6 +481,7 @@ calcResult :: (MonadIO m) => Apply -> m [Node]
calcResult apply@(Apply name _ callee _ _) =
evalTemplateMonad (runNodeList $ buildApplyCaller apply)
(X.Text "") ts
+
where ts = setTemplates (Map.singleton [unName name]
(InternalTemplate Nothing callee))
emptyTemplateState
Something went wrong with that request. Please try again.