aboutsummaryrefslogtreecommitdiff
path: root/tests/Test.hs
diff options
context:
space:
mode:
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)