[ruby/rdoc] Fix ToRdoc#accept_table
(https://github.com/ruby/rdoc/pull/1184) https://github.com/ruby/rdoc/commit/7b68545094
This commit is contained in:
parent
b421964b9d
commit
218445bb1f
@ -249,8 +249,8 @@ class RDoc::Markup::ToRdoc < RDoc::Markup::Formatter
|
|||||||
# Adds +table+ to the output
|
# Adds +table+ to the output
|
||||||
|
|
||||||
def accept_table header, body, aligns
|
def accept_table header, body, aligns
|
||||||
widths = header.zip(body) do |h, b|
|
widths = header.zip(*body).map do |cols|
|
||||||
[h.size, b.size].max
|
cols.map(&:size).max
|
||||||
end
|
end
|
||||||
aligns = aligns.map do |a|
|
aligns = aligns.map do |a|
|
||||||
case a
|
case a
|
||||||
@ -262,12 +262,12 @@ class RDoc::Markup::ToRdoc < RDoc::Markup::Formatter
|
|||||||
:rjust
|
:rjust
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@res << header.zip(widths, aligns) do |h, w, a|
|
@res << header.zip(widths, aligns).map do |h, w, a|
|
||||||
h.__send__(a, w)
|
h.__send__(a, w)
|
||||||
end.join("|").rstrip << "\n"
|
end.join("|").rstrip << "\n"
|
||||||
@res << widths.map {|w| "-" * w }.join("|") << "\n"
|
@res << widths.map {|w| "-" * w }.join("|") << "\n"
|
||||||
body.each do |row|
|
body.each do |row|
|
||||||
@res << row.zip(widths, aligns) do |t, w, a|
|
@res << row.zip(widths, aligns).map do |t, w, a|
|
||||||
t.__send__(a, w)
|
t.__send__(a, w)
|
||||||
end.join("|").rstrip << "\n"
|
end.join("|").rstrip << "\n"
|
||||||
end
|
end
|
||||||
|
@ -99,6 +99,23 @@ class RDoc::Markup::TextFormatterTestCase < RDoc::Markup::FormatterTestCase
|
|||||||
accept_paragraph_wrap
|
accept_paragraph_wrap
|
||||||
end
|
end
|
||||||
|
|
||||||
|
##
|
||||||
|
# Test case that calls <tt>@to.accept_table</tt>
|
||||||
|
|
||||||
|
def test_accept_table_align
|
||||||
|
header = ['AA', 'BB', 'CCCCC']
|
||||||
|
body = [
|
||||||
|
['', 'bbb', 'c'],
|
||||||
|
['aaaa', 'b', ''],
|
||||||
|
['a', '', 'cc']
|
||||||
|
]
|
||||||
|
aligns = [nil, :left, :right]
|
||||||
|
@to.start_accepting
|
||||||
|
@to.accept_table header, body, aligns
|
||||||
|
|
||||||
|
accept_table_align
|
||||||
|
end
|
||||||
|
|
||||||
##
|
##
|
||||||
# Test case that calls <tt>@to.attributes</tt> with an escaped
|
# Test case that calls <tt>@to.attributes</tt> with an escaped
|
||||||
# cross-reference. If this test doesn't pass something may be very
|
# cross-reference. If this test doesn't pass something may be very
|
||||||
|
@ -348,6 +348,17 @@ words words words words
|
|||||||
assert_equal expected, @to.end_accepting
|
assert_equal expected, @to.end_accepting
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def accept_table_align
|
||||||
|
expected = "\e[0m" + <<-EXPECTED
|
||||||
|
AA |BB |CCCCC
|
||||||
|
----|---|-----
|
||||||
|
|bbb| c
|
||||||
|
aaaa|b |
|
||||||
|
a | | cc
|
||||||
|
EXPECTED
|
||||||
|
assert_equal expected, @to.end_accepting
|
||||||
|
end
|
||||||
|
|
||||||
# functional test
|
# functional test
|
||||||
def test_convert_list_note
|
def test_convert_list_note
|
||||||
note_list = <<-NOTE_LIST
|
note_list = <<-NOTE_LIST
|
||||||
|
@ -349,4 +349,15 @@ words words words words
|
|||||||
assert_equal expected, @to.end_accepting
|
assert_equal expected, @to.end_accepting
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def accept_table_align
|
||||||
|
expected = <<-EXPECTED
|
||||||
|
AA |BB |CCCCC
|
||||||
|
----|---|-----
|
||||||
|
|bbb| c
|
||||||
|
aaaa|b |
|
||||||
|
a | | cc
|
||||||
|
EXPECTED
|
||||||
|
assert_equal expected, @to.end_accepting
|
||||||
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
@ -346,6 +346,17 @@ words words words words
|
|||||||
assert_equal expected, @to.end_accepting
|
assert_equal expected, @to.end_accepting
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def accept_table_align
|
||||||
|
expected = <<-EXPECTED
|
||||||
|
AA |BB |CCCCC
|
||||||
|
----|---|-----
|
||||||
|
|bbb| c
|
||||||
|
aaaa|b |
|
||||||
|
a | | cc
|
||||||
|
EXPECTED
|
||||||
|
assert_equal expected, @to.end_accepting
|
||||||
|
end
|
||||||
|
|
||||||
def test_convert_RDOCLINK
|
def test_convert_RDOCLINK
|
||||||
result = @to.convert 'rdoc-garbage:C'
|
result = @to.convert 'rdoc-garbage:C'
|
||||||
|
|
||||||
|
@ -346,6 +346,17 @@ words words words words
|
|||||||
assert_equal expected, @to.end_accepting
|
assert_equal expected, @to.end_accepting
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def accept_table_align
|
||||||
|
expected = <<-EXPECTED
|
||||||
|
AA |BB |CCCCC
|
||||||
|
----|---|-----
|
||||||
|
|bbb| c
|
||||||
|
aaaa|b |
|
||||||
|
a | | cc
|
||||||
|
EXPECTED
|
||||||
|
assert_equal expected, @to.end_accepting
|
||||||
|
end
|
||||||
|
|
||||||
# functional test
|
# functional test
|
||||||
def test_convert_list_note
|
def test_convert_list_note
|
||||||
note_list = <<-NOTE_LIST
|
note_list = <<-NOTE_LIST
|
||||||
|
Loading…
x
Reference in New Issue
Block a user