From 2f6ea95c2b3e19545c09ed5ff81d90bb3b120c16 Mon Sep 17 00:00:00 2001 From: Michael Orlitzky Date: Fri, 3 Oct 2014 12:06:07 -0400 Subject: [PATCH] Make the News SMS field optional. Add a News test case with an empty SMS element. --- src/TSN/XML/News.hs | 20 +++++++++++++++----- test/shell/import-duplicates.test | 4 ++-- test/xml/newsxml-empty-sms.xml | 1 + 3 files changed, 18 insertions(+), 7 deletions(-) create mode 100644 test/xml/newsxml-empty-sms.xml diff --git a/src/TSN/XML/News.hs b/src/TSN/XML/News.hs index 513bf5c..f401d41 100644 --- a/src/TSN/XML/News.hs +++ b/src/TSN/XML/News.hs @@ -120,7 +120,7 @@ data Message = xml_url :: Maybe String, xml_teams :: [NewsTeam], xml_locations :: [Location], - xml_sms :: String, + xml_sms :: Maybe String, xml_editor :: Maybe String, xml_text :: Maybe String, -- Text and continue seem to show up in pairs, xml_continue :: Maybe String, -- either both present or both missing. @@ -138,7 +138,7 @@ data News = db_mid :: MsgId, db_sport :: String, db_url :: Maybe String, - db_sms :: String, + db_sms :: Maybe String, db_editor :: Maybe String, db_text :: Maybe String, db_continue :: Maybe String, @@ -397,7 +397,7 @@ pickle_message = (xpElem "url" $ xpOption xpText) (xpList pickle_news_team) (xpList pickle_location) - (xpElem "SMS" xpText) + (xpElem "SMS" $ xpOption xpText) (xpOption (xpElem "Editor" xpText)) (xpOption (xpElem "text" xpText)) pickle_continue @@ -492,7 +492,10 @@ test_pickle_of_unpickle_is_identity = testGroup "pickle-unpickle tests" "test/xml/newsxml.xml", check "pickle composed with unpickle is the identity (with Editor)" - "test/xml/newsxml-with-editor.xml" ] + "test/xml/newsxml-with-editor.xml", + + check "pickle composed with unpickle is the identity (empty SMS)" + "test/xml/newsxml-empty-sms.xml" ] where check desc path = testCase desc $ do (expected, actual) <- pickle_unpickle pickle_message path @@ -507,7 +510,10 @@ test_unpickle_succeeds = testGroup "unpickle tests" "test/xml/newsxml.xml", check "unpickling succeeds (with Editor)" - "test/xml/newsxml-with-editor.xml" ] + "test/xml/newsxml-with-editor.xml", + + check "unpickling succeeds (empty SMS)" + "test/xml/newsxml-empty-sms.xml" ] where check desc path = testCase desc $ do actual <- unpickleable path pickle_message @@ -523,6 +529,10 @@ test_on_delete_cascade = testGroup "cascading delete tests" [ check "deleting news deletes its children" "test/xml/newsxml.xml" 4 -- 2 news_teams and 2 news_locations that should remain. + , + check "deleting news deletes its children (empty SMS)" + "test/xml/newsxml-empty-sms.xml" + 4 -- 2 news_teams and 2 news_locations ] where check desc path expected = testCase desc $ do diff --git a/test/shell/import-duplicates.test b/test/shell/import-duplicates.test index 183b684..a81bd04 100644 --- a/test/shell/import-duplicates.test +++ b/test/shell/import-duplicates.test @@ -16,7 +16,7 @@ rm -f shelltest.sqlite3 # and a newsxml that aren't really supposed to import. find ./test/xml -maxdepth 1 -name '*.xml' | wc -l >>> -33 +34 >>>= 0 # Run the imports again; we should get complaints about the duplicate @@ -24,7 +24,7 @@ find ./test/xml -maxdepth 1 -name '*.xml' | wc -l # occurrences of the string 'ERROR'. ./dist/build/htsn-import/htsn-import -c 'shelltest.sqlite3' test/xml/*.xml 2>&1 | grep ERROR | wc -l >>> -58 +60 >>>= 0 # Finally, clean up after ourselves. diff --git a/test/xml/newsxml-empty-sms.xml b/test/xml/newsxml-empty-sms.xml new file mode 100644 index 0000000..d08cff4 --- /dev/null +++ b/test/xml/newsxml-empty-sms.xml @@ -0,0 +1 @@ + 21904559 AFN;UTAH-UCLA 0 News CFOOT UCLA UTAH U-C-L-A CA USA Utah UT USA Pasadena, CA (SportsNetwork.com) - October 1, 2014, at 11:11 AM ET \ No newline at end of file -- 2.44.2