Class: TestHtmlTableHandler

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

Instance Method Summary (collapse)

Instance Method Details

- (Object) setup



250
251
252
# File 'test/test_util/html_parser.rb', line 250

def setup
  @handler = ODDB::HtmlTableHandler.new([])
end

- (Object) test_cdata1



273
274
275
276
277
278
279
280
281
282
283
284
285
# File 'test/test_util/html_parser.rb', line 273

def test_cdata1
  row = @handler.next_row([])
  row = @handler.next_row([])
  cell = @handler.next_cell([])
  cell = @handler.next_cell([])
  cell = @handler.next_cell([])
  @handler.send_cdata('Moin!')
  assert_equal('Moin!', @handler.cdata(2,1))
  val = assert_nothing_raised {
    @handler.cdata(0,4)
  }
  assert_nil(val)
end

- (Object) test_cdata2



286
287
288
289
290
291
292
# File 'test/test_util/html_parser.rb', line 286

def test_cdata2
  row = @handler.next_row([])
  cell = @handler.next_cell([["colspan","2"]])
  cell = @handler.next_cell([])
  @handler.send_cdata('Moin!')
  assert_equal('Moin!', @handler.cdata(2,0))
end

- (Object) test_extract_cdata



293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
# File 'test/test_util/html_parser.rb', line 293

def test_extract_cdata
  row = @handler.next_row([])
  cell = @handler.next_cell([])
  cell = @handler.next_cell([])
  @handler.send_cdata('fooval')
  row = @handler.next_row([])
  row = @handler.next_row([])
  cell = @handler.next_cell([])
  @handler.send_cdata('barval')
  row = @handler.next_row([])
  cell = @handler.next_cell([['colspan','2']])
  cell = @handler.next_cell([])
  @handler.send_cdata('valbaz')
  template = {
    :foo =>  [1,0],
    :bar =>  [0,2],
    :baz =>  [2,3],
  }
  expected = {
    :foo =>  "fooval",
    :bar =>  "barval",
    :baz =>  "valbaz",
  }
  assert_equal(expected, @handler.extract_cdata(template))
  assert_nothing_raised {
    @handler.extract_cdata({:no_such_pos=>[10,10]})
  }
end

- (Object) test_next_cell



259
260
261
262
263
264
# File 'test/test_util/html_parser.rb', line 259

def test_next_cell
  row = @handler.next_row([])
  cell = @handler.next_cell([])
  assert_instance_of(ODDB::HtmlTableHandler::Cell, cell)
  assert_equal({}, cell.attributes)
end

- (Object) test_next_row



253
254
255
256
257
258
# File 'test/test_util/html_parser.rb', line 253

def test_next_row
  attr = [[ 'class','foorow' ]]
  row = @handler.next_row(attr)
  assert_instance_of(ODDB::HtmlTableHandler::Row, row)
  assert_equal(attr, row.attributes)
end

- (Object) test_send_cdata



265
266
267
268
269
270
271
272
# File 'test/test_util/html_parser.rb', line 265

def test_send_cdata
  row = @handler.next_row([])
  cell = @handler.next_cell([])
  @handler.send_cdata('Hello World!')
  assert_equal('Hello World!', cell.cdata)
  @handler.send_cdata(' ...Goodbye!')
  assert_equal('Hello World! ...Goodbye!', cell.cdata)
end