test: use String#b instead of dup.force_encoding
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@53109 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
fcb4ab8d1c
commit
c81b224edc
@ -45,8 +45,7 @@ class MultiPart
|
|||||||
buf << "Content-Disposition: form-data: name=\"#{name}\"#{s}\r\n"
|
buf << "Content-Disposition: form-data: name=\"#{name}\"#{s}\r\n"
|
||||||
buf << "Content-Type: #{content_type}\r\n" if content_type
|
buf << "Content-Type: #{content_type}\r\n" if content_type
|
||||||
buf << "\r\n"
|
buf << "\r\n"
|
||||||
value = value.dup.force_encoding(::Encoding::ASCII_8BIT) if defined?(::Encoding)
|
buf << value.b
|
||||||
buf << value
|
|
||||||
buf << "\r\n"
|
buf << "\r\n"
|
||||||
return self
|
return self
|
||||||
end
|
end
|
||||||
|
@ -447,7 +447,7 @@ EOT
|
|||||||
end
|
end
|
||||||
|
|
||||||
def assert_valid_syntax(code, fname = caller_locations(1, 1)[0], mesg = fname.to_s, verbose: nil)
|
def assert_valid_syntax(code, fname = caller_locations(1, 1)[0], mesg = fname.to_s, verbose: nil)
|
||||||
code = code.dup.force_encoding("ascii-8bit")
|
code = code.b
|
||||||
code.sub!(/\A(?:\xef\xbb\xbf)?(\s*\#.*$)*(\n)?/n) {
|
code.sub!(/\A(?:\xef\xbb\xbf)?(\s*\#.*$)*(\n)?/n) {
|
||||||
"#$&#{"\n" if $1 && !$2}BEGIN{throw tag, :ok}\n"
|
"#$&#{"\n" if $1 && !$2}BEGIN{throw tag, :ok}\n"
|
||||||
}
|
}
|
||||||
@ -470,11 +470,11 @@ EOT
|
|||||||
end
|
end
|
||||||
|
|
||||||
def assert_syntax_error(code, error, fname = caller_locations(1, 1)[0], mesg = fname.to_s)
|
def assert_syntax_error(code, error, fname = caller_locations(1, 1)[0], mesg = fname.to_s)
|
||||||
code = code.dup.force_encoding("ascii-8bit")
|
code = code.b
|
||||||
code.sub!(/\A(?:\xef\xbb\xbf)?(\s*\#.*$)*(\n)?/n) {
|
code.sub!(/\A(?:\xef\xbb\xbf)?(\s*\#.*$)*(\n)?/n) {
|
||||||
"#$&#{"\n" if $1 && !$2}BEGIN{throw tag, :ng}\n"
|
"#$&#{"\n" if $1 && !$2}BEGIN{throw tag, :ng}\n"
|
||||||
}
|
}
|
||||||
code.force_encoding("us-ascii")
|
code.force_encoding(Encoding::US_ASCII)
|
||||||
verbose, $VERBOSE = $VERBOSE, nil
|
verbose, $VERBOSE = $VERBOSE, nil
|
||||||
yield if defined?(yield)
|
yield if defined?(yield)
|
||||||
case
|
case
|
||||||
|
@ -601,7 +601,7 @@ class TestOpenURI < Test::Unit::TestCase
|
|||||||
def test_content_encoding
|
def test_content_encoding
|
||||||
with_http {|srv, dr, url|
|
with_http {|srv, dr, url|
|
||||||
content = "abc" * 10000
|
content = "abc" * 10000
|
||||||
Zlib::GzipWriter.wrap(StringIO.new(content_gz="".dup.force_encoding("ascii-8bit"))) {|z| z.write content }
|
Zlib::GzipWriter.wrap(StringIO.new(content_gz="".b)) {|z| z.write content }
|
||||||
srv.mount_proc("/data/") {|req, res| res.body = content_gz; res['content-encoding'] = 'gzip' }
|
srv.mount_proc("/data/") {|req, res| res.body = content_gz; res['content-encoding'] = 'gzip' }
|
||||||
srv.mount_proc("/data2/") {|req, res| res.body = content_gz; res['content-encoding'] = 'gzip'; res.chunked = true }
|
srv.mount_proc("/data2/") {|req, res| res.body = content_gz; res['content-encoding'] = 'gzip'; res.chunked = true }
|
||||||
srv.mount_proc("/noce/") {|req, res| res.body = content_gz }
|
srv.mount_proc("/noce/") {|req, res| res.body = content_gz }
|
||||||
|
@ -208,7 +208,7 @@ class TestDir_M17N < Test::Unit::TestCase
|
|||||||
when /darwin/
|
when /darwin/
|
||||||
filename = filename.encode("utf-8", "euc-jp").b
|
filename = filename.encode("utf-8", "euc-jp").b
|
||||||
when /mswin|mingw/
|
when /mswin|mingw/
|
||||||
if ents.include?(win_expected_filename.dup.force_encoding("ASCII-8BIT"))
|
if ents.include?(win_expected_filename.b)
|
||||||
ents = Dir.entries(".", {:encoding => Encoding.find("filesystem")})
|
ents = Dir.entries(".", {:encoding => Encoding.find("filesystem")})
|
||||||
filename = win_expected_filename
|
filename = win_expected_filename
|
||||||
end
|
end
|
||||||
|
@ -3,12 +3,8 @@ require 'test/unit'
|
|||||||
class TestEncodingConverter < Test::Unit::TestCase
|
class TestEncodingConverter < Test::Unit::TestCase
|
||||||
def check_ec(edst, esrc, eres, dst, src, ec, off, len, opts=nil)
|
def check_ec(edst, esrc, eres, dst, src, ec, off, len, opts=nil)
|
||||||
res = ec.primitive_convert(src, dst, off, len, opts)
|
res = ec.primitive_convert(src, dst, off, len, opts)
|
||||||
assert_equal([edst.dup.force_encoding("ASCII-8BIT"),
|
assert_equal([edst.b, esrc.b, eres],
|
||||||
esrc.dup.force_encoding("ASCII-8BIT"),
|
[dst.b, src.b, res])
|
||||||
eres],
|
|
||||||
[dst.dup.force_encoding("ASCII-8BIT"),
|
|
||||||
src.dup.force_encoding("ASCII-8BIT"),
|
|
||||||
res])
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def assert_econv(converted, eres, obuf_bytesize, ec, consumed, rest, opts=nil)
|
def assert_econv(converted, eres, obuf_bytesize, ec, consumed, rest, opts=nil)
|
||||||
@ -22,8 +18,8 @@ class TestEncodingConverter < Test::Unit::TestCase
|
|||||||
|
|
||||||
def assert_errinfo(e_res, e_enc1, e_enc2, e_error_bytes, e_readagain_bytes, ec)
|
def assert_errinfo(e_res, e_enc1, e_enc2, e_error_bytes, e_readagain_bytes, ec)
|
||||||
assert_equal([e_res, e_enc1, e_enc2,
|
assert_equal([e_res, e_enc1, e_enc2,
|
||||||
e_error_bytes && e_error_bytes.dup.force_encoding("ASCII-8BIT"),
|
e_error_bytes && e_error_bytes.b,
|
||||||
e_readagain_bytes && e_readagain_bytes.dup.force_encoding("ASCII-8BIT")],
|
e_readagain_bytes && e_readagain_bytes.b],
|
||||||
ec.primitive_errinfo)
|
ec.primitive_errinfo)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -1711,8 +1711,7 @@ EOT
|
|||||||
args.each {|arg| f.print arg }
|
args.each {|arg| f.print arg }
|
||||||
}
|
}
|
||||||
content = File.read("t", :mode=>"rb:ascii-8bit")
|
content = File.read("t", :mode=>"rb:ascii-8bit")
|
||||||
assert_equal(expected.dup.force_encoding("ascii-8bit"),
|
assert_equal(expected.b, content.b)
|
||||||
content.force_encoding("ascii-8bit"))
|
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -1892,7 +1891,7 @@ EOT
|
|||||||
with_tmpdir {
|
with_tmpdir {
|
||||||
src = "\u3042\r\n"
|
src = "\u3042\r\n"
|
||||||
generate_file("t.txt", src)
|
generate_file("t.txt", src)
|
||||||
srcbin = src.dup.force_encoding("ascii-8bit")
|
srcbin = src.b
|
||||||
open("t.txt", "rt:utf-8:euc-jp") {|f|
|
open("t.txt", "rt:utf-8:euc-jp") {|f|
|
||||||
f.binmode
|
f.binmode
|
||||||
result = f.read
|
result = f.read
|
||||||
|
@ -8,7 +8,7 @@ class TestM17N < Test::Unit::TestCase
|
|||||||
|
|
||||||
module AESU
|
module AESU
|
||||||
def ua(str) str.dup.force_encoding("US-ASCII") end
|
def ua(str) str.dup.force_encoding("US-ASCII") end
|
||||||
def a(str) str.dup.force_encoding("ASCII-8BIT") end
|
def a(str) str.b end
|
||||||
def e(str) str.dup.force_encoding("EUC-JP") end
|
def e(str) str.dup.force_encoding("EUC-JP") end
|
||||||
def s(str) str.dup.force_encoding("Windows-31J") end
|
def s(str) str.dup.force_encoding("Windows-31J") end
|
||||||
def u(str) str.dup.force_encoding("UTF-8") end
|
def u(str) str.dup.force_encoding("UTF-8") end
|
||||||
@ -1130,7 +1130,7 @@ class TestM17N < Test::Unit::TestCase
|
|||||||
|
|
||||||
def test_dup_scan
|
def test_dup_scan
|
||||||
s1 = e("\xa4\xa2")*100
|
s1 = e("\xa4\xa2")*100
|
||||||
s2 = s1.dup.force_encoding("ascii-8bit")
|
s2 = s1.b
|
||||||
s2.scan(/\A./n) {|f|
|
s2.scan(/\A./n) {|f|
|
||||||
assert_equal(Encoding::ASCII_8BIT, f.encoding)
|
assert_equal(Encoding::ASCII_8BIT, f.encoding)
|
||||||
}
|
}
|
||||||
@ -1138,7 +1138,7 @@ class TestM17N < Test::Unit::TestCase
|
|||||||
|
|
||||||
def test_dup_aref
|
def test_dup_aref
|
||||||
s1 = e("\xa4\xa2")*100
|
s1 = e("\xa4\xa2")*100
|
||||||
s2 = s1.dup.force_encoding("ascii-8bit")
|
s2 = s1.b
|
||||||
assert_equal(Encoding::ASCII_8BIT, s2[10..-1].encoding)
|
assert_equal(Encoding::ASCII_8BIT, s2[10..-1].encoding)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -1575,8 +1575,8 @@ class TestM17NComb < Test::Unit::TestCase
|
|||||||
assert_raise(Encoding::CompatibilityError, desc) { s1.start_with?(s2) }
|
assert_raise(Encoding::CompatibilityError, desc) { s1.start_with?(s2) }
|
||||||
next
|
next
|
||||||
end
|
end
|
||||||
s1 = s1.dup.force_encoding("ASCII-8BIT")
|
s1 = s1.b
|
||||||
s2 = s2.dup.force_encoding("ASCII-8BIT")
|
s2 = s2.b
|
||||||
if s1.length < s2.length
|
if s1.length < s2.length
|
||||||
assert_equal(false, enccall(s1, :start_with?, s2), desc)
|
assert_equal(false, enccall(s1, :start_with?, s2), desc)
|
||||||
next
|
next
|
||||||
|
Loading…
x
Reference in New Issue
Block a user