]> gitweb.michael.orlitzky.com - dead/htsn-import.git/blobdiff - src/TSN/XML/GameInfo.hs
Derive the GameInfo test file paths from the DTD list.
[dead/htsn-import.git] / src / TSN / XML / GameInfo.hs
index ff4ca01b2e1778cf1daa8dabe82c7234cdb089f5..b13edd78af9c28c8e917fe3e2719a02291b5e6c4 100644 (file)
@@ -13,7 +13,7 @@
 --
 module TSN.XML.GameInfo (
   dtds,
-  gameinfo_tests,
+  game_info_tests,
   parse_xml,
   -- * WARNING: these are private but exported to silence warnings
   GameInfoConstructor(..) )
@@ -21,6 +21,7 @@ where
 
 -- System imports.
 import Data.Either ( rights )
+import Data.String.Utils ( replace )
 import Data.Time.Clock ( UTCTime )
 import Database.Groundhog (
   countAll,
@@ -54,7 +55,7 @@ import Xml (
   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
@@ -68,22 +69,19 @@ 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",
     "nflpreviewxml.dtd",
-    "NFL_NCAA_FB_Matchup_XML.dtd", -- missing DTD
+    "NFL_NCAA_FB_Matchup_XML.dtd",
     "nhlpreviewxml.dtd",
     "recapxml.dtd",
-    "WorldBaseballPreviewXML.dtd" -- missing DTD
-  ]
+    "WorldBaseballPreviewXML.dtd" ]
 
 
 -- | XML representation of a GameInfo \<message\>.
@@ -174,8 +172,8 @@ mkPersist tsn_codegen_config [groundhog|
 
 -- | 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,
@@ -184,32 +182,18 @@ gameinfo_tests =
 
 -- | 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/NCAA_FB_Preview_XML.xml",
-    "test/xml/gameinfo/nbapreviewxml.xml",
-    "test/xml/gameinfo/nflpreviewxml.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
@@ -221,14 +205,14 @@ test_parse_xml_succeeds =
       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
@@ -238,4 +222,4 @@ test_dbimport_succeeds = testCase "dbimport succeeds" $ do
 
   actual @?= expected
   where
-    expected = length gameinfo_test_files
+    expected = length game_info_test_files