Class: ODDB::TestSection

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

Instance Method Summary (collapse)

Instance Method Details

- (Object) setup



284
285
286
# File 'test/test_model/text.rb', line 284

def setup
  @section = ODDB::Text::Section.new
end

- (Object) test_clean



287
288
289
290
291
292
293
294
295
296
297
# File 'test/test_model/text.rb', line 287

def test_clean
  @section.subheading = ' '
  paragraph = @section.next_paragraph
  @section.clean!
  assert_equal([], @section.paragraphs)
  assert_equal('', @section.subheading)
  paragraph = @section.next_paragraph
  paragraph << "foo"
  @section.clean!
  assert_equal([paragraph], @section.paragraphs)
end

- (Object) test_empty



298
299
300
301
302
303
304
305
306
307
308
309
310
# File 'test/test_model/text.rb', line 298

def test_empty
  assert_equal([], @section.paragraphs)
  assert_equal('', @section.subheading)
  assert_equal(true, @section.empty?)
  @section.subheading = 'foo'
  assert_equal(false, @section.empty?)
  @section.subheading = ''
  assert_equal(true, @section.empty?)
  @section.paragraphs.push('goo')
  assert_equal(false, @section.empty?)
  @section.paragraphs.pop
  assert_equal(true, @section.empty?)
end

- (Object) test_gsub



332
333
334
335
336
337
338
# File 'test/test_model/text.rb', line 332

def test_gsub
  @section.subheading << 'subheading'
  @section.next_paragraph << 'a paragraph'
  @section.next_paragraph << 'another paragraph'
  @section.gsub! /[aeiou]/ do |match| match.upcase end
  assert_equal "sUbhEAdIng\nA pArAgrAph\nAnOthEr pArAgrAph\n".strip, @section.to_s
end

- (Object) test_match



311
312
313
314
315
316
317
318
# File 'test/test_model/text.rb', line 311

def test_match
  assert_nil(@section.match(/foo/)) 
  @section.subheading = 'foo'
  assert_instance_of(MatchData, @section.match(/foo/))
  assert_nil(@section.match(/bar/)) 
  @section.paragraphs.push('bar')
  assert_instance_of(MatchData, @section.match(/bar/))
end

- (Object) test_next_image



344
345
346
347
348
# File 'test/test_model/text.rb', line 344

def test_next_image
  img = @section.next_image
  assert_instance_of Text::ImageLink, img
  assert_equal [img], @section.paragraphs
end

- (Object) test_next_paragraph



349
350
351
352
353
354
355
356
# File 'test/test_model/text.rb', line 349

def test_next_paragraph
  par1 = @section.next_paragraph
  par2 = @section.next_paragraph
  assert_equal par1.object_id, par2.object_id
  par1 << 'foo'
  par3 = @section.next_paragraph
  assert_not_equal par1.object_id, par3.object_id
end

- (Object) test_to_s2



319
320
321
322
323
324
325
326
# File 'test/test_model/text.rb', line 319

def test_to_s2
  @section.subheading = "Hallo!"
  par1 = @section.next_paragraph
  par1 << "schöne"
  par2 = @section.next_paragraph
  par2 << "Welt!"
  assert_equal("Hallo!\nschöne\nWelt!", @section.to_s)
end

- (Object) test_to_s__no_subheading



327
328
329
330
331
# File 'test/test_model/text.rb', line 327

def test_to_s__no_subheading
  paragraph = @section.next_paragraph
  paragraph << "foo"
  assert_equal("foo", @section.to_s)
end