Class: TestFormatTable2

Inherits:
Minitest::Test
  • Object
show all
Defined in:
lib/format_table.rb

Instance Method Summary collapse

Instance Method Details

#setupObject



429
430
431
# File 'lib/format_table.rb', line 429

def setup
  @table = { delimiter: '|' }
end

#test_basic_formattingObject



433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
# File 'lib/format_table.rb', line 433

def test_basic_formatting
  lines = [
    '| Name | Age | City |',
    '| John | 30 | New York |',
    '| Jane | 25 | Los Angeles |'
  ]
  expected_output = [
    '| Name | Age | City        |',
    '| John | 30  | New York    |',
    '| Jane | 25  | Los Angeles |'
  ]
  assert_equal expected_output, MarkdownTableFormatter.format_table(
    lines: lines,
    column_count: 3,
    table: @table
  )
end

#test_complete_rowsObject



525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
# File 'lib/format_table.rb', line 525

def test_complete_rows
  lines = [
    '| Name | Age |',
    '| John | 30 |'
  ]
  expected_output = [
    '| Name | Age |',
    '| John | 30  |'
  ]
  assert_equal expected_output, MarkdownTableFormatter.format_table(
    lines: lines,
    column_count: 3,
    table: @table
  )
end

#test_empty_linesObject



515
516
517
518
519
520
521
522
523
# File 'lib/format_table.rb', line 515

def test_empty_lines
  lines = []
  expected_output = []
  assert_equal expected_output, MarkdownTableFormatter.format_table(
    lines: lines,
    column_count: 3,
    table: @table
  )
end

#test_extra_column_countObject



469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
# File 'lib/format_table.rb', line 469

def test_extra_column_count
  lines = [
    '| Name | Age | City | Country |',
    '| John | 30 | New York | USA |',
    '| Jane | 25 | Los Angeles | USA |'
  ]
  expected_output = [
    '| Name | Age | City        | Country |',
    '| John | 30  | New York    | USA     |',
    '| Jane | 25  | Los Angeles | USA     |'
  ]
  assert_equal expected_output, MarkdownTableFormatter.format_table(
    lines: lines,
    column_count: 4,
    table: @table
  )
end

#test_incomplete_column_countObject



451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
# File 'lib/format_table.rb', line 451

def test_incomplete_column_count
  lines = [
    '| Name | Age |',
    '| John | 30 | New York |',
    '| Jane | 25 | Los Angeles |'
  ]
  expected_output = [
    '| Name | Age |             |',
    '| John | 30  | New York    |',
    '| Jane | 25  | Los Angeles |'
  ]
  assert_equal expected_output, MarkdownTableFormatter.format_table(
    lines: lines,
    column_count: 3,
    table: @table
  )
end

#test_single_lineObject



505
506
507
508
509
510
511
512
513
# File 'lib/format_table.rb', line 505

def test_single_line
  lines = ['| Name | Age | City |']
  expected_output = ['| Name | Age | City |']
  assert_equal expected_output, MarkdownTableFormatter.format_table(
    lines: lines,
    column_count: 3,
    table: @table
  )
end

#test_varied_column_lengthsObject



487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
# File 'lib/format_table.rb', line 487

def test_varied_column_lengths
  lines = [
    '| Name | Age |',
    '| Johnathan | 30 | New York |',
    '| Jane | 25 | LA |'
  ]
  expected_output = [
    '| Name      | Age |          |',
    '| Johnathan | 30  | New York |',
    '| Jane      | 25  | LA       |'
  ]
  assert_equal expected_output, MarkdownTableFormatter.format_table(
    lines: lines,
    column_count: 3,
    table: @table
  )
end