From 4fd6088bc7b1dcde64728c9edcff577c13dc4e78 Mon Sep 17 00:00:00 2001 From: Michael Orlitzky Date: Thu, 2 Jan 2014 10:59:51 -0500 Subject: [PATCH] Update the newsxml DTD to make the Editor optional. Add a second test newsxml document which has an Editor element. Replicate News tests for the Editor-having document. --- src/TSN/XML/News.hs | 45 ++++++++++++++++++++++-------- test/xml/newsxml-with-editor.xml | 1 + test/xml/newsxml.dtd | 48 ++++++++++++++++---------------- 3 files changed, 59 insertions(+), 35 deletions(-) create mode 100644 test/xml/newsxml-with-editor.xml diff --git a/src/TSN/XML/News.hs b/src/TSN/XML/News.hs index 6612792..26ca8c0 100644 --- a/src/TSN/XML/News.hs +++ b/src/TSN/XML/News.hs @@ -37,7 +37,7 @@ import Text.XML.HXT.Core ( PU, XmlPickler(..), unpickleDoc, - xp12Tuple, + xp13Tuple, xpAttr, xpElem, xpInt, @@ -149,6 +149,7 @@ data MessageXml = xml_teams :: [NewsTeamXml], xml_locations :: [NewsLocationXml], xml_sms :: String, + xml_editor :: Maybe String, xml_text :: String, xml_continue :: String, xml_time_stamp :: String } @@ -160,6 +161,7 @@ data Message = db_sport :: String, db_url :: String, db_sms :: String, + db_editor :: Maybe String, db_text :: String, db_continue :: String } deriving (Data, Eq, Show, Typeable) @@ -181,14 +183,15 @@ instance ToFromXml Message where def def db_sms + db_editor db_text db_continue def -- We don't need the key argument (from_xml_fk) since the XML type -- contains more information in this case. - from_xml (MessageXml _ _ c _ e f _ _ i j k _) = - Message c e f i j k + from_xml (MessageXml _ _ c _ e f _ _ i j k l _) = + Message c e f i j k l mkPersist tsn_codegen_config [groundhog| @@ -261,7 +264,7 @@ pickle_message :: PU MessageXml pickle_message = xpElem "message" $ xpWrap (from_tuple, to_tuple) $ - xp12Tuple (xpElem "XML_File_ID" xpInt) + xp13Tuple (xpElem "XML_File_ID" xpInt) (xpElem "heading" xpText) pickle_msg_id (xpElem "category" xpText) @@ -270,6 +273,7 @@ pickle_message = (xpList $ pickle_news_team) (xpList $ pickle_location) (xpElem "SMS" xpText) + (xpOption (xpElem "Editor" xpText)) (xpElem "text" xpText) pickle_continue (xpElem "time_stamp" xpText) @@ -284,6 +288,7 @@ pickle_message = xml_teams m, xml_locations m, xml_sms m, + xml_editor m, xml_text m, xml_continue m, xml_time_stamp m) @@ -334,8 +339,10 @@ news_tests = testGroup "News tests" [ test_news_fields_have_correct_names, - test_pickle_of_unpickle_is_identity, - test_unpickle_succeeds ] + test_pickle_of_unpickle_is_identity1, + test_pickle_of_unpickle_is_identity2, + test_unpickle_succeeds1, + test_unpickle_succeeds2 ] test_news_fields_have_correct_names :: TestTree @@ -354,25 +361,41 @@ test_news_fields_have_correct_names = map (\x -> tsn_db_field_namer "herp" "derp" 8675309 x 90210) field_names actual :: [String] - actual = ["mid", "sport", "url", "sms", "text", "continue"] + actual = ["mid", "sport", "url", "sms", "editor", "text", "continue"] check (x,y) = (x @?= y) -- | Warning, succeess of this test does not mean that unpickling -- succeeded. -test_pickle_of_unpickle_is_identity :: TestTree -test_pickle_of_unpickle_is_identity = +test_pickle_of_unpickle_is_identity1 :: TestTree +test_pickle_of_unpickle_is_identity1 = testCase "pickle composed with unpickle is the identity" $ do let path = "test/xml/newsxml.xml" (expected :: [MessageXml], actual) <- pickle_unpickle "message" path actual @?= expected +-- | Repeat of 'test_pickle_of_unpickle_is_identity1' with a different +-- XML file. +test_pickle_of_unpickle_is_identity2 :: TestTree +test_pickle_of_unpickle_is_identity2 = + testCase "pickle composed with unpickle is the identity (with Editor)" $ do + let path = "test/xml/newsxml-with-editor.xml" + (expected :: [MessageXml], actual) <- pickle_unpickle "message" path + actual @?= expected -test_unpickle_succeeds :: TestTree -test_unpickle_succeeds = +test_unpickle_succeeds1 :: TestTree +test_unpickle_succeeds1 = testCase "unpickling succeeds" $ do let path = "test/xml/newsxml.xml" actual <- unpickleable path pickle_message let expected = True actual @?= expected + +test_unpickle_succeeds2 :: TestTree +test_unpickle_succeeds2 = + testCase "unpickling succeeds (with Editor)" $ do + let path = "test/xml/newsxml-with-editor.xml" + actual <- unpickleable path pickle_message + let expected = True + actual @?= expected diff --git a/test/xml/newsxml-with-editor.xml b/test/xml/newsxml-with-editor.xml new file mode 100644 index 0000000..f76816a --- /dev/null +++ b/test/xml/newsxml-with-editor.xml @@ -0,0 +1 @@ + 19956478 ACN;RECAP-HOU-SAN 4650108 News NBA /nba/news/ACN4650108.htm HOU SAN Houston TX USA San Antonio TX USA Harden powers Rockets past Spurs Washington Irving San Antonio, TX (SportsNetwork.com) - James Harden returned from a two-game absence and led all five Houston starters in double figures with 28 points, as the Rockets topped the San Antonio Spurs, 111-98, at AT&T Center.

Harden sat out games against Detroit and Dallas due to a sprained left ankle, but the veteran shooting guard was a one-man wrecking crew in the fourth quarter against the Spurs. Harden had 11 straight Houston points during the final period and scored 16 in the frame.

Dwight Howard contributed 15 points and 20 rebounds for the Rockets, who are within 3 1/2 games of the Spurs for first place in the Southwest Division. Terrence Jones had 21 points and 14 boards, while Chandler Parsons also scored 21 to go with six rebounds and six assists. Jeremy Lin had 13 points and eight helpers.

The Rockets, who didn't trail the entire game, made 12-of-24 shots from beyond the arc.

Manu Ginobili had 22 points for the Spurs, who suffered only their fourth home loss all season. Two of those defeats have come against the Rockets. Tim Duncan finished with 11 points, 14 rebounds, six blocks and five assists.

Kawhi Leonard scored 13 points for the Spurs, who lost for the second time in three contests.

December 25, 2013, at 10:38 PM ET
\ No newline at end of file diff --git a/test/xml/newsxml.dtd b/test/xml/newsxml.dtd index 72c6e3e..5f24baa 100644 --- a/test/xml/newsxml.dtd +++ b/test/xml/newsxml.dtd @@ -1,24 +1,24 @@ - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + -- 2.44.2