Class: ODDB::ChapterParse::TestWriter

Inherits:
Test::Unit::TestCase
  • Object
show all
Defined in:
ext/chapterparse/test/test_writer.rb

Instance Method Summary (collapse)

Instance Method Details

- (Object) setup



14
15
16
# File 'ext/chapterparse/test/test_writer.rb', line 14

def setup
  @writer = Writer.new
end

- (Object) test_2_sections_and_paragraphs



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
# File 'ext/chapterparse/test/test_writer.rb', line 85

def test_2_sections_and_paragraphs
  @writer.new_font([nil, 1, nil, nil])
  @writer.send_flowing_data('Subheading 1')
  @writer.new_font(nil)
  @writer.send_flowing_data('First Paragraph')
  @writer.send_line_break
  @writer.new_font([nil, 1, nil, nil])
  @writer.send_flowing_data('Subheading 2')
  @writer.new_font(nil)
  @writer.send_flowing_data('Second Paragraph')
  @writer.send_line_break
  chapter = @writer.chapter
  assert_equal(2, chapter.sections.size)
  section = chapter.sections.first
  assert_equal('Subheading 1', section.subheading)
  assert_equal(1, section.paragraphs.size)
  paragraph = section.paragraphs.first
  assert_equal('First Paragraph', paragraph.text)

  section = chapter.sections.last
  assert_equal('Subheading 2', section.subheading)
  assert_equal(1, section.paragraphs.size)
  paragraph = section.paragraphs.first
  assert_equal('Second Paragraph', paragraph.text)
end

- (Object) test_paragraph_with_italic



121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
# File 'ext/chapterparse/test/test_writer.rb', line 121

def test_paragraph_with_italic
  @writer.send_flowing_data('First Paragraph')
  @writer.new_font([nil, 1, nil, nil])
  @writer.send_flowing_data(' with italic text')
  @writer.new_font(nil)
  @writer.send_flowing_data(' and some more normal.')
  @writer.send_line_break
  chapter = @writer.chapter
  assert_equal(1, chapter.sections.size)
  section = chapter.sections.first
  assert_equal('', section.subheading)
  assert_equal(1, section.paragraphs.size)
  paragraph = section.paragraphs.first
  expected = 'First Paragraph with italic text and some more normal.'
  assert_equal(expected, paragraph.text)
  assert_equal(3, paragraph.formats.size)
  format = paragraph.formats.at(1)
  assert_equal(true, format.italic?)
  assert_equal(15..31, format.range)
end

- (Object) test_preformatted



141
142
143
144
145
146
147
148
149
150
151
152
# File 'ext/chapterparse/test/test_writer.rb', line 141

def test_preformatted
  @writer.new_font([nil, nil, nil, 1])
  @writer.send_literal_data('First Paragraph')
  chapter = @writer.chapter
  assert_equal(1, chapter.sections.size)
  section = chapter.sections.first
  assert_equal('', section.subheading)
  assert_equal(1, section.paragraphs.size)
  paragraph = section.paragraphs.first
  assert_equal(true, paragraph.preformatted?)
  assert_equal('First Paragraph', paragraph.text)
end

- (Object) test_preformatted_2_lines



153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
# File 'ext/chapterparse/test/test_writer.rb', line 153

def test_preformatted_2_lines
  @writer.new_font([nil, nil, nil, 1])
  @writer.send_literal_data('First Line')
  @writer.send_line_break
  @writer.new_font(nil)
  @writer.send_paragraph({})
  @writer.new_font([nil, nil, nil, 1])
  @writer.send_literal_data('Second Line')
  chapter = @writer.chapter
  assert_equal(1, chapter.sections.size)
  section = chapter.sections.first
  assert_equal('', section.subheading)
  assert_equal(1, section.paragraphs.size)
  paragraph = section.paragraphs.first
  assert_equal(true, paragraph.preformatted?)
  expected = "First Line\nSecond Line"
  assert_equal(expected, paragraph.text)
end

- (Object) test_preformatted_2_lines__too_many_newlines



171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
# File 'ext/chapterparse/test/test_writer.rb', line 171

def test_preformatted_2_lines__too_many_newlines
  @writer.new_font([nil, nil, nil, 1])
  @writer.send_literal_data('First Line')
  @writer.send_line_break
  @writer.new_font(nil)
  @writer.send_paragraph({})
  @writer.send_line_break
  @writer.send_line_break
  @writer.send_line_break
  @writer.new_font([nil, nil, nil, 1])
  @writer.send_literal_data('Second Line')
  chapter = @writer.chapter
  assert_equal(1, chapter.sections.size)
  section = chapter.sections.first
  assert_equal('', section.subheading)
  assert_equal(1, section.paragraphs.size)
  paragraph = section.paragraphs.first
  assert_equal(true, paragraph.preformatted?)
  expected = "First Line\nSecond Line"
  assert_equal(expected, paragraph.text)
end

- (Object) test_preformatted_to_normal



192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
# File 'ext/chapterparse/test/test_writer.rb', line 192

def test_preformatted_to_normal
  @writer.new_font([nil, nil, nil, 1])
  @writer.send_literal_data('First Line')
  @writer.send_line_break
  @writer.new_font(nil)
  @writer.send_paragraph({})
  @writer.send_flowing_data('Second Line')
  chapter = @writer.chapter
  assert_equal(1, chapter.sections.size)
  section = chapter.sections.first
  assert_equal('', section.subheading)
  assert_equal(2, section.paragraphs.size)
  paragraph = section.paragraphs.first
  assert_equal(true, paragraph.preformatted?)
  expected = "First Line\n"
  assert_equal(expected, paragraph.text)
  paragraph = section.paragraphs.last
  assert_equal(false, paragraph.preformatted?)
  expected = "Second Line"
  assert_equal(expected, paragraph.text)
end

- (Object) test_section



17
18
19
20
21
22
23
24
25
# File 'ext/chapterparse/test/test_writer.rb', line 17

def test_section
  @writer.new_font([nil, 1, nil, nil])
  @writer.send_flowing_data("Subheading")
  chapter = @writer.chapter
  assert_equal(1, chapter.sections.size)
  section = chapter.sections.first
  assert_equal('Subheading', section.subheading)
  assert_equal(0, section.paragraphs.size)
end

- (Object) test_section_and_2_paragraphs



67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
# File 'ext/chapterparse/test/test_writer.rb', line 67

def test_section_and_2_paragraphs
  @writer.new_font([nil, 1, nil, nil])
  @writer.send_flowing_data('Subheading')
  @writer.new_font(nil)
  @writer.send_flowing_data('First Paragraph')
  @writer.send_line_break
  @writer.send_flowing_data('Second Paragraph')
  @writer.send_line_break
  chapter = @writer.chapter
  assert_equal(1, chapter.sections.size)
  section = chapter.sections.first
  assert_equal('Subheading', section.subheading)
  assert_equal(2, section.paragraphs.size)
  paragraph = section.paragraphs.first
  assert_equal('First Paragraph', paragraph.text)
  paragraph = section.paragraphs.last
  assert_equal('Second Paragraph', paragraph.text)
end

- (Object) test_section_and_paragraph



26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'ext/chapterparse/test/test_writer.rb', line 26

def test_section_and_paragraph
  @writer.new_font([nil, 1, nil, nil])
  @writer.send_flowing_data('Subheading')
  @writer.new_font(nil)
  @writer.send_flowing_data("\302\240First Paragraph")
  chapter = @writer.chapter
  assert_equal(1, chapter.sections.size)
  section = chapter.sections.first
  assert_equal('Subheading', section.subheading)
  assert_equal(1, section.paragraphs.size)
  paragraph = section.paragraphs.first
  assert_equal('First Paragraph', paragraph.text)
end

- (Object) test_section_and_paragraph__on_new_line



39
40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'ext/chapterparse/test/test_writer.rb', line 39

def test_section_and_paragraph__on_new_line
  @writer.new_font([nil, 1, nil, nil])
  @writer.send_flowing_data("Subheading")
  @writer.send_line_break
  @writer.new_font(nil)
  @writer.send_flowing_data('First Paragraph')
  chapter = @writer.chapter
  assert_equal(1, chapter.sections.size)
  section = chapter.sections.first
  assert_equal("Subheading\n", section.subheading)
  assert_equal(1, section.paragraphs.size)
  paragraph = section.paragraphs.first
  assert_equal('First Paragraph', paragraph.text)
end

- (Object) test_section_and_paragraph__on_new_line__2



53
54
55
56
57
58
59
60
61
62
63
64
65
66
# File 'ext/chapterparse/test/test_writer.rb', line 53

def test_section_and_paragraph__on_new_line__2
  @writer.new_font([nil, 1, nil, nil])
  @writer.send_flowing_data("Subheading")
  @writer.new_font(nil)
  @writer.send_line_break
  @writer.send_flowing_data('First Paragraph')
  chapter = @writer.chapter
  assert_equal(1, chapter.sections.size)
  section = chapter.sections.first
  assert_equal("Subheading\n", section.subheading)
  assert_equal(1, section.paragraphs.size)
  paragraph = section.paragraphs.first
  assert_equal('First Paragraph', paragraph.text)
end

- (Object) test_section_without_subheading



110
111
112
113
114
115
116
117
118
119
120
# File 'ext/chapterparse/test/test_writer.rb', line 110

def test_section_without_subheading
  @writer.send_flowing_data('First Paragraph')
  @writer.send_line_break
  chapter = @writer.chapter
  assert_equal(1, chapter.sections.size)
  section = chapter.sections.first
  assert_equal('', section.subheading)
  assert_equal(1, section.paragraphs.size)
  paragraph = section.paragraphs.first
  assert_equal('First Paragraph', paragraph.text)
end