Class: TestFormatTable

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

Instance Method Summary collapse

Instance Method Details

#setupObject



326
327
328
# File 'lib/format_table.rb', line 326

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

#test_basic_formattingObject



330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
# File 'lib/format_table.rb', line 330

def test_basic_formatting
  lines = [
    '| Species| Genus| Family',
    '|-|-|-',
    '| Pongo tapanuliensis| Pongo| Hominidae',
    '| | Histiophryne| Antennariidae'
  ]
  column_count = 3
  expected = [
    '| Species             | Genus        | Family        |',
    '| ------------------- | ------------ | ------------- |',
    '| Pongo tapanuliensis | Pongo        | Hominidae     |',
    '|                     | Histiophryne | Antennariidae |'
  ]
  assert_equal expected, MarkdownTableFormatter.format_table(
    lines: lines,
    column_count: column_count,
    table: @table
  )
end

#test_empty_inputObject

def test_extra_column_count

lines = [
  "| A| B| C| D",
  "| 1| 2| 3| 4| 5"
]
column_count = 3
expected = [
  "| A | B | C ",
  "| 1 | 2 | 3 "
]
assert_equal expected, MarkdownTableFormatter.format_table(lines, column_count)

end



383
384
385
386
387
388
389
# File 'lib/format_table.rb', line 383

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

#test_missing_column_countObject



351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
# File 'lib/format_table.rb', line 351

def test_missing_column_count
  lines = [
    '| A| B| C',
    '| 1| 2',
    '| X'
  ]
  column_count = 3
  expected = [
    '| A | B | C |',
    '| 1 | 2 |   |',
    '| X |   |   |'
  ]
  assert_equal expected, MarkdownTableFormatter.format_table(
    lines: lines,
    column_count: column_count,
    table: @table
  )
end

#test_no_pipe_at_endObject



410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
# File 'lib/format_table.rb', line 410

def test_no_pipe_at_end
  lines = [
    '| A| B| C',
    '| 1| 2| 3'
  ]
  column_count = 3
  expected = [
    '| A | B | C |',
    '| 1 | 2 | 3 |'
  ]
  assert_equal expected, MarkdownTableFormatter.format_table(
    lines: lines,
    column_count: column_count,
    table: @table
  )
end

#test_single_columnObject



391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
# File 'lib/format_table.rb', line 391

def test_single_column
  lines = [
    '| A',
    '| Longer text',
    '| Short'
  ]
  column_count = 1
  expected = [
    '| A           |',
    '| Longer text |',
    '| Short       |'
  ]
  assert_equal expected, MarkdownTableFormatter.format_table(
    lines: lines,
    column_count: column_count,
    table: @table
  )
end