From 0b5d8d2d664a544e524a40082affa7c8aa0bc44d Mon Sep 17 00:00:00 2001 From: akr Date: Sun, 11 May 2003 04:53:57 +0000 Subject: [PATCH] * lib/pp.rb: refine to_s test. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@3780 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- ChangeLog | 4 +++- lib/pp.rb | 25 ++++++++++++++----------- lib/prettyprint.rb | 2 ++ 3 files changed, 19 insertions(+), 12 deletions(-) diff --git a/ChangeLog b/ChangeLog index 84dc726dcb..e6fcef0201 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,4 +1,6 @@ -Sun May 11 05:50:39 2003 Tanaka Akira +Sun May 11 13:50:12 2003 Tanaka Akira + + * lib/pp.rb: refine to_s test. * lib/pp.rb (PP::ObjectMixin#pretty_print): refine to_s handling. diff --git a/lib/pp.rb b/lib/pp.rb index 8eb9ce4afc..9babc1e7a9 100644 --- a/lib/pp.rb +++ b/lib/pp.rb @@ -115,6 +115,9 @@ PP#pp to print the object. If you implement (({pretty_print})), it can be used as follows. alias inspect pretty_print_inspect + +== AUTHOR +Tanaka Akira =end require 'prettyprint' @@ -524,21 +527,21 @@ if __FILE__ == $0 assert_equal("#{a.inspect}\n", PP.pp(a, '')) end - class Test_to_s_with_iv - def initialize() @a = nil end - def to_s() "aaa" end - end def test_to_s_with_iv - a = Test_to_s_with_iv.new - assert_equal("#{a.inspect}\n", PP.pp(a, '')) + a = Object.new + def a.to_s() "aaa" end + a.instance_eval { @a = nil } + result = PP.pp(a, '') + assert_equal("#{a.inspect}\n", result) + assert_match(/\A#\n\z/m, result) end - class Test_to_s_without_iv - def to_s() "aaa" end - end def test_to_s_without_iv - a = Test_to_s_without_iv.new - assert_equal("#{a.inspect}\n", PP.pp(a, '')) + a = Object.new + def a.to_s() "aaa" end + result = PP.pp(a, '') + assert_equal("#{a.inspect}\n", result) + assert_equal("aaa\n", result) end end diff --git a/lib/prettyprint.rb b/lib/prettyprint.rb index f7b9bbdf5f..a815f64538 100644 --- a/lib/prettyprint.rb +++ b/lib/prettyprint.rb @@ -119,6 +119,8 @@ Christian Lindig, Strictly Pretty, March 2000, Philip Wadler, A prettier printer, March 1998, (()) +== AUTHOR +Tanaka Akira =end class PrettyPrint