{-# LANGUAGE QuasiQuotes #-} {-# LANGUAGE TemplateHaskell #-} module Text.Shakespeare.HamletSpec (spec) where import HamletTestTypes (ARecord(..)) import Test.HUnit hiding (Test) import Test.Hspec hiding (Arg) import Prelude hiding (reverse) import Text.Hamlet import Text.Hamlet.RT 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,mconcat) import qualified Data.Set as Set import qualified Text.Blaze.Html.Renderer.Text import Text.Blaze.Html (toHtml) import Text.Blaze.Internal (preEscapedString) import Text.Blaze spec = do describe "hamlet" $ do 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 "hamlet tuple" caseTuple it "complex pattern" caseComplex it "record pattern" caseRecord it "record wildcard pattern #1" caseRecordWildCard it "record wildcard pattern #2" caseRecordWildCard1 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
\n" [hamlet|foo |] it "angle bracket syntax" $ helper "
HELLO
" [hamlet| $newline neverText
|] -} 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| $newline never1
2 not ignored |] it "Keeps SSI includes" $ helper "" [hamlet||] 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 "
\n" [hamlet||] helper "
\n" [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
\n" [hamlet|EMBEDDED|] ihelper "
EMBEDDED
\n" [ihamlet|