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.
16 module TSN.XML.Injuries (
22 import Data.Tuple.Curry ( uncurryN )
23 import Database.Groundhog()
24 import Database.Groundhog.TH (
28 import Test.Tasty ( TestTree, testGroup )
29 import Test.Tasty.HUnit ( (@?=), testCase )
30 import Text.XML.HXT.Core (
42 import TSN.DbImport ( DbImport(..), import_generic )
43 import Xml ( pickle_unpickle )
60 listings :: [Listing],
61 time_stamp :: String }
65 mkPersist defaultCodegenConfig [groundhog|
71 pickle_listing :: PU Listing
74 xpWrap (from_tuple, to_tuple) $
75 xp4Tuple (xpElem "team" xpText)
76 (xpElem "teamno" xpPrim)
77 (xpElem "injuries" xpText)
78 (xpElem "updated" xpPrim)
80 from_tuple = uncurryN Listing
81 to_tuple l = (team l, teamno l, injuries l, updated l)
83 instance XmlPickler Listing where
84 xpickle = pickle_listing
87 pickle_message :: PU Message
90 xpWrap (from_tuple, to_tuple) $
91 xp6Tuple (xpElem "XML_File_ID" xpPrim)
92 (xpElem "heading" xpText)
93 (xpElem "category" xpText)
94 (xpElem "sport" xpText)
95 (xpList pickle_listing)
96 (xpElem "time_stamp" xpText)
98 from_tuple = uncurryN Message
99 to_tuple m = (xml_file_id m,
106 instance XmlPickler Message where
107 xpickle = pickle_message
111 instance DbImport Listing where
112 dbimport = import_generic listings
115 injuries_tests :: TestTree
119 [ test_pickle_of_unpickle_is_identity ]
122 test_pickle_of_unpickle_is_identity :: TestTree
123 test_pickle_of_unpickle_is_identity =
124 testCase "pickle composed with unpickle is the identity" $ do
125 let path = "test/xml/injuriesxml.xml"
126 (expected :: [Message], actual) <- pickle_unpickle "message" path