Class: ODDB::ChapterParse::TestParserIntegrate

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

Instance Method Summary (collapse)

Instance Method Details

- (Object) setup



19
20
21
22
23
# File 'ext/chapterparse/test/test_integrate.rb', line 19

def setup
  @writer = ChapterParse::Writer.new
  @formatter = HtmlFormatter.new(@writer)
  @parser = ChapterParse::Parser.new(@formatter)
end

- (Object) test_courier_output



75
76
77
78
79
80
81
82
83
84
85
# File 'ext/chapterparse/test/test_integrate.rb', line 75

def test_courier_output
  src = "<span style=\"font-family: courier new,mono;\">Dies ist Courier.</span>\n"
  @parser.feed(src)
  chapter = @writer.chapter
  assert_equal(1, chapter.sections.size)
  section = chapter.sections.first
  assert_equal(1, section.paragraphs.size)
  paragraph = section.paragraphs.first
  assert_equal(true, paragraph.preformatted?)
  assert_equal("Dies ist Courier.\n", paragraph.text)
end

- (Object) test_italic_excipiens



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'ext/chapterparse/test/test_integrate.rb', line 24

def  test_italic_excipiens
  html = "<div class=\"section\">\n<span style=\"font-style: italic;\"> </span>\n<span class=\"paragraph\">\nDieser Text ist normal\n<span style=\"font-style: italic;\">\nund dieser in Italic\n</span>\n</span>\n</div>\n"
  @parser.feed(html)
  chapter = @writer.chapter
  assert_instance_of(Text::Chapter, chapter)
  assert_equal('', chapter.heading)
  assert_equal(1, chapter.sections.size)
  section = chapter.sections.first
  assert_equal('', section.subheading)
  assert_equal(1, section.paragraphs.size)
  paragraph = section.paragraphs.first
  assert_equal('Dieser Text ist normal und dieser in Italic',
    paragraph.text)
  assert_equal(3, paragraph.formats.size)
  fmt1 = paragraph.formats.at(0)
  assert_equal(0..21, fmt1.range)
  assert_equal([], fmt1.values)
  fmt2 = paragraph.formats.at(1)
  assert_equal(22..42, fmt2.range)
  assert_equal([:italic], fmt2.values)
  fmt3 = paragraph.formats.at(2)
  assert_equal(43..-1, fmt3.range)
  assert_equal([], fmt3.values)
end

- (Object) test_subheading_newline



59
60
61
62
63
64
65
66
67
68
69
70
71
# File 'ext/chapterparse/test/test_integrate.rb', line 59

def test_subheading_newline
  html = "<span style=\"font-style: italic;\">Kinder ab \275 Jahr: </span><br> <div style=\"font-style: italic;\"><span style=\"font-style: italic;\">\275-1 Jahr:</span>&nbsp;<span class=\"paragraph\">2\327&nbsp;t\344glich 1 Suppositorium 125&nbsp;mg.</span></div> <div style=\"font-style: italic;\"><span style=\"font-style: italic;\">1-3 Jahre:</span>&nbsp;<span class=\"paragraph\">3\327&nbsp;t\344glich 1 Suppositorium 125&nbsp;mg.</span></div><div style=\"font-style: italic;\"><span class=\"paragraph\"></span><span class=\"paragraph\"><br> </span><span class=\"paragraph\"></span></div>\n"
  @parser.feed(html)
  chapter = @writer.chapter
  assert_equal(5, chapter.sections.size)
  sct1, sct2, sct3 = chapter.sections
  assert_equal("Kinder ab ½ Jahr:\n", sct1.subheading)
  assert_equal([], sct1.paragraphs)
  assert_equal("½-1 Jahr:", sct2.subheading)
  assert_equal(0, sct2.paragraphs.size)
    #   pg1 = sct2.paragraphs.first
    #   assert_equal('2× täglich 1 Suppositorium 125 mg.', pg1.text)
end

- (Object) test_table



157
158
159
160
161
162
163
164
165
166
167
168
169
# File 'ext/chapterparse/test/test_integrate.rb', line 157

def test_table
  src = "<table border=\"1\" bordercolor=\"#000000\" cellpadding=\"5\" cellspacing=\"0\" frame=\"hsides\" rules=\"groups\" width=\"462\">\n<col width=\"143\">\n<col width=\"147\">\n<col width=\"143\">\n<tbody>\n<tr valign=\"top\">\n<td width=\"143\">\n<p lang=\"de-CH\"><br>\n</p>\n</td>\n<td width=\"147\">\n<p style=\"margin-bottom: 0cm;\" lang=\"de-CH\"><font face=\"Courier New, monospace\"><font size=\"2\">Disktest*</font></font></p>\n<p lang=\"de-CH\"><font face=\"Courier New, monospace\"><font size=\"2\">Hemmhofdurchmesser\n(mm)</font></font></p>\n</td>\n<td width=\"143\">\n<p style=\"margin-bottom: 0cm;\" lang=\"de-CH\"><font face=\"Courier New, monospace\"><font size=\"2\">Verd\374nnungstest**</font></font></p>\n<p lang=\"de-CH\"><font face=\"Courier New, monospace\"><font size=\"2\">MHK\n(mg/l) </font></font>\n</p>\n</td>\n</tr>\n</tbody>\n<tbody>\n<tr valign=\"top\">\n<td width=\"143\">\n<p lang=\"de-CH\">\n</p>\n</td>\n<td width=\"147\">\n<p lang=\"de-CH\"><font face=\"Arial Unicode MS, sans-serif\"><font size=\"3\"><font size=\"2\"><font face=\"Courier New, monospace\"><span lang=\"fr-FR\">\263\n</span>16</font></font></font></font></p>\n</td>\n<td width=\"143\">\n<p lang=\"de-CH\"><font face=\"Arial Unicode MS, sans-serif\"><font size=\"3\"><font size=\"2\"><font face=\"Courier New, monospace\">\243\n2 + \243 38</font></font></font></font></p>\n</td>\n</tr>\n<tr valign=\"top\">\n<td width=\"143\">\n<p lang=\"de-CH\"><br>\n</p>\n</td>\n<td width=\"147\">\n<p lang=\"de-CH\"><br>\n</p>\n</td>\n<td width=\"143\">\n<p lang=\"de-CH\"><br>\n</p>\n</td>\n</tr>\n<tr valign=\"top\">\n<td width=\"143\">\n<p lang=\"de-CH\"><font face=\"Courier New, monospace\"><font size=\"2\">Teilweise\nempfindlich</font></font></p>\n</td>\n<td width=\"147\">\n<p lang=\"de-CH\"><font face=\"Courier New, monospace\"><font size=\"2\">11\n- 15</font></font></p>\n</td>\n<td width=\"143\">\n<p lang=\"de-CH\"><font face=\"Courier New, monospace\"><font size=\"2\">4\n+ 76</font></font></p>\n</td>\n</tr>\n<tr valign=\"top\">\n<td width=\"143\">\n<p lang=\"de-CH\"><br>\n</p>\n</td>\n<td width=\"147\">\n<p lang=\"de-CH\"><br>\n</p>\n</td>\n<td width=\"143\">\n<p lang=\"de-CH\"><br>\n</p>\n</td>\n</tr>\n<tr valign=\"top\">\n<td width=\"143\">\n<p lang=\"de-CH\"><font face=\"Courier New, monospace\"><font size=\"2\">R\351sistance</font></font></p>\n</td>\n<td width=\"147\">\n<p lang=\"de-CH\"><font face=\"Arial Unicode MS, sans-serif\"><font size=\"3\"><font size=\"2\"><font face=\"Courier New, monospace\">\243\n10</font></font></font></font></p>\n</td>\n<td width=\"143\">\n<p lang=\"de-CH\"><font face=\"Arial Unicode MS, sans-serif\"><font size=\"3\"><font size=\"2\"><font face=\"Courier New, monospace\"><span lang=\"fr-FR\">\263\n</span>8 + <span lang=\"fr-FR\">\263 </span>152</font></font></font></font></p>\n</td>\n</tr>\n</tbody>\n</table>\n"
  @parser.feed(src)
  chapter = @writer.chapter
  assert_equal(1, chapter.sections.size)
  section = chapter.sections.first
  assert_equal(1, section.paragraphs.size)
  paragraph = section.paragraphs.first
  assert_equal(true, paragraph.preformatted?)
  expected = "-----------------------------------------------------------------\nDisktest*                Verd\374nnungstest**\nHemmhofdurchmesser (mm)  MHK (mg/l)\n\263 16                     \243 2 + \243 38\nTeilweise empfindlich  11 - 15                  4 + 76\nR\351sistance             \243 10                     \263 8 + \263 152\n-----------------------------------------------------------------\n"
  puts paragraph
  assert_equal(expected, paragraph.text)
end

- (Object) test_table__0



89
90
91
92
93
94
95
96
97
98
99
100
# File 'ext/chapterparse/test/test_integrate.rb', line 89

def test_table__0
  src = "<table>\n<tbody>\n<tr>\n<td>\ntable\n</td>\n</tr>\n</tbody>\n</table>\n"
  @parser.feed(src)
  chapter = @writer.chapter
  assert_equal(1, chapter.sections.size)
  section = chapter.sections.first
  assert_equal(1, section.paragraphs.size)
  paragraph = section.paragraphs.first
  assert_equal(true, paragraph.preformatted?)
  expected = "-----\ntable\n-----\n"
  assert_equal(expected, paragraph.text)
end

- (Object) test_table__1



112
113
114
115
116
117
118
119
120
121
122
123
124
# File 'ext/chapterparse/test/test_integrate.rb', line 112

def test_table__1
  src = "<table border=\"1\" bordercolor=\"#000000\" cellpadding=\"5\" cellspacing=\"0\" frame=\"hsides\" rules=\"groups\" width=\"462\">\n<col width=\"143\">\n<col width=\"147\">\n<col width=\"143\">\n<tbody>\n<tr valign=\"top\">\n<td width=\"143\">\n<p lang=\"de-CH\"><br>\n</p>\n</td>\n<td width=\"147\">\n<p style=\"margin-bottom: 0cm;\" lang=\"de-CH\"><font face=\"Courier New, monospace\"><font size=\"2\">Disktest*</font></font></p>\n<p lang=\"de-CH\"><font face=\"Courier New, monospace\"><font size=\"2\">Hemmhofdurchmesser\n(mm)</font></font></p>\n</td>\n<td width=\"143\">\n<p style=\"margin-bottom: 0cm;\" lang=\"de-CH\"><font face=\"Courier New, monospace\"><font size=\"2\">Verd\374nnungstest**</font></font></p>\n<p lang=\"de-CH\"><font face=\"Courier New, monospace\"><font size=\"2\">MHK\n(mg/l) </font></font>\n</p>\n</td>\n</tr>\n</tbody>\n</table>\n"
  @parser.feed(src)
  chapter = @writer.chapter
  assert_equal(1, chapter.sections.size)
  section = chapter.sections.first
  assert_equal(1, section.paragraphs.size)
  paragraph = section.paragraphs.first
  assert_equal(true, paragraph.preformatted?)
  expected = "--------------------------------------------\nDisktest*                Verd\374nnungstest**\nHemmhofdurchmesser (mm)  MHK (mg/l)\n--------------------------------------------\n"
  puts paragraph
  assert_equal(expected, paragraph.text)
end