{-# LANGUAGE QuasiQuotes #-} {-# LANGUAGE TemplateHaskell #-} module HamletTest (specs) where import Test.HUnit hiding (Test) import Test.Hspec import Test.Hspec.HUnit import Prelude hiding (reverse) import Text.Hamlet import Data.List (intercalate) import qualified Data.Text.Lazy as T import qualified Data.List import qualified Data.List as L import qualified Data.Map as Map import Data.Text (Text, pack, unpack) import Data.Monoid (mappend) import qualified Data.Set as Set import qualified Text.Blaze.Html.Renderer.Text import Text.Blaze.Html (toHtml) import Text.Blaze.Internal (preEscapedString) specs = describe "hamlet" [ it "empty" caseEmpty , it "static" caseStatic , it "tag" caseTag , it "var" caseVar , it "var chain " caseVarChain , it "url" caseUrl , it "url chain " caseUrlChain , it "embed" caseEmbed , it "embed chain " caseEmbedChain , it "if" caseIf , it "if chain " caseIfChain , it "else" caseElse , it "else chain " caseElseChain , it "elseif" caseElseIf , it "elseif chain " caseElseIfChain , it "list" caseList , it "list chain" caseListChain , it "with" caseWith , it "with multi" caseWithMulti , it "with chain" caseWithChain , it "with comma string" caseWithCommaString , it "with multi scope" caseWithMultiBindingScope , it "script not empty" caseScriptNotEmpty , it "meta empty" caseMetaEmpty , it "input empty" caseInputEmpty , it "multiple classes" caseMultiClass , it "attrib order" caseAttribOrder , it "nothing" caseNothing , it "nothing chain " caseNothingChain , it "just" caseJust , it "just chain " caseJustChain , it "constructor" caseConstructor , it "url + params" caseUrlParams , it "escape" caseEscape , it "empty statement list" caseEmptyStatementList , it "attribute conditionals" caseAttribCond , it "non-ascii" caseNonAscii , it "maybe function" caseMaybeFunction , it "trailing dollar sign" caseTrailingDollarSign , it "non leading percent sign" caseNonLeadingPercent , it "quoted attributes" caseQuotedAttribs , it "spaced derefs" caseSpacedDerefs , it "attrib vars" caseAttribVars , it "strings and html" caseStringsAndHtml , it "nesting" caseNesting , it "trailing space" caseTrailingSpace , it "currency symbols" caseCurrency , it "external" caseExternal , it "parens" caseParens , it "hamlet literals" caseHamletLiterals , it "hamlet' and xhamlet'" caseHamlet' , it "comments" $ do -- FIXME reconsider Hamlet comment syntax? helper "" [hamlet|$# this is a comment $# another comment $#a third one|] , it "ignores a blank line" $ do helper "
foo
" [hamlet|foo |] , it "hamlet angle bracket syntax" $ helper "
HELLO
" [hamlet|Text
|] -} , it "string literals" $ do helper "string" [hamlet|#{"string"}|] helper "string" [hamlet|#{id "string"}|] helper "gnirts" [hamlet|#{L.reverse $ id "string"}|] helper "str"ing" [hamlet|#{"str\"ing"}|] helper "str<ing" [hamlet|#{"str2 not ignored
" [hamlet|1
2 not ignored |] , it "nested maybes" $ do let muser = Just "User" :: Maybe String mprof = Nothing :: Maybe Int m3 = Nothing :: Maybe String helper "justnothing" [hamlet| $maybe user <- muser $maybe profile <- mprof First two are Just $maybe desc <- m3 \ and left us a description:
#{desc} $nothing and has left us no description. $nothing justnothing $nothing
|] helper "
" [hamlet||] helper "
" [hamlet||] , it "forall on Foldable" $ do let set = Set.fromList [1..5 :: Int] helper "12345" [hamlet| $forall x <- set #{x} |] , it "non-poly HTML" $ do helperHtml "
EMBEDDED|] helper "
EMBEDDED
" [hamlet|EMBEDDED|] ihelper "
EMBEDDED
" [ihamlet|<#bar>baz |] helper "