summaryrefslogtreecommitdiff
path: root/test/rdoc/test_rdoc_markdown.rb
blob: c223c44c1225f381add272b83bd5c0d0e104f427 (plain)
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
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
# coding: UTF-8
# frozen_string_literal: true

require_relative 'helper'
require_relative '../../lib/rdoc/markup/block_quote'
require_relative '../../lib/rdoc/markdown'

class TestRDocMarkdown < RDoc::TestCase

  def setup
    super

    @RM = RDoc::Markup

    @parser = RDoc::Markdown.new

    @to_html = RDoc::Markup::ToHtml.new(RDoc::Options.new, nil)
  end

  def test_class_parse
    doc = RDoc::Markdown.parse "hello\n\nworld"

    expected = doc(para("hello"), para("world"))

    assert_equal expected, doc
  end

  def test_emphasis
    assert_equal '_word_',             @parser.emphasis('word')
    assert_equal '<em>two words</em>', @parser.emphasis('two words')
    assert_equal '<em>*bold*</em>',    @parser.emphasis('*bold*')
  end

  def test_parse_auto_link_email
    doc = parse "Autolink: <nobody-0+_./!%~$@example>"

    expected = doc(para("Autolink: mailto:nobody-0+_./!%~$@example"))

    assert_equal expected, doc
  end

  def test_parse_auto_link_url
    doc = parse "Autolink: <http://example>"

    expected = doc(para("Autolink: http://example"))

    assert_equal expected, doc
  end

  def test_parse_block_quote
    doc = parse <<-BLOCK_QUOTE
> this is
> a block quote
    BLOCK_QUOTE

    expected =
      doc(
        block(
          para("this is\na block quote")))

    assert_equal expected, doc
  end

  def test_parse_block_quote_continue
    doc = parse <<-BLOCK_QUOTE
> this is
a block quote
    BLOCK_QUOTE

    expected =
      doc(
        block(
          para("this is\na block quote")))

    assert_equal expected, doc
  end

  def test_parse_block_quote_list
    doc = parse <<-BLOCK_QUOTE
> text
>
> * one
> * two
    BLOCK_QUOTE

    expected =
      doc(
        block(
          para("text"),
          list(:BULLET,
            item(nil, para("one")),
            item(nil, para("two")))))

    assert_equal expected, doc
  end

  def test_parse_block_quote_newline
    doc = parse <<-BLOCK_QUOTE
> this is
a block quote

    BLOCK_QUOTE

    expected =
      doc(
        block(
          para("this is\na block quote")))

    assert_equal expected, doc
  end

  def test_parse_block_quote_separate
    doc = parse <<-BLOCK_QUOTE
> this is
a block quote

> that continues
    BLOCK_QUOTE

    expected =
      doc(
        block(
          para("this is\na block quote"),
          para("that continues")))

    assert_equal expected, doc
  end

  def test_parse_char_entity
    doc = parse '&pi; &nn;'

    expected = doc(para('π &nn;'))

    assert_equal expected, doc
  end

  def test_parse_code
    doc = parse "Code: `text`"

    expected = doc(para("Code: <code>text</code>"))

    assert_equal expected, doc
  end

  def test_parse_code_github
    doc = <<-MD
Example:

```
code goes here
```
    MD

    expected =
      doc(
        para("Example:"),
        verb("code goes here\n"))

    assert_equal expected, parse(doc)
    assert_equal expected, parse(doc.sub(/^\n/, ''))

    @parser.github = false

    expected =
      doc(para("Example:"),
          para("<code>\n""code goes here\n</code>"))

    assert_equal expected, parse(doc)

    expected =
      doc(para("Example:\n<code>\n""code goes here\n</code>"))

    assert_equal expected, parse(doc.sub(/^\n/, ''))
  end

  def test_parse_code_github_format
    doc = <<-MD
Example:

``` ruby
code goes here
```
    MD

    code = verb("code goes here\n")
    code.format = :ruby

    expected =
      doc(
        para("Example:"),
        code)

    assert_equal expected, parse(doc)
    assert_equal expected, parse(doc.sub(/^\n/, ''))

    @parser.github = false

    expected =
      doc(para("Example:"),
          para("<code>ruby\n""code goes here\n</code>"))

    assert_equal expected, parse(doc)

    expected =
      doc(para("Example:\n<code>ruby\n""code goes here\n</code>"))

    assert_equal expected, parse(doc.sub(/^\n/, ''))
  end

  def test_parse_definition_list
    doc = parse <<-MD
one
:   This is a definition

two
:   This is another definition
    MD

    expected = doc(
      list(:NOTE,
        item(%w[one], para("This is a definition")),
        item(%w[two], para("This is another definition"))))

    assert_equal expected, doc
  end

  def test_parse_definition_list_indents
    doc = parse <<-MD
zero
: Indented zero characters

one
 : Indented one characters

two
  : Indented two characters

three
   : Indented three characters

four
    : Indented four characters

    MD

    expected = doc(
      list(:NOTE,
        item(%w[zero],  para("Indented zero characters")),
        item(%w[one],   para("Indented one characters")),
        item(%w[two],   para("Indented two characters")),
        item(%w[three], para("Indented three characters"))),
      para("four\n : Indented four characters"))

    assert_equal expected, doc
  end

  def test_parse_definition_list_multi_description
    doc = parse <<-MD
label
:   This is a definition

:   This is another definition
    MD

    expected = doc(
      list(:NOTE,
        item(%w[label], para("This is a definition")),
        item(nil,       para("This is another definition"))))

    assert_equal expected, doc
  end

  def test_parse_definition_list_multi_label
    doc = parse <<-MD
one
two
:   This is a definition
    MD

    expected = doc(
      list(:NOTE,
        item(%w[one two], para("This is a definition"))))

    assert_equal expected, doc
  end

  def test_parse_definition_list_multi_line
    doc = parse <<-MD
one
:   This is a definition
that extends to two lines

two
:   This is another definition
that also extends to two lines
    MD

    expected = doc(
      list(:NOTE,
        item(%w[one],
          para("This is a definition\nthat extends to two lines")),
        item(%w[two],
          para("This is another definition\nthat also extends to two lines"))))

    assert_equal expected, doc
  end

  def test_parse_definition_list_no
    @parser.definition_lists = false

    doc = parse <<-MD
one
:   This is a definition

two
:   This is another definition
    MD

    expected = doc(
        para("one\n: This is a definition"),
        para("two\n: This is another definition"))

    assert_equal expected, doc
  end

  def test_parse_entity_dec
    doc = parse "Entity: &#65;"

    expected = doc(para("Entity: A"))

    assert_equal expected, doc
  end

  def test_parse_entity_hex
    doc = parse "Entity: &#x41;"

    expected = doc(para("Entity: A"))

    assert_equal expected, doc
  end

  def test_parse_entity_named
    doc = parse "Entity: &pi;"

    expected = doc(para("Entity: π"))

    assert_equal expected, doc
  end

  def test_parse_emphasis_star
    doc = parse "it *works*\n"

    expected = @RM::Document.new(
      @RM::Paragraph.new("it _works_"))

    assert_equal expected, doc
  end

  def test_parse_emphasis_underscore
    doc = parse "it _works_\n"

    expected =
      doc(
        para("it _works_"))

    assert_equal expected, doc
  end

  def test_parse_emphasis_underscore_embedded
    doc = parse "foo_bar bar_baz\n"

    expected =
      doc(
        para("foo_bar bar_baz"))

    assert_equal expected, doc
  end

  def test_parse_emphasis_underscore_in_word
    doc = parse "it foo_bar_baz\n"

    expected =
      doc(
        para("it foo_bar_baz"))

    assert_equal expected, doc
  end

  def test_parse_escape
    assert_equal doc(para("Backtick: `")), parse("Backtick: \\`")

    assert_equal doc(para("Backslash: \\")), parse("Backslash: \\\\")

    assert_equal doc(para("Colon: :")), parse("Colon: \\:")
  end

  def test_parse_heading_atx
    doc = parse "# heading\n"

    expected = @RM::Document.new(
      @RM::Heading.new(1, "heading"))

    assert_equal expected, doc
  end

  def test_parse_heading_setext_dash
    doc = parse <<-MD
heading
---
    MD

    expected = @RM::Document.new(
      @RM::Heading.new(2, "heading"))

    assert_equal expected, doc
  end

  def test_parse_heading_setext_equals
    doc = parse <<-MD
heading
===
    MD

    expected = @RM::Document.new(
      @RM::Heading.new(1, "heading"))

    assert_equal expected, doc
  end

  def test_parse_html
    @parser.html = true

    doc = parse "<address>Links here</address>\n"

    expected = doc(
      @RM::Raw.new("<address>Links here</address>"))

    assert_equal expected, doc
  end

  def test_parse_html_hr
    @parser.html = true

    doc = parse "<hr>\n"

    expected = doc(raw("<hr>"))

    assert_equal expected, doc
  end

  def test_parse_html_no_html
    @parser.html = false

    doc = parse "<address>Links here</address>\n"

    expected = doc()

    assert_equal expected, doc
  end

  def test_parse_image
    doc = parse "image ![alt text](path/to/image.jpg)"

    expected = doc(para("image rdoc-image:path/to/image.jpg"))

    assert_equal expected, doc
  end

  def test_parse_image_link
    @parser.html = true

    doc = parse "[![alt text](path/to/image.jpg)](http://example.com)"

    expected =
      doc(
        para('{rdoc-image:path/to/image.jpg}[http://example.com]'))

    assert_equal expected, doc
  end

  def test_parse_line_break
    doc = parse "Some text  \nwith extra lines"

    expected = doc(
      para("Some text", hard_break, "with extra lines"))

    assert_equal expected, doc
  end

  def test_parse_link_reference_id
    doc = parse <<-MD
This is [an example][id] reference-style link.

[id]: http://example.com "Optional Title Here"
    MD

    expected = doc(
      para("This is {an example}[http://example.com] reference-style link."))

    assert_equal expected, doc
  end

  def test_parse_link_reference_id_adjacent
    doc = parse <<-MD
[this] [this] should work

[this]: example
    MD

    expected = doc(
      para("{this}[example] should work"))

    assert_equal expected, doc
  end

  def test_parse_link_reference_id_eof
    doc = parse <<-MD.chomp
This is [an example][id] reference-style link.

[id]: http://example.com "Optional Title Here"
    MD

    expected = doc(
      para("This is {an example}[http://example.com] reference-style link."))

    assert_equal expected, doc
  end

  def test_parse_link_reference_id_many
    doc = parse <<-MD
This is [an example][id] reference-style link.

And [another][id].

[id]: http://example.com "Optional Title Here"
    MD

    expected = doc(
      para("This is {an example}[http://example.com] reference-style link."),
      para("And {another}[http://example.com]."))

    assert_equal expected, doc
  end

  def test_parse_link_reference_implicit
    doc = parse <<-MD
This is [an example][] reference-style link.

[an example]: http://example.com "Optional Title Here"
    MD

    expected = doc(
      para("This is {an example}[http://example.com] reference-style link."))

    assert_equal expected, doc
  end

  def test_parse_list_bullet
    doc = parse <<-MD
* one
* two
    MD

    expected = doc(
      list(:BULLET,
        item(nil, para("one")),
        item(nil, para("two"))))

    assert_equal expected, doc
  end

  def test_parse_list_bullet_auto_link
    doc = parse <<-MD
* <http://example/>
    MD

    expected = doc(
      list(:BULLET,
        item(nil, para("http://example/"))))

    assert_equal expected, doc
  end

  def test_parse_list_bullet_continue
    doc = parse <<-MD
* one

* two
    MD

    expected = doc(
      list(:BULLET,
        item(nil, para("one")),
        item(nil, para("two"))))

    assert_equal expected, doc
  end

  def test_parse_list_bullet_multiline
    doc = parse <<-MD
* one
  two
    MD

    expected = doc(
      list(:BULLET,
        item(nil, para("one\n two"))))

    assert_equal expected, doc
  end

  def test_parse_list_bullet_nest
    doc = parse <<-MD
* outer
    * inner
    MD

    expected = doc(
      list(:BULLET,
        item(nil,
          para("outer"),
          list(:BULLET,
            item(nil,
              para("inner"))))))

    assert_equal expected, doc
  end

  def test_parse_list_bullet_nest_loose
    doc = parse <<-MD
* outer

    * inner
    MD

    expected = doc(
      list(:BULLET,
        item(nil,
          para("outer"),
          list(:BULLET,
            item(nil, para("inner"))))))

    assert_equal expected, doc
  end

  def test_parse_list_bullet_nest_continue
    doc = parse <<-MD
* outer
    * inner
  continue inner
* outer 2
    MD

    expected = doc(
      list(:BULLET,
        item(nil,
          para("outer"),
          list(:BULLET,
            item(nil,
              para("inner\n continue inner")))),
        item(nil,
          para("outer 2"))))

    assert_equal expected, doc
  end

  def test_parse_list_number
    doc = parse <<-MD
1. one
1. two
    MD

    expected = doc(
      list(:NUMBER,
        item(nil, para("one")),
        item(nil, para("two"))))

    assert_equal expected, doc
  end

  def test_parse_list_number_continue
    doc = parse <<-MD
1. one

1. two
    MD

    expected = doc(
      list(:NUMBER,
        item(nil, para("one")),
        item(nil, para("two"))))

    assert_equal expected, doc
  end

  def test_parse_note
    @parser.notes = true

    doc = parse <<-MD
Some text.[^1]

[^1]: With a footnote
    MD

    expected = doc(
      para("Some text.{*1}[rdoc-label:foottext-1:footmark-1]"),
      @RM::Rule.new(1),
      para("{^1}[rdoc-label:footmark-1:foottext-1] With a footnote"))

    assert_equal expected, doc
  end

  def test_parse_note_indent
    @parser.notes = true

    doc = parse <<-MD
Some text.[^1]

[^1]: With a footnote

    more
    MD

    expected = doc(
      para("Some text.{*1}[rdoc-label:foottext-1:footmark-1]"),
      rule(1),
      para("{^1}[rdoc-label:footmark-1:foottext-1] With a footnote\n\nmore"))

    assert_equal expected, doc
  end

  def test_parse_note_inline
    @parser.notes = true

    doc = parse <<-MD
Some text. ^[With a footnote]
    MD

    expected = doc(
      para("Some text. {*1}[rdoc-label:foottext-1:footmark-1]"),
      @RM::Rule.new(1),
      para("{^1}[rdoc-label:footmark-1:foottext-1] With a footnote"))

    assert_equal expected, doc
  end

  def test_parse_note_no_notes
    @parser.notes = false

    assert_raise RDoc::Markdown::ParseError do
      parse "Some text.[^1]"
    end
  end

  def test_parse_note_multiple
    @parser.notes = true

    doc = parse <<-MD
Some text[^1]
with inline notes^[like this]
and an extra note.[^2]

[^1]: With a footnote

[^2]: Which should be numbered correctly
    MD

    expected = doc(
      para("Some text{*1}[rdoc-label:foottext-1:footmark-1]\n" +
           "with inline notes{*2}[rdoc-label:foottext-2:footmark-2]\n" +
           "and an extra note.{*3}[rdoc-label:foottext-3:footmark-3]"),

      rule(1),

      para("{^1}[rdoc-label:footmark-1:foottext-1] With a footnote"),
      para("{^2}[rdoc-label:footmark-2:foottext-2] like this"),
      para("{^3}[rdoc-label:footmark-3:foottext-3] " +
           "Which should be numbered correctly"))

    assert_equal expected, doc
  end

  def test_parse_paragraph
    doc = parse "it worked\n"

    expected = doc(para("it worked"))

    assert_equal expected, doc
  end

  def test_parse_paragraph_break_on_newline
    @parser.break_on_newline = true

    doc = parse "one\ntwo\n"

    expected = doc(para("one", hard_break, "two"))

    assert_equal expected, doc

    doc = parse "one  \ntwo\nthree\n"

    expected = doc(para("one", hard_break, "two", hard_break, "three"))

    assert_equal expected, doc
  end

  def test_parse_paragraph_stars
    doc = parse "it worked ****\n"

    expected = @RM::Document.new(
      @RM::Paragraph.new("it worked ****"))

    assert_equal expected, doc
  end

  def test_parse_paragraph_html
    @parser.html = true

    doc = parse "<address>Links here</address>"

    expected = doc(raw("<address>Links here</address>"))

    assert_equal expected, doc
  end

  def test_parse_paragraph_html_no_html
    @parser.html = false

    doc = parse "<address>Links here</address>"

    expected = doc()

    assert_equal expected, doc
  end

  def test_parse_paragraph_indent_one
    doc = parse <<-MD
 text
    MD

    expected = doc(para("text"))

    assert_equal expected, doc
  end

  def test_parse_paragraph_indent_two
    doc = parse <<-MD
  text
    MD

    expected = doc(para("text"))

    assert_equal expected, doc
  end

  def test_parse_paragraph_indent_three
    doc = parse <<-MD
   text
    MD

    expected = doc(para("text"))

    assert_equal expected, doc
  end

  def test_parse_paragraph_multiline
    doc = parse "one\ntwo"

    expected = doc(para("one\ntwo"))

    assert_equal expected, doc
  end

  def test_parse_paragraph_two
    doc = parse "one\n\ntwo"

    expected = @RM::Document.new(
      @RM::Paragraph.new("one"),
      @RM::Paragraph.new("two"))

    assert_equal expected, doc
  end

  def test_parse_plain
    doc = parse "it worked"

    expected = @RM::Document.new(
      @RM::Paragraph.new("it worked"))

    assert_equal expected, doc
  end

  def test_parse_reference_link_embedded_bracket
    doc = parse "With [embedded [brackets]] [b].\n\n[b]: /url/\n"

    expected =
      doc(
        para("With {embedded [brackets]}[/url/]."))

    assert_equal expected, doc
  end

  def test_parse_rule_dash
    doc = parse "- - -\n\n"

    expected = @RM::Document.new(@RM::Rule.new(1))

    assert_equal expected, doc
  end

  def test_parse_rule_underscore
    doc = parse "_ _ _\n\n"

    expected = @RM::Document.new(@RM::Rule.new(1))

    assert_equal expected, doc
  end

  def test_parse_rule_star
    doc = parse "* * *\n\n"

    expected = @RM::Document.new(@RM::Rule.new(1))

    assert_equal expected, doc
  end

  def test_parse_strong_star
    doc = parse "it **works**\n"

    expected = @RM::Document.new(
      @RM::Paragraph.new("it *works*"))

    assert_equal expected, doc
  end

  def test_parse_strong_underscore
    doc = parse "it __works__\n"

    expected = @RM::Document.new(
      @RM::Paragraph.new("it *works*"))

    assert_equal expected, doc
  end

  def test_parse_strong_emphasis_star
    doc = parse "it ***works***\n"

    expected = @RM::Document.new(
      @RM::Paragraph.new("it <b>_works_</b>"))

    assert_equal expected, doc
  end

  def test_parse_strong_emphasis_underscore
    doc = parse "it ___works___\n"

    expected = @RM::Document.new(
      @RM::Paragraph.new("it <b>_works_</b>"))

    assert_equal expected, doc
  end

  def test_parse_strike_tilde
    doc = parse "it ~~works~~\n"

    expected = @RM::Document.new(
      @RM::Paragraph.new("it ~works~"))

    assert_equal expected, doc
  end

  def test_parse_strike_words_tilde
    doc = parse "it ~~works fine~~\n"

    expected = @RM::Document.new(
      @RM::Paragraph.new("it <s>works fine</s>"))

    assert_equal expected, doc
  end

  def test_parse_strike_tilde_no
    @parser.strike = false

    doc = parse "it ~~works fine~~\n"

    expected = @RM::Document.new(
      @RM::Paragraph.new("it ~~works fine~~"))

    assert_equal expected, doc
  end

  def test_parse_style
    @parser.css = true

    doc = parse "<style>h1 { color: red }</style>\n"

    expected = doc(
      @RM::Raw.new("<style>h1 { color: red }</style>"))

    assert_equal expected, doc
  end

  def test_parse_style_disabled
    doc = parse "<style>h1 { color: red }</style>\n"

    expected = doc()

    assert_equal expected, doc
  end

  def test_parse_verbatim
    doc = parse <<-MD
    text
    MD

    expected = doc(verb("text\n"))

    assert_equal expected, doc
  end

  def test_parse_verbatim_eof
    doc = parse "    text"

    expected = doc(verb("text\n"))

    assert_equal expected, doc
  end

  def test_strong
    assert_equal '*word*',            @parser.strong('word')
    assert_equal '<b>two words</b>',  @parser.strong('two words')
    assert_equal '<b>_emphasis_</b>', @parser.strong('_emphasis_')
  end

  def test_code_fence_with_unintended_array
    doc = parse '```<ruby>```'

    expected = doc(verb('<ruby>'))

    assert_equal expected, doc
  end

  def test_gfm_table
    doc = parse <<~MD
    |      |                 |compare-ruby|built-ruby|
    |------|:----------------|-----------:|---------:|
    |test  | 1               |     11.618M|   10.757M|
    |      |                 |       1.08x|         -|
    |test  | 10              |      1.849M|    1.723M|
    |      |                 |       1.07x|         -|
    MD

    head = ["", "", "compare-ruby", "built-ruby"]
    align = [nil, :left, :right, :right]
    body = [
      ["test", "1", "11.618M", "10.757M"],
      ["", "", "1.08x", "-"],
      ["test", "10", "1.849M", "1.723M"],
      ["", "", "1.07x", "-"],
    ]
    expected = doc(@RM::Table.new(head, align, body))

    assert_equal expected, doc
  end

  def parse text
    @parser.parse text
  end

end