summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorkou <kou@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2011-06-11 07:29:48 +0000
committerkou <kou@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2011-06-11 07:29:48 +0000
commitda672779e241c043133fbd549121cdecc2fc986a (patch)
tree854fbd63a4830074020bd50f7a9bbf475e8d889d
parent962956e8a128bfcc03e694e41316d67ba98122ef (diff)
* lib/rexml/formatters/pretty.rb
(REXML::Formatters::Pretty#write_text), test/rexml/test_core.rb (Tester#test_pretty_format_long_text_finite): don't ignore 'width' parameter in pretty formatter. fixes #4498 Reported by Michael Frasca. Thanks!!! git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@31997 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
-rw-r--r--ChangeLog9
-rw-r--r--lib/rexml/formatters/pretty.rb2
-rw-r--r--test/rexml/test_core.rb61
3 files changed, 71 insertions, 1 deletions
diff --git a/ChangeLog b/ChangeLog
index f1d8176..de88271 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,12 @@
+Sat Jun 11 16:28:25 2011 Kouhei Sutou <kou@cozmixng.org>
+
+ * lib/rexml/formatters/pretty.rb
+ (REXML::Formatters::Pretty#write_text),
+ test/rexml/test_core.rb
+ (Tester#test_pretty_format_long_text_finite): don't ignore
+ 'width' parameter in pretty formatter. fixes #4498
+ Reported by Michael Frasca. Thanks!!!
+
Sat Jun 11 16:11:36 2011 Kouhei Sutou <kou@cozmixng.org>
* test/rexml/test_core.rb
diff --git a/lib/rexml/formatters/pretty.rb b/lib/rexml/formatters/pretty.rb
index 1747397..63f726e 100644
--- a/lib/rexml/formatters/pretty.rb
+++ b/lib/rexml/formatters/pretty.rb
@@ -88,7 +88,7 @@ module REXML
s = node.to_s()
s.gsub!(/\s/,' ')
s.squeeze!(" ")
- s = wrap(s, 80-@level)
+ s = wrap(s, @width - @level)
s = indent_text(s, @level, " ", true)
output << (' '*@level + s)
end
diff --git a/test/rexml/test_core.rb b/test/rexml/test_core.rb
index bcc7269..e530cc1 100644
--- a/test/rexml/test_core.rb
+++ b/test/rexml/test_core.rb
@@ -1153,6 +1153,67 @@ EOL
output)
end
+ def test_pretty_format_deep_indent
+ n = 6
+ elements = ""
+ n.times do |i|
+ elements << "<element#{i}>"
+ elements << "element#{i} " * 5
+ end
+ (n - 1).downto(0) do |i|
+ elements << "</element#{i}>"
+ end
+ xml = "<doc>#{elements}</doc>"
+ document = REXML::Document.new(xml)
+ formatter = REXML::Formatters::Pretty.new
+ formatter.width = 20
+ output = ""
+ formatter.write(document, output)
+ assert_equal(<<-XML.strip, output)
+<doc>
+ <element0>
+ element0
+ element0
+ element0
+ element0
+ element0
+ <element1>
+ element1
+ element1
+ element1
+ element1
+ element1
+ <element2>
+ element2
+ element2
+ element2
+ element2
+ element2
+ <element3>
+ element3
+ element3
+ element3
+ element3
+ element3
+ <element4>
+ element4
+ element4
+ element4
+ element4
+ element4
+
+ <element5>
+ element5 element5 element5 element5 element5
+ </element5>
+ </element4>
+ </element3>
+ </element2>
+ </element1>
+ </element0>
+</doc>
+ XML
+ end
+
def test_ticket_58
doc = REXML::Document.new
doc << REXML::XMLDecl.default