git.iko.soy/typeable/pandoc
on master help sign in
Markdown writer: add test for note placement.
commit4b0dbdc11822aa57fcd8b96d6e0be5b645d33a87 authorJesse Rosenthal <jrosenthal@jhu.edu> dateTue 11 Oct 2016, 22:26 (10 years ago) parent14209b2
1 file changed+138−2
tests/Tests/Writers/Markdown.hs+138−2
tests/Tests/Writers/Markdown.hs+138−2
@@ -11,6 +11,9 @@ import Tests.Arbitrary()
1111markdown :: (ToPandoc a) => a -> String
1212markdown = writeMarkdown def . toPandoc
1313
14+markdownWithOpts :: (ToPandoc a) => WriterOptions -> a -> String
15+markdownWithOpts opts x = writeMarkdown opts $ toPandoc x
16+
1417{-
1518 "my test" =: X =?> Y
1619
@@ -36,13 +39,146 @@ tests = [ "indented code after list"
3639 =: bulletList [ plain "foo" <> bulletList [ plain "bar" ],
3740 plain "baz" ]
3841 =?> "- foo\n - bar\n- baz\n"
39− ] ++ [shortcutLinkRefsTests]
42+ ] ++ [noteTests] ++ [shortcutLinkRefsTests]
43+
44+{-
45+
46+Testing with the following text:
47+
48+First Header
49+============
50+
51+This is a footnote.[^1] And this is a [link](https://www.google.com).
52+
53+> A note inside a block quote.[^2]
54+>
55+> A second paragraph.
56+
57+Second Header
58+=============
59+
60+Some more text.
61+
62+
63+[^1]: Down here.
64+
65+[^2]: The second note.
66+
67+-}
68+
69+noteTestDoc :: Blocks
70+noteTestDoc =
71+ header 1 "First Header" <>
72+ para ("This is a footnote." <>
73+ note (para "Down here.") <>
74+ " And this is a " <>
75+ link "https://www.google.com" "" "link" <>
76+ ".") <>
77+ blockQuote (para ("A note inside a block quote." <>
78+ note (para "The second note.")) <>
79+ para ("A second paragraph.")) <>
80+ header 1 "Second Header" <>
81+ para "Some more text."
82+
83+
84+
85+noteTests :: Test
86+noteTests = testGroup "note and reference location"
87+ [ test (markdownWithOpts def)
88+ "footnotes at the end of a document" $
89+ noteTestDoc =?>
90+ (unlines $ [ "First Header"
91+ , "============"
92+ , ""
93+ , "This is a footnote.[^1] And this is a [link](https://www.google.com)."
94+ , ""
95+ , "> A note inside a block quote.[^2]"
96+ , ">"
97+ , "> A second paragraph."
98+ , ""
99+ , "Second Header"
100+ , "============="
101+ , ""
102+ , "Some more text."
103+ , ""
104+ , "[^1]: Down here."
105+ , ""
106+ , "[^2]: The second note."
107+ ])
108+ , test (markdownWithOpts def{writerReferenceLocation=EndOfBlock})
109+ "footnotes at the end of blocks" $
110+ noteTestDoc =?>
111+ (unlines $ [ "First Header"
112+ , "============"
113+ , ""
114+ , "This is a footnote.[^1] And this is a [link](https://www.google.com)."
115+ , ""
116+ , "[^1]: Down here."
117+ , ""
118+ , "> A note inside a block quote.[^2]"
119+ , ">"
120+ , "> A second paragraph."
121+ , ""
122+ , "[^2]: The second note."
123+ , ""
124+ , "Second Header"
125+ , "============="
126+ , ""
127+ , "Some more text."
128+ ])
129+ , test (markdownWithOpts def{writerReferenceLocation=EndOfBlock, writerReferenceLinks=True})
130+ "footnotes and reference links at the end of blocks" $
131+ noteTestDoc =?>
132+ (unlines $ [ "First Header"
133+ , "============"
134+ , ""
135+ , "This is a footnote.[^1] And this is a [link]."
136+ , ""
137+ , "[^1]: Down here."
138+ , ""
139+ , " [link]: https://www.google.com"
140+ , ""
141+ , "> A note inside a block quote.[^2]"
142+ , ">"
143+ , "> A second paragraph."
144+ , ""
145+ , "[^2]: The second note."
146+ , ""
147+ , "Second Header"
148+ , "============="
149+ , ""
150+ , "Some more text."
151+ ])
152+ , test (markdownWithOpts def{writerReferenceLocation=EndOfSection})
153+ "footnotes at the end of section" $
154+ noteTestDoc =?>
155+ (unlines $ [ "First Header"
156+ , "============"
157+ , ""
158+ , "This is a footnote.[^1] And this is a [link](https://www.google.com)."
159+ , ""
160+ , "> A note inside a block quote.[^2]"
161+ , ">"
162+ , "> A second paragraph."
163+ , ""
164+ , "[^1]: Down here."
165+ , ""
166+ , "[^2]: The second note."
167+ , ""
168+ , "Second Header"
169+ , "============="
170+ , ""
171+ , "Some more text."
172+ ])
173+
174+ ]
40175
41176shortcutLinkRefsTests :: Test
42177shortcutLinkRefsTests =
43178 let infix 4 =:
44179 (=:) :: (ToString a, ToPandoc a)
45− => String -> (a, String) -> Test
180+
181+ => String -> (a, String) -> Test
46182 (=:) = test (writeMarkdown (def {writerReferenceLinks = True}) . toPandoc)
47183 in testGroup "Shortcut reference links"
48184 [ "Simple link (shortcutable)"