From 82d9f5eb8ba60bca5760ac84357ed056c0cf4853 Mon Sep 17 00:00:00 2001 From: John MacFarlane Date: Tue, 8 Mar 2022 09:53:57 -0800 Subject: [PATCH] Add tests for idempotency of makeSections. See #7950. --- test/Tests/Shared.hs | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/test/Tests/Shared.hs b/test/Tests/Shared.hs index 797d9fe75..439196145 100644 --- a/test/Tests/Shared.hs +++ b/test/Tests/Shared.hs @@ -15,6 +15,7 @@ module Tests.Shared (tests) where import System.FilePath.Posix (joinPath) import Test.Tasty import Text.Pandoc.Arbitrary () +import Test.Tasty.QuickCheck (testProperty) import Text.Pandoc.Builder import Text.Pandoc.Shared import Test.Tasty.HUnit @@ -33,7 +34,21 @@ tests = [ testGroup "compactifyDL" , testGroup "collapseFilePath" testCollapse , testGroup "toLegacyTable" testLegacyTable , testGroup "table of contents" testTOC - ] + , testGroup "makeSections" + [ testProperty "makeSections is idempotent" makeSectionsIsIdempotent + , testCase "makeSections is idempotent for test case" $ + let d = header 1 "H1" <> header 2 "H2" <> header 3 "H3" <> + header 2 "H2a" <> header 4 "H4" <> header 1 "H1a" + d' = makeSections False Nothing $ toList d + in assertBool "makeSections is idempotent for test case" + (makeSections False Nothing d' == d') + ] + ] + +makeSectionsIsIdempotent :: [Block] -> Bool +makeSectionsIsIdempotent d = + let d' = makeSections False Nothing d + in d' == makeSections False Nothing d' givesTOC :: String -> (Blocks, Blocks) -> TestTree givesTOC desc (blocks, toc) = test (toTableOfContents def) desc (toList blocks, head . toList $ toc)