Class: ODDB::TestTable

Inherits:
Test::Unit::TestCase
  • Object
show all
Defined in:
test/test_model/text.rb

Instance Method Summary (collapse)

Instance Method Details

- (Object) setup



490
491
492
# File 'test/test_model/text.rb', line 490

def setup
  @table = Text::Table.new
end

- (Object) test_cell



493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
# File 'test/test_model/text.rb', line 493

def test_cell
  @table.next_row!
  cell1 = @table.next_cell!
  @table << 'cell1'
  cell2 = @table.next_cell!
  @table << 'cell2'
  @table.next_row!
  cell3 = @table.next_cell!
  @table << 'cell3'
  cell4 = @table.next_cell!
  @table << 'cell4'
  assert_equal cell1, @table.cell(0,0)
  assert_equal cell2, @table.cell(0,1)
  assert_equal cell3, @table.cell(1,0)
  assert_equal cell4, @table.cell(1,1)
end

- (Object) test_clean



509
510
511
512
513
514
515
516
517
518
519
# File 'test/test_model/text.rb', line 509

def test_clean
  @table.next_row!
  cell1 = @table.next_cell!
  @table << 'foo'
  cell2 = @table.next_cell!
  @table.next_row!
  cell3 = @table.next_cell!
  cell4 = @table.next_cell!
  @table.clean!
  assert_equal "---\nfoo\n---\n".strip, @table.to_s
end

- (Object) test_column_widths



525
526
527
528
529
530
531
532
533
534
535
536
537
# File 'test/test_model/text.rb', line 525

def test_column_widths
  @table.next_row!
  cell1 = @table.next_cell!
  @table << 'cell1'
  cell2 = @table.next_cell!
  @table << 'cell2 longer'
  @table.next_row!
  cell3 = @table.next_cell!
  @table << 'cell3'
  cell4 = @table.next_cell!
  @table << 'cell4'
  assert_equal [5, 12], @table.column_widths
end

- (Object) test_current_cell



538
539
540
541
542
543
544
545
546
547
# File 'test/test_model/text.rb', line 538

def test_current_cell
  assert_nothing_raised do @table.current_cell end
  assert_nil @table.current_cell
  @table.next_row!
  assert_nil @table.current_cell
  cell1 = @table.next_cell!
  assert_equal cell1, @table.current_cell
  cell2 = @table.next_cell!
  assert_equal cell2, @table.current_cell
end

- (Object) test_current_row



548
549
550
551
552
553
554
555
# File 'test/test_model/text.rb', line 548

def test_current_row
  assert_nothing_raised do @table.current_row end
  assert_nil @table.current_row
  row1 = @table.next_row!
  assert_equal row1, @table.current_row
  row2 = @table.next_row!
  assert_equal row2, @table.current_row
end

- (Object) test_each_normalized



556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
# File 'test/test_model/text.rb', line 556

def test_each_normalized
  @table.next_row!
  cell1 = @table.next_cell!
  @table << 'cell1'
  @table.next_row!
  cell3 = @table.next_cell!
  @table << 'cell3'
  cell4 = @table.next_cell!
  @table << 'cell4'
  rows = []
  @table.each_normalized do |row|
    rows.push row
  end
  assert_equal [[cell1, nil], [cell3, cell4]], rows
end

- (Object) test_empty



571
572
573
574
575
576
577
578
579
# File 'test/test_model/text.rb', line 571

def test_empty
  assert_equal true, @table.empty?
  @table.next_row!
  assert_equal true, @table.empty?
  @table.next_cell!
  assert_equal true, @table.empty?
  @table << 'cell1'
  assert_equal false, @table.empty?
end

- (Object) test_gsub



580
581
582
583
584
585
586
587
588
589
590
591
592
593
# File 'test/test_model/text.rb', line 580

def test_gsub
  @table.next_row!
  @table.next_cell!
  @table << 'cell1'
  @table.next_cell!
  @table << 'cell2'
  @table.next_row!
  @table.next_cell!
  @table << 'cell3'
  @table.next_cell!
  @table << 'cell4'
  @table.gsub! /[aeiou]/ do |match| match.upcase end
  assert_equal "------------\ncEll1  cEll2\n------------\ncEll3  cEll4\n------------\n".strip, @table.to_s
end

- (Object) test_next_paragraph



601
602
603
604
605
606
607
608
609
# File 'test/test_model/text.rb', line 601

def test_next_paragraph
  @table.next_row!
  @table.next_cell!
  @table << 'cell1'
  @table.next_paragraph
  @table << 'still cell1'
  assert_equal "-----------\ncell1\nstill cell1\n-----------\n".strip, @table.to_s

end

- (Object) test_preformatted



616
617
618
# File 'test/test_model/text.rb', line 616

def test_preformatted
  assert_equal true, @table.preformatted?
end

- (Object) test_to_s



619
620
621
622
623
624
625
626
627
628
629
630
631
# File 'test/test_model/text.rb', line 619

def test_to_s
  @table.next_row!
  @table.next_cell!
  @table << 'cell1'
  @table.next_cell!
  @table << 'cell2'
  @table.next_row!
  @table.next_cell!
  @table << 'cell3'
  @table.next_cell!
  @table << 'cell4'
  assert_equal "------------\ncell1  cell2\n------------\ncell3  cell4\n------------\n".strip, @table.to_s
end

- (Object) test_to_s__wrapped



639
640
641
642
643
644
645
646
647
648
649
650
651
# File 'test/test_model/text.rb', line 639

def test_to_s__wrapped
  @table.next_row!
  @table.next_cell!
  @table << 'This table needs to be wrapped'
  @table.next_cell!
  @table << 'Ideally, this test will use the hyphenator library'
  @table.next_row!
  @table.next_cell!
  @table << 'Hopefully it will work'
  @table.next_cell!
  @table << 'And we will see some hyphens'
  assert_equal "--------------------\nThis     Ideally,\ntable    this test\nneeds    will use the\nto be    hyphenator\nwrapped  library\n--------------------\nHopef-   And we will\nully it  see some\nwill     hyphens\nwork\n--------------------\n".strip, @table.to_s(:width => 20)
end

- (Object) test_width



666
667
668
669
670
671
672
673
674
675
676
# File 'test/test_model/text.rb', line 666

def test_width
  @table.next_row!
  cell1 = @table.next_cell!
  @table << 'cell1'
  @table.next_row!
  cell3 = @table.next_cell!
  @table << 'cell3'
  cell4 = @table.next_cell!
  @table << 'cell4'
  assert_equal 2, @table.width
end