--
module TSN.XML.GameInfo (
dtds,
- gameinfo_tests,
+ game_info_tests,
parse_xml,
-- * WARNING: these are private but exported to silence warnings
GameInfoConstructor(..) )
-- System imports.
import Data.Either ( rights )
+import Data.String.Utils ( replace )
import Data.Time.Clock ( UTCTime )
import Database.Groundhog (
countAll,
unsafe_read_document )
--- | The DTDs for everything that we consider "Game Info."
+-- | The DTDs for everything that we consider \"Game Info.\"
--
-- TODO: This is the list from the old implementation. We need to
-- make sure that we are really receiving XML for these DTDs
"Matchup_NBA_NHL_XML.dtd",
"mlbpreviewxml.dtd",
"MLB_Gaming_Matchup_XML.dtd",
- "MLB.dtd", -- missing DTD
"MLB_Lineup_XML.dtd",
"MLB_Matchup_XML.dtd",
"MLS_Preview_XML.dtd",
"NBA_Gaming_Matchup_XML.dtd",
- "NBA.dtd", -- missing DTD
"NBA_Playoff_Matchup_XML.dtd",
"NBALineupXML.dtd",
"nbapreviewxml.dtd",
- "NCAA_FB_Preview_XML.dtd", -- missing DTD
- "nflpreviewxml.dtd", -- missing DTD
- "NFL_NCAA_FB_Matchup_XML.dtd", -- missing DTD
+ "NCAA_FB_Preview_XML.dtd",
+ "nflpreviewxml.dtd",
+ "NFL_NCAA_FB_Matchup_XML.dtd",
"nhlpreviewxml.dtd",
"recapxml.dtd",
- "WorldBaseballPreviewXML.dtd" -- missing DTD
- ]
+ "WorldBaseballPreviewXML.dtd" ]
-- | XML representation of a GameInfo \<message\>.
-- | A list of all tests for this module.
--
-gameinfo_tests :: TestTree
-gameinfo_tests =
+game_info_tests :: TestTree
+game_info_tests =
testGroup
"GameInfo tests"
[ test_parse_xml_succeeds,
-- | Sample XML documents for GameInfo types.
--
-gameinfo_test_files :: [FilePath]
-gameinfo_test_files =
- [ "test/xml/gameinfo/CBASK_Lineup_XML.xml",
- "test/xml/gameinfo/cbaskpreviewxml.xml",
- "test/xml/gameinfo/cflpreviewxml.xml",
- "test/xml/gameinfo/Matchup_NBA_NHL_XML.xml",
- "test/xml/gameinfo/MLB_Gaming_Matchup_XML.xml",
- "test/xml/gameinfo/MLB_Lineup_XML.xml",
- "test/xml/gameinfo/MLB_Matchup_XML.xml",
- "test/xml/gameinfo/mlbpreviewxml.xml",
- "test/xml/gameinfo/MLS_Preview_XML.xml",
- "test/xml/gameinfo/NBA_Gaming_Matchup_XML.xml",
- "test/xml/gameinfo/NBALineupXML.xml",
- "test/xml/gameinfo/NBA_Playoff_Matchup_XML.xml",
- "test/xml/gameinfo/nbapreviewxml.xml",
- "test/xml/gameinfo/nhlpreviewxml.xml",
- "test/xml/gameinfo/recapxml.xml" ]
-
-
--- | Make sure we can parse every element of 'gameinfo_test_files'.
+game_info_test_files :: [FilePath]
+game_info_test_files =
+ map (change_suffix . add_path) dtds
+ where
+ add_path = ("test/xml/gameinfo/" ++ )
+ change_suffix = replace ".dtd" ".xml"
+
+-- | Make sure we can parse every element of 'game_info_test_files'.
--
test_parse_xml_succeeds :: TestTree
test_parse_xml_succeeds =
- testGroup "parse_xml" $ map check gameinfo_test_files
+ testGroup "parse_xml" $ map check game_info_test_files
where
check t = testCase t $ do
x <- unsafe_read_document t
actual @?= expected
--- | Ensure that each element of 'gameinfo_test_files' can be imported
+-- | Ensure that each element of 'game_info_test_files' can be imported
-- by counting the total number of database records (after
-- importing) and comparing it against the length of
--- 'gameinfo_test_files'.
+-- 'game_info_test_files'.
--
test_dbimport_succeeds :: TestTree
test_dbimport_succeeds = testCase "dbimport succeeds" $ do
- xmltrees <- mapM unsafe_read_document gameinfo_test_files
+ xmltrees <- mapM unsafe_read_document game_info_test_files
let msgs = rights $ map (parse_xml "dummy") xmltrees
actual <- withSqliteConn ":memory:" $ runDbConn $ do
runMigration silentMigrationLogger $ do
actual @?= expected
where
- expected = length gameinfo_test_files
+ expected = length game_info_test_files