Class: ODDB::TestParagraph

Inherits:
Test::Unit::TestCase
  • Object
show all
Defined in:
test/test_model/text.rb

Instance Method Summary (collapse)

Instance Method Details

- (Object) setup



72
73
74
# File 'test/test_model/text.rb', line 72

def setup
  @paragraph = ODDB::Text::Paragraph.new
end

- (Object) test_access



75
76
77
78
# File 'test/test_model/text.rb', line 75

def test_access
  @paragraph << ' foo bar baz'
  assert_equal 'foo bar', @paragraph[1,7]
end

- (Object) test_append



79
80
81
82
83
84
85
86
87
# File 'test/test_model/text.rb', line 79

def test_append
  assert_equal('', @paragraph.text)
  @paragraph << ' foo'
  assert_equal('foo', @paragraph.text)
  @paragraph << ' bar '
  assert_equal('foo bar', @paragraph.text)
  @paragraph << 'baz'
  assert_equal('foo bar baz', @paragraph.text)
end

- (Object) test_append2



88
89
90
91
92
93
# File 'test/test_model/text.rb', line 88

def test_append2
  @paragraph.preformatted!
  @paragraph << "\tfoo\t"
  @paragraph << "bar"
  assert_equal('        foo     bar', @paragraph.text)
end

- (Object) test_append__hyphenated



243
244
245
246
247
248
249
# File 'test/test_model/text.rb', line 243

def test_append__hyphenated
  assert_equal('', @paragraph.text)
  @paragraph << " foo-\n"
  assert_equal('foo-', @paragraph.text)
  @paragraph << "bar"
  assert_equal('foobar', @paragraph.text)
end

- (Object) test_append__hyphenated__preformatted



250
251
252
253
254
255
256
257
# File 'test/test_model/text.rb', line 250

def test_append__hyphenated__preformatted
  @paragraph.preformatted!
  assert_equal('', @paragraph.text)
  @paragraph << " foo-\n"
  assert_equal(" foo-\n", @paragraph.text)
  @paragraph << "bar"
  assert_equal(" foo-\nbar", @paragraph.text)
end

- (Object) test_augment_format1



143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
# File 'test/test_model/text.rb', line 143

def test_augment_format1
  format1 = @paragraph.set_format(:italic)
  assert_equal(0..-1, format1.range)
  assert_equal(true, format1.italic?)
  assert_equal(false, format1.bold?)
  assert_equal([:italic], format1.values)
  assert_equal([format1], @paragraph.formats)
  @paragraph << "Formatted"
  format2 = @paragraph.augment_format(:bold)
  assert_equal([format1, format2], @paragraph.formats)
  assert_equal(0..8, format1.range)
  assert_equal(true, format1.italic?)
  assert_equal(false, format1.bold?)
  assert_equal(9..-1, format2.range)
  assert_equal(true, format2.italic?)
  assert_equal(true, format2.bold?)
  assert_equal([:italic, :bold], format2.values)
end

- (Object) test_empty



94
95
96
97
98
99
100
# File 'test/test_model/text.rb', line 94

def test_empty
  assert_equal(true, @paragraph.empty?)
  @paragraph << ' '
  assert_equal(true, @paragraph.empty?)
  @paragraph << 'foo'
  assert_equal(false, @paragraph.empty?)
end

- (Object) test_gsub



258
259
260
261
262
263
264
# File 'test/test_model/text.rb', line 258

def test_gsub
  @paragraph << 'Some Text with largely lowercase letters'
  @paragraph.gsub! /[aeiou]/ do |match| match.upcase end
  assert_equal 'SOmE TExt wIth lArgEly lOwErcAsE lEttErs', @paragraph.to_s
  @paragraph << ' and some more'
  assert_equal 'SOmE TExt wIth lArgEly lOwErcAsE lEttErs and some more', @paragraph.to_s
end

- (Object) test_length



265
266
267
268
269
270
271
# File 'test/test_model/text.rb', line 265

def test_length
  assert_equal 0, @paragraph.length
  @paragraph << 'foo '
  assert_equal 3, @paragraph.length
  @paragraph << 'bar'
  assert_equal 7, @paragraph.length
end

- (Object) test_match



272
273
274
275
276
277
# File 'test/test_model/text.rb', line 272

def test_match
  @paragraph << 'Some Text with largely lowercase letters'
  assert_nil @paragraph.match 'X'
  match = @paragraph.match /text/i
  assert_instance_of MatchData, match
end

- (Object) test_prepend



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
# File 'test/test_model/text.rb', line 205

def test_prepend
  format1 = @paragraph.set_format
  @paragraph << "UnFormatted"
  assert_equal(0..-1, format1.range)
  assert_equal(false, format1.italic?)
  assert_equal(false, format1.bold?)
  assert_equal([], format1.values)
  assert_equal([format1], @paragraph.formats)
  format2 = @paragraph.set_format(:bold)
  @paragraph << "Bold"
  assert_equal(0..10, format1.range)
  assert_equal(false, format1.italic?)
  assert_equal(false, format1.bold?)
  assert_equal([], format1.values)
  assert_equal(11..-1, format2.range)
  assert_equal(false, format2.italic?)
  assert_equal(true, format2.bold?)
  assert_equal([:bold], format2.values)
  assert_equal([format1, format2], @paragraph.formats)
  @paragraph.prepend('Formatted', :italic)
  format3 = @paragraph.formats.first
  assert_equal(0..8, format3.range)
  assert_equal(true, format3.italic?)
  assert_equal(false, format3.bold?)
  assert_equal([:italic], format3.values)
  assert_equal(9..19, format1.range)
  assert_equal(false, format1.italic?)
  assert_equal(false, format1.bold?)
  assert_equal([], format1.values)
  assert_equal(20..-1, format2.range)
  assert_equal(false, format2.italic?)
  assert_equal(true, format2.bold?)
  assert_equal([:bold], format2.values)
  assert_equal([format3, format1, format2], @paragraph.formats)
  assert_equal('FormattedUnFormattedBold', @paragraph.text)
  @paragraph << " The End"
  assert_equal('FormattedUnFormattedBold The End', @paragraph.text)
end

- (Object) test_reduce_format1



161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
# File 'test/test_model/text.rb', line 161

def test_reduce_format1
  format1 = @paragraph.set_format(:italic, :bold)
  assert_equal(0..-1, format1.range)
  assert_equal(true, format1.italic?)
  assert_equal(true, format1.bold?)
  assert_equal([:italic, :bold], format1.values)
  assert_equal([format1], @paragraph.formats)
  @paragraph << "Formatted"
  format2 = @paragraph.reduce_format(:italic)
  assert_equal([format1, format2], @paragraph.formats)
  assert_equal(0..8, format1.range)
  assert_equal(true, format1.italic?)
  assert_equal(true, format1.bold?)
  assert_equal(9..-1, format2.range)
  assert_equal(false, format2.italic?)
  assert_equal(true, format2.bold?)
  assert_equal([:bold], format2.values)
end

- (Object) test_set_format1



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
# File 'test/test_model/text.rb', line 101

def test_set_format1
  format1 = @paragraph.set_format(:italic)
  assert_equal(0..-1, format1.range)
  assert_equal(true, format1.italic?)
  assert_equal(false, format1.bold?)
  assert_equal([:italic], format1.values)
  assert_equal([format1], @paragraph.formats)
  @paragraph << "Formatted"
  format2 = @paragraph.set_format(:bold)
  assert_equal([format1, format2], @paragraph.formats)
  assert_equal(0..8, format1.range)
  assert_equal(true, format1.italic?)
  assert_equal(false, format1.bold?)
  assert_equal(9..-1, format2.range)
  assert_equal(false, format2.italic?)
  assert_equal(true, format2.bold?)
  assert_equal([:bold], format2.values)
  @paragraph << " text "
  format3 = @paragraph.set_format
  assert_equal([format1, format2, format3], @paragraph.formats)
  assert_equal(9..13, format2.range)
  assert_equal(14..-1, format3.range)
  assert_equal(false, format3.italic?)
  assert_equal(false, format3.bold?)
  assert_equal([], format3.values)
  @paragraph << "is nice!"
  assert_equal('Formatted text is nice!', @paragraph.text)
end

- (Object) test_set_format2



129
130
131
132
133
134
135
136
137
138
139
140
141
142
# File 'test/test_model/text.rb', line 129

def test_set_format2
  format1 = @paragraph.set_format(:italic)
  assert_equal(0..-1, format1.range)
  assert_equal(true, format1.italic?)
  assert_equal(false, format1.bold?)
  assert_equal([:italic], format1.values)
  assert_equal([format1], @paragraph.formats)
  format2 = @paragraph.set_format(:bold)
  assert_equal([format2], @paragraph.formats)
  assert_equal(0..-1, format2.range)
  assert_equal(false, format2.italic?)
  assert_equal(true, format2.bold?)
  assert_equal([:bold], format2.values)
end

- (Object) test_strip



278
279
280
281
# File 'test/test_model/text.rb', line 278

def test_strip
  @paragraph << ' foo bar '
  assert_equal 'foo bar', @paragraph.strip
end

- (Object) test_to_s1



179
180
181
182
# File 'test/test_model/text.rb', line 179

def test_to_s1
  @paragraph << "Hallo Welt!"
  assert_equal("Hallo Welt!", @paragraph.to_s)
end

- (Object) test_to_s2



183
184
185
186
187
188
189
190
191
# File 'test/test_model/text.rb', line 183

def test_to_s2
  @paragraph << "Hallo Welt!"
  assert_equal("Hallo Welt!", @paragraph.to_s)
  @paragraph.set_format(:symbol)
  @paragraph << " ≥ "
  @paragraph.set_format
  @paragraph << "Hallo Zürich!"
  assert_equal("Hallo Welt! ≥ Hallo Zürich!", @paragraph.to_s)
end

- (Object) test_to_s3



192
193
194
195
196
197
198
199
# File 'test/test_model/text.rb', line 192

def test_to_s3
  @paragraph.preformatted!
  @paragraph << "     | Header1 | Header2\n"
  @paragraph << "------------------------\n"
  @paragraph << "Row1 |  Cell1  |  Cell2 \n"
  expected = "| Header1 | Header2\n------------------------\nRow1 |  Cell1  |  Cell2\n"
  assert_equal(expected, @paragraph.to_s)
end