{-# LANGUAGE QuasiQuotes #-}
import Test.Framework (defaultMain, testGroup, Test)
import Test.Framework.Providers.HUnit
import Test.HUnit hiding (Test)
import qualified Text.Hamlet.Parse
import Text.Hamlet
import Data.ByteString.UTF8 (fromString)
import Data.ByteString.Lazy.UTF8 (toString)
main :: IO ()
main = defaultMain
[ Text.Hamlet.Parse.testSuite
, testSuite
]
testSuite :: Test
testSuite = testGroup "Text.Hamlet"
[ testCase "empty" caseEmpty
, testCase "static" caseStatic
, testCase "tag" caseTag
, testCase "var" caseVar
, testCase "var chain " caseVarChain
, testCase "url" caseUrl
, testCase "url chain " caseUrlChain
, testCase "embed" caseEmbed
, testCase "embed chain " caseEmbedChain
, testCase "if" caseIf
, testCase "if chain " caseIfChain
, testCase "else" caseElse
, testCase "else chain " caseElseChain
, testCase "elseif" caseElseIf
, testCase "elseif chain " caseElseIfChain
, testCase "list" caseList
, testCase "list chain" caseListChain
, testCase "script not empty" caseScriptNotEmpty
, testCase "meta empty" caseMetaEmpty
, testCase "input empty" caseInputEmpty
, testCase "multiple classes" caseMultiClass
, testCase "attrib order" caseAttribOrder
, testCase "nothing" caseNothing
, testCase "nothing chain " caseNothingChain
, testCase "just" caseJust
, testCase "just chain " caseJustChain
, testCase "constructor" caseConstructor
, testCase "url + params" caseUrlParams
, testCase "escape" caseEscape
, testCase "empty statement list" caseEmptyStatementList
, testCase "attribute conditionals" caseAttribCond
, testCase "non-ascii" caseNonAscii
, testCase "maybe function" caseMaybeFunction
, testCase "trailing dollar sign" caseTrailingDollarSign
]
data Url = Home | Sub SubUrl
data SubUrl = SubUrl
render :: Url -> String
render Home = "url"
render (Sub SubUrl) = "suburl"
data Arg url = Arg
{ getArg :: Arg url
, var :: Html ()
, url :: Url
, embed :: Hamlet url
, true :: Bool
, false :: Bool
, list :: [Arg url]
, nothing :: Maybe (Html ())
, just :: Maybe (Html ())
, urlParams :: (Url, [(String, String)])
}
theArg :: Arg url
theArg = Arg
{ getArg = theArg
, var = string ""
, url = Home
, embed = [$hamlet|embed|]
, true = True
, false = False
, list = [theArg, theArg, theArg]
, nothing = Nothing
, just = Just $ string "just"
, urlParams = (Home, [("foo", "bar"), ("foo1", "bar1")])
}
helper :: String -> Hamlet Url -> Assertion
helper res h = do
let x = renderHamlet render h
res @=? toString x
caseEmpty :: Assertion
caseEmpty = helper "" [$hamlet||]
caseStatic :: Assertion
caseStatic = helper "some static content" [$hamlet|some static content|]
caseTag :: Assertion
caseTag = helper "