diff options
Diffstat (limited to 'tests')
-rw-r--r-- | tests/Helper.hs | 3 | ||||
-rw-r--r-- | tests/Test.hs | 17 | ||||
-rw-r--r-- | tests/resources/a.conf | 7 | ||||
-rw-r--r-- | tests/resources/b.conf | 6 | ||||
-rw-r--r-- | tests/resources/c.conf | 2 |
5 files changed, 32 insertions, 3 deletions
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 |