diff options
Diffstat (limited to 'test/Main.hs')
-rw-r--r-- | test/Main.hs | 19 |
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 |