Class: ODDB::TestChapter

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

Instance Method Summary (collapse)

Instance Method Details

- (Object) setup



359
360
361
# File 'test/test_model/text.rb', line 359

def setup
  @chapter = ODDB::Text::Chapter.new
end

- (Object) test_clean



362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
# File 'test/test_model/text.rb', line 362

def test_clean
  @chapter.heading = ' '
  section = @chapter.next_section
  @chapter.clean!
  assert_equal('', @chapter.heading)
  assert_equal([], @chapter.sections)
  section = @chapter.next_section
  paragraph = section.next_paragraph
  @chapter.clean!
  assert_equal([], @chapter.sections)
  section = @chapter.next_section
  paragraph = section.next_paragraph
  paragraph << 'foo'
  @chapter.clean!
  assert_equal([section], @chapter.sections)
end

- (Object) test_empty



378
379
380
381
382
383
384
385
# File 'test/test_model/text.rb', line 378

def test_empty
  @chapter.heading << 'heading'
  assert_equal false, @chapter.empty?
  @chapter.heading.replace ''
  assert_equal true, @chapter.empty?
  @chapter.next_section.next_paragraph << 'paragraph'
  assert_equal false, @chapter.empty?
end

- (Object) test_gsub



386
387
388
389
390
391
392
393
# File 'test/test_model/text.rb', line 386

def test_gsub
  @chapter.heading << 'heading'
  section = @chapter.next_section
  section.subheading << 'subheading'
  section.next_paragraph << 'paragraph'
  @chapter.gsub! /[aeiou]/ do |match| match.upcase end
  assert_equal "hEAdIng\nsUbhEAdIng\npArAgrAph\n".strip, @chapter.to_s
end

- (Object) test_include



399
400
401
402
403
# File 'test/test_model/text.rb', line 399

def test_include
  assert_equal false, @chapter.include?(Text::Section.new)
  seq = @chapter.next_section
  assert_equal true, @chapter.include?(seq)
end

- (Object) test_match



404
405
406
407
408
409
410
411
# File 'test/test_model/text.rb', line 404

def test_match
  assert_nil(@chapter.match(/foo/)) 
  @chapter.heading = 'foo'
  assert_instance_of(MatchData, @chapter.match(/foo/))
  assert_nil(@chapter.match(/bar/)) 
  @chapter.sections.push('bar')
  assert_instance_of(MatchData, @chapter.match(/bar/))
end

- (Object) test_next_section



412
413
414
415
416
417
418
419
420
421
422
423
424
425
# File 'test/test_model/text.rb', line 412

def test_next_section
  assert_equal(0, @chapter.sections.size)
  section = @chapter.next_section
  assert_instance_of(ODDB::Text::Section, section)
  assert_equal(1, @chapter.sections.size)
  section1 = @chapter.next_section
  assert_instance_of(ODDB::Text::Section, section1)
  assert_equal(1, @chapter.sections.size)
  assert_equal(section, section1)
  section.subheading = 'foo'
  section2 = @chapter.next_section
  assert_equal(2, @chapter.sections.size)
  assert_not_equal(section, section2)
end

- (Object) test_paragraphs



426
427
428
429
430
431
432
433
434
# File 'test/test_model/text.rb', line 426

def test_paragraphs
  expected = []
  ['txt1', 'txt2', 'txt3'].each { |str|
    par = @chapter.next_section.next_paragraph
    par << str
    expected << par
  }
  assert_equal(expected, @chapter.paragraphs)
end

- (Object) test_to_s3



448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
# File 'test/test_model/text.rb', line 448

def test_to_s3
  @chapter.heading = "Hallo!"
  sec1 = @chapter.next_section
  sec1.subheading = "Auch Hallo!"
  par1 = sec1.next_paragraph
  par1 << "Schöne foo..."
  par2 = sec1.next_paragraph
  par2 << "Schöne bar..."
  sec2 = @chapter.next_section
  sec2.subheading = "Nochmals Hallo!"
  par3 = sec2.next_paragraph
  par3 << "Schöne baz..."
  par4 = sec2.next_paragraph
  par4 << "Schöne Welt!"
  expected = "Hallo!\nAuch Hallo!\nSch\303\266ne foo...\nSch\303\266ne bar...\nNochmals Hallo!\nSch\303\266ne baz...\nSch\303\266ne Welt!\n"
  assert_equal(expected.strip, @chapter.to_s)
end

- (Object) test_to_s__no_heading



443
444
445
446
447
# File 'test/test_model/text.rb', line 443

def test_to_s__no_heading
  section = @chapter.next_section
  section.subheading = "foo"
  assert_equal("foo", @chapter.to_s)
end

- (Object) test_to_search



435
436
437
438
439
440
441
442
# File 'test/test_model/text.rb', line 435

def test_to_search
  @chapter.heading << 'heading'
  section = @chapter.next_section
  section.subheading << 'subheading'
  section.next_paragraph << 'paragraph'
  expected = "heading subheading paragraph"
  assert_equal expected, @chapter.to_search
end