{-# LANGUAGE QuasiQuotes #-} {-# LANGUAGE OverloadedStrings #-} import Text.Hamlet.XML import qualified Text.XML as X import Test.HUnit import Test.Hspec import Test.Hspec.HUnit () main :: IO () main = hspecX $ describe "xml-hamlet" [ it "handles plain tags" $ [xml| bin |] @?= [ X.NodeElement $ X.Element "foo" [] [ X.NodeElement $ X.Element "baz" [] [ X.NodeContent "bin" ] ] ] , it "handles variables" $ [xml| #{bin} |] @?= [ X.NodeElement $ X.Element "foo" [] [ X.NodeElement $ X.Element "baz" [] [ X.NodeContent "bin" ] ] ] , it "handles embed" $ [xml| ^{nodes} |] @?= [ X.NodeElement $ X.Element "foo" [] [ X.NodeElement $ X.Element "baz" [] nodes ] ] , it "handles attributes" $ [xml| #{x} |] @?= [ X.NodeElement $ X.Element "word" [] [X.NodeContent "foo"] , X.NodeElement $ X.Element "word" [] [X.NodeContent "bar"] , X.NodeElement $ X.Element "word" [] [X.NodeContent "baz"] ] , it "handles with" $ [xml| $with ys <- xs $forall x <- ys #{x} |] @?= [ X.NodeElement $ X.Element "word" [] [X.NodeContent "foo"] , X.NodeElement $ X.Element "word" [] [X.NodeContent "bar"] , X.NodeElement $ X.Element "word" [] [X.NodeContent "baz"] ] , it "handles maybe" $ [xml| $maybe _x <- Just five $nothing $maybe _x <- Nothing $nothing |] @?= [ X.NodeElement $ X.Element "one" [] [] , X.NodeElement $ X.Element "four" [] [] ] , it "handles conditionals" $ [xml| $if True $else $if False $elseif True $if False $elseif False $else |] @?= [ X.NodeElement $ X.Element "one" [] [] , X.NodeElement $ X.Element "four" [] [] , X.NodeElement $ X.Element "seven" [] [] ] , it "recognizes clark notation" $ [xml| <{foo}bar {baz}bin="x" |] @?= [X.NodeElement $ X.Element "{foo}bar" [("{baz}bin", "x")] []] , it "recognizes clark with URLs" $ [xml| <{http://www.example.com/foo/bar}baz> |] @?= [X.NodeElement $ X.Element "{http://www.example.com/foo/bar}baz" [] []] , it "allow embedding comments" $[xml|^{comment}|] @?= comment ] where bin = "bin" nodes = [X.NodeInstruction $ X.Instruction "ifoo" "ibar"] true = "true" xs = ["foo", "bar", "baz"] comment = [X.NodeComment "somecomment"] five :: Int five = 5