Skip to content

Commit 7b68545

Browse files
authored
Fix ToRdoc#accept_table (#1184)
1 parent ed00d1c commit 7b68545

6 files changed

+65
-4
lines changed

lib/rdoc/markup/to_rdoc.rb

+4-4
Original file line numberDiff line numberDiff line change
@@ -249,8 +249,8 @@ def accept_verbatim verbatim
249249
# Adds +table+ to the output
250250

251251
def accept_table header, body, aligns
252-
widths = header.zip(body) do |h, b|
253-
[h.size, b.size].max
252+
widths = header.zip(*body).map do |cols|
253+
cols.map(&:size).max
254254
end
255255
aligns = aligns.map do |a|
256256
case a
@@ -262,12 +262,12 @@ def accept_table header, body, aligns
262262
:rjust
263263
end
264264
end
265-
@res << header.zip(widths, aligns) do |h, w, a|
265+
@res << header.zip(widths, aligns).map do |h, w, a|
266266
h.__send__(a, w)
267267
end.join("|").rstrip << "\n"
268268
@res << widths.map {|w| "-" * w }.join("|") << "\n"
269269
body.each do |row|
270-
@res << row.zip(widths, aligns) do |t, w, a|
270+
@res << row.zip(widths, aligns).map do |t, w, a|
271271
t.__send__(a, w)
272272
end.join("|").rstrip << "\n"
273273
end

test/rdoc/support/text_formatter_test_case.rb

+17
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,23 @@ def test_accept_paragraph_wrap
9999
accept_paragraph_wrap
100100
end
101101

102+
##
103+
# Test case that calls <tt>@to.accept_table</tt>
104+
105+
def test_accept_table_align
106+
header = ['AA', 'BB', 'CCCCC']
107+
body = [
108+
['', 'bbb', 'c'],
109+
['aaaa', 'b', ''],
110+
['a', '', 'cc']
111+
]
112+
aligns = [nil, :left, :right]
113+
@to.start_accepting
114+
@to.accept_table header, body, aligns
115+
116+
accept_table_align
117+
end
118+
102119
##
103120
# Test case that calls <tt>@to.attributes</tt> with an escaped
104121
# cross-reference. If this test doesn't pass something may be very

test/rdoc/test_rdoc_markup_to_ansi.rb

+11
Original file line numberDiff line numberDiff line change
@@ -348,6 +348,17 @@ def list_verbatim
348348
assert_equal expected, @to.end_accepting
349349
end
350350

351+
def accept_table_align
352+
expected = "\e[0m" + <<-EXPECTED
353+
AA |BB |CCCCC
354+
----|---|-----
355+
|bbb| c
356+
aaaa|b |
357+
a | | cc
358+
EXPECTED
359+
assert_equal expected, @to.end_accepting
360+
end
361+
351362
# functional test
352363
def test_convert_list_note
353364
note_list = <<-NOTE_LIST

test/rdoc/test_rdoc_markup_to_bs.rb

+11
Original file line numberDiff line numberDiff line change
@@ -349,4 +349,15 @@ def list_verbatim
349349
assert_equal expected, @to.end_accepting
350350
end
351351

352+
def accept_table_align
353+
expected = <<-EXPECTED
354+
AA |BB |CCCCC
355+
----|---|-----
356+
|bbb| c
357+
aaaa|b |
358+
a | | cc
359+
EXPECTED
360+
assert_equal expected, @to.end_accepting
361+
end
362+
352363
end

test/rdoc/test_rdoc_markup_to_markdown.rb

+11
Original file line numberDiff line numberDiff line change
@@ -346,6 +346,17 @@ def list_verbatim
346346
assert_equal expected, @to.end_accepting
347347
end
348348

349+
def accept_table_align
350+
expected = <<-EXPECTED
351+
AA |BB |CCCCC
352+
----|---|-----
353+
|bbb| c
354+
aaaa|b |
355+
a | | cc
356+
EXPECTED
357+
assert_equal expected, @to.end_accepting
358+
end
359+
349360
def test_convert_RDOCLINK
350361
result = @to.convert 'rdoc-garbage:C'
351362

test/rdoc/test_rdoc_markup_to_rdoc.rb

+11
Original file line numberDiff line numberDiff line change
@@ -346,6 +346,17 @@ def list_verbatim
346346
assert_equal expected, @to.end_accepting
347347
end
348348

349+
def accept_table_align
350+
expected = <<-EXPECTED
351+
AA |BB |CCCCC
352+
----|---|-----
353+
|bbb| c
354+
aaaa|b |
355+
a | | cc
356+
EXPECTED
357+
assert_equal expected, @to.end_accepting
358+
end
359+
349360
# functional test
350361
def test_convert_list_note
351362
note_list = <<-NOTE_LIST

0 commit comments

Comments
 (0)