1 {-# LANGUAGE FlexibleInstances #-}
3 {-# LANGUAGE QuasiQuotes #-}
4 {-# LANGUAGE ScopedTypeVariables #-}
5 {-# LANGUAGE StandaloneDeriving #-}
6 {-# LANGUAGE TemplateHaskell #-}
7 {-# LANGUAGE TypeFamilies #-}
9 -- | Parse TSN XML for the DTD "injuriesxml.dtd". Each document
10 -- contains a root element \<message\> that in turn contains zero or
13 -- The listings will be mapped to a database table called "injuries"
14 -- automatically. The root message is not retained.
22 import Data.Tuple.Curry ( uncurryN )
23 import Database.Groundhog()
24 import Database.Groundhog.TH
25 import Test.Tasty ( TestTree, testGroup )
26 import Test.Tasty.HUnit ( (@?=), testCase )
27 import Text.XML.HXT.Core (
39 import Xml ( pickle_unpickle )
56 listings :: [Listing],
57 time_stamp :: String }
61 mkPersist defaultCodegenConfig [groundhog|
67 pickle_listing :: PU Listing
70 xpWrap (from_tuple, to_tuple) $
71 xp4Tuple (xpElem "team" xpText)
72 (xpElem "teamno" xpPrim)
73 (xpElem "injuries" xpText)
74 (xpElem "updated" xpPrim)
76 from_tuple = uncurryN Listing
77 to_tuple l = (team l, teamno l, injuries l, updated l)
79 instance XmlPickler Listing where
80 xpickle = pickle_listing
83 pickle_message :: PU Message
86 xpWrap (from_tuple, to_tuple) $
87 xp6Tuple (xpElem "XML_File_ID" xpPrim)
88 (xpElem "heading" xpText)
89 (xpElem "category" xpText)
90 (xpElem "sport" xpText)
91 (xpList pickle_listing)
92 (xpElem "time_stamp" xpText)
94 from_tuple = uncurryN Message
95 to_tuple m = (xml_file_id m,
102 instance XmlPickler Message where
103 xpickle = pickle_message
108 injuries_tests :: TestTree
112 [ test_pickle_of_unpickle_is_identity ]
115 test_pickle_of_unpickle_is_identity :: TestTree
116 test_pickle_of_unpickle_is_identity =
117 testCase "pickle composed with unpickle is the identity" $ do
118 let path = "test/xml/injuriesxml.xml"
119 (expected :: [Message], actual) <- pickle_unpickle "message" path