X-Git-Url: http://gitweb.michael.orlitzky.com/?a=blobdiff_plain;f=src%2FTSN%2FInjuries.hs;h=8c2de14b04006e0a954fd156505ec8dc5fa8ae2c;hb=f8a623928407ceaaa8c28b60316e9123a4f3821b;hp=3877c12efc551a5e6c55ee3bed5d2354e5be7b6e;hpb=767dc8dbacaf6dcdefd268c7c8c08cd0c23c3391;p=dead%2Fhtsn-import.git diff --git a/src/TSN/Injuries.hs b/src/TSN/Injuries.hs index 3877c12..8c2de14 100644 --- a/src/TSN/Injuries.hs +++ b/src/TSN/Injuries.hs @@ -1,6 +1,7 @@ {-# LANGUAGE FlexibleInstances #-} {-# LANGUAGE GADTs #-} {-# LANGUAGE QuasiQuotes #-} +{-# LANGUAGE ScopedTypeVariables #-} {-# LANGUAGE StandaloneDeriving #-} {-# LANGUAGE TemplateHaskell #-} {-# LANGUAGE TypeFamilies #-} @@ -14,12 +15,18 @@ -- module TSN.Injuries ( Listing, - Message( listings ) ) + Message( listings ), + injuries_tests ) where import Data.Tuple.Curry ( uncurryN ) import Database.Groundhog() -import Database.Groundhog.TH +import Database.Groundhog.TH ( + defaultCodegenConfig, + groundhog, + mkPersist ) +import Test.Tasty ( TestTree, testGroup ) +import Test.Tasty.HUnit ( (@?=), testCase ) import Text.XML.HXT.Core ( PU, XmlPickler(..), @@ -32,13 +39,17 @@ import Text.XML.HXT.Core ( xpWrap ) +import TSN.DbImport ( DbImport(..), import_generic ) +import Xml ( pickle_unpickle ) + + data Listing = Listing { team :: String, teamno :: Int, injuries :: String, updated :: Bool } - deriving (Show) + deriving (Eq, Show) data Message = Message { @@ -48,7 +59,7 @@ data Message = sport :: String, listings :: [Listing], time_stamp :: String } - deriving (Show) + deriving (Eq, Show) mkPersist defaultCodegenConfig [groundhog| @@ -94,3 +105,23 @@ pickle_message = instance XmlPickler Message where xpickle = pickle_message + + + +instance DbImport Listing where + dbimport = import_generic listings + +-- * Tasty Tests +injuries_tests :: TestTree +injuries_tests = + testGroup + "Injuries tests" + [ test_pickle_of_unpickle_is_identity ] + + +test_pickle_of_unpickle_is_identity :: TestTree +test_pickle_of_unpickle_is_identity = + testCase "pickle composed with unpickle is the identity" $ do + let path = "test/xml/injuriesxml.xml" + (expected :: [Message], actual) <- pickle_unpickle "message" path + actual @?= expected