-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test: add property tests for core module
Add property tests for NMonad.Core.
- Loading branch information
Showing
3 changed files
with
40 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
{-# LANGUAGE StandaloneDeriving #-} | ||
|
||
module NMonad.CoreSpec (spec) where | ||
|
||
import Test.Hspec | ||
import Test.Hspec.QuickCheck | ||
import Test.QuickCheck | ||
import Test.NMonad | ||
|
||
import NMonad.Core | ||
|
||
deriving instance Show DBusNotification | ||
deriving instance Eq Expiration | ||
deriving instance Eq Notification | ||
|
||
spec :: Spec | ||
spec = do | ||
describe "notificationFromDBus :: DBusNotification -> N Notification" $ do | ||
prop "respects replacesId if set to something other than 0" $ \dbusnotif -> do | ||
replacesId <- generate $ arbitrary `suchThat` (/= 0) | ||
let (DBusNotification an _ ai s b a h t) = dbusnotif | ||
dbusnotif' = DBusNotification an replacesId ai s b a h t | ||
(notification, _, _) <- runGenN $ notificationFromDBus dbusnotif' | ||
identifier notification `shouldBe` replacesId | ||
|
||
prop "generates some notification id when replacesId is 0" $ \dbusnotif -> do | ||
let (DBusNotification an _ ai s b a h t) = dbusnotif | ||
dbusnotif' = DBusNotification an 0 ai s b a h t | ||
(notification, finalState, (_, initialState)) <- runGenN $ notificationFromDBus dbusnotif' | ||
identifier notification `shouldNotBe` 0 | ||
notificationCount finalState `shouldBe` 1 + notificationCount initialState | ||
|
||
describe "addToNotificationsAndReturnId :: Notification -> N Word32" $ do | ||
prop "adds the notification to the state and returns its identifier" $ \notif -> do | ||
(returnedId, finalState, (_, initialState)) <- runGenN $ addToNotificationsAndReturnId notif | ||
notif `shouldNotSatisfy` (`elem` notifications initialState) | ||
notif `shouldSatisfy` (`elem` notifications finalState) | ||
identifier notif `shouldBe` returnedId |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1 @@ | ||
main :: IO () | ||
main = putStrLn "Test suite not yet implemented" | ||
{-# OPTIONS_GHC -F -pgmF hspec-discover #-} |