summaryrefslogtreecommitdiff
path: root/jni/ruby/test/rdoc/test_rdoc_rd_inline_parser.rb
blob: e4a765b4fb0b720d6d0a375d88432e503e3f5a12 (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
require 'rdoc/test_case'

class TestRDocRdInlineParser < RDoc::TestCase

  def setup
    super

    @block_parser = RDoc::RD::BlockParser.new
    @block_parser.instance_variable_set :@i, 0
    @inline_parser = RDoc::RD::InlineParser.new @block_parser
  end

  def test_parse
    assert_equal 'regular <em>emphasis</em>', parse('regular ((*emphasis*))')
  end

  def test_parse_code
    assert_equal '<code>text</code>', parse('(({text}))')
  end

  def test_parse_em
    assert_equal '<em>text</em>', parse('((*text*))')
  end

  def test_parse_footnote
    assert_equal '{*1}[rdoc-label:foottext-1:footmark-1]', parse('((-text-))')

    expected = [
      @RM::Paragraph.new('{^1}[rdoc-label:footmark-1:foottext-1]', ' ', 'text'),
      blank_line,
    ]

    assert_equal expected, @block_parser.footnotes
  end

  def test_parse_index
    assert_equal '<span id="label-text">text</span>', parse('((:text:))')

    assert_includes @block_parser.labels, 'text'
  end

  def test_parse_kbd
    assert_equal '<tt>text</tt>', parse('((%text%))')
  end

  def test_parse_multiple
    assert_equal '<em>one</em> <em>two</em>', parse('((*one*)) ((*two*))')
  end

  def test_parse_newline
    assert_equal "one\ntwo", parse("one\ntwo")
  end

  def test_parse_quote
    assert_equal 'one " two', parse('one " two')
  end

  def test_parse_ref
    assert_equal '{text}[rdoc-label:text]', parse('((<text>))')
  end

  def test_parse_ref_em
    assert_equal '{<em>text</em>}[rdoc-label:text]', parse('((<((*text*))>))')
  end

  def test_parse_ref_filename_quote
    assert_equal '{RD/foo}[rdoc-label:RD/foo]', parse('((<RD/"foo">))')
  end

  def test_parse_ref_filename
    assert_equal '{RD}[rdoc-label:RD/]', parse('((<RD/>))')
  end

  def test_parse_ref_quote
    assert_equal '{text \\"}[rdoc-label:text \\"]', parse('((<text \">))')
  end

  def test_parse_ref_quote_content
    assert_equal '{<em>text</em>}[rdoc-label:text]',
                 parse('((<"((*text*))">))')
  end

  def test_parse_ref_quote_content_multi
    assert_equal '{<em>one</em> <em>two</em>}[rdoc-label:one two]',
                 parse('((<"((*one*)) ((*two*))">))')
  end

  def test_parse_ref_substitute
    assert_equal '{text}[rdoc-label:thing]', parse('((<text|thing>))')
  end

  def test_parse_ref_substitute_element_quote
    assert_equal '{text}[rdoc-label:"RD"]',
                 parse('((<text|"RD">))')
  end

  def test_parse_ref_substitute_filename
    assert_equal '{text}[rdoc-label:RD/]', parse('((<text|RD/>))')
  end

  def test_parse_ref_substitute_filename_label
    assert_equal '{text}[rdoc-label:RD/label]',
                 parse('((<text|RD/label>))')
  end

  def test_parse_ref_substitute_filename_quote
    assert_equal '{text}[rdoc-label:"RD"/]', parse('((<text|"RD"/>))')
  end

  def test_parse_ref_substitute_multi_content
    assert_equal '{<em>one</em> two}[rdoc-label:thing]',
                 parse('((<((*one*)) two|thing>))')
  end

  def test_parse_ref_substitute_multi_content2
    assert_equal '{<em>one</em> \\" two}[rdoc-label:thing]',
                 parse('((<((*one*)) \" two|thing>))')
  end

  def test_parse_ref_substitute_multi_content3
    assert_equal '{<em>one</em> \\" <em>two</em>}[rdoc-label:thing]',
                 parse('((<((*one*)) \" ((*two*))|thing>))')
  end

  def test_parse_ref_substitute_quote
    assert_equal '{one | two}[rdoc-label:thing]',
                 parse('((<"one | two"|thing>))')
  end

  def test_parse_ref_substitute_quote_content
    assert_equal '{<em>text</em>}[rdoc-label:thing]',
                 parse('((<"((*text*))"|thing>))')
  end

  def test_parse_ref_substitute_url
    assert_equal '{text}[http://example]',
                 parse('((<text|URL:http://example>))')
  end

  def test_parse_ref_url
    assert_equal '{http://example}[http://example]',
                 parse('((<URL:http://example>))')
  end

  def test_parse_var
    assert_equal '+text+', parse('((|text|))')
  end

  def test_parse_verb
    assert_equal '<tt>text</tt>', parse("(('text'))")
  end

  def test_parse_verb_backslash
    assert_equal "<tt>(('text'))</tt>", parse("(('(('text\\'))'))")
  end

  def test_parse_verb_backslash_backslash
    assert_equal '<tt>text \\</tt>', parse("(('text \\\\'))")
  end

  def test_parse_verb_backslash_quote
    assert_equal '<tt>text "</tt>', parse("(('text \\\"'))")
  end

  def test_parse_verb_emphasis
    assert_equal '<tt>((*emphasis*))</tt>', parse("(('((*emphasis*))'))")
  end

  def test_parse_verb_multiple
    assert_equal '<tt>((*text*))</tt>', parse("(('((*text*))'))")
  end

  def parse text
    @inline_parser.parse text
  end

end