Class: ODDB::FiParse::TestFachinfoHpricot

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

Instance Method Summary collapse

Instance Method Details

#setupObject



20
21
22
# File 'ext/fiparse/test/test_fachinfo_hpricot.rb', line 20

def setup
  @writer = FachinfoHpricot.new
end

#test_chapterObject



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
# File 'ext/fiparse/test/test_fachinfo_hpricot.rb', line 23

def test_chapter
  html = <<-HTML
    <div class="paragraph">
      <h2><a name="3300">Zusammensetzung</a></h2>
      <p class="spacing1"><span style="font-style:italic; ">Wirkstoffe:</span></p>
      <p class="spacing1">1 Brausetablette enthält: Carbasalatum calcicum 528 mg corresp. Acidum Acetylsalicylicum 415 mg, Acidum ascorbicum 250 mg.</p>
      <p class="noSpacing"><span style="font-style:italic; ">Hilfsstoffe: </span>Saccharinum, Cyclamas, Aromatica, Color.: E 120.</p>
    </div>
  HTML
  code, chapter = @writer.chapter(Hpricot(html).at("div.paragraph"))
  assert_equal('3300', code)
  assert_instance_of(ODDB::Text::Chapter, chapter )
  assert_equal('Zusammensetzung', chapter.heading)
  assert_equal(1, chapter.sections.size)
  section = chapter.sections.first
  assert_equal("", section.subheading)
  assert_equal(3, section.paragraphs.size)
  paragraph = section.paragraphs.at(0)
  expected =  "Wirkstoffe:"
  assert_equal(2, paragraph.formats.size)
  fmt = paragraph.formats.first
  assert_equal([:italic], fmt.values)
  assert_equal(0..10, fmt.range)
  fmt = paragraph.formats.last
  assert_equal([], fmt.values)
  assert_equal(11..-1, fmt.range)
  assert_equal(expected, paragraph.text)
  paragraph = section.paragraphs.at(1)
  expected =  /1 Brausetablette enth.*lt: Carbasalatum calcicum 528.*mg corresp\. Acidum Acetylsalicylicum 415.*mg, Acidum ascorbicum 250.*mg\./
  assert_match(expected, paragraph.text)
  paragraph = section.paragraphs.at(2)
  assert_equal(2, paragraph.formats.size)
  fmt = paragraph.formats.first
  assert_equal([:italic], fmt.values)
  assert_equal(0..11, fmt.range)
  fmt = paragraph.formats.last
  assert_equal([], fmt.values)
  assert_equal(12..-1, fmt.range)
  expected =  /Hilfsstoffe: Saccharinum, Cyclamas, Aromatica, Color.: E.*120./
  assert_match(expected, paragraph.text)
end

#test_identify_chapter__raises_unknown_chaptercodeObject



64
65
66
67
68
# File 'ext/fiparse/test/test_fachinfo_hpricot.rb', line 64

def test_identify_chapter__raises_unknown_chaptercode
  assert_raises(RuntimeError) { 
    @writer.identify_chapter('7800', nil)
  }
end