From c6c01d7c248bca1078285c4afeaa25493e9974b3 Mon Sep 17 00:00:00 2001 From: Joris Date: Wed, 16 Mar 2016 21:09:44 +0100 Subject: Add import expression --- tests/Test.hs | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) (limited to 'tests/Test.hs') 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) -- cgit v1.2.3