aboutsummaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorJoris2016-03-26 20:29:15 +0100
committerJoris2016-03-26 20:29:36 +0100
commit2e411664ce8da96fd50340b1ecb9e6e2e16f6ca2 (patch)
tree4d9399723a470a2fcd24b1df05aeb481468492de /tests
parent88aef982ff7a1be7fba2abf7264773b511608404 (diff)
Parse durations
Diffstat (limited to 'tests')
-rw-r--r--tests/Test.hs42
1 files changed, 41 insertions, 1 deletions
diff --git a/tests/Test.hs b/tests/Test.hs
index 641e1e6..3956236 100644
--- a/tests/Test.hs
+++ b/tests/Test.hs
@@ -18,6 +18,8 @@ import Test.HUnit hiding (Test)
import Data.ConfigManager
import Data.ConfigManager.Types (Config(..))
import qualified Data.Text as T
+import Data.Time.Clock (DiffTime)
+import qualified Data.Time.Clock as Time
import Helper (forceGetConfig, getConfig, eitherToMaybe)
@@ -32,6 +34,7 @@ tests =
, testCase "value" valueAssertion
, testCase "skip" skipAssertion
, testCase "import" importAssertion
+ , testCase "duration" durationAssertion
]
bindingAssertion :: Assertion
@@ -41,7 +44,7 @@ bindingAssertion = do
oneBinding <- forceGetConfig "x = \"foo\""
assertEqual "one binding present" (Right "foo") (lookup "x" oneBinding)
- assertBool "one binding missing" (isLeft $ (lookup "y" oneBinding :: Either Text Int))
+ assertBool "one binding missing" (isLeft (lookup "y" oneBinding :: Either Text Int))
assertEqual "one binding count" 1 (M.size . hashMap $ oneBinding)
multipleBindings <- forceGetConfig $ T.unlines
@@ -133,3 +136,40 @@ importAssertion = do
, "x = 4"
]
assertEqual "missing optional config" (Right 4) (lookup "x" missingOptionalConfig)
+
+durationAssertion :: Assertion
+durationAssertion = do
+ config <- forceGetConfig $ T.unlines
+ [ "a = 1 second"
+ , "b = 5 seconds"
+ , "c = 1 minute"
+ , "d = 10 minutes"
+ , "e = 1 hour"
+ , "f = 7 hours"
+ , "g = 1 day"
+ , "h = 2 days"
+ , "i = 1 week"
+ , "j = 9 weeks"
+ , ""
+ , "k = 1 minutes"
+ , "l = 20 weeks"
+ ]
+
+ let second = 1
+ let minute = 60 * second
+ let hour = 60 * minute
+ let day = 24 * hour
+ let week = 7 * day
+
+ assertEqual "a" (Right (Time.secondsToDiffTime $ 1 * second)) (lookup "a" config)
+ assertEqual "b" (Right (Time.secondsToDiffTime $ 5 * second)) (lookup "b" config)
+ assertEqual "c" (Right (Time.secondsToDiffTime $ 1 * minute)) (lookup "c" config)
+ assertEqual "d" (Right (Time.secondsToDiffTime $ 10 * minute)) (lookup "d" config)
+ assertEqual "e" (Right (Time.secondsToDiffTime $ 1 * hour)) (lookup "e" config)
+ assertEqual "f" (Right (Time.secondsToDiffTime $ 7 * hour)) (lookup "f" config)
+ assertEqual "g" (Right (Time.secondsToDiffTime $ 1 * day)) (lookup "g" config)
+ assertEqual "h" (Right (Time.secondsToDiffTime $ 2 * day)) (lookup "h" config)
+ assertEqual "i" (Right (Time.secondsToDiffTime $ 1 * week)) (lookup "i" config)
+ assertEqual "j" (Right (Time.secondsToDiffTime $ 9 * week)) (lookup "j" config)
+ assertBool "k" (isLeft (lookup "k" config :: Either Text DiffTime))
+ assertBool "l" (isLeft (lookup "l" config :: Either Text DiffTime))