Class: TestHtmlFormatter

Inherits:
Test::Unit::TestCase
  • Object
show all
Defined in:
test/test_util/html_parser.rb

Defined Under Namespace

Classes: StubTableHandler, StubWriter

Instance Method Summary (collapse)

Instance Method Details

- (Object) setup



130
131
132
133
# File 'test/test_util/html_parser.rb', line 130

def setup
  @writer = StubWriter.new
  @formatter = ODDB::HtmlFormatter.new(@writer)
end

- (Object) test_interface_additions



209
210
211
212
213
# File 'test/test_util/html_parser.rb', line 209

def test_interface_additions
  writer = ODDB::NullWriter.new
  assert_respond_to(writer, :new_tablehandler)
  assert_equal(1, writer.method(:new_tablehandler).arity)
end


148
149
150
151
152
153
154
155
156
157
158
159
160
# File 'test/test_util/html_parser.rb', line 148

def test_pop_link
  @formatter.link_stack = [
    'first', 'second', 
  ]
  @formatter.pop_link
  assert_equal(['first'], @formatter.link_stack)
  assert_equal(:new_linkhandler, @writer.called)
  assert_equal(['first'], @writer.arguments)
  @formatter.pop_link
  assert_equal([], @formatter.link_stack)
  assert_equal(:new_linkhandler, @writer.called)
  assert_equal([nil], @writer.arguments)
end

- (Object) test_pop_table



174
175
176
177
178
179
180
181
182
183
184
185
186
# File 'test/test_util/html_parser.rb', line 174

def test_pop_table
  @formatter.table_stack = [
    'first', 'second', 
  ]
  @formatter.pop_table
  assert_equal(['first'], @formatter.table_stack)
  assert_equal(:new_tablehandler, @writer.called)
  assert_equal(['first'], @writer.arguments)
  @formatter.pop_table
  assert_equal([], @formatter.table_stack)
  assert_equal(:new_tablehandler, @writer.called)
  assert_equal([nil], @writer.arguments)
end

- (Object) test_pop_tablecell



206
207
208
# File 'test/test_util/html_parser.rb', line 206

def test_pop_tablecell
  assert_respond_to(@formatter, :pop_tablecell)
end

- (Object) test_pop_tablerow



195
196
197
# File 'test/test_util/html_parser.rb', line 195

def test_pop_tablerow
  assert_respond_to(@formatter, :pop_tablerow)
end


134
135
136
137
138
139
140
141
142
143
144
145
146
147
# File 'test/test_util/html_parser.rb', line 134

def test_push_link
  attrs = [ ["foo","bar"] ]
  @formatter.push_link(attrs)
  assert_equal(1, @formatter.link_stack.size)
  lhandler = @formatter.link_stack.first
  assert_instance_of(ODDB::HtmlLinkHandler, lhandler)
  hash = {'foo' => 'bar'}
  assert_equal(hash, lhandler.attributes)
  assert_equal(:new_linkhandler, @writer.called)
  @formatter.push_link(attrs)
  assert_equal(2, @formatter.link_stack.size)
  lhandler = @formatter.link_stack.last
  assert_instance_of(ODDB::HtmlLinkHandler, lhandler)
end

- (Object) test_push_table



161
162
163
164
165
166
167
168
169
170
171
172
173
# File 'test/test_util/html_parser.rb', line 161

def test_push_table
  attrs = [ ["foo","bar"] ]
  @formatter.push_table(attrs)
  assert_equal(1, @formatter.table_stack.size)
  thandler = @formatter.table_stack.first
  assert_instance_of(ODDB::HtmlTableHandler, thandler)
  assert_equal(attrs, thandler.attributes)
  assert_equal(:new_tablehandler, @writer.called)
  @formatter.push_table(attrs)
  assert_equal(2, @formatter.table_stack.size)
  thandler = @formatter.table_stack.last
  assert_instance_of(ODDB::HtmlTableHandler, thandler)
end

- (Object) test_push_tablecell



198
199
200
201
202
203
204
205
# File 'test/test_util/html_parser.rb', line 198

def test_push_tablecell
  handler = StubTableHandler.new
  @formatter.tablehandler = handler
  attrs = [[ "foo","bar" ]]
  @formatter.push_tablecell(attrs)  
  assert_equal(:next_cell, handler.called)
  assert_equal([attrs], handler.arguments)
end

- (Object) test_push_tablerow



187
188
189
190
191
192
193
194
# File 'test/test_util/html_parser.rb', line 187

def test_push_tablerow
  handler = StubTableHandler.new
  @formatter.tablehandler = handler
  attrs = [[ "foo","bar" ]]
  @formatter.push_tablerow(attrs) 
  assert_equal(:next_row, handler.called)
  assert_equal([attrs], handler.arguments)
end