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/Helper.hs | 3 ++- tests/Test.hs | 17 +++++++++++++++-- tests/resources/a.conf | 7 +++++++ tests/resources/b.conf | 6 ++++++ tests/resources/c.conf | 2 ++ 5 files changed, 32 insertions(+), 3 deletions(-) create mode 100644 tests/resources/a.conf create mode 100644 tests/resources/b.conf create mode 100644 tests/resources/c.conf (limited to 'tests') diff --git a/tests/Helper.hs b/tests/Helper.hs index 5979ae2..3dcc267 100644 --- a/tests/Helper.hs +++ b/tests/Helper.hs @@ -1,6 +1,7 @@ module Helper ( forceGetConfig , getConfig + , eitherToMaybe ) where @@ -25,7 +26,7 @@ getConfig input = T.writeFile filePath input config <- readConfig filePath removeFile filePath - putStrLn . show $ config + -- putStrLn . show $ config return $ eitherToMaybe config ) 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) diff --git a/tests/resources/a.conf b/tests/resources/a.conf new file mode 100644 index 0000000..4a475f1 --- /dev/null +++ b/tests/resources/a.conf @@ -0,0 +1,7 @@ +a = "foo" +b = "bar" +c = "baz" + +import "b.conf" + +e = "re nam" diff --git a/tests/resources/b.conf b/tests/resources/b.conf new file mode 100644 index 0000000..c75a415 --- /dev/null +++ b/tests/resources/b.conf @@ -0,0 +1,6 @@ +import "c.conf" + +b = 15 +c = "re baz" +d = "zap" +e = "nam" diff --git a/tests/resources/c.conf b/tests/resources/c.conf new file mode 100644 index 0000000..c4f1642 --- /dev/null +++ b/tests/resources/c.conf @@ -0,0 +1,2 @@ +f = 8.5 +b = False -- cgit v1.2.3