aboutsummaryrefslogtreecommitdiff
path: root/tests/Test.hs
diff options
context:
space:
mode:
authorJoris2016-03-16 21:09:44 +0100
committerJoris2016-03-16 22:09:54 +0100
commitc6c01d7c248bca1078285c4afeaa25493e9974b3 (patch)
tree7b060664b16ffcae25cb62089dfbeed5a0b7c69a /tests/Test.hs
parentf2dc23683ceae93135223713e4ca7fa3a12edbea (diff)
Add import expression
Diffstat (limited to 'tests/Test.hs')
-rw-r--r--tests/Test.hs17
1 files changed, 15 insertions, 2 deletions
diff --git a/tests/Test.hs b/tests/Test.hs
index 51ced1f..957f3ae 100644
--- a/tests/Test.hs
+++ b/tests/Test.hs
@@ -7,6 +7,7 @@ module Main
import Prelude hiding (lookup)
import qualified Data.HashMap.Strict as M
+import Data.Maybe (fromJust)
import Test.Framework
import Test.Framework.Providers.HUnit
@@ -16,7 +17,7 @@ import Data.ConfigManager
import Data.ConfigManager.Config
import qualified Data.Text as T
-import Helper (forceGetConfig, getConfig)
+import Helper (forceGetConfig, getConfig, eitherToMaybe)
main :: IO ()
main = defaultMain tests
@@ -27,6 +28,7 @@ tests =
, testCase "name" nameAssertion
, testCase "value" valueAssertion
, testCase "skip" skipAssertion
+ , testCase "import" importAssertion
]
bindingAssertion :: Assertion
@@ -78,13 +80,14 @@ valueAssertion = do
[ "a = \"lorem ipsum sir dolor emet\""
, "b = 4 "
, "c = 5.0 "
- , " "
+ , "d = True "
]
assertEqual "string" (Just "lorem ipsum sir dolor emet") (lookup "a" config :: Maybe String)
assertEqual "integer" (Just 4) (lookup "b" config :: Maybe Int)
assertEqual "double 1" (Just 4.0) (lookup "b" config :: Maybe Double)
assertEqual "double 2" (Just 5.0) (lookup "c" config :: Maybe Double)
assertEqual "integer fail" Nothing (lookup "c" config :: Maybe Int)
+ assertEqual "boolean" (Just True) (lookup "d" config :: Maybe Bool)
return ()
skipAssertion :: Assertion
@@ -102,3 +105,13 @@ skipAssertion = do
assertEqual "bindings count" 2 (M.size . hashMap $ config)
assertEqual "bindings x" (Just "foo") (lookup "x" config :: Maybe String)
assertEqual "bindings y" (Just "bar") (lookup "y" config :: Maybe String)
+
+importAssertion :: Assertion
+importAssertion = do
+ config <- fromJust . eitherToMaybe <$> readConfig "tests/resources/a.conf"
+ assertEqual "a" (Just "foo") (lookup "a" config :: Maybe String)
+ assertEqual "b" (Just 15) (lookup "b" config :: Maybe Int)
+ assertEqual "c" (Just "re baz") (lookup "c" config :: Maybe String)
+ assertEqual "d" (Just "zap") (lookup "d" config :: Maybe String)
+ assertEqual "e" (Just "re nam") (lookup "e" config :: Maybe String)
+ assertEqual "f" (Just 8.5) (lookup "f" config :: Maybe Double)