X-Git-Url: http://gitweb.michael.orlitzky.com/?a=blobdiff_plain;f=src%2FTSN%2FXML%2FGameInfo.hs;h=b13edd78af9c28c8e917fe3e2719a02291b5e6c4;hb=7ab10646746d18c3d5c00d4c68e78807197aa560;hp=c6b90e01ca2a4d28e3ec8a344b10387f07878576;hpb=172963e3c71523c704bacdfb2b885a307acb93cf;p=dead%2Fhtsn-import.git diff --git a/src/TSN/XML/GameInfo.hs b/src/TSN/XML/GameInfo.hs index c6b90e0..b13edd7 100644 --- a/src/TSN/XML/GameInfo.hs +++ b/src/TSN/XML/GameInfo.hs @@ -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 @@ -80,8 +81,7 @@ dtds = "NFL_NCAA_FB_Matchup_XML.dtd", "nhlpreviewxml.dtd", "recapxml.dtd", - "WorldBaseballPreviewXML.dtd" -- missing DTD - ] + "WorldBaseballPreviewXML.dtd" ] -- | XML representation of a GameInfo \. @@ -172,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, @@ -182,33 +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/NFL_NCAA_FB_Matchup_XML.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 @@ -220,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 @@ -237,4 +222,4 @@ test_dbimport_succeeds = testCase "dbimport succeeds" $ do actual @?= expected where - expected = length gameinfo_test_files + expected = length game_info_test_files