{-# language BangPatterns #-} {-# language MultiWayIf #-} {-# language NumDecimals #-} {-# language OverloadedLists #-} {-# language OverloadedStrings #-} {-# language ScopedTypeVariables #-} {-# language TypeApplications #-} import Xml import Test.Tasty (defaultMain,testGroup,TestTree) import Test.Tasty.HUnit ((@=?),testCase) import qualified Data.Bytes as Bytes main :: IO () main = defaultMain tests decodeString :: String -> Maybe Node decodeString = Xml.decode . Bytes.fromAsciiString tests :: TestTree tests = testGroup "xml" [ testCase "A" $ Just ( Element Content { tag = "foo" , attributes = mempty , children = [Text "hello"] } ) @=? decodeString "hello" , testCase "B" $ Just ( Element Content { tag = "foo" , attributes = [Attribute "bar" "baz"] , children = [Text "hi"] } ) @=? decodeString "hi" , testCase "C" $ Just ( Element Content { tag = "foo" , attributes = [Attribute "bar" "baz"] , children = [Text "hi"] } ) @=? decodeString "hi" , testCase "D" $ Just ( Element Content { tag = "foo" , attributes = [Attribute "bar" "baz"] , children = mempty } ) @=? decodeString "" , testCase "E" $ Just ( Element Content { tag = "foo" , attributes = mempty , children = [Text "hello"] } ) @=? decodeString "hello" , testCase "F" $ Just ( Element Content { tag = "foo" , attributes = [Attribute "bar" "baz"] , children = [ Text " " , Element Content{tag="hey",attributes=mempty,children=mempty} , Text " " , Element Content{tag="hi",attributes=mempty,children=mempty} ] } ) @=? decodeString " " ]