Class: TestFormatTable

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

Instance Method Summary collapse

Instance Method Details

#test_basic_formattingObject



269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
# File 'lib/format_table.rb', line 269

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
  )
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



320
321
322
323
324
325
# File 'lib/format_table.rb', line 320

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

#test_missing_column_countObject



289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
# File 'lib/format_table.rb', line 289

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
  )
end

#test_no_pipe_at_endObject



345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
# File 'lib/format_table.rb', line 345

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
  )
end

#test_single_columnObject



327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
# File 'lib/format_table.rb', line 327

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
  )
end