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

- (Object) setup



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

def setup
  @writer = FachinfoHpricot.new
end

- (Object) test_chapter



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

def test_chapter
  html = "<div class=\"paragraph\">\n<h2><a name=\"3300\">Zusammensetzung</a></h2>\n<p class=\"spacing1\"><span style=\"font-style:italic; \">Wirkstoffe:</span></p>\n<p class=\"spacing1\">1 Brausetablette enth\303\244lt: Carbasalatum calcicum 528 mg corresp. Acidum Acetylsalicylicum 415 mg, Acidum ascorbicum 250 mg.</p>\n<p class=\"noSpacing\"><span style=\"font-style:italic; \">Hilfsstoffe: </span>Saccharinum, Cyclamas, Aromatica, Color.: E\302\240120.</p>\n</div>\n"
  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

- (Object) test_identify_chapter__raises_unknown_chaptercode



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

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