From 66fd3247eac9a564aca179ca9fe4fd007ee471e7 Mon Sep 17 00:00:00 2001 From: Sascha Wilde Date: Fri, 27 Oct 2017 01:19:28 +0200 Subject: Creole reader (#3994) This is feature complete but not very thoroughly tested yet. --- test/Tests/Readers/Creole.hs | 273 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 273 insertions(+) create mode 100644 test/Tests/Readers/Creole.hs (limited to 'test/Tests/Readers/Creole.hs') diff --git a/test/Tests/Readers/Creole.hs b/test/Tests/Readers/Creole.hs new file mode 100644 index 000000000..96517c25c --- /dev/null +++ b/test/Tests/Readers/Creole.hs @@ -0,0 +1,273 @@ +{-# LANGUAGE OverloadedStrings #-} +module Tests.Readers.Creole (tests) where + +import Data.Text (Text) +import qualified Data.Text as T +import Test.Tasty +import Tests.Helpers +import Text.Pandoc +import Text.Pandoc.Arbitrary () +import Text.Pandoc.Builder + +creole :: Text -> Pandoc +creole = purely $ readCreole def{ readerStandalone = True } + +infix 4 =: +(=:) :: ToString c + => String -> (Text, c) -> TestTree +(=:) = test creole + +tests :: [TestTree] +tests = [ + testGroup "Basic Text Formatting" [ + "bold, single line, fully delimited" =: + "only **bold** is bold" + =?> para ("only " <> strong "bold" <> " is bold") + , "italics, single line, fully delimited" =: + "only //this// is in italics" + =?> para ("only " <> emph "this" <> " is in italics") + , "bold in italics, fully delimited" =: + "//**this**// is in bold italics" + =?> para (emph (strong "this") <> " is in bold italics") + , "italics in bold, fully delimited" =: + "**//this//** is in bold italics" + =?> para (strong (emph "this") <> " is in bold italics") + + , "escape bold marker" =: + "~**not bold" =?> para "**not bold" + , "escape italics marker" =: + "~//not in italics" =?> para "//not in italics" + + , "inline nowiki, simple" =: + "this is {{{**not** ~interpreted}}} at all" + =?> para ("this is " <> code "**not** ~interpreted" <> " at all") + , "inline nowiki, curly braces inside" =: + "this is {{{{{{//including// some `}' chars}}}}}}" + =?> para ("this is " <> code "{{{//including// some `}' chars}}}") + + , "placeholder" =: + "foo <<>> bar" + =?> para "foo bar" + , "placeholder escaped" =: + "foo ~<<>> bar" + =?> para "foo <<>> bar" + ] + , testGroup "Headers" [ + "header level 1, no space, no trailing =" =: + "= Top-Level Header" + =?> header 1 (str "Top-Level Header") + , "header level 1, leading space, trailing =" =: + " = Top-Level Header = " + =?> header 1 (str "Top-Level Header") + , "header level 2, no space, no trailing =" =: + "== Second Level" + =?> header 2 (str "Second Level") + , "header level 2, leading space, no trailing =" =: + " == Second Level" + =?> header 2 (str "Second Level") + , "header level 3, no space, no trailing =" =: + "=== Third" + =?> header 3 (str "Third") + , "header level 3, no space, > 3 trailing =" =: + "=== Third =======" + =?> header 3 (str "Third") + , "header level 4, no space, no trailing =" =: + "==== Fourth Level Heading" + =?> header 4 (str "Fourth Level Heading") + , "header level 4, no space, < 4 trailing =" =: + "==== Fourth Level Heading ==" + =?> header 4 (str "Fourth Level Heading") + , "header level 5, no space, no trailing =" =: + "===== Fifth" + =?> header 5 (str "Fifth") + , "header level 6, no space, no trailing =" =: + "====== Sixth" + =?> header 6 (str "Sixth") + ] + , testGroup "Paragraphs" [ + "paragraphs: multiple, one line" =: + "first line\n\nanother line\n" + =?> para "first line" <> para "another line" + ] + , testGroup "Lists" [ + "unordered list, two entries, one separating space" =: + "* foo\n* bar" + =?> bulletList [ plain "foo", plain "bar" ] + , "unordered list, three entries, one separating space" =: + "* foo\n* bar\n* baz" + =?> bulletList [ plain "foo", plain "bar", plain "baz" ] + , "para followed by, unordered list, two entries, one separating space" =: + "blubber\n* foo\n* bar" + =?> para "blubber" <> bulletList [ plain "foo", plain "bar" ] + , "nested unordered list, one separating space" =: + "* foo\n** bar\n** baz\n* blubb" + =?> bulletList [ plain "foo" + <> bulletList [ plain "bar", plain "baz" ] + , plain "blubb" ] + , "nested many unordered lists, one separating space" =: + ("* foo\n** bar\n*** third\n*** third two\n** baz\n*** third again\n" + <> "**** fourth\n***** fith\n* blubb") + =?> bulletList [ plain "foo" + <> bulletList [ plain "bar" + <> bulletList [ plain "third" + , plain "third two"] + , plain "baz" + <> bulletList [ plain "third again" + <> bulletList [ + plain "fourth" + <> bulletList [ + plain "fith" + ] + ] + ] + ] + , plain "blubb" ] + , "nested unordered list, mixed separating space" =: + "*foo\n ** bar\n **baz\n * blubb" + =?> bulletList [ plain "foo" + <> bulletList [ plain "bar", plain "baz" ] + , plain "blubb" ] + , "ordered list, two entries, one separating space" =: + "# foo\n# bar" + =?> orderedList [ plain "foo", plain "bar" ] + , "ordered list, three entries, one separating space" =: + "# foo\n# bar\n# baz" + =?> orderedList [ plain "foo", plain "bar", plain "baz" ] + , "para followed by, ordered list, two entries, one separating space" =: + "blubber\n# foo\n# bar" + =?> para "blubber" <> orderedList [ plain "foo", plain "bar" ] + , "nested ordered list, one separating space" =: + "# foo\n## bar\n## baz\n# blubb" + =?> orderedList [ plain "foo" + <> orderedList [ plain "bar", plain "baz" ] + , plain "blubb" ] + , "nested many ordered lists, one separating space" =: + ("# foo\n## bar\n### third\n### third two\n## baz\n### third again\n" + <> "#### fourth\n##### fith\n# blubb") + =?> orderedList [ plain "foo" + <> orderedList [ plain "bar" + <> orderedList [ plain "third" + , plain "third two"] + , plain "baz" + <> orderedList [ plain "third again" + <> orderedList [ + plain "fourth" + <> orderedList [ + plain "fith" + ] + ] + ] + ] + , plain "blubb" ] + , "nested ordered list, mixed separating space" =: + "#foo\n ## bar\n ##baz\n # blubb" + =?> orderedList [ plain "foo" + <> orderedList [ plain "bar", plain "baz" ] + , plain "blubb" ] + , "mixed nested ordered and unordered lists, one separating space" =: + ("# foo\n** bar\n### third\n### third two\n** baz\n### third again\n" + <> "#### fourth\n***** fith\n# blubb") + =?> orderedList [ plain "foo" + <> bulletList [ plain "bar" + <> orderedList [ plain "third" + , plain "third two"] + , plain "baz" + <> orderedList [ plain "third again" + <> orderedList [ + plain "fourth" + <> bulletList [ + plain "fith" + ] + ] + ] + ] + , plain "blubb" ] + ] + , testGroup "NoWiki" [ + "quoted block, simple" =: + "{{{\nfoo bar\n //baz//\n}}}" + =?> codeBlock "foo bar\n //baz//" + , "quoted block, curly bracket exception" =: + "{{{\nfoo bar\n }}}\nbaz\n }}}\n}}}" + =?> codeBlock "foo bar\n }}}\nbaz\n}}}" + , "forced line breaks" =: + "{{{no break!\\\\here}}} but a break\\\\here!" + =?> para (code "no break!\\\\here" <> " but a break" + <> linebreak <> "here!") + ] + , testGroup "Images and Links" [ + "image simple" =: + "{{foo.png}}" =?> para (image "foo.png" "" (str "")) + , "image with alt text" =: + "Image of a bar: {{/path/to/bar.png|A Bar}} look at it!" + =?> para ("Image of a bar: " + <> image "/path/to/bar.png" "" (str "A Bar") <> " look at it!") + + , "auto link" =: + "foo http://foo.example.com/bar/baz.html bar" + =?> para ("foo " + <> link "http://foo.example.com/bar/baz.html" "" + (str "http://foo.example.com/bar/baz.html") + <> " bar") + , "escaped auto link" =: + "foo ~http://foo.example.com/bar/baz.html bar" + =?> para ("foo http://foo.example.com/bar/baz.html bar") + , "wiki link simple" =: + "foo [[http://foo.example.com/foo.png]] bar" + =?> para ("foo " + <> link "http://foo.example.com/foo.png" "" + (str "http://foo.example.com/foo.png") + <> " bar") + , "wiki link with name" =: + "foo [[http://foo.example.com/foo.png|my link]] bar" + =?> para ("foo " + <> link "http://foo.example.com/foo.png" "" + (str "my link") + <> " bar") + , "image link" =: + "[[http://foo.example.com/|{{foo.png}}]]" + =?> para (link "http://foo.example.com/" "" (image "foo.png" "" (str ""))) + ] + , testGroup "Table" [ + "Table with Header" =: + T.unlines [ "|= Foo |= Bar |= Baz |" + , "| One | Two | Three |" + , "| 1 | 2 | 3 |" + , "| A | B | C |" + ] + =?> simpleTable + [plain "Foo", plain "Bar" , plain "Baz"] + [[plain "One", plain "Two" , plain "Three"] + ,[plain "1", plain "2" , plain "3"] + ,[plain "A", plain "B" , plain "C"]] + , "Table without Header" =: + T.unlines [ "| One | Two | Three |" + , "| 1 | 2 | 3 |" + , "| A | B | C |" + ] + =?> simpleTable [mempty] + [[plain "One", plain "Two" , plain "Three"] + ,[plain "1", plain "2" , plain "3"] + ,[plain "A", plain "B" , plain "C"]] + , "Table without Header, no markers at line ends" =: + T.unlines [ "| One | Two | Three" + , "| 1 | 2 | 3" + , "| A | B | C " + ] + =?> simpleTable [mempty] + [[plain "One", plain "Two" , plain "Three"] + ,[plain "1", plain "2" , plain "3"] + ,[plain "A", plain "B" , plain "C"]] + , "Table with Header, with formatting" =: + T.unlines [ "|= **Foo** |= **Bar** |= **Baz** |" + , "|//one// element |//second// elt|Three |" + , "| {{{1}}} | {{{{}}}} | [[link]] |" + ] + =?> simpleTable + [plain $ strong "Foo", plain $ strong "Bar" , plain $ strong "Baz"] + [[plain (emph "one" <> " element"), plain (emph "second" <> " elt") + ,plain "Three"] + ,[plain $ code "1", plain $ code "{}" + ,plain $ link "link" "" (str "link")]] + ] + ] -- cgit v1.2.3 From fa67d6e86ff1464874480cde84d329f02f132474 Mon Sep 17 00:00:00 2001 From: Sascha Wilde Date: Tue, 31 Oct 2017 18:55:27 +0100 Subject: Creole reader: fixed lists with trailing white space. --- test/Tests/Readers/Creole.hs | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'test/Tests/Readers/Creole.hs') diff --git a/test/Tests/Readers/Creole.hs b/test/Tests/Readers/Creole.hs index 96517c25c..5b8e452b3 100644 --- a/test/Tests/Readers/Creole.hs +++ b/test/Tests/Readers/Creole.hs @@ -127,6 +127,11 @@ tests = [ =?> bulletList [ plain "foo" <> bulletList [ plain "bar", plain "baz" ] , plain "blubb" ] + , "nested unordered list, one separating space, trailing space" =: + "* foo \n** bar \n** baz \n* blubb " + =?> bulletList [ plain "foo" + <> bulletList [ plain "bar", plain "baz" ] + , plain "blubb" ] , "ordered list, two entries, one separating space" =: "# foo\n# bar" =?> orderedList [ plain "foo", plain "bar" ] @@ -141,6 +146,11 @@ tests = [ =?> orderedList [ plain "foo" <> orderedList [ plain "bar", plain "baz" ] , plain "blubb" ] + , "nested ordered list, one separating space, trailing space" =: + "# foo \n## bar \n## baz \n# blubb " + =?> orderedList [ plain "foo" + <> orderedList [ plain "bar", plain "baz" ] + , plain "blubb" ] , "nested many ordered lists, one separating space" =: ("# foo\n## bar\n### third\n### third two\n## baz\n### third again\n" <> "#### fourth\n##### fith\n# blubb") -- cgit v1.2.3 From 03361f0a685865d6e476dbd5a11ab75968af7b5c Mon Sep 17 00:00:00 2001 From: Sascha Wilde Date: Tue, 31 Oct 2017 22:26:35 +0100 Subject: Creole reader: additional test on nowiki-block after para. --- test/Tests/Readers/Creole.hs | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'test/Tests/Readers/Creole.hs') diff --git a/test/Tests/Readers/Creole.hs b/test/Tests/Readers/Creole.hs index 5b8e452b3..3a21df738 100644 --- a/test/Tests/Readers/Creole.hs +++ b/test/Tests/Readers/Creole.hs @@ -203,7 +203,10 @@ tests = [ , "forced line breaks" =: "{{{no break!\\\\here}}} but a break\\\\here!" =?> para (code "no break!\\\\here" <> " but a break" - <> linebreak <> "here!") + <> linebreak <> "here!"), + "quoted block, after trailing white space" =: + "this is a paragraph \n{{{\nfoo bar\n //baz//\n}}}" + =?> para "this is a paragraph" <> codeBlock "foo bar\n //baz//" ] , testGroup "Images and Links" [ "image simple" =: -- cgit v1.2.3 From b8ffd834cff717fe424f22e506351f2ecec4655a Mon Sep 17 00:00:00 2001 From: John MacFarlane Date: Fri, 19 Jan 2018 21:25:24 -0800 Subject: hlint code improvements. --- test/Tests/Readers/Creole.hs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'test/Tests/Readers/Creole.hs') diff --git a/test/Tests/Readers/Creole.hs b/test/Tests/Readers/Creole.hs index 3a21df738..3f60a523d 100644 --- a/test/Tests/Readers/Creole.hs +++ b/test/Tests/Readers/Creole.hs @@ -224,7 +224,7 @@ tests = [ <> " bar") , "escaped auto link" =: "foo ~http://foo.example.com/bar/baz.html bar" - =?> para ("foo http://foo.example.com/bar/baz.html bar") + =?> para "foo http://foo.example.com/bar/baz.html bar" , "wiki link simple" =: "foo [[http://foo.example.com/foo.png]] bar" =?> para ("foo " -- cgit v1.2.3