1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

* 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.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@39721 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
naruse 2013-03-11 08:29:46 +00:00
parent 756cd2852d
commit 7590de68e2
3 changed files with 51 additions and 20 deletions

View file

@ -1,3 +1,12 @@
Mon Mar 11 17:27:57 2013 NARUSE, Yui <naruse@ruby-lang.org>
* 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@ruby-lang.org>
* io.c (extract_binmode): raise error even if binmode and textmode

View file

@ -127,6 +127,30 @@ module EnvUtil
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

View file

@ -479,14 +479,13 @@ EOT
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
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
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)