From 1fc07ff4dae5b3673ac2090d0a52f69afc1f078e Mon Sep 17 00:00:00 2001 From: Albert Krewinkel Date: Sun, 27 Nov 2016 20:31:04 +0100 Subject: Refactor top-level division selection (#3261) The "default" option is no longer represented as `Nothing` but via a new type constructor, making the `Maybe` wrapper superfluous. The default behavior of using heuristics can now be enabled explicitly by setting `--top-level-division=default`. API change (`Text.Pandoc.Options`): The `Division` type was renamed to `TopLevelDivision`. The `Section`, `Chapter`, and `Part` constructors were renamed to `TopLevelSection`, `TopLevelChapter`, and `TopLevelPart`, respectively. An additional `TopLevelDefault` constructor was added, which is now also the new default value of the `writerTopLevelDivision` field in `WriterOptions`. --- tests/Tests/Writers/Docbook.hs | 28 +++++++++++++++++++++++----- tests/Tests/Writers/LaTeX.hs | 39 +++++++++++++++++++++++++++++---------- 2 files changed, 52 insertions(+), 15 deletions(-) (limited to 'tests/Tests/Writers') diff --git a/tests/Tests/Writers/Docbook.hs b/tests/Tests/Writers/Docbook.hs index f2a1e9d7b..a288242dc 100644 --- a/tests/Tests/Writers/Docbook.hs +++ b/tests/Tests/Writers/Docbook.hs @@ -236,11 +236,13 @@ tests = [ testGroup "line blocks" <> header 2 (text "header2") <> header 3 (text "header3") - docbookTopLevelDiv :: (ToPandoc a) => Division -> a -> String + docbookTopLevelDiv :: (ToPandoc a) + => TopLevelDivision -> a -> String docbookTopLevelDiv division = - docbookWithOpts def{ writerTopLevelDivision = Just division } + docbookWithOpts def{ writerTopLevelDivision = division } in - [ test (docbookTopLevelDiv Section) "sections as top-level" $ headers =?> + [ test (docbookTopLevelDiv TopLevelSection) "sections as top-level" $ + headers =?> unlines [ "" , " header1" , " " @@ -253,7 +255,8 @@ tests = [ testGroup "line blocks" , " " , "" ] - , test (docbookTopLevelDiv Chapter) "chapters as top-level" $ headers =?> + , test (docbookTopLevelDiv TopLevelChapter) "chapters as top-level" $ + headers =?> unlines [ "" , " header1" , " " @@ -266,7 +269,8 @@ tests = [ testGroup "line blocks" , " " , "" ] - , test (docbookTopLevelDiv Part) "parts as top-level" $ headers =?> + , test (docbookTopLevelDiv TopLevelPart) "parts as top-level" $ + headers =?> unlines [ "" , " header1" , " " @@ -279,6 +283,20 @@ tests = [ testGroup "line blocks" , " " , "" ] + , test (docbookTopLevelDiv TopLevelDefault) "default top-level" $ + headers =?> + unlines [ "" + , " header1" + , " " + , " header2" + , " " + , " header3" + , " " + , " " + , " " + , " " + , "" + ] ] ] ] diff --git a/tests/Tests/Writers/LaTeX.hs b/tests/Tests/Writers/LaTeX.hs index fb230e89a..d8bfa5924 100644 --- a/tests/Tests/Writers/LaTeX.hs +++ b/tests/Tests/Writers/LaTeX.hs @@ -88,45 +88,64 @@ tests = [ testGroup "code blocks" <> header 2 (text "header2") <> header 3 (text "header3") - latexTopLevelDiv :: (ToPandoc a) => Division -> a -> String + latexTopLevelDiv :: (ToPandoc a) => TopLevelDivision -> a -> String latexTopLevelDiv division = - latexWithOpts def{ writerTopLevelDivision = Just division } + latexWithOpts def{ writerTopLevelDivision = division } - beamerTopLevelDiv :: (ToPandoc a) => Division -> a -> String + beamerTopLevelDiv :: (ToPandoc a) + => TopLevelDivision -> a -> String beamerTopLevelDiv division = - latexWithOpts def { writerTopLevelDivision = Just division + latexWithOpts def { writerTopLevelDivision = division , writerBeamer = True } in - [ test (latexTopLevelDiv Section) "sections as top-level" $ headers =?> + [ test (latexTopLevelDiv TopLevelSection) + "sections as top-level" $ headers =?> unlines [ "\\section{header1}\n" , "\\subsection{header2}\n" , "\\subsubsection{header3}" ] - , test (latexTopLevelDiv Chapter) "chapters as top-level" $ headers =?> + , test (latexTopLevelDiv TopLevelChapter) + "chapters as top-level" $ headers =?> unlines [ "\\chapter{header1}\n" , "\\section{header2}\n" , "\\subsection{header3}" ] - , test (latexTopLevelDiv Part) "parts as top-level" $ headers =?> + , test (latexTopLevelDiv TopLevelPart) + "parts as top-level" $ headers =?> unlines [ "\\part{header1}\n" , "\\chapter{header2}\n" , "\\section{header3}" ] - , test (beamerTopLevelDiv Section) "sections as top-level in beamer" $ headers =?> + , test (latexTopLevelDiv TopLevelDefault) + "default top-level" $ headers =?> unlines [ "\\section{header1}\n" , "\\subsection{header2}\n" , "\\subsubsection{header3}" ] - , test (beamerTopLevelDiv Chapter) "chapters are as part in beamer" $ headers =?> + , test (beamerTopLevelDiv TopLevelSection) + "sections as top-level in beamer" $ headers =?> + unlines [ "\\section{header1}\n" + , "\\subsection{header2}\n" + , "\\subsubsection{header3}" + ] + , test (beamerTopLevelDiv TopLevelChapter) + "chapters are as part in beamer" $ headers =?> unlines [ "\\part{header1}\n" , "\\section{header2}\n" , "\\subsection{header3}" ] - , test (beamerTopLevelDiv Part) "parts as top-level in beamer" $ headers =?> + , test (beamerTopLevelDiv TopLevelPart) + "parts as top-level in beamer" $ headers =?> unlines [ "\\part{header1}\n" , "\\section{header2}\n" , "\\subsection{header3}" ] + , test (beamerTopLevelDiv TopLevelDefault) + "default top-level in beamer" $ headers =?> + unlines [ "\\section{header1}\n" + , "\\subsection{header2}\n" + , "\\subsubsection{header3}" + ] ] ] ] -- cgit v1.2.3