Class: TestFormatTable
- Defined in:
- lib/format_table.rb
Instance Method Summary collapse
- #setup ⇒ Object
- #test_basic_formatting ⇒ Object
-
#test_empty_input ⇒ Object
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.
- #test_missing_column_count ⇒ Object
- #test_no_pipe_at_end ⇒ Object
- #test_single_column ⇒ Object
Instance Method Details
#setup ⇒ Object
340 341 342 |
# File 'lib/format_table.rb', line 340 def setup @table = { delimiter: '|' } end |
#test_basic_formatting ⇒ Object
344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 |
# File 'lib/format_table.rb', line 344 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_input ⇒ Object
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
398 399 400 401 402 403 404 |
# File 'lib/format_table.rb', line 398 def test_empty_input assert_equal [], MarkdownTableFormatter.format_table( lines: [], column_count: 3, table: @table ) end |
#test_missing_column_count ⇒ Object
365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 |
# File 'lib/format_table.rb', line 365 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_end ⇒ Object
425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 |
# File 'lib/format_table.rb', line 425 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_column ⇒ Object
406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 |
# File 'lib/format_table.rb', line 406 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 |