ruby-changes:27669
From: naruse <ko1@a...>
Date: Mon, 11 Mar 2013 17:29:56 +0900 (JST)
Subject: [ruby-changes:27669] naruse:r39721 (trunk): * test/ruby/envutil.rb (EnvUtil.with_default_external): add for
naruse 2013-03-11 17:29:46 +0900 (Mon, 11 Mar 2013) New Revision: 39721 http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=39721 Log: * test/ruby/envutil.rb (EnvUtil.with_default_external): add for changing Encoding.default_external without warnings. * test/ruby/envutil.rb (EnvUtil.with_default_internal): ditto. * test/ruby/test_io_m17n.rb: use above with_default_external. Modified files: trunk/ChangeLog trunk/test/ruby/envutil.rb trunk/test/ruby/test_io_m17n.rb Index: ChangeLog =================================================================== --- ChangeLog (revision 39720) +++ ChangeLog (revision 39721) @@ -1,3 +1,12 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1 +Mon Mar 11 17:27:57 2013 NARUSE, Yui <naruse@r...> + + * test/ruby/envutil.rb (EnvUtil.with_default_external): add for + changing Encoding.default_external without warnings. + + * test/ruby/envutil.rb (EnvUtil.with_default_internal): ditto. + + * test/ruby/test_io_m17n.rb: use above with_default_external. + Mon Mar 11 16:57:00 2013 NARUSE, Yui <naruse@r...> * io.c (extract_binmode): raise error even if binmode and textmode Index: test/ruby/test_io_m17n.rb =================================================================== --- test/ruby/test_io_m17n.rb (revision 39720) +++ test/ruby/test_io_m17n.rb (revision 39721) @@ -479,14 +479,13 @@ EOT https://github.com/ruby/ruby/blob/trunk/test/ruby/test_io_m17n.rb#L479 with_tmpdir { src = "\u3042" generate_file('tmp', src) - defext = Encoding.default_external - Encoding.default_external = Encoding::UTF_8 - open("tmp", "rt") {|f| - s = f.getc - assert_equal(true, s.valid_encoding?) - assert_equal("\u3042", s) - } - Encoding.default_external = defext + EnvUtil.with_default_external(Encoding::UTF_8) do + open("tmp", "rt") {|f| + s = f.getc + assert_equal(true, s.valid_encoding?) + assert_equal("\u3042", s) + } + end } end @@ -494,17 +493,16 @@ EOT https://github.com/ruby/ruby/blob/trunk/test/ruby/test_io_m17n.rb#L493 with_tmpdir { src = "\xE3\x81" generate_file('tmp', src) - defext = Encoding.default_external - Encoding.default_external = Encoding::UTF_8 - open("tmp", "rt") {|f| - s = f.getc - assert_equal(false, s.valid_encoding?) - assert_equal("\xE3".force_encoding("UTF-8"), s) - s = f.getc - assert_equal(false, s.valid_encoding?) - assert_equal("\x81".force_encoding("UTF-8"), s) - } - Encoding.default_external = defext + EnvUtil.with_default_external(Encoding::UTF_8) do + open("tmp", "rt") {|f| + s = f.getc + assert_equal(false, s.valid_encoding?) + assert_equal("\xE3".force_encoding("UTF-8"), s) + s = f.getc + assert_equal(false, s.valid_encoding?) + assert_equal("\x81".force_encoding("UTF-8"), s) + } + end } end @@ -1681,7 +1679,7 @@ EOT https://github.com/ruby/ruby/blob/trunk/test/ruby/test_io_m17n.rb#L1679 u16 = "\x85\x35\0\r\x00\xa2\0\r\0\n\0\n".force_encoding("utf-16be") i = "\e$B\x42\x22\e(B\r\e$B\x21\x71\e(B\r\n\n".force_encoding("iso-2022-jp") n = system_newline - un = n.encode("utf-16be").force_encoding("ascii-8bit") + n.encode("utf-16be").force_encoding("ascii-8bit") assert_write("a\rb\r#{n}c#{n}", "wt", a) assert_write("\xc2\xa2", "wt", e) Index: test/ruby/envutil.rb =================================================================== --- test/ruby/envutil.rb (revision 39720) +++ test/ruby/envutil.rb (revision 39721) @@ -127,6 +127,30 @@ module EnvUtil https://github.com/ruby/ruby/blob/trunk/test/ruby/envutil.rb#L127 GC.stress = stress end module_function :under_gc_stress + + def with_default_external(enc) + verbose, $VERBOSE = $VERBOSE, nil + origenc, Encoding.default_external = Encoding.default_external, enc + $VERBOSE = verbose + yield + ensure + verbose, $VERBOSE = $VERBOSE, nil + Encoding.default_external = origenc + $VERBOSE = verbose + end + module_function :with_default_external + + def with_default_internal(enc) + verbose, $VERBOSE = $VERBOSE, nil + origenc, Encoding.default_internal = Encoding.default_internal, enc + $VERBOSE = verbose + yield + ensure + verbose, $VERBOSE = $VERBOSE, nil + Encoding.default_internal = origenc + $VERBOSE = verbose + end + module_function :with_default_internal end module Test -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/