1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74
|
{-# LANGUAGE OverloadedLists #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE QuasiQuotes #-}
module Main where
import Data.Text (Text)
import Test.Tasty (TestTree, defaultMain, testGroup)
import Test.Tasty.HUnit ((@?=), testCase)
import Text.XML
(Document(..), Element(..), Name(..), Node(..), Prologue(..))
import Text.XML.QQ (xmlRaw, xmlUnsafe)
main :: IO ()
main = defaultMain tests
tests :: TestTree
tests = testGroup "tests" [xmlTests]
xmlTests :: TestTree
xmlTests = testGroup "xml" [xmlUnsafeTests, xmlRawTests]
xmlUnsafeTests :: TestTree
xmlUnsafeTests = testGroup "xmlUnsafe" [xmlUnsafeWorksCorrectly]
xmlUnsafeWorksCorrectly :: TestTree
xmlUnsafeWorksCorrectly = testCase "works correctly" $ doc @?= expectedDoc
where
doc :: Document
doc =
let a = "hello" :: Text
in [xmlUnsafe|<html>#{a}</html>|]
expectedDoc :: Document
expectedDoc =
Document
{ documentPrologue =
Prologue
{prologueBefore = [], prologueDoctype = Nothing, prologueAfter = []}
, documentRoot =
Element
{ elementName =
Name
{ nameLocalName = "html"
, nameNamespace = Nothing
, namePrefix = Nothing
}
, elementAttributes = mempty
, elementNodes = [NodeContent "hello"]
}
, documentEpilogue = []
}
xmlRawTests :: TestTree
xmlRawTests = testGroup "xmlRaw" [xmlRawWorksCorrectly]
xmlRawWorksCorrectly :: TestTree
xmlRawWorksCorrectly = testCase "works correctly" $ doc @?= expectedDoc
where
doc :: Document
doc = [xmlRaw|<html></html>|]
expectedDoc :: Document
expectedDoc =
Document
{ documentPrologue =
Prologue
{prologueBefore = [], prologueDoctype = Nothing, prologueAfter = []}
, documentRoot =
Element
{elementName = "html", elementAttributes = mempty, elementNodes = []}
, documentEpilogue = []
}
|