-
Notifications
You must be signed in to change notification settings - Fork 158
/
CommonMarkSpecTest.fs
263 lines (213 loc) · 5.79 KB
/
CommonMarkSpecTest.fs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
module FSharp.Markdown.Tests.CommonMarkSpecTest
open System.IO
open System.Diagnostics
let (</>) a b = Path.Combine(a, b)
let testdir = __SOURCE_DIRECTORY__ </> Path.Combine("..", "..", "tests")
open FSharp.Data
type CommonMarkSpecJson = JsonProvider<"../../tests/commonmark_spec.json">
let sample = CommonMarkSpecJson.GetSamples()
let sections = sample |> Seq.groupBy (fun s -> s.Section)
open FsUnit
open NUnit.Framework
open FSharp.Formatting.Markdown
let properNewLines (text: string) =
text.Replace("\r\n", "\n").Replace("\n", System.Environment.NewLine)
let enabledSections = [ "Fenced code blocks"; "Indented code blocks"; "Paragraphs"; "Precedence"; "Tabs" ]
let getTests () =
sample
|> Seq.choose (fun s ->
let test =
TestCaseData(
s.Section,
s.Markdown,
match s.Html with
| Some html -> html
| None -> ""
)
if enabledSections |> List.contains s.Section |> not then
// test.Ignore("section is not enabled") // too verbose NUnit output
None
elif s.Html.IsNone then
// test.Ignore("html was not given in the test json") // too verbose NUnit output
None
else
Some test)
[<Test>]
[<TestCaseSource("getTests")>]
let ``Commonmark specification`` (_section: string) (markdown: string) (html: string) =
printfn "Markdown: '%s'" markdown
(Markdown.ToHtml(markdown, "\n")) |> should equal html
[<Test>]
let ``manual markdown test: show a blockquote with a code block`` () =
let markdown =
"""Blockquotes can contain other Markdown elements, including headers, lists,
and code blocks:
> ## This is a header.
>
> 1. This is the first list item.
> 2. This is the second list item.
>
> Here's some example code:
>
> return shell_exec("echo $input | $markdown_script");
Any decent text editor should make email-style quoting easy."""
let html =
properNewLines
"""<p>Blockquotes can contain other Markdown elements, including headers, lists,
and code blocks:</p>
<pre><code>> ## This is a header.
>
> 1. This is the first list item.
> 2. This is the second list item.
>
> Here's some example code:
>
> return shell_exec("echo $input | $markdown_script");
</code></pre>
<p>Any decent text editor should make email-style quoting easy.</p>
"""
(Markdown.ToHtml(markdown)) |> should equal html
[<Test>]
let ``manual markdown test: use spaces in the first line of a code block (indent more than 4 spaces)`` () =
let markdown =
"""For example, this:
<div class="footer">
© 2004 Foo Corporation
</div>
will turn into:"""
let html =
properNewLines
"""<p>For example, this:</p>
<pre><code> <div class="footer">
&copy; 2004 Foo Corporation
</div>
</code></pre>
<p>will turn into:</p>
"""
(Markdown.ToHtml(markdown)) |> should equal html
[<Test>]
let ``manual markdown test: use tabs for defining a list`` () =
let markdown =
"+ this is a list item
\tindented with tabs
+ this is a list item
indented with spaces
"
let html =
properNewLines
"""<ul>
<li>
<p>this is a list item
indented with tabs</p>
</li>
<li>
<p>this is a list item
indented with spaces</p>
</li>
</ul>
"""
(Markdown.ToHtml(markdown)) |> should equal html
[<Test>]
let ``manual markdown test: test if we support continuation lines`` () =
let markdown =
"+ this is a list item
with a continuation line
+ this is a list item
indented with spaces
"
let html =
properNewLines
"""<ul>
<li>
<p>this is a list item
with a continuation line</p>
</li>
<li>
<p>this is a list item
indented with spaces</p>
</li>
</ul>
"""
(Markdown.ToHtml(markdown)) |> should equal html
[<Test>]
let ``manual markdown test: test if we can handle paragraph ending with two spaces`` () =
let markdown =
"this is a paragraph ending with two spaces\t\032\032
with a continuation line
"
let html =
properNewLines
"<p>this is a paragraph ending with two spaces\t<br />
with a continuation line</p>
"
(Markdown.ToHtml(markdown)) |> should equal html
[<Test>]
let ``manual markdown test: test that we don't trim tab character at the end`` () =
let markdown =
"this is a paragraph ending with tab \t
with a continuation line
"
let html =
properNewLines
"<p>this is a paragraph ending with tab \t
with a continuation line</p>
"
(Markdown.ToHtml(markdown)) |> should equal html
[<Test>]
let ``manual markdown test: test code block (with tabs) in list`` () =
let markdown =
"- \t Code Block
"
let html =
properNewLines
"<ul>
<li>
<pre><code> Code Block
</code></pre>
</li>
</ul>
"
(Markdown.ToHtml(markdown)) |> should equal html
[<Test>]
let ``manual markdown test: test code block (with spaces) in list`` () =
let markdown =
"- Code Block
"
let html =
properNewLines
"<ul>
<li>
<pre><code> Code Block
</code></pre>
</li>
</ul>
"
(Markdown.ToHtml(markdown)) |> should equal html
[<Test>]
let ``manual markdown test: blockquote with continuation`` () =
let markdown =
"> blockquote
with continuation
"
let html =
properNewLines
"<blockquote>
<p>blockquote
with continuation</p>
</blockquote>
"
(Markdown.ToHtml(markdown)) |> should equal html
[<Test>]
let ``manual markdown test: blockquote without continuation`` () =
let markdown =
"> blockquote
# without continuation
"
let html =
properNewLines
"<blockquote>
<p>blockquote</p>
</blockquote>
<h1>without continuation</h1>
"
(Markdown.ToHtml(markdown)) |> should equal html