lib/core/stream: LineIterator use CachedIterator
[nit.git] / lib / markdown2 / tests / test_markdown_man.nit
1 # This file is part of NIT ( http://www.nitlanguage.org ).
2 #
3 # Licensed under the Apache License, Version 2.0 (the "License");
4 # you may not use this file except in compliance with the License.
5 # You may obtain a copy of the License at
6 #
7 # http://www.apache.org/licenses/LICENSE-2.0
8 #
9 # Unless required by applicable law or agreed to in writing, software
10 # distributed under the License is distributed on an "AS IS" BASIS,
11 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 # See the License for the specific language governing permissions and
13 # limitations under the License.
14
15 # Tests for markdown rendering to manpage
16 module test_markdown_man is test
17
18 import test_markdown
19 import markdown_man_rendering
20
21 # Abstract test class that defines the test methods for Man rendering
22 abstract class TestMarkdownMan
23 super TestMarkdown
24
25 # Man renderer used in tests
26 var man_renderer = new ManRenderer
27
28 # Render the `md` string as Manpage format
29 fun md_to_man(md: String): String do
30 var node = parse_md(md)
31 return man_renderer.render(node)
32 end
33 end
34
35 class TestManRendering
36 super TestMarkdownMan
37 test
38
39 fun test_headings is test do
40 var md = """# title1\n## title2\n### title3\n#### title4\n##### title5\n###### title6\n"""
41 var man = """.SH title1\n.SS title2\n.TP\ntitle3\n.TP\ntitle4\n.TP\ntitle5\n.TP\ntitle6\n"""
42 assert md_to_man(md) == man
43 end
44
45 fun test_bquotes is test do
46 var md = """> line 1\n> line 2\n\n> line 3\n>line 4"""
47 var man = """.RS\nline 1\nline 2\n.RE\n.RS\nline 3\nline 4\n.RE\n"""
48 assert md_to_man(md) == man
49 end
50
51 fun test_breaks is test do
52 var md = """* * *"""
53 var man = """***\n"""
54 assert md_to_man(md) == man
55 end
56
57 fun test_indented_code is test do
58 var md = """\tline 1\n\tline 2\n"""
59 var man = """.RS\n.nf\n\\f[C]\nline\\ 1\nline\\ 2\n\\f[]\n.fi\n.RE\n"""
60 assert md_to_man(md) == man
61 end
62
63 fun test_fenced_code is test do
64 var md = """~~~\nline 1\nline 2\n~~~\n"""
65 var man = """.RS\n.nf\n\\f[C]\nline\\ 1\nline\\ 2\n\\f[]\n.fi\n.RE\n"""
66 assert md_to_man(md) == man
67 end
68
69 fun test_escaped_code is test do
70 var md = """\tline - 1\n\tline - 2\n"""
71 var man = """.RS\n.nf\n\\f[C]\nline\\ \\-\\ 1\nline\\ \\-\\ 2\n\\f[]\n.fi\n.RE\n"""
72 assert md_to_man(md) == man
73 end
74
75 fun test_unordered_list is test do
76 var md = """* line 1\n* line 2\n"""
77 var man = """.RS\n.IP \\[bu] 3\nline 1\n.IP \\[bu] 3\nline 2\n.RE\n"""
78 assert md_to_man(md) == man
79 end
80
81 fun test_ordered_list is test do
82 var md = """2) line 1\n3) line 2\n"""
83 var man = """.RS\n.IP "2." 3\nline 1\n.IP "3." 3\nline 2\n.RE\n"""
84 assert md_to_man(md) == man
85 end
86
87 fun test_paragraph is test do
88 var md = """line 1\nline 2\n\nline 3\nline 4\n"""
89 var man = """\nline 1\nline 2\n\nline 3\nline 4\n"""
90 assert md_to_man(md) == man
91 end
92
93 fun test_escaped_text is test do
94 var md = """foo - bar\n"""
95 var man = """\nfoo \\- bar\n"""
96 assert md_to_man(md) == man
97 end
98
99 fun test_inline_code is test do
100 var md = """`foo - bar`\n"""
101 var man = """\n\\f[C]foo\\ \\-\\ bar\\f[]\n"""
102 assert md_to_man(md) == man
103 end
104
105 fun test_emphasis is test do
106 var md = """*foo*\n"""
107 var man = """\n\\f[I]foo\\f[]\n"""
108 assert md_to_man(md) == man
109 end
110
111 fun test_strong_emphasis is test do
112 var md = """**foo**\n"""
113 var man = """\n\\f[B]foo\\f[]\n"""
114 assert md_to_man(md) == man
115 end
116
117 fun test_link is test do
118 var md = """[foo](url "title")\n"""
119 var man = """\nfoo (url title)\n"""
120 assert md_to_man(md) == man
121 end
122
123 fun test_image is test do
124 var md = """![foo](url "title")\n"""
125 var man = """\nfoo (url title)\n"""
126 assert md_to_man(md) == man
127 end
128
129 fun test_full_document is test do
130
131 var md = """
132 # NAME
133
134 nitdoc - generates HTML pages of API documentation from Nit source files.
135
136 # SYNOPSIS
137
138 nitdoc [*options*]... FILE...
139
140 # DESCRIPTION
141
142 `nitdoc` takes one or more modules and generate HTML pages of API documentation for these modules and their imported modules.
143
144 The documentation is extracted from the comments found above the definition of modules, classes, and properties.
145
146 Internally, `nitdoc` relies on the presence of the `dot` command from the [graphviz] project.
147 If the dot program is not present or not found, no image of hierarchies are generated.
148 See option `--no-dot`.
149
150 The documentation of the Nit [standard library] is generated with this tool.
151
152 [graphviz]: http://www.graphviz.org
153 [standard library]: http://nitlanguage.org/doc/stdlib
154
155 # DOCUMENTATION FORMAT
156
157 The format of the documentation is a dialect of [markdown] that allows GitHub fences (`~~~`).
158
159 Code blocks are interpreted as snippets of Nit programs and intended to be used as examples of code.
160 When these code snippets are valid, executable and contain at least and `assert` clause, they could be automatically executed and verified.
161 See `nitunit(1)` for details.
162
163 [markdown]: http://daringfireball.net/projects/markdown
164
165 # OPTIONS
166
167 ### `-d`, `--dir`
168 Output directory.
169
170 Where the HTML files are generated.
171
172 By default, the directory is named `doc`.
173
174 ### `--source`
175 Format to link source code.
176
177 The format string is used to generated links to some parts of the source-code.
178 Use `%f` for filename, `%l` for first line, and `%L` for last line.
179
180 For instance, the [standard library] use the following value to link to files in GitHub:
181
182 "https://github.com/nitlang/nit/blob/$(git rev-parse HEAD)/%f#L%l-%L"
183
184 Here, the `git rev-parse HEAD` is used to link to the current snapshot revision of the file.
185
186 ### `--no-attributes`
187 Ignore the attributes.
188
189 Note: In Nit, attributes are private. Therefore, this option is only useful
190 when combined with `--private`.
191
192 ### `--no-dot`
193 Do not generate graphs with graphviz.
194
195 ### `--private`
196 Also generate private API.
197
198 ## CUSTOMIZATION
199
200 ### `--share-dir`
201 Directory containing tools assets.
202
203 By default `$NIT_DIR/share/nitdoc/` is used.
204
205 ### `--shareurl`
206 Use shareurl instead of copy shared files.
207
208 By default, assets from the sharedir a copied into the output directory and referred with a relative path in the generated files.
209 With this option, the assets are not copied and the given URL of path is used in the generated files to locate assets.
210
211 ### `--custom-title`
212 Custom title for homepage.
213
214 ### `--custom-footer-text`
215 Custom footer text.
216
217 ### `--custom-overview-text`
218 Custom intro text for homepage.
219
220 ### `--custom-brand`
221 Custom link to external site.
222
223 ## SERVICES
224
225 ### `--github-upstream`
226 Git branch where edited commits will be pulled into (ex: user:repo:branch).
227
228 ### `--github-base-sha1`
229 Git sha1 of base commit used to create pull request.
230
231 ### `--github-gitdir`
232 Git working directory used to resolve path name (ex: /home/me/myproject/).
233
234 ### `--piwik-tracker`
235 Piwik tracker URL (ex: `nitlanguage.org/piwik/`).
236
237 ### `--piwik-site-id`
238 Piwik site ID.
239
240 ## TESTING
241
242 ### `--test`
243 Print test data (metrics and structure).
244
245 ### `--no-render`
246 Do not render HTML files.
247
248 # SEE ALSO
249
250 The Nit language documentation and the source code of its tools and libraries may be downloaded from <http://nitlanguage.org>
251 """
252
253 var man = """
254 .SH NAME
255
256 nitdoc \\- generates HTML pages of API documentation from Nit source files.
257 .SH SYNOPSIS
258
259 nitdoc [\\f[I]options\\f[]]... FILE...
260 .SH DESCRIPTION
261
262 \\f[C]nitdoc\\f[] takes one or more modules and generate HTML pages of API documentation for these modules and their imported modules.
263
264 The documentation is extracted from the comments found above the definition of modules, classes, and properties.
265
266 Internally, \\f[C]nitdoc\\f[] relies on the presence of the \\f[C]dot\\f[] command from the graphviz (http://www.graphviz.org) project.
267 If the dot program is not present or not found, no image of hierarchies are generated.
268 See option \\f[C]\\-\\-no\\-dot\\f[].
269
270 The documentation of the Nit standard library (http://nitlanguage.org/doc/stdlib) is generated with this tool.
271 .SH DOCUMENTATION FORMAT
272
273 The format of the documentation is a dialect of markdown (http://daringfireball.net/projects/markdown) that allows GitHub fences (\\f[C]~~~\\f[]).
274
275 Code blocks are interpreted as snippets of Nit programs and intended to be used as examples of code.
276 When these code snippets are valid, executable and contain at least and \\f[C]assert\\f[] clause, they could be automatically executed and verified.
277 See \\f[C]nitunit(1)\\f[] for details.
278 .SH OPTIONS
279 .TP
280 \\f[C]\\-d\\f[], \\f[C]\\-\\-dir\\f[]
281
282 Output directory.
283
284 Where the HTML files are generated.
285
286 By default, the directory is named \\f[C]doc\\f[].
287 .TP
288 \\f[C]\\-\\-source\\f[]
289
290 Format to link source code.
291
292 The format string is used to generated links to some parts of the source\\-code.
293 Use \\f[C]%f\\f[] for filename, \\f[C]%l\\f[] for first line, and \\f[C]%L\\f[] for last line.
294
295 For instance, the standard library (http://nitlanguage.org/doc/stdlib) use the following value to link to files in GitHub:
296 .RS
297 .nf
298 \\f[C]
299 "https://github.com/nitlang/nit/blob/$(git\\ rev\\-parse\\ HEAD)/%f#L%l\\-%L"
300 \\f[]
301 .fi
302 .RE
303
304 Here, the \\f[C]git\\ rev\\-parse\\ HEAD\\f[] is used to link to the current snapshot revision of the file.
305 .TP
306 \\f[C]\\-\\-no\\-attributes\\f[]
307
308 Ignore the attributes.
309
310 Note: In Nit, attributes are private. Therefore, this option is only useful
311 when combined with \\f[C]\\-\\-private\\f[].
312 .TP
313 \\f[C]\\-\\-no\\-dot\\f[]
314
315 Do not generate graphs with graphviz.
316 .TP
317 \\f[C]\\-\\-private\\f[]
318
319 Also generate private API.
320 .SS CUSTOMIZATION
321 .TP
322 \\f[C]\\-\\-share\\-dir\\f[]
323
324 Directory containing tools assets.
325
326 By default \\f[C]$NIT_DIR/share/nitdoc/\\f[] is used.
327 .TP
328 \\f[C]\\-\\-shareurl\\f[]
329
330 Use shareurl instead of copy shared files.
331
332 By default, assets from the sharedir a copied into the output directory and referred with a relative path in the generated files.
333 With this option, the assets are not copied and the given URL of path is used in the generated files to locate assets.
334 .TP
335 \\f[C]\\-\\-custom\\-title\\f[]
336
337 Custom title for homepage.
338 .TP
339 \\f[C]\\-\\-custom\\-footer\\-text\\f[]
340
341 Custom footer text.
342 .TP
343 \\f[C]\\-\\-custom\\-overview\\-text\\f[]
344
345 Custom intro text for homepage.
346 .TP
347 \\f[C]\\-\\-custom\\-brand\\f[]
348
349 Custom link to external site.
350 .SS SERVICES
351 .TP
352 \\f[C]\\-\\-github\\-upstream\\f[]
353
354 Git branch where edited commits will be pulled into (ex: user:repo:branch).
355 .TP
356 \\f[C]\\-\\-github\\-base\\-sha1\\f[]
357
358 Git sha1 of base commit used to create pull request.
359 .TP
360 \\f[C]\\-\\-github\\-gitdir\\f[]
361
362 Git working directory used to resolve path name (ex: /home/me/myproject/).
363 .TP
364 \\f[C]\\-\\-piwik\\-tracker\\f[]
365
366 Piwik tracker URL (ex: \\f[C]nitlanguage.org/piwik/\\f[]).
367 .TP
368 \\f[C]\\-\\-piwik\\-site\\-id\\f[]
369
370 Piwik site ID.
371 .SS TESTING
372 .TP
373 \\f[C]\\-\\-test\\f[]
374
375 Print test data (metrics and structure).
376 .TP
377 \\f[C]\\-\\-no\\-render\\f[]
378
379 Do not render HTML files.
380 .SH SEE ALSO
381
382 The Nit language documentation and the source code of its tools and libraries may be downloaded from http://nitlanguage.org (http://nitlanguage.org)
383 """
384 assert md_to_man(md) == man
385 end
386 end