summaryrefslogtreecommitdiff
path: root/test/rdoc/test_rdoc_markup_document.rb
blob: 718ae6d4c40e1c534e804845782f5437309b6670 (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
require 'rdoc/test_case'

class TestRDocMarkupDocument < RDoc::TestCase

  def setup
    super

    @d = @RM::Document.new
  end

  def test_append
    @d << @RM::Paragraph.new('hi')

    expected = @RM::Document.new @RM::Paragraph.new('hi')

    assert_equal expected, @d
  end

  def test_append_document
    @d << @RM::Document.new

    assert_empty @d

    @d << @RM::Document.new(@RM::Paragraph.new('hi'))

    expected = @RM::Document.new @RM::Paragraph.new('hi'), @RM::BlankLine.new

    assert_equal expected, @d
  end

  def test_append_string
    @d << ''

    assert_empty @d

    assert_raises ArgumentError do
      @d << 'hi'
    end
  end

  def test_concat
    @d.concat [@RM::BlankLine.new, @RM::BlankLine.new]

    refute_empty @d
  end

  def test_each
    a = @RM::Document.new
    b = @RM::Document.new(@RM::Paragraph.new('hi'))

    @d.push a, b

    assert_equal [a, b], @d.map { |sub_doc| sub_doc }
  end

  def test_empty_eh
    assert_empty @d

    @d << @RM::BlankLine.new

    refute_empty @d
  end

  def test_empty_eh_document
    d = @RM::Document.new @d

    assert_empty d
  end

  def test_equals2
    d2 = @RM::Document.new

    assert_equal @d, d2

    d2 << @RM::BlankLine.new

    refute_equal @d, d2
  end

  def test_equals2_file
    d2 = @RM::Document.new
    d2.file = 'file.rb'

    refute_equal @d, d2

    @d.file = 'file.rb'

    assert_equal @d, d2
  end

  def test_file_equals
    @d.file = 'file.rb'

    assert_equal 'file.rb', @d.file
  end

  def test_file_equals_top_level
    @d.file = @store.add_file 'file.rb'

    assert_equal 'file.rb', @d.file
  end

  def test_lt2
    @d << @RM::BlankLine.new

    refute_empty @d
  end

  def test_merge
    original = @RM::Document.new @RM::Paragraph.new 'original'
    original.file = 'file.rb'
    root = @RM::Document.new original

    replace = @RM::Document.new @RM::Paragraph.new 'replace'
    replace.file = 'file.rb'

    other = @RM::Document.new replace

    result = root.merge other

    inner = @RM::Document.new @RM::Paragraph.new 'replace'
    inner.file = 'file.rb'
    expected = @RM::Document.new inner

    assert_equal expected, result
  end

  def test_merge_add
    original = @RM::Document.new @RM::Paragraph.new 'original'
    original.file = 'file.rb'
    root = @RM::Document.new original

    addition = @RM::Document.new @RM::Paragraph.new 'addition'
    addition.file = 'other.rb'

    other = @RM::Document.new addition

    result = root.merge other

    expected = @RM::Document.new original, addition

    assert_equal expected, result
  end

  def test_merge_empty
    original = @RM::Document.new
    root = @RM::Document.new original

    replace = @RM::Document.new @RM::Paragraph.new 'replace'
    replace.file = 'file.rb'

    other = @RM::Document.new replace

    result = root.merge other

    inner = @RM::Document.new @RM::Paragraph.new 'replace'
    inner.file = 'file.rb'
    expected = @RM::Document.new inner

    assert_equal expected, result
  end

  def test_push
    @d.push @RM::BlankLine.new, @RM::BlankLine.new

    refute_empty @d
  end

  def test_table_of_contents
    doc = @RM::Document.new(
      @RM::Heading.new(1, 'A'),
      @RM::Paragraph.new('B'),
      @RM::Heading.new(2, 'C'),
      @RM::Paragraph.new('D'),
      @RM::Heading.new(1, 'E'),
      @RM::Paragraph.new('F'))

    expected = [
      @RM::Heading.new(1, 'A'),
      @RM::Heading.new(2, 'C'),
      @RM::Heading.new(1, 'E'),
    ]

    assert_equal expected, doc.table_of_contents
  end

  def test_table_of_contents_omit_headings_below
    document = doc(
      head(1, 'A'),
      para('B'),
      head(2, 'C'),
      para('D'),
      head(1, 'E'),
      para('F'))

    document.omit_headings_below = 1

    expected = [
      head(1, 'A'),
      head(1, 'E'),
    ]

    assert_equal expected, document.table_of_contents
  end

end