summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorstuebinm2024-06-07 22:36:40 +0200
committerstuebinm2024-06-07 22:36:40 +0200
commitc1cf159fa67a107a395166c199c401aac0918c31 (patch)
tree968941b8bd717df0f17f24595be9327267ec3042 /test
parent17631c7294ee21a48f78ce4e51c827da93b501fa (diff)
the Config interface should be Applicative, not Monad
this allows for safer alternative uses for it, such as running it on an empty list of config sources to just get the list of keys it uses.
Diffstat (limited to '')
-rw-r--r--test/Main.hs19
1 files changed, 16 insertions, 3 deletions
diff --git a/test/Main.hs b/test/Main.hs
index 5c01f64..1af3d9a 100644
--- a/test/Main.hs
+++ b/test/Main.hs
@@ -2,6 +2,7 @@
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE DeriveAnyClass #-}
{-# LANGUAGE TemplateHaskell #-}
+{-# LANGUAGE ApplicativeDo #-}
module Main (main) where
import Conftrack
@@ -15,6 +16,7 @@ import Test.QuickCheck.Monadic
import Test.QuickCheck.Instances ()
import System.Exit (exitFailure, exitSuccess)
import qualified Data.Text.Encoding as BS
+import Data.List ((\\))
data TestFlat = TestType { testFoo :: Text, testBar :: Integer }
@@ -35,9 +37,10 @@ instance Config TestFlat where
<*> readRequiredValue (Key ["bar"])
instance Config TestNested where
- readConfig = TestNested
- <$> readRequiredValue (Key ["foo"])
- <*> readNested (Key ["nested"])
+ readConfig = do
+ a <- readRequiredValue (Key ["foo"])
+ b <- readNested (Key ["nested"])
+ pure (TestNested a b)
testTypeToTrivial :: TestFlat -> SomeSource
testTypeToTrivial (TestType foo bar) = mkTrivialSource
@@ -81,6 +84,16 @@ prop_aeson_flat = roundtripVia testTypeToJson
prop_aeson_nested :: TestNested -> Property
prop_aeson_nested = roundtripVia nestedToJson
+prop_flat_keys :: Property
+prop_flat_keys = monadicIO $ do
+ keys <- run $ configKeysOf @TestFlat
+ assert (null (keys \\ [ Key ["foo"], Key ["bar"] ]))
+
+prop_nested_keys :: Property
+prop_nested_keys = monadicIO $ do
+ keys <- run $ configKeysOf @TestNested
+ assert (null (keys \\ [ Key ["foo"], Key ["nested", "bar"], Key ["nested", "foo"] ]))
+
-- see quickcheck docs for why this return is here
return []
runTests = $quickCheckAll