From 085b7ba3e803962f3bc66204fec840ea93a6e22d Mon Sep 17 00:00:00 2001 From: Steffen Jost Date: Wed, 20 Jul 2022 17:31:05 +0200 Subject: [PATCH] refactor(tests): pandoc tests simplified --- src/Model/Types/Lms.hs | 2 +- src/Utils/Print.hs | 3 ++- test/PandocSpec.hs | 10 +++------- 3 files changed, 6 insertions(+), 9 deletions(-) diff --git a/src/Model/Types/Lms.hs b/src/Model/Types/Lms.hs index fc3317cbb..6df3a7302 100644 --- a/src/Model/Types/Lms.hs +++ b/src/Model/Types/Lms.hs @@ -36,7 +36,7 @@ isLmsSuccess :: LmsStatus -> Bool isLmsSuccess LmsSuccess{} = True isLmsSuccess _other = False --- Entscheidung 08.04.22: LmsSuccess gewinnt immer über LmsBlocked oder umgekehrt +-- Entscheidung 08.04.22: LmsSuccess gewinnt immer über LmsBlocked oder umgekehrt; siehe Model.TypesSpec instance Semigroup LmsStatus where a <> b | a >= b = a | otherwise = b diff --git a/src/Utils/Print.hs b/src/Utils/Print.hs index 3d3af0622..2dfd77640 100644 --- a/src/Utils/Print.hs +++ b/src/Utils/Print.hs @@ -70,11 +70,12 @@ appMeta :: (P.Meta -> P.Meta) -> P.Pandoc -> P.Pandoc appMeta f (P.Pandoc m bs) = P.Pandoc (f m) bs -- appMeta f = _Meta %~ f -- lens version. Not sure this is better --- Add tests for applyMetas, if ever needed +-- For tests see module PandocSpec applyMetas :: (P.HasMeta p, Foldable t, P.ToMetaValue a) => t (Text, a) -> p -> p applyMetas metas doc = Fold.foldr (uncurry P.setMeta) doc metas -- | Add meta to pandoc. Existing variables will be overwritten. +-- For specification, see module PandocSpec addMeta :: P.Meta -> P.Pandoc -> P.Pandoc addMeta m = appMeta (<> m) -- Data.Map says: (<>) == union and union should prefer the left operand, but somehow it does not! --addMeta m p = meta <> p diff --git a/test/PandocSpec.hs b/test/PandocSpec.hs index 579fd1747..abccb5c38 100644 --- a/test/PandocSpec.hs +++ b/test/PandocSpec.hs @@ -62,8 +62,7 @@ spec = do metaOriginal = unArbitraryMeta abMetaOriginal pd = Pandoc metaOriginal blocks (Pandoc newMeta _) = addMeta metaOverwrite pd - keysToPreserve = Map.keysSet $ unMeta metaOverwrite - mlist metaOverwrite `shouldMatchList` Map.toList (unMeta newMeta `Map.restrictKeys` keysToPreserve) + (unMeta metaOverwrite `Map.isSubmapOf` unMeta newMeta) `shouldBe` True it "should preserve untouched settings" $ do (abMetaOverwrite, abMetaOriginal, blocks) <- generate arbitrary @@ -72,16 +71,13 @@ spec = do metaOriginal = unArbitraryMeta abMetaOriginal pd = Pandoc metaOriginal blocks (Pandoc newMeta _) = addMeta metaOverwrite pd - keysToPreserve = Map.keysSet (unMeta metaOriginal) `Set.difference` Map.keysSet (unMeta metaOverwrite) - Map.toList (Map.restrictKeys (unMeta newMeta) keysToPreserve) - `shouldMatchList` - Map.toList (Map.restrictKeys (unMeta metaOriginal) keysToPreserve) + ((unMeta metaOriginal `Map.difference` unMeta metaOverwrite) `Map.isSubmapOf` unMeta newMeta) `shouldBe` True it "should preserve document blocks" $ do (metaOverwrite, pd) <- generate arbitrary let (Pandoc _ oldBlocks) = pd (Pandoc _ newBlocks) = addMeta (unArbitraryMeta metaOverwrite) pd - oldBlocks `shouldBe` newBlocks + newBlocks `shouldBe` oldBlocks -- describe "_Meta" . it "is a lens" . property $ isLens _Meta \ No newline at end of file