pseudohikiparser 0.0.0.6.develop → 0.0.0.7.develop

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,436 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'test/unit'
4
+ require 'pseudohiki/markdownformat'
5
+
6
+ class TC_MarkDownFormat < Test::Unit::TestCase
7
+ include PseudoHiki
8
+
9
+ def setup
10
+ @formatter = MarkDownFormat.create
11
+ @gfm_formatter = MarkDownFormat.create({ :gfm_style => true })
12
+ @forced_gfm_formatter = MarkDownFormat.create({ :gfm_style => :force })
13
+ end
14
+
15
+ def test_plain
16
+ text = <<TEXT
17
+ test string
18
+ TEXT
19
+ tree = BlockParser.parse(text.lines.to_a)
20
+ assert_equal("test string\n#{$/}", @formatter.format(tree).to_s)
21
+ end
22
+
23
+ def test_link_url
24
+ text = <<TEXT
25
+ A test string with a [[link|http://www.example.org/]] is here.
26
+ TEXT
27
+ tree = BlockParser.parse(text.lines.to_a)
28
+ assert_equal("A test string with a [link](http://www.example.org/) is here.\n#{$/}", @formatter.format(tree).to_s)
29
+ end
30
+
31
+ def test_link_image
32
+ image = <<IMAGE
33
+ A test for a link to [[an image|image.png]]
34
+ IMAGE
35
+ tree = BlockParser.parse(image.lines.to_a)
36
+ assert_equal("A test for a link to ![an image](image.png)\n#{$/}", @formatter.format(tree).to_s)
37
+ end
38
+
39
+ def test_em
40
+ text = "string with ''emphasis'' "
41
+ tree = BlockParser.parse(text.lines.to_a)
42
+ assert_equal("string with _emphasis_ #{$/}", @formatter.format(tree).to_s)
43
+ end
44
+
45
+ def test_strong
46
+ text = "string with '''emphasis''' "
47
+ tree = BlockParser.parse(text.lines.to_a)
48
+ assert_equal("string with **emphasis** #{$/}", @formatter.format(tree).to_s)
49
+ end
50
+
51
+ def test_del
52
+ text = "a ==striked out string=="
53
+ tree = BlockParser.parse(text.lines.to_a)
54
+ assert_equal("a ~~striked out string~~#{$/}", @formatter.format(tree).to_s)
55
+ end
56
+
57
+ def test_hr
58
+ text = "----#{$/}"
59
+ md_text = "----#{$/}"
60
+ tree = BlockParser.parse(text.lines.to_a)
61
+ assert_equal(md_text, @formatter.format(tree).to_s)
62
+ end
63
+
64
+ def test_desc
65
+ text = <<TEXT
66
+ :word 1:description of word 1
67
+ :word 2:description of word 2
68
+ TEXT
69
+
70
+ html = <<HTML
71
+ <dt>word 1</dt>
72
+ <dd>description of word 1</dd>
73
+ <dt>word 2</dt>
74
+ <dd>description of word 2</dd>
75
+
76
+ HTML
77
+
78
+ tree = BlockParser.parse(text.lines.to_a)
79
+ assert_equal(html, @formatter.format(tree).to_s)
80
+ end
81
+
82
+ def test_verbatim
83
+ text = <<TEXT
84
+ verbatim ''line'' 1
85
+ verbatim line 2
86
+ TEXT
87
+
88
+ gfm_text =<<TEXT
89
+ ```
90
+ verbatim ''line'' 1
91
+ verbatim line 2
92
+ ```
93
+
94
+ TEXT
95
+
96
+ md_text = <<TEXT
97
+ verbatim ''line'' 1
98
+ verbatim line 2
99
+
100
+ TEXT
101
+
102
+ tree = BlockParser.parse(text.lines.to_a)
103
+ assert_equal(gfm_text, @gfm_formatter.format(tree).to_s)
104
+ assert_equal(md_text, @formatter.format(tree).to_s)
105
+ end
106
+
107
+ def test_comment_out
108
+ text = <<TEXT
109
+ a line
110
+ //a comment
111
+ TEXT
112
+
113
+ md_text = <<TEXT
114
+ a line
115
+
116
+ TEXT
117
+
118
+ tree = BlockParser.parse(text.lines.to_a)
119
+ assert_equal(md_text, @formatter.format(tree).to_s)
120
+ end
121
+
122
+ def test_quote
123
+ text = <<TEXT
124
+ ""quoted text: line 1
125
+ ""quoted text: line 2
126
+ TEXT
127
+
128
+ md_text = <<TEXT
129
+ > quoted text: line 1
130
+ > quoted text: line 2
131
+
132
+ TEXT
133
+ tree = BlockParser.parse(text.lines.to_a)
134
+ assert_equal(md_text, @formatter.format(tree).to_s)
135
+ end
136
+
137
+ def test_table
138
+ text = <<TEXT
139
+ ||!header 1||!header 2
140
+ ||cell 1-1||cell 1-2
141
+ ||cell 2-1||cell 2-2
142
+ ||cell 3-1 (a bit wider)||cell 3-2
143
+ TEXT
144
+
145
+ md_text = <<TEXT
146
+ |header 1 |header 2|
147
+ |----------------------|--------|
148
+ |cell 1-1 |cell 1-2|
149
+ |cell 2-1 |cell 2-2|
150
+ |cell 3-1 (a bit wider)|cell 3-2|
151
+ TEXT
152
+
153
+ html =<<HTML
154
+ <table>
155
+ <tr><th>header 1</th><th>header 2</th></tr>
156
+ <tr><td>cell 1-1</td><td>cell 1-2</td></tr>
157
+ <tr><td>cell 2-1</td><td>cell 2-2</td></tr>
158
+ <tr><td>cell 3-1 (a bit wider)</td><td>cell 3-2</td></tr>
159
+ </table>
160
+
161
+ HTML
162
+
163
+ tree = BlockParser.parse(text.lines.to_a)
164
+ assert_equal(md_text, @gfm_formatter.format(tree).to_s)
165
+ assert_equal(html, @formatter.format(tree).to_s)
166
+ end
167
+
168
+ def test_non_gfm_conformant_table
169
+ text = <<TEXT
170
+ ||header 1||!header 2
171
+ ||cell 1-1||cell 1-2
172
+ ||cell 2-1||cell 2-2
173
+ ||cell 3-1 (a bit wider)||cell 3-2
174
+ TEXT
175
+
176
+ md_text = <<TEXT
177
+ |header 1 |header 2|
178
+ |----------------------|--------|
179
+ |cell 1-1 |cell 1-2|
180
+ |cell 2-1 |cell 2-2|
181
+ |cell 3-1 (a bit wider)|cell 3-2|
182
+ TEXT
183
+
184
+ html =<<HTML
185
+ <table>
186
+ <tr><td>header 1</td><th>header 2</th></tr>
187
+ <tr><td>cell 1-1</td><td>cell 1-2</td></tr>
188
+ <tr><td>cell 2-1</td><td>cell 2-2</td></tr>
189
+ <tr><td>cell 3-1 (a bit wider)</td><td>cell 3-2</td></tr>
190
+ </table>
191
+
192
+ HTML
193
+
194
+ # assert_raise(MarkDownFormat::TableNodeFormatter::NotConformantStyleError) do
195
+ tree = BlockParser.parse(text.lines.to_a)
196
+ assert_equal(html, @gfm_formatter.format(tree).to_s)
197
+ assert_equal(html, @formatter.format(tree).to_s)
198
+ assert_equal(md_text, @forced_gfm_formatter.format(tree).to_s)
199
+ # end
200
+ end
201
+
202
+ def test_non_gfm_conformant_table_with_multi_headers
203
+ text = <<TEXT
204
+ ||!header 1-1||!header 1-2
205
+ ||!header 2-1||!header 2-2
206
+ ||cell 1-1||cell 1-2
207
+ ||cell 2-1||cell 2-2
208
+ ||cell 3-1 (a bit wider)||cell 3-2
209
+ TEXT
210
+
211
+ md_text = <<TEXT
212
+ |header 1-1 |header 1-2|
213
+ |----------------------|----------|
214
+ |header 2-1 |header 2-2|
215
+ |cell 1-1 |cell 1-2 |
216
+ |cell 2-1 |cell 2-2 |
217
+ |cell 3-1 (a bit wider)|cell 3-2 |
218
+ TEXT
219
+
220
+ html = <<HTML
221
+ <table>
222
+ <tr><th>header 1-1</th><th>header 1-2</th></tr>
223
+ <tr><th>header 2-1</th><th>header 2-2</th></tr>
224
+ <tr><td>cell 1-1</td><td>cell 1-2</td></tr>
225
+ <tr><td>cell 2-1</td><td>cell 2-2</td></tr>
226
+ <tr><td>cell 3-1 (a bit wider)</td><td>cell 3-2</td></tr>
227
+ </table>
228
+
229
+ HTML
230
+
231
+ # assert_raise(MarkDownFormat::TableNodeFormatter::NotConformantStyleError) do
232
+ tree = BlockParser.parse(text.lines.to_a)
233
+ assert_equal(html, @gfm_formatter.format(tree).to_s)
234
+ assert_equal(html, @formatter.format(tree).to_s)
235
+ assert_equal(md_text, @forced_gfm_formatter.format(tree).to_s)
236
+ # end
237
+ end
238
+
239
+ def test_non_gfm_conformant_table_with_multicolumn_cells
240
+ text = <<TEXT
241
+ ||!header 1-1||!header 1-2||!header 1-3||!header 1-4
242
+ ||cell 1-1||cell 1-2||cell 1-3||cell 1-4
243
+ ||cell 2-1||>cell 2-2||cell 2-4
244
+ ||cell 3-1 (a bit wider)||cell 3-2||cell 3-3||cell 3-4
245
+ TEXT
246
+
247
+ md_text = <<TEXT
248
+ |header 1-1 |header 1-2|header 1-3|header 1-4|
249
+ |----------------------|----------|----------|----------|
250
+ |cell 1-1 |cell 1-2 |cell 1-3 |cell 1-4 |
251
+ |cell 2-1 |cell 2-2 | |cell 2-4 |
252
+ |cell 3-1 (a bit wider)|cell 3-2 |cell 3-3 |cell 3-4 |
253
+ TEXT
254
+
255
+ html = <<HTML
256
+ <table>
257
+ <tr><th>header 1-1</th><th>header 1-2</th><th>header 1-3</th><th>header 1-4</th></tr>
258
+ <tr><td>cell 1-1</td><td>cell 1-2</td><td>cell 1-3</td><td>cell 1-4</td></tr>
259
+ <tr><td>cell 2-1</td><td colspan="2">cell 2-2</td><td>cell 2-4</td></tr>
260
+ <tr><td>cell 3-1 (a bit wider)</td><td>cell 3-2</td><td>cell 3-3</td><td>cell 3-4</td></tr>
261
+ </table>
262
+
263
+ HTML
264
+
265
+ # assert_raise(MarkDownFormat::TableNodeFormatter::NotConformantStyleError) do
266
+ tree = BlockParser.parse(text.lines.to_a)
267
+ assert_equal(html, @gfm_formatter.format(tree).to_s)
268
+ assert_equal(html, @formatter.format(tree).to_s)
269
+ assert_equal(md_text, @forced_gfm_formatter.format(tree).to_s)
270
+ # end
271
+ end
272
+
273
+ def test_non_gfm_conformant_table_with_multirow_cells
274
+ text = <<TEXT
275
+ ||!header 1-1||!header 1-2||!header 1-3||!header 1-4
276
+ ||cell 1-1||cell 1-2||^cell 1-3||cell 1-4
277
+ ||cell 2-1||>cell 2-2||cell 2-4
278
+ ||cell 3-1 (a bit wider)||cell 3-2||cell 3-3||cell 3-4
279
+ TEXT
280
+
281
+ md_text = <<TEXT
282
+ |header 1-1 |header 1-2|header 1-3|header 1-4|
283
+ |----------------------|----------|----------|----------|
284
+ |cell 1-1 |cell 1-2 |cell 1-3 |cell 1-4 |
285
+ |cell 2-1 |cell 2-2 | |cell 2-4 |
286
+ |cell 3-1 (a bit wider)|cell 3-2 |cell 3-3 |cell 3-4 |
287
+ TEXT
288
+
289
+ html = <<HTML
290
+ <table>
291
+ <tr><th>header 1-1</th><th>header 1-2</th><th>header 1-3</th><th>header 1-4</th></tr>
292
+ <tr><td>cell 1-1</td><td>cell 1-2</td><td rowspan=\"2\">cell 1-3</td><td>cell 1-4</td></tr>
293
+ <tr><td>cell 2-1</td><td colspan="2">cell 2-2</td><td>cell 2-4</td></tr>
294
+ <tr><td>cell 3-1 (a bit wider)</td><td>cell 3-2</td><td>cell 3-3</td><td>cell 3-4</td></tr>
295
+ </table>
296
+
297
+ HTML
298
+
299
+ # assert_raise(MarkDownFormat::TableNodeFormatter::NotConformantStyleError) do
300
+ tree = BlockParser.parse(text.lines.to_a)
301
+ assert_equal(html, @gfm_formatter.format(tree).to_s)
302
+ assert_equal(html, @formatter.format(tree).to_s)
303
+ assert_equal(md_text, @forced_gfm_formatter.format(tree).to_s)
304
+ # end
305
+ end
306
+
307
+ def test_list
308
+ text = <<TEXT
309
+ * item 1
310
+ * item 2
311
+ ** item 2-1
312
+ ** item 2-2
313
+ *** item 2-2-1
314
+ TEXT
315
+
316
+ md_text = <<TEXT
317
+ * item 1
318
+ * item 2
319
+ * item 2-1
320
+ * item 2-2
321
+ * item 2-2-1
322
+
323
+ TEXT
324
+
325
+ tree = BlockParser.parse(text.lines.to_a)
326
+ assert_equal(md_text, @formatter.format(tree).to_s)
327
+ end
328
+
329
+ def test_enum_list
330
+ text = <<TEXT
331
+ # item 1
332
+ # item 2
333
+ ## item 2-1
334
+ ## item 2-2
335
+ ### item 2-2-1
336
+ TEXT
337
+
338
+ md_text = <<TEXT
339
+ 1. item 1
340
+ 1. item 2
341
+ 2. item 2-1
342
+ 2. item 2-2
343
+ 3. item 2-2-1
344
+
345
+ TEXT
346
+
347
+ tree = BlockParser.parse(text.lines.to_a)
348
+ assert_equal(md_text, @formatter.format(tree).to_s)
349
+ end
350
+
351
+ def test_heading
352
+ text = <<TEXT
353
+ !!heading
354
+ TEXT
355
+ tree = BlockParser.parse(text.lines.to_a)
356
+ assert_equal("## heading#{$/ * 2}", @formatter.format(tree).to_s)
357
+ end
358
+
359
+ def test_paragraph
360
+ text = <<TEXT
361
+ the first paragraph
362
+
363
+ the second paragraph
364
+ TEXT
365
+
366
+ md_text = <<TEXT
367
+ the first paragraph
368
+
369
+ the second paragraph
370
+
371
+ TEXT
372
+
373
+ tree = BlockParser.parse(text.lines.to_a)
374
+ assert_equal(md_text, @formatter.format(tree).to_s)
375
+ end
376
+
377
+ def test_escape
378
+ text = "test string with *asterisk and _underscore"
379
+ md_text = "test string with \\*asterisk and \\_underscore#{$/}"
380
+
381
+ tree = BlockParser.parse(text.lines.to_a)
382
+ assert_equal(md_text, @formatter.format(tree).to_s)
383
+ end
384
+
385
+ def test_not_escaped
386
+ text = <<TEXT
387
+ <<<
388
+ a verbatim asterisk *
389
+ a verbatim _underscore_
390
+ >>>
391
+ TEXT
392
+
393
+ gfm_text = <<TEXT
394
+ ```
395
+ a verbatim asterisk *
396
+ a verbatim _underscore_
397
+ ```
398
+
399
+ TEXT
400
+
401
+ md_text = <<TEXT
402
+ a verbatim asterisk *
403
+ a verbatim _underscore_
404
+
405
+ TEXT
406
+
407
+ tree = BlockParser.parse(text.lines.to_a)
408
+ assert_equal(gfm_text, @gfm_formatter.format(tree).to_s)
409
+ assert_equal(md_text, @formatter.format(tree).to_s)
410
+ end
411
+
412
+ def test_document
413
+ text = <<TEXT
414
+ !! heading
415
+
416
+ # item 1
417
+ ## item 1-1
418
+
419
+ a paragraph for testing a striked through ==string with an ''emphasis'' in it.==
420
+ TEXT
421
+
422
+ md_text = <<TEXT
423
+ ## heading
424
+
425
+ 1. item 1
426
+ 2. item 1-1
427
+
428
+ a paragraph for testing a striked through ~~string with an _emphasis_ in it.~~
429
+
430
+ TEXT
431
+
432
+ tree = BlockParser.parse(text.lines.to_a)
433
+ assert_equal(md_text, @formatter.format(tree).to_s)
434
+ end
435
+ end
436
+
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pseudohikiparser
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.0.6.develop
4
+ version: 0.0.0.7.develop
5
5
  platform: ruby
6
6
  authors:
7
7
  - HASHIMOTO, Naoki
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-12-01 00:00:00.000000000 Z
11
+ date: 2014-02-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -56,6 +56,7 @@ files:
56
56
  - lib/pseudohiki/htmlformat.rb
57
57
  - lib/pseudohiki/htmlplugin.rb
58
58
  - lib/pseudohiki/inlineparser.rb
59
+ - lib/pseudohiki/markdownformat.rb
59
60
  - lib/pseudohiki/plaintextformat.rb
60
61
  - lib/pseudohiki/treestack.rb
61
62
  - lib/pseudohiki/version.rb
@@ -66,6 +67,7 @@ files:
66
67
  - test/test_htmlplugin.rb
67
68
  - test/test_htmltemplate.rb
68
69
  - test/test_inlineparser.rb
70
+ - test/test_markdownformat.rb
69
71
  - test/test_plaintextformat.rb
70
72
  - test/test_treestack.rb
71
73
  homepage: https://github.com/nico-hn/PseudoHikiParser/wiki
@@ -99,5 +101,6 @@ test_files:
99
101
  - test/test_htmlelement.rb
100
102
  - test/test_treestack.rb
101
103
  - test/test_inlineparser.rb
104
+ - test/test_markdownformat.rb
102
105
  - test/test_htmlformat.rb
103
106
  - test/test_htmlplugin.rb