+
+
+--
+-- Tasty Tests
+--
+
+-- | A list of all tests for this module.
+--
+game_info_tests :: TestTree
+game_info_tests =
+ testGroup
+ "GameInfo tests"
+ [ test_parse_xml_succeeds,
+ test_dbimport_succeeds ]
+
+
+-- | Sample XML documents for GameInfo types.
+--
+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 game_info_test_files
+ where
+ check t = testCase t $ do
+ x <- unsafe_read_document t
+ let result = parse_xml "dummy" x
+ let actual = case result of -- isRight appears in base-4.7
+ Left _ -> False
+ Right _ -> True
+ let expected = True
+ actual @?= expected
+
+
+-- | 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
+-- 'game_info_test_files'.
+--
+test_dbimport_succeeds :: TestTree
+test_dbimport_succeeds = testCase "dbimport succeeds" $ do
+ 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
+ migrate (undefined :: GameInfo)
+ mapM_ dbimport msgs
+ countAll (undefined :: GameInfo)
+
+ actual @?= expected
+ where
+ expected = length game_info_test_files