This commit is contained in:
Andrew Konchin 2024-12-09 20:32:39 +02:00 committed by Benoit Daloze
parent a90d8c335a
commit de5df203bc
Notes: git 2024-12-10 13:39:11 +00:00
40 changed files with 1319 additions and 373 deletions

View File

@ -57,9 +57,9 @@ describe :array_pack_basic_non_float, shared: true do
# NOTE: Added this case just to not forget about the decision in the ticket # NOTE: Added this case just to not forget about the decision in the ticket
it "raise ArgumentError when a directive is unknown" do it "raise ArgumentError when a directive is unknown" do
# additional directive ('a') is required for the X directive # additional directive ('a') is required for the X directive
-> { [@obj, @obj].pack("a R" + pack_format) }.should raise_error(ArgumentError) -> { [@obj, @obj].pack("a R" + pack_format) }.should raise_error(ArgumentError, /unknown pack directive 'R'/)
-> { [@obj, @obj].pack("a 0" + pack_format) }.should raise_error(ArgumentError) -> { [@obj, @obj].pack("a 0" + pack_format) }.should raise_error(ArgumentError, /unknown pack directive '0'/)
-> { [@obj, @obj].pack("a :" + pack_format) }.should raise_error(ArgumentError) -> { [@obj, @obj].pack("a :" + pack_format) }.should raise_error(ArgumentError, /unknown pack directive ':'/)
end end
end end

View File

@ -12,7 +12,7 @@ describe :dir_glob, shared: true do
end end
it "raises an Encoding::CompatibilityError if the argument encoding is not compatible with US-ASCII" do it "raises an Encoding::CompatibilityError if the argument encoding is not compatible with US-ASCII" do
pattern = "file*".dup.force_encoding Encoding::UTF_16BE pattern = "files*".dup.force_encoding Encoding::UTF_16BE
-> { Dir.send(@method, pattern) }.should raise_error(Encoding::CompatibilityError) -> { Dir.send(@method, pattern) }.should raise_error(Encoding::CompatibilityError)
end end

View File

@ -114,11 +114,11 @@ describe "Encoding.compatible? String, String" do
end end
it "returns nil when the second's Encoding is invalid and ASCII only" do it "returns nil when the second's Encoding is invalid and ASCII only" do
Encoding.compatible?(@str, "\x7f".dup.force_encoding("utf-16be")).should be_nil Encoding.compatible?(@str, "\x7f\x7f".dup.force_encoding("utf-16be")).should be_nil
end end
it "returns nil when the second's Encoding is invalid and not ASCII only" do it "returns nil when the second's Encoding is invalid and not ASCII only" do
Encoding.compatible?(@str, "\xff".dup.force_encoding("utf-16be")).should be_nil Encoding.compatible?(@str, "\xff\xff".dup.force_encoding("utf-16be")).should be_nil
end end
it "returns the Encoding when the second's Encoding is invalid but the same as the first" do it "returns the Encoding when the second's Encoding is invalid but the same as the first" do
@ -186,8 +186,8 @@ describe "Encoding.compatible? String, String" do
# #
# VALUES = { # VALUES = {
# empty: "", # empty: "",
# :"7bits" => "\x01", # :"7bits" => "\x01\x01",
# non7bits: "\x81" # non7bits: "\x01\x81"
# } # }
# #
# ENCODINGS.product(TYPES, ENCODINGS, TYPES).each do |encoding1, type1, encoding2, type2| # ENCODINGS.product(TYPES, ENCODINGS, TYPES).each do |encoding1, type1, encoding2, type2|
@ -202,329 +202,329 @@ describe "Encoding.compatible? String, String" do
matrix = [ matrix = [
["US-ASCII", "", "US-ASCII", "", "US-ASCII"], ["US-ASCII", "", "US-ASCII", "", "US-ASCII"],
["US-ASCII", "", "US-ASCII", "\x01", "US-ASCII"], ["US-ASCII", "", "US-ASCII", "\x01\x01", "US-ASCII"],
["US-ASCII", "", "US-ASCII", "\x81", "US-ASCII"], ["US-ASCII", "", "US-ASCII", "\x01\x81", "US-ASCII"],
["US-ASCII", "", "UTF-8", "", "US-ASCII"], ["US-ASCII", "", "UTF-8", "", "US-ASCII"],
["US-ASCII", "", "UTF-8", "\u0001", "US-ASCII"], ["US-ASCII", "", "UTF-8", "\u0001\u0001", "US-ASCII"],
["US-ASCII", "", "UTF-8", "\x81", "UTF-8"], ["US-ASCII", "", "UTF-8", "\u0001\x81", "UTF-8"],
["US-ASCII", "", "ASCII-8BIT", "", "US-ASCII"], ["US-ASCII", "", "ASCII-8BIT", "", "US-ASCII"],
["US-ASCII", "", "ASCII-8BIT", "\x01", "US-ASCII"], ["US-ASCII", "", "ASCII-8BIT", "\x01\x01", "US-ASCII"],
["US-ASCII", "", "ASCII-8BIT", "\x81", "ASCII-8BIT"], ["US-ASCII", "", "ASCII-8BIT", "\x01\x81", "ASCII-8BIT"],
["US-ASCII", "", "ISO-8859-1", "", "US-ASCII"], ["US-ASCII", "", "ISO-8859-1", "", "US-ASCII"],
["US-ASCII", "", "ISO-8859-1", "\x01", "US-ASCII"], ["US-ASCII", "", "ISO-8859-1", "\x01\x01", "US-ASCII"],
["US-ASCII", "", "ISO-8859-1", "\x81", "ISO-8859-1"], ["US-ASCII", "", "ISO-8859-1", "\x01\x81", "ISO-8859-1"],
["US-ASCII", "", "UTF-16BE", "", "US-ASCII"], ["US-ASCII", "", "UTF-16BE", "", "US-ASCII"],
["US-ASCII", "", "UTF-16BE", "\x01", "UTF-16BE"], ["US-ASCII", "", "UTF-16BE", "\u0101", "UTF-16BE"],
["US-ASCII", "", "UTF-16BE", "\x81", "UTF-16BE"], ["US-ASCII", "", "UTF-16BE", "\u0181", "UTF-16BE"],
["US-ASCII", "", "ISO-2022-JP", "", "US-ASCII"], ["US-ASCII", "", "ISO-2022-JP", "", "US-ASCII"],
["US-ASCII", "", "ISO-2022-JP", "\x01", "ISO-2022-JP"], ["US-ASCII", "", "ISO-2022-JP", "\x01\x01", "ISO-2022-JP"],
["US-ASCII", "", "ISO-2022-JP", "\x81", "ISO-2022-JP"], ["US-ASCII", "", "ISO-2022-JP", "\x01\x81", "ISO-2022-JP"],
["US-ASCII", "\x01", "US-ASCII", "", "US-ASCII"], ["US-ASCII", "\x01\x01", "US-ASCII", "", "US-ASCII"],
["US-ASCII", "\x01", "US-ASCII", "\x01", "US-ASCII"], ["US-ASCII", "\x01\x01", "US-ASCII", "\x01\x01", "US-ASCII"],
["US-ASCII", "\x01", "US-ASCII", "\x81", "US-ASCII"], ["US-ASCII", "\x01\x01", "US-ASCII", "\x01\x81", "US-ASCII"],
["US-ASCII", "\x01", "UTF-8", "", "US-ASCII"], ["US-ASCII", "\x01\x01", "UTF-8", "", "US-ASCII"],
["US-ASCII", "\x01", "UTF-8", "\u0001", "US-ASCII"], ["US-ASCII", "\x01\x01", "UTF-8", "\u0001\u0001", "US-ASCII"],
["US-ASCII", "\x01", "UTF-8", "\x81", "UTF-8"], ["US-ASCII", "\x01\x01", "UTF-8", "\u0001\x81", "UTF-8"],
["US-ASCII", "\x01", "ASCII-8BIT", "", "US-ASCII"], ["US-ASCII", "\x01\x01", "ASCII-8BIT", "", "US-ASCII"],
["US-ASCII", "\x01", "ASCII-8BIT", "\x01", "US-ASCII"], ["US-ASCII", "\x01\x01", "ASCII-8BIT", "\x01\x01", "US-ASCII"],
["US-ASCII", "\x01", "ASCII-8BIT", "\x81", "ASCII-8BIT"], ["US-ASCII", "\x01\x01", "ASCII-8BIT", "\x01\x81", "ASCII-8BIT"],
["US-ASCII", "\x01", "ISO-8859-1", "", "US-ASCII"], ["US-ASCII", "\x01\x01", "ISO-8859-1", "", "US-ASCII"],
["US-ASCII", "\x01", "ISO-8859-1", "\x01", "US-ASCII"], ["US-ASCII", "\x01\x01", "ISO-8859-1", "\x01\x01", "US-ASCII"],
["US-ASCII", "\x01", "ISO-8859-1", "\x81", "ISO-8859-1"], ["US-ASCII", "\x01\x01", "ISO-8859-1", "\x01\x81", "ISO-8859-1"],
["US-ASCII", "\x01", "UTF-16BE", "", "US-ASCII"], ["US-ASCII", "\x01\x01", "UTF-16BE", "", "US-ASCII"],
["US-ASCII", "\x01", "UTF-16BE", "\x01", nil], ["US-ASCII", "\x01\x01", "UTF-16BE", "\u0101", nil],
["US-ASCII", "\x01", "UTF-16BE", "\x81", nil], ["US-ASCII", "\x01\x01", "UTF-16BE", "\u0181", nil],
["US-ASCII", "\x01", "ISO-2022-JP", "", "US-ASCII"], ["US-ASCII", "\x01\x01", "ISO-2022-JP", "", "US-ASCII"],
["US-ASCII", "\x01", "ISO-2022-JP", "\x01", nil], ["US-ASCII", "\x01\x01", "ISO-2022-JP", "\x01\x01", nil],
["US-ASCII", "\x01", "ISO-2022-JP", "\x81", nil], ["US-ASCII", "\x01\x01", "ISO-2022-JP", "\x01\x81", nil],
["US-ASCII", "\x81", "US-ASCII", "", "US-ASCII"], ["US-ASCII", "\x01\x81", "US-ASCII", "", "US-ASCII"],
["US-ASCII", "\x81", "US-ASCII", "\x01", "US-ASCII"], ["US-ASCII", "\x01\x81", "US-ASCII", "\x01\x01", "US-ASCII"],
["US-ASCII", "\x81", "US-ASCII", "\x81", "US-ASCII"], ["US-ASCII", "\x01\x81", "US-ASCII", "\x01\x81", "US-ASCII"],
["US-ASCII", "\x81", "UTF-8", "", "US-ASCII"], ["US-ASCII", "\x01\x81", "UTF-8", "", "US-ASCII"],
["US-ASCII", "\x81", "UTF-8", "\u0001", "US-ASCII"], ["US-ASCII", "\x01\x81", "UTF-8", "\u0001\u0001", "US-ASCII"],
["US-ASCII", "\x81", "UTF-8", "\x81", nil], ["US-ASCII", "\x01\x81", "UTF-8", "\u0001\x81", nil],
["US-ASCII", "\x81", "ASCII-8BIT", "", "US-ASCII"], ["US-ASCII", "\x01\x81", "ASCII-8BIT", "", "US-ASCII"],
["US-ASCII", "\x81", "ASCII-8BIT", "\x01", "US-ASCII"], ["US-ASCII", "\x01\x81", "ASCII-8BIT", "\x01\x01", "US-ASCII"],
["US-ASCII", "\x81", "ASCII-8BIT", "\x81", nil], ["US-ASCII", "\x01\x81", "ASCII-8BIT", "\x01\x81", nil],
["US-ASCII", "\x81", "ISO-8859-1", "", "US-ASCII"], ["US-ASCII", "\x01\x81", "ISO-8859-1", "", "US-ASCII"],
["US-ASCII", "\x81", "ISO-8859-1", "\x01", "US-ASCII"], ["US-ASCII", "\x01\x81", "ISO-8859-1", "\x01\x01", "US-ASCII"],
["US-ASCII", "\x81", "ISO-8859-1", "\x81", nil], ["US-ASCII", "\x01\x81", "ISO-8859-1", "\x01\x81", nil],
["US-ASCII", "\x81", "UTF-16BE", "", "US-ASCII"], ["US-ASCII", "\x01\x81", "UTF-16BE", "", "US-ASCII"],
["US-ASCII", "\x81", "UTF-16BE", "\x01", nil], ["US-ASCII", "\x01\x81", "UTF-16BE", "\u0101", nil],
["US-ASCII", "\x81", "UTF-16BE", "\x81", nil], ["US-ASCII", "\x01\x81", "UTF-16BE", "\u0181", nil],
["US-ASCII", "\x81", "ISO-2022-JP", "", "US-ASCII"], ["US-ASCII", "\x01\x81", "ISO-2022-JP", "", "US-ASCII"],
["US-ASCII", "\x81", "ISO-2022-JP", "\x01", nil], ["US-ASCII", "\x01\x81", "ISO-2022-JP", "\x01\x01", nil],
["US-ASCII", "\x81", "ISO-2022-JP", "\x81", nil], ["US-ASCII", "\x01\x81", "ISO-2022-JP", "\x01\x81", nil],
["UTF-8", "", "US-ASCII", "", "UTF-8"], ["UTF-8", "", "US-ASCII", "", "UTF-8"],
["UTF-8", "", "US-ASCII", "\x01", "UTF-8"], ["UTF-8", "", "US-ASCII", "\x01\x01", "UTF-8"],
["UTF-8", "", "US-ASCII", "\x81", "US-ASCII"], ["UTF-8", "", "US-ASCII", "\x01\x81", "US-ASCII"],
["UTF-8", "", "UTF-8", "", "UTF-8"], ["UTF-8", "", "UTF-8", "", "UTF-8"],
["UTF-8", "", "UTF-8", "\u0001", "UTF-8"], ["UTF-8", "", "UTF-8", "\u0001\u0001", "UTF-8"],
["UTF-8", "", "UTF-8", "\x81", "UTF-8"], ["UTF-8", "", "UTF-8", "\u0001\x81", "UTF-8"],
["UTF-8", "", "ASCII-8BIT", "", "UTF-8"], ["UTF-8", "", "ASCII-8BIT", "", "UTF-8"],
["UTF-8", "", "ASCII-8BIT", "\x01", "UTF-8"], ["UTF-8", "", "ASCII-8BIT", "\x01\x01", "UTF-8"],
["UTF-8", "", "ASCII-8BIT", "\x81", "ASCII-8BIT"], ["UTF-8", "", "ASCII-8BIT", "\x01\x81", "ASCII-8BIT"],
["UTF-8", "", "ISO-8859-1", "", "UTF-8"], ["UTF-8", "", "ISO-8859-1", "", "UTF-8"],
["UTF-8", "", "ISO-8859-1", "\x01", "UTF-8"], ["UTF-8", "", "ISO-8859-1", "\x01\x01", "UTF-8"],
["UTF-8", "", "ISO-8859-1", "\x81", "ISO-8859-1"], ["UTF-8", "", "ISO-8859-1", "\x01\x81", "ISO-8859-1"],
["UTF-8", "", "UTF-16BE", "", "UTF-8"], ["UTF-8", "", "UTF-16BE", "", "UTF-8"],
["UTF-8", "", "UTF-16BE", "\x01", "UTF-16BE"], ["UTF-8", "", "UTF-16BE", "\u0101", "UTF-16BE"],
["UTF-8", "", "UTF-16BE", "\x81", "UTF-16BE"], ["UTF-8", "", "UTF-16BE", "\u0181", "UTF-16BE"],
["UTF-8", "", "ISO-2022-JP", "", "UTF-8"], ["UTF-8", "", "ISO-2022-JP", "", "UTF-8"],
["UTF-8", "", "ISO-2022-JP", "\x01", "ISO-2022-JP"], ["UTF-8", "", "ISO-2022-JP", "\x01\x01", "ISO-2022-JP"],
["UTF-8", "", "ISO-2022-JP", "\x81", "ISO-2022-JP"], ["UTF-8", "", "ISO-2022-JP", "\x01\x81", "ISO-2022-JP"],
["UTF-8", "\u0001", "US-ASCII", "", "UTF-8"], ["UTF-8", "\u0001\u0001", "US-ASCII", "", "UTF-8"],
["UTF-8", "\u0001", "US-ASCII", "\x01", "UTF-8"], ["UTF-8", "\u0001\u0001", "US-ASCII", "\x01\x01", "UTF-8"],
["UTF-8", "\u0001", "US-ASCII", "\x81", "US-ASCII"], ["UTF-8", "\u0001\u0001", "US-ASCII", "\x01\x81", "US-ASCII"],
["UTF-8", "\u0001", "UTF-8", "", "UTF-8"], ["UTF-8", "\u0001\u0001", "UTF-8", "", "UTF-8"],
["UTF-8", "\u0001", "UTF-8", "\u0001", "UTF-8"], ["UTF-8", "\u0001\u0001", "UTF-8", "\u0001\u0001", "UTF-8"],
["UTF-8", "\u0001", "UTF-8", "\x81", "UTF-8"], ["UTF-8", "\u0001\u0001", "UTF-8", "\u0001\x81", "UTF-8"],
["UTF-8", "\u0001", "ASCII-8BIT", "", "UTF-8"], ["UTF-8", "\u0001\u0001", "ASCII-8BIT", "", "UTF-8"],
["UTF-8", "\u0001", "ASCII-8BIT", "\x01", "UTF-8"], ["UTF-8", "\u0001\u0001", "ASCII-8BIT", "\x01\x01", "UTF-8"],
["UTF-8", "\u0001", "ASCII-8BIT", "\x81", "ASCII-8BIT"], ["UTF-8", "\u0001\u0001", "ASCII-8BIT", "\x01\x81", "ASCII-8BIT"],
["UTF-8", "\u0001", "ISO-8859-1", "", "UTF-8"], ["UTF-8", "\u0001\u0001", "ISO-8859-1", "", "UTF-8"],
["UTF-8", "\u0001", "ISO-8859-1", "\x01", "UTF-8"], ["UTF-8", "\u0001\u0001", "ISO-8859-1", "\x01\x01", "UTF-8"],
["UTF-8", "\u0001", "ISO-8859-1", "\x81", "ISO-8859-1"], ["UTF-8", "\u0001\u0001", "ISO-8859-1", "\x01\x81", "ISO-8859-1"],
["UTF-8", "\u0001", "UTF-16BE", "", "UTF-8"], ["UTF-8", "\u0001\u0001", "UTF-16BE", "", "UTF-8"],
["UTF-8", "\u0001", "UTF-16BE", "\x01", nil], ["UTF-8", "\u0001\u0001", "UTF-16BE", "\u0101", nil],
["UTF-8", "\u0001", "UTF-16BE", "\x81", nil], ["UTF-8", "\u0001\u0001", "UTF-16BE", "\u0181", nil],
["UTF-8", "\u0001", "ISO-2022-JP", "", "UTF-8"], ["UTF-8", "\u0001\u0001", "ISO-2022-JP", "", "UTF-8"],
["UTF-8", "\u0001", "ISO-2022-JP", "\x01", nil], ["UTF-8", "\u0001\u0001", "ISO-2022-JP", "\x01\x01", nil],
["UTF-8", "\u0001", "ISO-2022-JP", "\x81", nil], ["UTF-8", "\u0001\u0001", "ISO-2022-JP", "\x01\x81", nil],
["UTF-8", "\x81", "US-ASCII", "", "UTF-8"], ["UTF-8", "\u0001\x81", "US-ASCII", "", "UTF-8"],
["UTF-8", "\x81", "US-ASCII", "\x01", "UTF-8"], ["UTF-8", "\u0001\x81", "US-ASCII", "\x01\x01", "UTF-8"],
["UTF-8", "\x81", "US-ASCII", "\x81", nil], ["UTF-8", "\u0001\x81", "US-ASCII", "\x01\x81", nil],
["UTF-8", "\x81", "UTF-8", "", "UTF-8"], ["UTF-8", "\u0001\x81", "UTF-8", "", "UTF-8"],
["UTF-8", "\x81", "UTF-8", "\u0001", "UTF-8"], ["UTF-8", "\u0001\x81", "UTF-8", "\u0001\u0001", "UTF-8"],
["UTF-8", "\x81", "UTF-8", "\x81", "UTF-8"], ["UTF-8", "\u0001\x81", "UTF-8", "\u0001\x81", "UTF-8"],
["UTF-8", "\x81", "ASCII-8BIT", "", "UTF-8"], ["UTF-8", "\u0001\x81", "ASCII-8BIT", "", "UTF-8"],
["UTF-8", "\x81", "ASCII-8BIT", "\x01", "UTF-8"], ["UTF-8", "\u0001\x81", "ASCII-8BIT", "\x01\x01", "UTF-8"],
["UTF-8", "\x81", "ASCII-8BIT", "\x81", nil], ["UTF-8", "\u0001\x81", "ASCII-8BIT", "\x01\x81", nil],
["UTF-8", "\x81", "ISO-8859-1", "", "UTF-8"], ["UTF-8", "\u0001\x81", "ISO-8859-1", "", "UTF-8"],
["UTF-8", "\x81", "ISO-8859-1", "\x01", "UTF-8"], ["UTF-8", "\u0001\x81", "ISO-8859-1", "\x01\x01", "UTF-8"],
["UTF-8", "\x81", "ISO-8859-1", "\x81", nil], ["UTF-8", "\u0001\x81", "ISO-8859-1", "\x01\x81", nil],
["UTF-8", "\x81", "UTF-16BE", "", "UTF-8"], ["UTF-8", "\u0001\x81", "UTF-16BE", "", "UTF-8"],
["UTF-8", "\x81", "UTF-16BE", "\x01", nil], ["UTF-8", "\u0001\x81", "UTF-16BE", "\u0101", nil],
["UTF-8", "\x81", "UTF-16BE", "\x81", nil], ["UTF-8", "\u0001\x81", "UTF-16BE", "\u0181", nil],
["UTF-8", "\x81", "ISO-2022-JP", "", "UTF-8"], ["UTF-8", "\u0001\x81", "ISO-2022-JP", "", "UTF-8"],
["UTF-8", "\x81", "ISO-2022-JP", "\x01", nil], ["UTF-8", "\u0001\x81", "ISO-2022-JP", "\x01\x01", nil],
["UTF-8", "\x81", "ISO-2022-JP", "\x81", nil], ["UTF-8", "\u0001\x81", "ISO-2022-JP", "\x01\x81", nil],
["ASCII-8BIT", "", "US-ASCII", "", "ASCII-8BIT"], ["ASCII-8BIT", "", "US-ASCII", "", "ASCII-8BIT"],
["ASCII-8BIT", "", "US-ASCII", "\x01", "ASCII-8BIT"], ["ASCII-8BIT", "", "US-ASCII", "\x01\x01", "ASCII-8BIT"],
["ASCII-8BIT", "", "US-ASCII", "\x81", "US-ASCII"], ["ASCII-8BIT", "", "US-ASCII", "\x01\x81", "US-ASCII"],
["ASCII-8BIT", "", "UTF-8", "", "ASCII-8BIT"], ["ASCII-8BIT", "", "UTF-8", "", "ASCII-8BIT"],
["ASCII-8BIT", "", "UTF-8", "\u0001", "ASCII-8BIT"], ["ASCII-8BIT", "", "UTF-8", "\u0001\u0001", "ASCII-8BIT"],
["ASCII-8BIT", "", "UTF-8", "\x81", "UTF-8"], ["ASCII-8BIT", "", "UTF-8", "\u0001\x81", "UTF-8"],
["ASCII-8BIT", "", "ASCII-8BIT", "", "ASCII-8BIT"], ["ASCII-8BIT", "", "ASCII-8BIT", "", "ASCII-8BIT"],
["ASCII-8BIT", "", "ASCII-8BIT", "\x01", "ASCII-8BIT"], ["ASCII-8BIT", "", "ASCII-8BIT", "\x01\x01", "ASCII-8BIT"],
["ASCII-8BIT", "", "ASCII-8BIT", "\x81", "ASCII-8BIT"], ["ASCII-8BIT", "", "ASCII-8BIT", "\x01\x81", "ASCII-8BIT"],
["ASCII-8BIT", "", "ISO-8859-1", "", "ASCII-8BIT"], ["ASCII-8BIT", "", "ISO-8859-1", "", "ASCII-8BIT"],
["ASCII-8BIT", "", "ISO-8859-1", "\x01", "ASCII-8BIT"], ["ASCII-8BIT", "", "ISO-8859-1", "\x01\x01", "ASCII-8BIT"],
["ASCII-8BIT", "", "ISO-8859-1", "\x81", "ISO-8859-1"], ["ASCII-8BIT", "", "ISO-8859-1", "\x01\x81", "ISO-8859-1"],
["ASCII-8BIT", "", "UTF-16BE", "", "ASCII-8BIT"], ["ASCII-8BIT", "", "UTF-16BE", "", "ASCII-8BIT"],
["ASCII-8BIT", "", "UTF-16BE", "\x01", "UTF-16BE"], ["ASCII-8BIT", "", "UTF-16BE", "\u0101", "UTF-16BE"],
["ASCII-8BIT", "", "UTF-16BE", "\x81", "UTF-16BE"], ["ASCII-8BIT", "", "UTF-16BE", "\u0181", "UTF-16BE"],
["ASCII-8BIT", "", "ISO-2022-JP", "", "ASCII-8BIT"], ["ASCII-8BIT", "", "ISO-2022-JP", "", "ASCII-8BIT"],
["ASCII-8BIT", "", "ISO-2022-JP", "\x01", "ISO-2022-JP"], ["ASCII-8BIT", "", "ISO-2022-JP", "\x01\x01", "ISO-2022-JP"],
["ASCII-8BIT", "", "ISO-2022-JP", "\x81", "ISO-2022-JP"], ["ASCII-8BIT", "", "ISO-2022-JP", "\x01\x81", "ISO-2022-JP"],
["ASCII-8BIT", "\x01", "US-ASCII", "", "ASCII-8BIT"], ["ASCII-8BIT", "\x01\x01", "US-ASCII", "", "ASCII-8BIT"],
["ASCII-8BIT", "\x01", "US-ASCII", "\x01", "ASCII-8BIT"], ["ASCII-8BIT", "\x01\x01", "US-ASCII", "\x01\x01", "ASCII-8BIT"],
["ASCII-8BIT", "\x01", "US-ASCII", "\x81", "US-ASCII"], ["ASCII-8BIT", "\x01\x01", "US-ASCII", "\x01\x81", "US-ASCII"],
["ASCII-8BIT", "\x01", "UTF-8", "", "ASCII-8BIT"], ["ASCII-8BIT", "\x01\x01", "UTF-8", "", "ASCII-8BIT"],
["ASCII-8BIT", "\x01", "UTF-8", "\u0001", "ASCII-8BIT"], ["ASCII-8BIT", "\x01\x01", "UTF-8", "\u0001\u0001", "ASCII-8BIT"],
["ASCII-8BIT", "\x01", "UTF-8", "\x81", "UTF-8"], ["ASCII-8BIT", "\x01\x01", "UTF-8", "\u0001\x81", "UTF-8"],
["ASCII-8BIT", "\x01", "ASCII-8BIT", "", "ASCII-8BIT"], ["ASCII-8BIT", "\x01\x01", "ASCII-8BIT", "", "ASCII-8BIT"],
["ASCII-8BIT", "\x01", "ASCII-8BIT", "\x01", "ASCII-8BIT"], ["ASCII-8BIT", "\x01\x01", "ASCII-8BIT", "\x01\x01", "ASCII-8BIT"],
["ASCII-8BIT", "\x01", "ASCII-8BIT", "\x81", "ASCII-8BIT"], ["ASCII-8BIT", "\x01\x01", "ASCII-8BIT", "\x01\x81", "ASCII-8BIT"],
["ASCII-8BIT", "\x01", "ISO-8859-1", "", "ASCII-8BIT"], ["ASCII-8BIT", "\x01\x01", "ISO-8859-1", "", "ASCII-8BIT"],
["ASCII-8BIT", "\x01", "ISO-8859-1", "\x01", "ASCII-8BIT"], ["ASCII-8BIT", "\x01\x01", "ISO-8859-1", "\x01\x01", "ASCII-8BIT"],
["ASCII-8BIT", "\x01", "ISO-8859-1", "\x81", "ISO-8859-1"], ["ASCII-8BIT", "\x01\x01", "ISO-8859-1", "\x01\x81", "ISO-8859-1"],
["ASCII-8BIT", "\x01", "UTF-16BE", "", "ASCII-8BIT"], ["ASCII-8BIT", "\x01\x01", "UTF-16BE", "", "ASCII-8BIT"],
["ASCII-8BIT", "\x01", "UTF-16BE", "\x01", nil], ["ASCII-8BIT", "\x01\x01", "UTF-16BE", "\u0101", nil],
["ASCII-8BIT", "\x01", "UTF-16BE", "\x81", nil], ["ASCII-8BIT", "\x01\x01", "UTF-16BE", "\u0181", nil],
["ASCII-8BIT", "\x01", "ISO-2022-JP", "", "ASCII-8BIT"], ["ASCII-8BIT", "\x01\x01", "ISO-2022-JP", "", "ASCII-8BIT"],
["ASCII-8BIT", "\x01", "ISO-2022-JP", "\x01", nil], ["ASCII-8BIT", "\x01\x01", "ISO-2022-JP", "\x01\x01", nil],
["ASCII-8BIT", "\x01", "ISO-2022-JP", "\x81", nil], ["ASCII-8BIT", "\x01\x01", "ISO-2022-JP", "\x01\x81", nil],
["ASCII-8BIT", "\x81", "US-ASCII", "", "ASCII-8BIT"], ["ASCII-8BIT", "\x01\x81", "US-ASCII", "", "ASCII-8BIT"],
["ASCII-8BIT", "\x81", "US-ASCII", "\x01", "ASCII-8BIT"], ["ASCII-8BIT", "\x01\x81", "US-ASCII", "\x01\x01", "ASCII-8BIT"],
["ASCII-8BIT", "\x81", "US-ASCII", "\x81", nil], ["ASCII-8BIT", "\x01\x81", "US-ASCII", "\x01\x81", nil],
["ASCII-8BIT", "\x81", "UTF-8", "", "ASCII-8BIT"], ["ASCII-8BIT", "\x01\x81", "UTF-8", "", "ASCII-8BIT"],
["ASCII-8BIT", "\x81", "UTF-8", "\u0001", "ASCII-8BIT"], ["ASCII-8BIT", "\x01\x81", "UTF-8", "\u0001\u0001", "ASCII-8BIT"],
["ASCII-8BIT", "\x81", "UTF-8", "\x81", nil], ["ASCII-8BIT", "\x01\x81", "UTF-8", "\u0001\x81", nil],
["ASCII-8BIT", "\x81", "ASCII-8BIT", "", "ASCII-8BIT"], ["ASCII-8BIT", "\x01\x81", "ASCII-8BIT", "", "ASCII-8BIT"],
["ASCII-8BIT", "\x81", "ASCII-8BIT", "\x01", "ASCII-8BIT"], ["ASCII-8BIT", "\x01\x81", "ASCII-8BIT", "\x01\x01", "ASCII-8BIT"],
["ASCII-8BIT", "\x81", "ASCII-8BIT", "\x81", "ASCII-8BIT"], ["ASCII-8BIT", "\x01\x81", "ASCII-8BIT", "\x01\x81", "ASCII-8BIT"],
["ASCII-8BIT", "\x81", "ISO-8859-1", "", "ASCII-8BIT"], ["ASCII-8BIT", "\x01\x81", "ISO-8859-1", "", "ASCII-8BIT"],
["ASCII-8BIT", "\x81", "ISO-8859-1", "\x01", "ASCII-8BIT"], ["ASCII-8BIT", "\x01\x81", "ISO-8859-1", "\x01\x01", "ASCII-8BIT"],
["ASCII-8BIT", "\x81", "ISO-8859-1", "\x81", nil], ["ASCII-8BIT", "\x01\x81", "ISO-8859-1", "\x01\x81", nil],
["ASCII-8BIT", "\x81", "UTF-16BE", "", "ASCII-8BIT"], ["ASCII-8BIT", "\x01\x81", "UTF-16BE", "", "ASCII-8BIT"],
["ASCII-8BIT", "\x81", "UTF-16BE", "\x01", nil], ["ASCII-8BIT", "\x01\x81", "UTF-16BE", "\u0101", nil],
["ASCII-8BIT", "\x81", "UTF-16BE", "\x81", nil], ["ASCII-8BIT", "\x01\x81", "UTF-16BE", "\u0181", nil],
["ASCII-8BIT", "\x81", "ISO-2022-JP", "", "ASCII-8BIT"], ["ASCII-8BIT", "\x01\x81", "ISO-2022-JP", "", "ASCII-8BIT"],
["ASCII-8BIT", "\x81", "ISO-2022-JP", "\x01", nil], ["ASCII-8BIT", "\x01\x81", "ISO-2022-JP", "\x01\x01", nil],
["ASCII-8BIT", "\x81", "ISO-2022-JP", "\x81", nil], ["ASCII-8BIT", "\x01\x81", "ISO-2022-JP", "\x01\x81", nil],
["ISO-8859-1", "", "US-ASCII", "", "ISO-8859-1"], ["ISO-8859-1", "", "US-ASCII", "", "ISO-8859-1"],
["ISO-8859-1", "", "US-ASCII", "\x01", "ISO-8859-1"], ["ISO-8859-1", "", "US-ASCII", "\x01\x01", "ISO-8859-1"],
["ISO-8859-1", "", "US-ASCII", "\x81", "US-ASCII"], ["ISO-8859-1", "", "US-ASCII", "\x01\x81", "US-ASCII"],
["ISO-8859-1", "", "UTF-8", "", "ISO-8859-1"], ["ISO-8859-1", "", "UTF-8", "", "ISO-8859-1"],
["ISO-8859-1", "", "UTF-8", "\u0001", "ISO-8859-1"], ["ISO-8859-1", "", "UTF-8", "\u0001\u0001", "ISO-8859-1"],
["ISO-8859-1", "", "UTF-8", "\x81", "UTF-8"], ["ISO-8859-1", "", "UTF-8", "\u0001\x81", "UTF-8"],
["ISO-8859-1", "", "ASCII-8BIT", "", "ISO-8859-1"], ["ISO-8859-1", "", "ASCII-8BIT", "", "ISO-8859-1"],
["ISO-8859-1", "", "ASCII-8BIT", "\x01", "ISO-8859-1"], ["ISO-8859-1", "", "ASCII-8BIT", "\x01\x01", "ISO-8859-1"],
["ISO-8859-1", "", "ASCII-8BIT", "\x81", "ASCII-8BIT"], ["ISO-8859-1", "", "ASCII-8BIT", "\x01\x81", "ASCII-8BIT"],
["ISO-8859-1", "", "ISO-8859-1", "", "ISO-8859-1"], ["ISO-8859-1", "", "ISO-8859-1", "", "ISO-8859-1"],
["ISO-8859-1", "", "ISO-8859-1", "\x01", "ISO-8859-1"], ["ISO-8859-1", "", "ISO-8859-1", "\x01\x01", "ISO-8859-1"],
["ISO-8859-1", "", "ISO-8859-1", "\x81", "ISO-8859-1"], ["ISO-8859-1", "", "ISO-8859-1", "\x01\x81", "ISO-8859-1"],
["ISO-8859-1", "", "UTF-16BE", "", "ISO-8859-1"], ["ISO-8859-1", "", "UTF-16BE", "", "ISO-8859-1"],
["ISO-8859-1", "", "UTF-16BE", "\x01", "UTF-16BE"], ["ISO-8859-1", "", "UTF-16BE", "\u0101", "UTF-16BE"],
["ISO-8859-1", "", "UTF-16BE", "\x81", "UTF-16BE"], ["ISO-8859-1", "", "UTF-16BE", "\u0181", "UTF-16BE"],
["ISO-8859-1", "", "ISO-2022-JP", "", "ISO-8859-1"], ["ISO-8859-1", "", "ISO-2022-JP", "", "ISO-8859-1"],
["ISO-8859-1", "", "ISO-2022-JP", "\x01", "ISO-2022-JP"], ["ISO-8859-1", "", "ISO-2022-JP", "\x01\x01", "ISO-2022-JP"],
["ISO-8859-1", "", "ISO-2022-JP", "\x81", "ISO-2022-JP"], ["ISO-8859-1", "", "ISO-2022-JP", "\x01\x81", "ISO-2022-JP"],
["ISO-8859-1", "\x01", "US-ASCII", "", "ISO-8859-1"], ["ISO-8859-1", "\x01\x01", "US-ASCII", "", "ISO-8859-1"],
["ISO-8859-1", "\x01", "US-ASCII", "\x01", "ISO-8859-1"], ["ISO-8859-1", "\x01\x01", "US-ASCII", "\x01\x01", "ISO-8859-1"],
["ISO-8859-1", "\x01", "US-ASCII", "\x81", "US-ASCII"], ["ISO-8859-1", "\x01\x01", "US-ASCII", "\x01\x81", "US-ASCII"],
["ISO-8859-1", "\x01", "UTF-8", "", "ISO-8859-1"], ["ISO-8859-1", "\x01\x01", "UTF-8", "", "ISO-8859-1"],
["ISO-8859-1", "\x01", "UTF-8", "\u0001", "ISO-8859-1"], ["ISO-8859-1", "\x01\x01", "UTF-8", "\u0001\u0001", "ISO-8859-1"],
["ISO-8859-1", "\x01", "UTF-8", "\x81", "UTF-8"], ["ISO-8859-1", "\x01\x01", "UTF-8", "\u0001\x81", "UTF-8"],
["ISO-8859-1", "\x01", "ASCII-8BIT", "", "ISO-8859-1"], ["ISO-8859-1", "\x01\x01", "ASCII-8BIT", "", "ISO-8859-1"],
["ISO-8859-1", "\x01", "ASCII-8BIT", "\x01", "ISO-8859-1"], ["ISO-8859-1", "\x01\x01", "ASCII-8BIT", "\x01\x01", "ISO-8859-1"],
["ISO-8859-1", "\x01", "ASCII-8BIT", "\x81", "ASCII-8BIT"], ["ISO-8859-1", "\x01\x01", "ASCII-8BIT", "\x01\x81", "ASCII-8BIT"],
["ISO-8859-1", "\x01", "ISO-8859-1", "", "ISO-8859-1"], ["ISO-8859-1", "\x01\x01", "ISO-8859-1", "", "ISO-8859-1"],
["ISO-8859-1", "\x01", "ISO-8859-1", "\x01", "ISO-8859-1"], ["ISO-8859-1", "\x01\x01", "ISO-8859-1", "\x01\x01", "ISO-8859-1"],
["ISO-8859-1", "\x01", "ISO-8859-1", "\x81", "ISO-8859-1"], ["ISO-8859-1", "\x01\x01", "ISO-8859-1", "\x01\x81", "ISO-8859-1"],
["ISO-8859-1", "\x01", "UTF-16BE", "", "ISO-8859-1"], ["ISO-8859-1", "\x01\x01", "UTF-16BE", "", "ISO-8859-1"],
["ISO-8859-1", "\x01", "UTF-16BE", "\x01", nil], ["ISO-8859-1", "\x01\x01", "UTF-16BE", "\u0101", nil],
["ISO-8859-1", "\x01", "UTF-16BE", "\x81", nil], ["ISO-8859-1", "\x01\x01", "UTF-16BE", "\u0181", nil],
["ISO-8859-1", "\x01", "ISO-2022-JP", "", "ISO-8859-1"], ["ISO-8859-1", "\x01\x01", "ISO-2022-JP", "", "ISO-8859-1"],
["ISO-8859-1", "\x01", "ISO-2022-JP", "\x01", nil], ["ISO-8859-1", "\x01\x01", "ISO-2022-JP", "\x01\x01", nil],
["ISO-8859-1", "\x01", "ISO-2022-JP", "\x81", nil], ["ISO-8859-1", "\x01\x01", "ISO-2022-JP", "\x01\x81", nil],
["ISO-8859-1", "\x81", "US-ASCII", "", "ISO-8859-1"], ["ISO-8859-1", "\x01\x81", "US-ASCII", "", "ISO-8859-1"],
["ISO-8859-1", "\x81", "US-ASCII", "\x01", "ISO-8859-1"], ["ISO-8859-1", "\x01\x81", "US-ASCII", "\x01\x01", "ISO-8859-1"],
["ISO-8859-1", "\x81", "US-ASCII", "\x81", nil], ["ISO-8859-1", "\x01\x81", "US-ASCII", "\x01\x81", nil],
["ISO-8859-1", "\x81", "UTF-8", "", "ISO-8859-1"], ["ISO-8859-1", "\x01\x81", "UTF-8", "", "ISO-8859-1"],
["ISO-8859-1", "\x81", "UTF-8", "\u0001", "ISO-8859-1"], ["ISO-8859-1", "\x01\x81", "UTF-8", "\u0001\u0001", "ISO-8859-1"],
["ISO-8859-1", "\x81", "UTF-8", "\x81", nil], ["ISO-8859-1", "\x01\x81", "UTF-8", "\u0001\x81", nil],
["ISO-8859-1", "\x81", "ASCII-8BIT", "", "ISO-8859-1"], ["ISO-8859-1", "\x01\x81", "ASCII-8BIT", "", "ISO-8859-1"],
["ISO-8859-1", "\x81", "ASCII-8BIT", "\x01", "ISO-8859-1"], ["ISO-8859-1", "\x01\x81", "ASCII-8BIT", "\x01\x01", "ISO-8859-1"],
["ISO-8859-1", "\x81", "ASCII-8BIT", "\x81", nil], ["ISO-8859-1", "\x01\x81", "ASCII-8BIT", "\x01\x81", nil],
["ISO-8859-1", "\x81", "ISO-8859-1", "", "ISO-8859-1"], ["ISO-8859-1", "\x01\x81", "ISO-8859-1", "", "ISO-8859-1"],
["ISO-8859-1", "\x81", "ISO-8859-1", "\x01", "ISO-8859-1"], ["ISO-8859-1", "\x01\x81", "ISO-8859-1", "\x01\x01", "ISO-8859-1"],
["ISO-8859-1", "\x81", "ISO-8859-1", "\x81", "ISO-8859-1"], ["ISO-8859-1", "\x01\x81", "ISO-8859-1", "\x01\x81", "ISO-8859-1"],
["ISO-8859-1", "\x81", "UTF-16BE", "", "ISO-8859-1"], ["ISO-8859-1", "\x01\x81", "UTF-16BE", "", "ISO-8859-1"],
["ISO-8859-1", "\x81", "UTF-16BE", "\x01", nil], ["ISO-8859-1", "\x01\x81", "UTF-16BE", "\u0101", nil],
["ISO-8859-1", "\x81", "UTF-16BE", "\x81", nil], ["ISO-8859-1", "\x01\x81", "UTF-16BE", "\u0181", nil],
["ISO-8859-1", "\x81", "ISO-2022-JP", "", "ISO-8859-1"], ["ISO-8859-1", "\x01\x81", "ISO-2022-JP", "", "ISO-8859-1"],
["ISO-8859-1", "\x81", "ISO-2022-JP", "\x01", nil], ["ISO-8859-1", "\x01\x81", "ISO-2022-JP", "\x01\x01", nil],
["ISO-8859-1", "\x81", "ISO-2022-JP", "\x81", nil], ["ISO-8859-1", "\x01\x81", "ISO-2022-JP", "\x01\x81", nil],
["UTF-16BE", "", "US-ASCII", "", "UTF-16BE"], ["UTF-16BE", "", "US-ASCII", "", "UTF-16BE"],
["UTF-16BE", "", "US-ASCII", "\x01", "US-ASCII"], ["UTF-16BE", "", "US-ASCII", "\x01\x01", "US-ASCII"],
["UTF-16BE", "", "US-ASCII", "\x81", "US-ASCII"], ["UTF-16BE", "", "US-ASCII", "\x01\x81", "US-ASCII"],
["UTF-16BE", "", "UTF-8", "", "UTF-16BE"], ["UTF-16BE", "", "UTF-8", "", "UTF-16BE"],
["UTF-16BE", "", "UTF-8", "\u0001", "UTF-8"], ["UTF-16BE", "", "UTF-8", "\u0001\u0001", "UTF-8"],
["UTF-16BE", "", "UTF-8", "\x81", "UTF-8"], ["UTF-16BE", "", "UTF-8", "\u0001\x81", "UTF-8"],
["UTF-16BE", "", "ASCII-8BIT", "", "UTF-16BE"], ["UTF-16BE", "", "ASCII-8BIT", "", "UTF-16BE"],
["UTF-16BE", "", "ASCII-8BIT", "\x01", "ASCII-8BIT"], ["UTF-16BE", "", "ASCII-8BIT", "\x01\x01", "ASCII-8BIT"],
["UTF-16BE", "", "ASCII-8BIT", "\x81", "ASCII-8BIT"], ["UTF-16BE", "", "ASCII-8BIT", "\x01\x81", "ASCII-8BIT"],
["UTF-16BE", "", "ISO-8859-1", "", "UTF-16BE"], ["UTF-16BE", "", "ISO-8859-1", "", "UTF-16BE"],
["UTF-16BE", "", "ISO-8859-1", "\x01", "ISO-8859-1"], ["UTF-16BE", "", "ISO-8859-1", "\x01\x01", "ISO-8859-1"],
["UTF-16BE", "", "ISO-8859-1", "\x81", "ISO-8859-1"], ["UTF-16BE", "", "ISO-8859-1", "\x01\x81", "ISO-8859-1"],
["UTF-16BE", "", "UTF-16BE", "", "UTF-16BE"], ["UTF-16BE", "", "UTF-16BE", "", "UTF-16BE"],
["UTF-16BE", "", "UTF-16BE", "\x01", "UTF-16BE"], ["UTF-16BE", "", "UTF-16BE", "\u0101", "UTF-16BE"],
["UTF-16BE", "", "UTF-16BE", "\x81", "UTF-16BE"], ["UTF-16BE", "", "UTF-16BE", "\u0181", "UTF-16BE"],
["UTF-16BE", "", "ISO-2022-JP", "", "UTF-16BE"], ["UTF-16BE", "", "ISO-2022-JP", "", "UTF-16BE"],
["UTF-16BE", "", "ISO-2022-JP", "\x01", "ISO-2022-JP"], ["UTF-16BE", "", "ISO-2022-JP", "\x01\x01", "ISO-2022-JP"],
["UTF-16BE", "", "ISO-2022-JP", "\x81", "ISO-2022-JP"], ["UTF-16BE", "", "ISO-2022-JP", "\x01\x81", "ISO-2022-JP"],
["UTF-16BE", "\x01", "US-ASCII", "", "UTF-16BE"], ["UTF-16BE", "\u0101", "US-ASCII", "", "UTF-16BE"],
["UTF-16BE", "\x01", "US-ASCII", "\x01", nil], ["UTF-16BE", "\u0101", "US-ASCII", "\x01\x01", nil],
["UTF-16BE", "\x01", "US-ASCII", "\x81", nil], ["UTF-16BE", "\u0101", "US-ASCII", "\x01\x81", nil],
["UTF-16BE", "\x01", "UTF-8", "", "UTF-16BE"], ["UTF-16BE", "\u0101", "UTF-8", "", "UTF-16BE"],
["UTF-16BE", "\x01", "UTF-8", "\u0001", nil], ["UTF-16BE", "\u0101", "UTF-8", "\u0001\u0001", nil],
["UTF-16BE", "\x01", "UTF-8", "\x81", nil], ["UTF-16BE", "\u0101", "UTF-8", "\u0001\x81", nil],
["UTF-16BE", "\x01", "ASCII-8BIT", "", "UTF-16BE"], ["UTF-16BE", "\u0101", "ASCII-8BIT", "", "UTF-16BE"],
["UTF-16BE", "\x01", "ASCII-8BIT", "\x01", nil], ["UTF-16BE", "\u0101", "ASCII-8BIT", "\x01\x01", nil],
["UTF-16BE", "\x01", "ASCII-8BIT", "\x81", nil], ["UTF-16BE", "\u0101", "ASCII-8BIT", "\x01\x81", nil],
["UTF-16BE", "\x01", "ISO-8859-1", "", "UTF-16BE"], ["UTF-16BE", "\u0101", "ISO-8859-1", "", "UTF-16BE"],
["UTF-16BE", "\x01", "ISO-8859-1", "\x01", nil], ["UTF-16BE", "\u0101", "ISO-8859-1", "\x01\x01", nil],
["UTF-16BE", "\x01", "ISO-8859-1", "\x81", nil], ["UTF-16BE", "\u0101", "ISO-8859-1", "\x01\x81", nil],
["UTF-16BE", "\x01", "UTF-16BE", "", "UTF-16BE"], ["UTF-16BE", "\u0101", "UTF-16BE", "", "UTF-16BE"],
["UTF-16BE", "\x01", "UTF-16BE", "\x01", "UTF-16BE"], ["UTF-16BE", "\u0101", "UTF-16BE", "\u0101", "UTF-16BE"],
["UTF-16BE", "\x01", "UTF-16BE", "\x81", "UTF-16BE"], ["UTF-16BE", "\u0101", "UTF-16BE", "\u0181", "UTF-16BE"],
["UTF-16BE", "\x01", "ISO-2022-JP", "", "UTF-16BE"], ["UTF-16BE", "\u0101", "ISO-2022-JP", "", "UTF-16BE"],
["UTF-16BE", "\x01", "ISO-2022-JP", "\x01", nil], ["UTF-16BE", "\u0101", "ISO-2022-JP", "\x01\x01", nil],
["UTF-16BE", "\x01", "ISO-2022-JP", "\x81", nil], ["UTF-16BE", "\u0101", "ISO-2022-JP", "\x01\x81", nil],
["UTF-16BE", "\x81", "US-ASCII", "", "UTF-16BE"], ["UTF-16BE", "\u0181", "US-ASCII", "", "UTF-16BE"],
["UTF-16BE", "\x81", "US-ASCII", "\x01", nil], ["UTF-16BE", "\u0181", "US-ASCII", "\x01\x01", nil],
["UTF-16BE", "\x81", "US-ASCII", "\x81", nil], ["UTF-16BE", "\u0181", "US-ASCII", "\x01\x81", nil],
["UTF-16BE", "\x81", "UTF-8", "", "UTF-16BE"], ["UTF-16BE", "\u0181", "UTF-8", "", "UTF-16BE"],
["UTF-16BE", "\x81", "UTF-8", "\u0001", nil], ["UTF-16BE", "\u0181", "UTF-8", "\u0001\u0001", nil],
["UTF-16BE", "\x81", "UTF-8", "\x81", nil], ["UTF-16BE", "\u0181", "UTF-8", "\u0001\x81", nil],
["UTF-16BE", "\x81", "ASCII-8BIT", "", "UTF-16BE"], ["UTF-16BE", "\u0181", "ASCII-8BIT", "", "UTF-16BE"],
["UTF-16BE", "\x81", "ASCII-8BIT", "\x01", nil], ["UTF-16BE", "\u0181", "ASCII-8BIT", "\x01\x01", nil],
["UTF-16BE", "\x81", "ASCII-8BIT", "\x81", nil], ["UTF-16BE", "\u0181", "ASCII-8BIT", "\x01\x81", nil],
["UTF-16BE", "\x81", "ISO-8859-1", "", "UTF-16BE"], ["UTF-16BE", "\u0181", "ISO-8859-1", "", "UTF-16BE"],
["UTF-16BE", "\x81", "ISO-8859-1", "\x01", nil], ["UTF-16BE", "\u0181", "ISO-8859-1", "\x01\x01", nil],
["UTF-16BE", "\x81", "ISO-8859-1", "\x81", nil], ["UTF-16BE", "\u0181", "ISO-8859-1", "\x01\x81", nil],
["UTF-16BE", "\x81", "UTF-16BE", "", "UTF-16BE"], ["UTF-16BE", "\u0181", "UTF-16BE", "", "UTF-16BE"],
["UTF-16BE", "\x81", "UTF-16BE", "\x01", "UTF-16BE"], ["UTF-16BE", "\u0181", "UTF-16BE", "\u0101", "UTF-16BE"],
["UTF-16BE", "\x81", "UTF-16BE", "\x81", "UTF-16BE"], ["UTF-16BE", "\u0181", "UTF-16BE", "\u0181", "UTF-16BE"],
["UTF-16BE", "\x81", "ISO-2022-JP", "", "UTF-16BE"], ["UTF-16BE", "\u0181", "ISO-2022-JP", "", "UTF-16BE"],
["UTF-16BE", "\x81", "ISO-2022-JP", "\x01", nil], ["UTF-16BE", "\u0181", "ISO-2022-JP", "\x01\x01", nil],
["UTF-16BE", "\x81", "ISO-2022-JP", "\x81", nil], ["UTF-16BE", "\u0181", "ISO-2022-JP", "\x01\x81", nil],
["ISO-2022-JP", "", "US-ASCII", "", "ISO-2022-JP"], ["ISO-2022-JP", "", "US-ASCII", "", "ISO-2022-JP"],
["ISO-2022-JP", "", "US-ASCII", "\x01", "US-ASCII"], ["ISO-2022-JP", "", "US-ASCII", "\x01\x01", "US-ASCII"],
["ISO-2022-JP", "", "US-ASCII", "\x81", "US-ASCII"], ["ISO-2022-JP", "", "US-ASCII", "\x01\x81", "US-ASCII"],
["ISO-2022-JP", "", "UTF-8", "", "ISO-2022-JP"], ["ISO-2022-JP", "", "UTF-8", "", "ISO-2022-JP"],
["ISO-2022-JP", "", "UTF-8", "\u0001", "UTF-8"], ["ISO-2022-JP", "", "UTF-8", "\u0001\u0001", "UTF-8"],
["ISO-2022-JP", "", "UTF-8", "\x81", "UTF-8"], ["ISO-2022-JP", "", "UTF-8", "\u0001\x81", "UTF-8"],
["ISO-2022-JP", "", "ASCII-8BIT", "", "ISO-2022-JP"], ["ISO-2022-JP", "", "ASCII-8BIT", "", "ISO-2022-JP"],
["ISO-2022-JP", "", "ASCII-8BIT", "\x01", "ASCII-8BIT"], ["ISO-2022-JP", "", "ASCII-8BIT", "\x01\x01", "ASCII-8BIT"],
["ISO-2022-JP", "", "ASCII-8BIT", "\x81", "ASCII-8BIT"], ["ISO-2022-JP", "", "ASCII-8BIT", "\x01\x81", "ASCII-8BIT"],
["ISO-2022-JP", "", "ISO-8859-1", "", "ISO-2022-JP"], ["ISO-2022-JP", "", "ISO-8859-1", "", "ISO-2022-JP"],
["ISO-2022-JP", "", "ISO-8859-1", "\x01", "ISO-8859-1"], ["ISO-2022-JP", "", "ISO-8859-1", "\x01\x01", "ISO-8859-1"],
["ISO-2022-JP", "", "ISO-8859-1", "\x81", "ISO-8859-1"], ["ISO-2022-JP", "", "ISO-8859-1", "\x01\x81", "ISO-8859-1"],
["ISO-2022-JP", "", "UTF-16BE", "", "ISO-2022-JP"], ["ISO-2022-JP", "", "UTF-16BE", "", "ISO-2022-JP"],
["ISO-2022-JP", "", "UTF-16BE", "\x01", "UTF-16BE"], ["ISO-2022-JP", "", "UTF-16BE", "\u0101", "UTF-16BE"],
["ISO-2022-JP", "", "UTF-16BE", "\x81", "UTF-16BE"], ["ISO-2022-JP", "", "UTF-16BE", "\u0181", "UTF-16BE"],
["ISO-2022-JP", "", "ISO-2022-JP", "", "ISO-2022-JP"], ["ISO-2022-JP", "", "ISO-2022-JP", "", "ISO-2022-JP"],
["ISO-2022-JP", "", "ISO-2022-JP", "\x01", "ISO-2022-JP"], ["ISO-2022-JP", "", "ISO-2022-JP", "\x01\x01", "ISO-2022-JP"],
["ISO-2022-JP", "", "ISO-2022-JP", "\x81", "ISO-2022-JP"], ["ISO-2022-JP", "", "ISO-2022-JP", "\x01\x81", "ISO-2022-JP"],
["ISO-2022-JP", "\x01", "US-ASCII", "", "ISO-2022-JP"], ["ISO-2022-JP", "\x01\x01", "US-ASCII", "", "ISO-2022-JP"],
["ISO-2022-JP", "\x01", "US-ASCII", "\x01", nil], ["ISO-2022-JP", "\x01\x01", "US-ASCII", "\x01\x01", nil],
["ISO-2022-JP", "\x01", "US-ASCII", "\x81", nil], ["ISO-2022-JP", "\x01\x01", "US-ASCII", "\x01\x81", nil],
["ISO-2022-JP", "\x01", "UTF-8", "", "ISO-2022-JP"], ["ISO-2022-JP", "\x01\x01", "UTF-8", "", "ISO-2022-JP"],
["ISO-2022-JP", "\x01", "UTF-8", "\u0001", nil], ["ISO-2022-JP", "\x01\x01", "UTF-8", "\u0001\u0001", nil],
["ISO-2022-JP", "\x01", "UTF-8", "\x81", nil], ["ISO-2022-JP", "\x01\x01", "UTF-8", "\u0001\x81", nil],
["ISO-2022-JP", "\x01", "ASCII-8BIT", "", "ISO-2022-JP"], ["ISO-2022-JP", "\x01\x01", "ASCII-8BIT", "", "ISO-2022-JP"],
["ISO-2022-JP", "\x01", "ASCII-8BIT", "\x01", nil], ["ISO-2022-JP", "\x01\x01", "ASCII-8BIT", "\x01\x01", nil],
["ISO-2022-JP", "\x01", "ASCII-8BIT", "\x81", nil], ["ISO-2022-JP", "\x01\x01", "ASCII-8BIT", "\x01\x81", nil],
["ISO-2022-JP", "\x01", "ISO-8859-1", "", "ISO-2022-JP"], ["ISO-2022-JP", "\x01\x01", "ISO-8859-1", "", "ISO-2022-JP"],
["ISO-2022-JP", "\x01", "ISO-8859-1", "\x01", nil], ["ISO-2022-JP", "\x01\x01", "ISO-8859-1", "\x01\x01", nil],
["ISO-2022-JP", "\x01", "ISO-8859-1", "\x81", nil], ["ISO-2022-JP", "\x01\x01", "ISO-8859-1", "\x01\x81", nil],
["ISO-2022-JP", "\x01", "UTF-16BE", "", "ISO-2022-JP"], ["ISO-2022-JP", "\x01\x01", "UTF-16BE", "", "ISO-2022-JP"],
["ISO-2022-JP", "\x01", "UTF-16BE", "\x01", nil], ["ISO-2022-JP", "\x01\x01", "UTF-16BE", "\u0101", nil],
["ISO-2022-JP", "\x01", "UTF-16BE", "\x81", nil], ["ISO-2022-JP", "\x01\x01", "UTF-16BE", "\u0181", nil],
["ISO-2022-JP", "\x01", "ISO-2022-JP", "", "ISO-2022-JP"], ["ISO-2022-JP", "\x01\x01", "ISO-2022-JP", "", "ISO-2022-JP"],
["ISO-2022-JP", "\x01", "ISO-2022-JP", "\x01", "ISO-2022-JP"], ["ISO-2022-JP", "\x01\x01", "ISO-2022-JP", "\x01\x01", "ISO-2022-JP"],
["ISO-2022-JP", "\x01", "ISO-2022-JP", "\x81", "ISO-2022-JP"], ["ISO-2022-JP", "\x01\x01", "ISO-2022-JP", "\x01\x81", "ISO-2022-JP"],
["ISO-2022-JP", "\x81", "US-ASCII", "", "ISO-2022-JP"], ["ISO-2022-JP", "\x01\x81", "US-ASCII", "", "ISO-2022-JP"],
["ISO-2022-JP", "\x81", "US-ASCII", "\x01", nil], ["ISO-2022-JP", "\x01\x81", "US-ASCII", "\x01\x01", nil],
["ISO-2022-JP", "\x81", "US-ASCII", "\x81", nil], ["ISO-2022-JP", "\x01\x81", "US-ASCII", "\x01\x81", nil],
["ISO-2022-JP", "\x81", "UTF-8", "", "ISO-2022-JP"], ["ISO-2022-JP", "\x01\x81", "UTF-8", "", "ISO-2022-JP"],
["ISO-2022-JP", "\x81", "UTF-8", "\u0001", nil], ["ISO-2022-JP", "\x01\x81", "UTF-8", "\u0001\u0001", nil],
["ISO-2022-JP", "\x81", "UTF-8", "\x81", nil], ["ISO-2022-JP", "\x01\x81", "UTF-8", "\u0001\x81", nil],
["ISO-2022-JP", "\x81", "ASCII-8BIT", "", "ISO-2022-JP"], ["ISO-2022-JP", "\x01\x81", "ASCII-8BIT", "", "ISO-2022-JP"],
["ISO-2022-JP", "\x81", "ASCII-8BIT", "\x01", nil], ["ISO-2022-JP", "\x01\x81", "ASCII-8BIT", "\x01\x01", nil],
["ISO-2022-JP", "\x81", "ASCII-8BIT", "\x81", nil], ["ISO-2022-JP", "\x01\x81", "ASCII-8BIT", "\x01\x81", nil],
["ISO-2022-JP", "\x81", "ISO-8859-1", "", "ISO-2022-JP"], ["ISO-2022-JP", "\x01\x81", "ISO-8859-1", "", "ISO-2022-JP"],
["ISO-2022-JP", "\x81", "ISO-8859-1", "\x01", nil], ["ISO-2022-JP", "\x01\x81", "ISO-8859-1", "\x01\x01", nil],
["ISO-2022-JP", "\x81", "ISO-8859-1", "\x81", nil], ["ISO-2022-JP", "\x01\x81", "ISO-8859-1", "\x01\x81", nil],
["ISO-2022-JP", "\x81", "UTF-16BE", "", "ISO-2022-JP"], ["ISO-2022-JP", "\x01\x81", "UTF-16BE", "", "ISO-2022-JP"],
["ISO-2022-JP", "\x81", "UTF-16BE", "\x01", nil], ["ISO-2022-JP", "\x01\x81", "UTF-16BE", "\u0101", nil],
["ISO-2022-JP", "\x81", "UTF-16BE", "\x81", nil], ["ISO-2022-JP", "\x01\x81", "UTF-16BE", "\u0181", nil],
["ISO-2022-JP", "\x81", "ISO-2022-JP", "", "ISO-2022-JP"], ["ISO-2022-JP", "\x01\x81", "ISO-2022-JP", "", "ISO-2022-JP"],
["ISO-2022-JP", "\x81", "ISO-2022-JP", "\x01", "ISO-2022-JP"], ["ISO-2022-JP", "\x01\x81", "ISO-2022-JP", "\x01\x01", "ISO-2022-JP"],
["ISO-2022-JP", "\x81", "ISO-2022-JP", "\x81", "ISO-2022-JP"], ["ISO-2022-JP", "\x01\x81", "ISO-2022-JP", "\x01\x81", "ISO-2022-JP"],
] ]
matrix.each do |encoding1, value1, encoding2, value2, compatible_encoding| matrix.each do |encoding1, value1, encoding2, value2, compatible_encoding|

View File

@ -53,6 +53,11 @@ describe "SystemCallError.new" do
e.should be_an_instance_of(@example_errno_class) e.should be_an_instance_of(@example_errno_class)
end end
it "sets an error message corresponding to an appropriate Errno class" do
e = SystemCallError.new(@example_errno)
e.message.should == 'Invalid argument'
end
it "accepts an optional custom message preceding the errno" do it "accepts an optional custom message preceding the errno" do
exc = SystemCallError.new("custom message", @example_errno) exc = SystemCallError.new("custom message", @example_errno)
exc.should be_an_instance_of(@example_errno_class) exc.should be_an_instance_of(@example_errno_class)
@ -81,6 +86,35 @@ describe "SystemCallError.new" do
SystemCallError.new('foo', 2.9).should == SystemCallError.new('foo', 2) SystemCallError.new('foo', 2.9).should == SystemCallError.new('foo', 2)
end end
it "treats nil errno as unknown error value" do
SystemCallError.new(nil).should be_an_instance_of(SystemCallError)
end
it "treats nil custom message as if it is not passed at all" do
exc = SystemCallError.new(nil, @example_errno)
exc.message.should == 'Invalid argument'
end
it "sets an 'unknown error' message when an unknown error number" do
platform_is_not :windows do
SystemCallError.new(-1).message.should =~ /Unknown error(:)? -1/
end
platform_is :windows do
SystemCallError.new(-1).message.should == "The operation completed successfully."
end
end
it "adds a custom error message to an 'unknown error' message when an unknown error number and a custom message specified" do
platform_is_not :windows do
SystemCallError.new("custom message", -1).message.should =~ /Unknown error(:)? -1 - custom message/
end
platform_is :windows do
SystemCallError.new("custom message", -1).message.should == "The operation completed successfully. - custom message"
end
end
it "converts to Integer if errno is a Complex convertible to Integer" do it "converts to Integer if errno is a Complex convertible to Integer" do
SystemCallError.new('foo', Complex(2.9, 0)).should == SystemCallError.new('foo', 2) SystemCallError.new('foo', Complex(2.9, 0)).should == SystemCallError.new('foo', 2)
end end

View File

@ -59,6 +59,12 @@ guard -> { platform_is_not :windows or ruby_version_is "3.3" } do
@file.pread(0, 4).should == "" @file.pread(0, 4).should == ""
end end
it "returns a buffer for maxlen = 0 when buffer specified" do
buffer = +"foo"
@file.pread(0, 4, buffer).should.equal?(buffer)
buffer.should == "foo"
end
it "ignores the offset for maxlen = 0, even if it is out of file bounds" do it "ignores the offset for maxlen = 0, even if it is out of file bounds" do
@file.pread(0, 400).should == "" @file.pread(0, 400).should == ""
end end

View File

@ -62,11 +62,11 @@ describe "IO#set_encoding_by_bom" do
@io.rewind @io.rewind
@io.set_encoding(Encoding::ASCII_8BIT) @io.set_encoding(Encoding::ASCII_8BIT)
File.binwrite(@name, "\xFE\xFFabc") File.binwrite(@name, "\xFE\xFFabcd")
@io.set_encoding_by_bom.should == Encoding::UTF_16BE @io.set_encoding_by_bom.should == Encoding::UTF_16BE
@io.external_encoding.should == Encoding::UTF_16BE @io.external_encoding.should == Encoding::UTF_16BE
@io.read.b.should == "abc".b @io.read.b.should == "abcd".b
end end
it "returns the result encoding if found BOM UTF_32LE sequence" do it "returns the result encoding if found BOM UTF_32LE sequence" do
@ -94,11 +94,11 @@ describe "IO#set_encoding_by_bom" do
@io.rewind @io.rewind
@io.set_encoding(Encoding::ASCII_8BIT) @io.set_encoding(Encoding::ASCII_8BIT)
File.binwrite(@name, "\x00\x00\xFE\xFFabc") File.binwrite(@name, "\x00\x00\xFE\xFFabcd")
@io.set_encoding_by_bom.should == Encoding::UTF_32BE @io.set_encoding_by_bom.should == Encoding::UTF_32BE
@io.external_encoding.should == Encoding::UTF_32BE @io.external_encoding.should == Encoding::UTF_32BE
@io.read.b.should == "abc".b @io.read.b.should == "abcd".b
end end
it "returns nil if io is empty" do it "returns nil if io is empty" do

View File

@ -51,18 +51,15 @@ describe "Kernel#sleep" do
t.value.should == 5 t.value.should == 5
end end
quarantine! do # fails transiently on at least linux & darwin it "sleeps with nanosecond precision" do
it "sleeps with nanosecond precision" do start_time = Process.clock_gettime(Process::CLOCK_MONOTONIC)
start_time = Process.clock_gettime(Process::CLOCK_MONOTONIC) 100.times do
100.times do sleep(0.0001)
sleep(0.0001)
end
end_time = Process.clock_gettime(Process::CLOCK_MONOTONIC)
actual_duration = end_time - start_time
(actual_duration > 0.01).should == true # 100 * 0.0001 => 0.01
(actual_duration < 0.03).should == true
end end
end_time = Process.clock_gettime(Process::CLOCK_MONOTONIC)
actual_duration = end_time - start_time
actual_duration.should > 0.01 # 100 * 0.0001 => 0.01
end end
ruby_version_is ""..."3.3" do ruby_version_is ""..."3.3" do

View File

@ -283,6 +283,28 @@ describe "Marshal.dump" do
end end
end end
ruby_version_is "3.2" do
describe "with a Data" do
it "dumps a Data" do
Marshal.dump(MarshalSpec::DataSpec::Measure.new(100, 'km')).should == "\x04\bS:#MarshalSpec::DataSpec::Measure\a:\vamountii:\tunit\"\akm"
end
it "dumps an extended Data" do
obj = MarshalSpec::DataSpec::MeasureExtended.new(100, "km")
Marshal.dump(obj).should == "\x04\bS:+MarshalSpec::DataSpec::MeasureExtended\a:\vamountii:\tunit\"\akm"
end
it "ignores overridden name method" do
obj = MarshalSpec::DataSpec::MeasureWithOverriddenName.new(100, "km")
Marshal.dump(obj).should == "\x04\bS:5MarshalSpec::DataSpec::MeasureWithOverriddenName\a:\vamountii:\tunit\"\akm"
end
it "raises TypeError with an anonymous Struct" do
-> { Marshal.dump(Data.define(:a).new(1)) }.should raise_error(TypeError, /can't dump anonymous class/)
end
end
end
describe "with a String" do describe "with a String" do
it "dumps a blank String" do it "dumps a blank String" do
Marshal.dump("".dup.force_encoding("binary")).should == "\004\b\"\000" Marshal.dump("".dup.force_encoding("binary")).should == "\004\b\"\000"

View File

@ -486,6 +486,22 @@ module MarshalSpec
"\004\bS:\024Struct::Pyramid\000"], "\004\bS:\024Struct::Pyramid\000"],
"Random" => random_data, "Random" => random_data,
} }
if defined? Data # TODO: remove the condition when minimal supported version is 3.2
module DataSpec
Measure = Data.define(:amount, :unit)
Empty = Data.define
MeasureExtended = Class.new(Measure)
MeasureExtended.extend(Enumerable)
class MeasureWithOverriddenName < Measure
def self.name
"Foo"
end
end
end
end
end end
class ArraySub < Array class ArraySub < Array

View File

@ -749,6 +749,34 @@ describe :marshal_load, shared: true do
end end
end end
ruby_version_is "3.2" do
describe "for a Data" do
it "loads a Data" do
obj = MarshalSpec::DataSpec::Measure.new(100, 'km')
dumped = "\x04\bS:#MarshalSpec::DataSpec::Measure\a:\vamountii:\tunit\"\akm"
Marshal.dump(obj).should == dumped
Marshal.send(@method, dumped).should == obj
end
it "loads an extended Data" do
obj = MarshalSpec::DataSpec::MeasureExtended.new(100, "km")
dumped = "\x04\bS:+MarshalSpec::DataSpec::MeasureExtended\a:\vamountii:\tunit\"\akm"
Marshal.dump(obj).should == dumped
Marshal.send(@method, dumped).should == obj
end
it "returns a frozen object" do
obj = MarshalSpec::DataSpec::Measure.new(100, 'km')
dumped = "\x04\bS:#MarshalSpec::DataSpec::Measure\a:\vamountii:\tunit\"\akm"
Marshal.dump(obj).should == dumped
Marshal.send(@method, dumped).should.frozen?
end
end
end
describe "for an Exception" do describe "for an Exception" do
it "loads a marshalled exception with no message" do it "loads a marshalled exception with no message" do
obj = Exception.new obj = Exception.new

View File

@ -1,5 +1,35 @@
require_relative '../../../spec_helper' require_relative '../../../spec_helper'
describe "Process::Status#&" do describe "Process::Status#&" do
it "needs to be reviewed for spec completeness" it "returns a bitwise and of the integer status of an exited child" do
suppress_warning do
ruby_exe("exit(29)", exit_status: 29)
($? & 0).should == 0
($? & $?.to_i).should == $?.to_i
# Actual value is implementation specific
platform_is :linux do
# 29 == 0b11101
($? & 0b1011100000000).should == 0b1010100000000
end
end
end
ruby_version_is "3.3" do
it "raises an ArgumentError if mask is negative" do
suppress_warning do
ruby_exe("exit(0)")
-> {
$? & -1
}.should raise_error(ArgumentError, 'negative mask value: -1')
end
end
it "shows a deprecation warning" do
ruby_exe("exit(0)")
-> {
$? & 0
}.should complain(/warning: Process::Status#& is deprecated and will be removed .*use other Process::Status predicates instead/)
end
end
end end

View File

@ -1,5 +1,34 @@
require_relative '../../../spec_helper' require_relative '../../../spec_helper'
describe "Process::Status#>>" do describe "Process::Status#>>" do
it "needs to be reviewed for spec completeness" it "returns a right shift of the integer status of an exited child" do
suppress_warning do
ruby_exe("exit(29)", exit_status: 29)
($? >> 0).should == $?.to_i
($? >> 1).should == $?.to_i >> 1
# Actual value is implementation specific
platform_is :linux do
($? >> 8).should == 29
end
end
end
ruby_version_is "3.3" do
it "raises an ArgumentError if shift value is negative" do
suppress_warning do
ruby_exe("exit(0)")
-> {
$? >> -1
}.should raise_error(ArgumentError, 'negative shift value: -1')
end
end
it "shows a deprecation warning" do
ruby_exe("exit(0)")
-> {
$? >> 0
}.should complain(/warning: Process::Status#>> is deprecated and will be removed .*use other Process::Status attributes instead/)
end
end
end end

View File

@ -0,0 +1,103 @@
require_relative '../../spec_helper'
ruby_version_is "3.3" do
describe "Range#reverse_each" do
it "traverses the Range in reverse order and passes each element to block" do
a = []
(1..3).reverse_each { |i| a << i }
a.should == [3, 2, 1]
a = []
(1...3).reverse_each { |i| a << i }
a.should == [2, 1]
end
it "returns self" do
r = (1..3)
r.reverse_each { |x| }.should equal(r)
end
it "returns an Enumerator if no block given" do
enum = (1..3).reverse_each
enum.should be_an_instance_of(Enumerator)
enum.to_a.should == [3, 2, 1]
end
it "raises a TypeError for endless Ranges of Integers" do
-> {
(1..).reverse_each.take(3)
}.should raise_error(TypeError, "can't iterate from NilClass")
end
it "raises a TypeError for endless Ranges of non-Integers" do
-> {
("a"..).reverse_each.take(3)
}.should raise_error(TypeError, "can't iterate from NilClass")
end
context "Integer boundaries" do
it "supports beginningless Ranges" do
(..5).reverse_each.take(3).should == [5, 4, 3]
end
end
context "non-Integer boundaries" do
it "uses #succ to iterate a Range of non-Integer elements" do
y = mock('y')
x = mock('x')
x.should_receive(:succ).any_number_of_times.and_return(y)
x.should_receive(:<=>).with(y).any_number_of_times.and_return(-1)
x.should_receive(:<=>).with(x).any_number_of_times.and_return(0)
y.should_receive(:<=>).with(x).any_number_of_times.and_return(1)
y.should_receive(:<=>).with(y).any_number_of_times.and_return(0)
a = []
(x..y).each { |i| a << i }
a.should == [x, y]
end
it "uses #succ to iterate a Range of Strings" do
a = []
('A'..'D').reverse_each { |i| a << i }
a.should == ['D','C','B','A']
end
it "uses #succ to iterate a Range of Symbols" do
a = []
(:A..:D).reverse_each { |i| a << i }
a.should == [:D, :C, :B, :A]
end
it "raises a TypeError when `begin` value does not respond to #succ" do
-> { (Time.now..Time.now).reverse_each { |x| x } }.should raise_error(TypeError, /can't iterate from Time/)
-> { (//..//).reverse_each { |x| x } }.should raise_error(TypeError, /can't iterate from Regexp/)
-> { ([]..[]).reverse_each { |x| x } }.should raise_error(TypeError, /can't iterate from Array/)
end
it "does not support beginningless Ranges" do
-> {
(..'a').reverse_each { |x| x }
}.should raise_error(TypeError, /can't iterate from NilClass/)
end
end
context "when no block is given" do
describe "returned Enumerator size" do
it "returns the Range size when Range size is finite" do
(1..3).reverse_each.size.should == 3
end
ruby_bug "#20936", "3.4"..."3.5" do
it "returns Infinity when Range size is infinite" do
(..3).reverse_each.size.should == Float::INFINITY
end
end
it "returns nil when Range size is unknown" do
('a'..'z').reverse_each.size.should == nil
end
end
end
end
end

View File

@ -1,8 +1,13 @@
require_relative '../../spec_helper' require_relative "../../spec_helper"
require_relative 'shared/target'
describe "Refinement#refined_class" do describe "Refinement#refined_class" do
ruby_version_is "3.2"..."3.3" do ruby_version_is "3.2"..."3.3" do
it "returns the class refined by the receiver" do it_behaves_like :refinement_target, :refined_class
end
ruby_version_is "3.3"..."3.4" do
it "has been deprecated in favour of Refinement#target" do
refinement_int = nil refinement_int = nil
Module.new do Module.new do
@ -11,7 +16,23 @@ describe "Refinement#refined_class" do
end end
end end
refinement_int.refined_class.should == Integer -> {
refinement_int.refined_class
}.should complain(/warning: Refinement#refined_class is deprecated and will be removed in Ruby 3.4; use Refinement#target instead/)
end
end
ruby_version_is "3.4" do
it "has been removed" do
refinement_int = nil
Module.new do
refine Integer do
refinement_int = self
end
end
refinement_int.should_not.respond_to?(:refined_class)
end end
end end
end end

View File

@ -0,0 +1,13 @@
describe :refinement_target, shared: true do
it "returns the class refined by the receiver" do
refinement_int = nil
Module.new do
refine Integer do
refinement_int = self
end
end
refinement_int.send(@method).should == Integer
end
end

View File

@ -0,0 +1,8 @@
require_relative "../../spec_helper"
require_relative 'shared/target'
describe "Refinement#target" do
ruby_version_is "3.3" do
it_behaves_like :refinement_target, :target
end
end

View File

@ -8,6 +8,15 @@ describe :string_unpack_basic, shared: true do
d.should_receive(:to_str).and_return("a"+unpack_format) d.should_receive(:to_str).and_return("a"+unpack_format)
"abc".unpack(d).should be_an_instance_of(Array) "abc".unpack(d).should be_an_instance_of(Array)
end end
ruby_version_is "3.3" do
# https://bugs.ruby-lang.org/issues/19150
it 'raise ArgumentError when a directive is unknown' do
-> { "abcdefgh".unpack("a R" + unpack_format) }.should raise_error(ArgumentError, /unknown unpack directive 'R'/)
-> { "abcdefgh".unpack("a 0" + unpack_format) }.should raise_error(ArgumentError, /unknown unpack directive '0'/)
-> { "abcdefgh".unpack("a :" + unpack_format) }.should raise_error(ArgumentError, /unknown unpack directive ':'/)
end
end
end end
describe :string_unpack_no_platform, shared: true do describe :string_unpack_no_platform, shared: true do

View File

@ -55,6 +55,32 @@ describe "Time#<=>" do
}.should_not complain }.should_not complain
end end
context "given different timezones" do
it "returns 0 if time is the same as other" do
# three timezones, all at the same timestamp
time_utc = Time.new(2000, 1, 1, 0, 0, 0, 0)
time_cet = Time.new(2000, 1, 1, 1, 0, 0, '+01:00')
time_brt = Time.new(1999, 12, 31, 21, 0, 0, '-03:00')
(time_utc <=> time_cet).should == 0
(time_utc <=> time_brt).should == 0
(time_cet <=> time_brt).should == 0
end
it "returns -1 if the first argument is before the second argument" do
# time_brt is later, even though the date is earlier
time_utc = Time.new(2000, 1, 1, 0, 0, 0, 0)
time_brt = Time.new(1999, 12, 31, 23, 0, 0, '-03:00')
(time_utc <=> time_brt).should == -1
end
it "returns 1 if the first argument is before the second argument" do
# time_brt is later, even though the date is earlier
time_utc = Time.new(2000, 1, 1, 0, 0, 0, 0)
time_brt = Time.new(1999, 12, 31, 23, 0, 0, '-03:00')
(time_brt <=> time_utc).should == 1
end
end
describe "given a non-Time argument" do describe "given a non-Time argument" do
it "returns nil if argument <=> self returns nil" do it "returns nil if argument <=> self returns nil" do
t = Time.now t = Time.now

View File

@ -564,6 +564,12 @@ describe "Time.new with a timezone argument" do
Time.new("2020-12-25") Time.new("2020-12-25")
}.should raise_error(ArgumentError, /no time information|can't parse:/) }.should raise_error(ArgumentError, /no time information|can't parse:/)
end end
it "raises ArgumentError if day is missing" do
-> {
Time.new("2020-12")
}.should raise_error(ArgumentError, /no time information|can't parse:/)
end
end end
it "raises ArgumentError if subsecond is missing after dot" do it "raises ArgumentError if subsecond is missing after dot" do
@ -679,6 +685,26 @@ describe "Time.new with a timezone argument" do
Time.new("2021-11-31 00:00:59 +09:00 abc") Time.new("2021-11-31 00:00:59 +09:00 abc")
}.should raise_error(ArgumentError, /can't parse.+ abc/) }.should raise_error(ArgumentError, /can't parse.+ abc/)
end end
ruby_version_is "3.2.3" do
it "raises ArgumentError when there are leading space characters" do
-> { Time.new(" 2020-12-02 00:00:00") }.should raise_error(ArgumentError, /can't parse/)
-> { Time.new("\t2020-12-02 00:00:00") }.should raise_error(ArgumentError, /can't parse/)
-> { Time.new("\n2020-12-02 00:00:00") }.should raise_error(ArgumentError, /can't parse/)
-> { Time.new("\v2020-12-02 00:00:00") }.should raise_error(ArgumentError, /can't parse/)
-> { Time.new("\f2020-12-02 00:00:00") }.should raise_error(ArgumentError, /can't parse/)
-> { Time.new("\r2020-12-02 00:00:00") }.should raise_error(ArgumentError, /can't parse/)
end
it "raises ArgumentError when there are trailing whitespaces" do
-> { Time.new("2020-12-02 00:00:00 ") }.should raise_error(ArgumentError, /can't parse/)
-> { Time.new("2020-12-02 00:00:00\t") }.should raise_error(ArgumentError, /can't parse/)
-> { Time.new("2020-12-02 00:00:00\n") }.should raise_error(ArgumentError, /can't parse/)
-> { Time.new("2020-12-02 00:00:00\v") }.should raise_error(ArgumentError, /can't parse/)
-> { Time.new("2020-12-02 00:00:00\f") }.should raise_error(ArgumentError, /can't parse/)
-> { Time.new("2020-12-02 00:00:00\r") }.should raise_error(ArgumentError, /can't parse/)
end
end
end end
end end
end end

View File

@ -4,7 +4,14 @@ describe :time_gmtime, shared: true do
with_timezone("CST", -6) do with_timezone("CST", -6) do
t = Time.local(2007, 1, 9, 6, 0, 0) t = Time.local(2007, 1, 9, 6, 0, 0)
t.send(@method) t.send(@method)
t.should == Time.gm(2007, 1, 9, 12, 0, 0) # Time#== compensates for time zones, so check all parts separately
t.year.should == 2007
t.month.should == 1
t.mday.should == 9
t.hour.should == 12
t.min.should == 0
t.sec.should == 0
t.zone.should == "UTC"
end end
end end

View File

@ -17,4 +17,22 @@ describe 'TracePoint#raised_exception' do
raised_exception.should equal(error_result) raised_exception.should equal(error_result)
end end
end end
ruby_version_is "3.3" do
it 'returns value from exception rescued on the :rescue event' do
raised_exception, error_result = nil
trace = TracePoint.new(:rescue) { |tp|
next unless TracePointSpec.target_thread?
raised_exception = tp.raised_exception
}
trace.enable do
begin
raise StandardError
rescue => e
error_result = e
end
raised_exception.should equal(error_result)
end
end
end
end end

View File

@ -999,6 +999,7 @@ describe "Post-args" do
end end
end end
# tested more thoroughly in language/delegation_spec.rb
describe "Anonymous block forwarding" do describe "Anonymous block forwarding" do
ruby_version_is "3.1" do ruby_version_is "3.1" do
it "forwards blocks to other method that formally declares anonymous block" do it "forwards blocks to other method that formally declares anonymous block" do
@ -1072,3 +1073,32 @@ describe "Anonymous block forwarding" do
end end
end end
end end
describe "`it` calls without arguments in a block with no ordinary parameters" do
ruby_version_is "3.3"..."3.4" do
it "emits a deprecation warning" do
-> {
eval "proc { it }"
}.should complain(/warning: `it` calls without arguments will refer to the first block param in Ruby 3.4; use it\(\) or self.it/)
end
it "does not emit a deprecation warning when a block has parameters" do
-> { eval "proc { |a, b| it }" }.should_not complain
-> { eval "proc { |*rest| it }" }.should_not complain
-> { eval "proc { |*| it }" }.should_not complain
-> { eval "proc { |a:, b:| it }" }.should_not complain
-> { eval "proc { |**kw| it }" }.should_not complain
-> { eval "proc { |**| it }" }.should_not complain
-> { eval "proc { |&block| it }" }.should_not complain
-> { eval "proc { |&| it }" }.should_not complain
end
it "does not emit a deprecation warning when `it` calls with arguments" do
-> { eval "proc { it(42) }" }.should_not complain
end
it "does not emit a deprecation warning when `it` calls with explicit empty arguments list" do
-> { eval "proc { it() }" }.should_not complain
end
end
end

View File

@ -900,6 +900,10 @@ describe "The defined? keyword for a scoped constant" do
defined?(DefinedSpecs::Undefined).should be_nil defined?(DefinedSpecs::Undefined).should be_nil
end end
it "returns nil when the constant is not defined and the outer module implements .const_missing" do
defined?(DefinedSpecs::ModuleWithConstMissing::Undefined).should be_nil
end
it "does not call .const_missing if the constant is not defined" do it "does not call .const_missing if the constant is not defined" do
DefinedSpecs.should_not_receive(:const_missing) DefinedSpecs.should_not_receive(:const_missing)
defined?(DefinedSpecs::UnknownChild).should be_nil defined?(DefinedSpecs::UnknownChild).should be_nil

View File

@ -1,6 +1,7 @@
require_relative '../spec_helper' require_relative '../spec_helper'
require_relative 'fixtures/delegation' require_relative 'fixtures/delegation'
# Forwarding anonymous parameters
describe "delegation with def(...)" do describe "delegation with def(...)" do
it "delegates rest and kwargs" do it "delegates rest and kwargs" do
a = Class.new(DelegationSpecs::Target) a = Class.new(DelegationSpecs::Target)
@ -10,10 +11,10 @@ describe "delegation with def(...)" do
end end
RUBY RUBY
a.new.delegate(1, b: 2).should == [[1], {b: 2}] a.new.delegate(1, b: 2).should == [[1], {b: 2}, nil]
end end
it "delegates block" do it "delegates a block literal" do
a = Class.new(DelegationSpecs::Target) a = Class.new(DelegationSpecs::Target)
a.class_eval(<<-RUBY) a.class_eval(<<-RUBY)
def delegate_block(...) def delegate_block(...)
@ -24,6 +25,18 @@ describe "delegation with def(...)" do
a.new.delegate_block(1, b: 2) { |x| x }.should == [{b: 2}, [1]] a.new.delegate_block(1, b: 2) { |x| x }.should == [{b: 2}, [1]]
end end
it "delegates a block argument" do
a = Class.new(DelegationSpecs::Target)
a.class_eval(<<-RUBY)
def delegate(...)
target(...)
end
RUBY
block = proc {}
a.new.delegate(1, b: 2, &block).should == [[1], {b: 2}, block]
end
it "parses as open endless Range when brackets are omitted" do it "parses as open endless Range when brackets are omitted" do
a = Class.new(DelegationSpecs::Target) a = Class.new(DelegationSpecs::Target)
suppress_warning do suppress_warning do
@ -34,7 +47,7 @@ describe "delegation with def(...)" do
RUBY RUBY
end end
a.new.delegate(1, b: 2).should == Range.new([[], {}], nil, true) a.new.delegate(1, b: 2).should == Range.new([[], {}, nil], nil, true)
end end
end end
@ -47,10 +60,10 @@ describe "delegation with def(x, ...)" do
end end
RUBY RUBY
a.new.delegate(0, 1, b: 2).should == [[1], {b: 2}] a.new.delegate(0, 1, b: 2).should == [[1], {b: 2}, nil]
end end
it "delegates block" do it "delegates a block literal" do
a = Class.new(DelegationSpecs::Target) a = Class.new(DelegationSpecs::Target)
a.class_eval(<<-RUBY) a.class_eval(<<-RUBY)
def delegate_block(x, ...) def delegate_block(x, ...)
@ -60,6 +73,18 @@ describe "delegation with def(x, ...)" do
a.new.delegate_block(0, 1, b: 2) { |x| x }.should == [{b: 2}, [1]] a.new.delegate_block(0, 1, b: 2) { |x| x }.should == [{b: 2}, [1]]
end end
it "delegates a block argument" do
a = Class.new(DelegationSpecs::Target)
a.class_eval(<<-RUBY)
def delegate(...)
target(...)
end
RUBY
block = proc {}
a.new.delegate(1, b: 2, &block).should == [[1], {b: 2}, block]
end
end end
ruby_version_is "3.2" do ruby_version_is "3.2" do
@ -70,9 +95,19 @@ ruby_version_is "3.2" do
def delegate(*) def delegate(*)
target(*) target(*)
end end
RUBY RUBY
a.new.delegate(0, 1).should == [[0, 1], {}] a.new.delegate(0, 1).should == [[0, 1], {}, nil]
end
ruby_version_is "3.3" do
context "within a block that accepts anonymous rest within a method that accepts anonymous rest" do
it "does not allow delegating rest" do
-> {
eval "def m(*); proc { |*| n(*) } end"
}.should raise_error(SyntaxError, /anonymous rest parameter is also used within block/)
end
end
end end
end end
end end
@ -85,9 +120,45 @@ ruby_version_is "3.2" do
def delegate(**) def delegate(**)
target(**) target(**)
end end
RUBY RUBY
a.new.delegate(a: 1) { |x| x }.should == [[], {a: 1}] a.new.delegate(a: 1) { |x| x }.should == [[], {a: 1}, nil]
end
ruby_version_is "3.3" do
context "within a block that accepts anonymous kwargs within a method that accepts anonymous kwargs" do
it "does not allow delegating kwargs" do
-> {
eval "def m(**); proc { |**| n(**) } end"
}.should raise_error(SyntaxError, /anonymous keyword rest parameter is also used within block/)
end
end
end
end
end
ruby_version_is "3.1" do
describe "delegation with def(&)" do
it "delegates an anonymous block parameter" do
a = Class.new(DelegationSpecs::Target)
a.class_eval(<<-RUBY)
def delegate(&)
target(&)
end
RUBY
block = proc {}
a.new.delegate(&block).should == [[], {}, block]
end
ruby_version_is "3.3" do
context "within a block that accepts anonymous block within a method that accepts anonymous block" do
it "does not allow delegating a block" do
-> {
eval "def m(&); proc { |&| n(&) } end"
}.should raise_error(SyntaxError, /anonymous block parameter is also used within block/)
end
end
end end
end end
end end

View File

@ -285,6 +285,12 @@ module DefinedSpecs
end end
end end
module ModuleWithConstMissing
def self.const_missing(const)
const
end
end
class SuperWithIntermediateModules class SuperWithIntermediateModules
include IntermediateModule1 include IntermediateModule1
include IntermediateModule2 include IntermediateModule2

View File

@ -1,7 +1,7 @@
module DelegationSpecs module DelegationSpecs
class Target class Target
def target(*args, **kwargs) def target(*args, **kwargs, &block)
[args, kwargs] [args, kwargs, block]
end end
def target_block(*args, **kwargs) def target_block(*args, **kwargs)

View File

@ -0,0 +1,58 @@
require_relative '../../../spec_helper'
ruby_version_is "3.1" do
require 'random/formatter'
describe "Random::Formatter#alphanumeric" do
before :each do
@object = Object.new
@object.extend(Random::Formatter)
@object.define_singleton_method(:bytes) do |n|
"\x00".b * n
end
end
it "generates a random alphanumeric string" do
@object.alphanumeric.should =~ /\A[A-Za-z0-9]+\z/
end
it "has a default size of 16 characters" do
@object.alphanumeric.size.should == 16
end
it "accepts a 'size' argument" do
@object.alphanumeric(10).size.should == 10
end
it "uses the default size if 'nil' is given as size argument" do
@object.alphanumeric(nil).size.should == 16
end
it "raises an ArgumentError if the size is not numeric" do
-> {
@object.alphanumeric("10")
}.should raise_error(ArgumentError)
end
it "does not coerce the size argument with #to_int" do
size = mock("size")
size.should_not_receive(:to_int)
-> {
@object.alphanumeric(size)
}.should raise_error(ArgumentError)
end
ruby_version_is "3.3" do
it "accepts a 'chars' argument with the output alphabet" do
@object.alphanumeric(chars: ['a', 'b']).should =~ /\A[ab]+\z/
end
it "converts the elements of chars using #to_s" do
to_s = mock("to_s")
to_s.should_receive(:to_s).and_return("[mock to_s]")
# Using 1 value in chars results in an infinite loop
@object.alphanumeric(1, chars: [to_s, to_s]).should == "[mock to_s]"
end
end
end
end

View File

@ -11,8 +11,8 @@ describe "SecureRandom.random_number" do
(1..64).each do |idx| (1..64).each do |idx|
num = SecureRandom.random_number(idx) num = SecureRandom.random_number(idx)
num.should be_kind_of(Integer) num.should be_kind_of(Integer)
(0 <= num).should == true 0.should <= num
(num < idx).should == true num.should < idx
end end
end end
@ -21,8 +21,8 @@ describe "SecureRandom.random_number" do
11.times do 11.times do
num = SecureRandom.random_number max num = SecureRandom.random_number max
num.should be_kind_of(Integer) num.should be_kind_of(Integer)
(0 <= num).should == true 0.should <= num
(num < max).should == true num.should < max
end end
end end
@ -30,8 +30,8 @@ describe "SecureRandom.random_number" do
64.times do 64.times do
num = SecureRandom.random_number num = SecureRandom.random_number
num.should be_kind_of(Float) num.should be_kind_of(Float)
(0.0 <= num).should == true 0.0.should <= num
(num < 1.0).should == true num.should < 1.0
end end
end end
@ -39,8 +39,8 @@ describe "SecureRandom.random_number" do
64.times do 64.times do
num = SecureRandom.random_number 11...13 num = SecureRandom.random_number 11...13
num.should be_kind_of(Integer) num.should be_kind_of(Integer)
(11 <= num).should == true 11.should <= num
(num < 13).should == true num.should < 13
end end
end end
@ -50,8 +50,8 @@ describe "SecureRandom.random_number" do
32.times do 32.times do
num = SecureRandom.random_number lower..upper num = SecureRandom.random_number lower..upper
num.should be_kind_of(Integer) num.should be_kind_of(Integer)
(lower <= num).should == true lower.should <= num
(num <= upper).should == true num.should <= upper
end end
end end
@ -59,23 +59,23 @@ describe "SecureRandom.random_number" do
64.times do 64.times do
num = SecureRandom.random_number 0.6..0.9 num = SecureRandom.random_number 0.6..0.9
num.should be_kind_of(Float) num.should be_kind_of(Float)
(0.6 <= num).should == true 0.6.should <= num
(num <= 0.9).should == true num.should <= 0.9
end end
end end
it "generates a random float number between 0.0 and 1.0 if argument is negative" do it "generates a random float number between 0.0 and 1.0 if argument is negative" do
num = SecureRandom.random_number(-10) num = SecureRandom.random_number(-10)
num.should be_kind_of(Float) num.should be_kind_of(Float)
(0.0 <= num).should == true 0.0.should <= num
(num < 1.0).should == true num.should < 1.0
end end
it "generates a random float number between 0.0 and 1.0 if argument is negative float" do it "generates a random float number between 0.0 and 1.0 if argument is negative float" do
num = SecureRandom.random_number(-11.1) num = SecureRandom.random_number(-11.1)
num.should be_kind_of(Float) num.should be_kind_of(Float)
(0.0 <= num).should == true 0.0.should <= num
(num < 1.0).should == true num.should < 1.0
end end
it "generates different float numbers with subsequent invocations" do it "generates different float numbers with subsequent invocations" do
@ -84,7 +84,7 @@ describe "SecureRandom.random_number" do
256.times do 256.times do
val = SecureRandom.random_number val = SecureRandom.random_number
# make sure the random values are not repeating # make sure the random values are not repeating
values.include?(val).should == false values.should_not include(val)
values << val values << val
end end
end end

View File

@ -94,7 +94,7 @@ describe :stringio_write_string, shared: true do
end end
it "does not transcode the given string when the external encoding is set and the string encoding is BINARY" do it "does not transcode the given string when the external encoding is set and the string encoding is BINARY" do
str = "été".b str = "été_".b
io = StringIO.new.set_encoding(Encoding::UTF_16BE) io = StringIO.new.set_encoding(Encoding::UTF_16BE)
io.external_encoding.should == Encoding::UTF_16BE io.external_encoding.should == Encoding::UTF_16BE

View File

@ -2,6 +2,6 @@ require_relative '../../spec_helper'
require_relative 'shared/xmlschema' require_relative 'shared/xmlschema'
require 'time' require 'time'
describe "Time.xmlschema" do describe "Time.iso8601" do
it_behaves_like :time_library_xmlschema, :iso8601 it_behaves_like :time_library_xmlschema, :iso8601
end end

View File

@ -134,6 +134,20 @@ VALUE hash_spec_compute_a_hash_code(VALUE self, VALUE seed) {
return ULONG2NUM(h); return ULONG2NUM(h);
} }
VALUE hash_spec_rb_hash_bulk_insert(VALUE self, VALUE array_len, VALUE array, VALUE hash) {
VALUE* ptr;
if (array == Qnil) {
ptr = NULL;
} else {
ptr = RARRAY_PTR(array);
}
long len = FIX2LONG(array_len);
rb_hash_bulk_insert(len, ptr, hash);
return Qnil;
}
void Init_hash_spec(void) { void Init_hash_spec(void) {
VALUE cls = rb_define_class("CApiHashSpecs", rb_cObject); VALUE cls = rb_define_class("CApiHashSpecs", rb_cObject);
rb_define_method(cls, "rb_hash", hash_spec_rb_hash, 1); rb_define_method(cls, "rb_hash", hash_spec_rb_hash, 1);
@ -162,6 +176,7 @@ void Init_hash_spec(void) {
rb_define_method(cls, "rb_hash_size", hash_spec_rb_hash_size, 1); rb_define_method(cls, "rb_hash_size", hash_spec_rb_hash_size, 1);
rb_define_method(cls, "rb_hash_set_ifnone", hash_spec_rb_hash_set_ifnone, 2); rb_define_method(cls, "rb_hash_set_ifnone", hash_spec_rb_hash_set_ifnone, 2);
rb_define_method(cls, "compute_a_hash_code", hash_spec_compute_a_hash_code, 1); rb_define_method(cls, "compute_a_hash_code", hash_spec_compute_a_hash_code, 1);
rb_define_method(cls, "rb_hash_bulk_insert", hash_spec_rb_hash_bulk_insert, 3);
} }
#ifdef __cplusplus #ifdef __cplusplus

View File

@ -371,6 +371,27 @@ static VALUE io_spec_rb_io_mode(VALUE self, VALUE io) {
static VALUE io_spec_rb_io_path(VALUE self, VALUE io) { static VALUE io_spec_rb_io_path(VALUE self, VALUE io) {
return rb_io_path(io); return rb_io_path(io);
} }
static VALUE io_spec_rb_io_closed_p(VALUE self, VALUE io) {
return rb_io_closed_p(io);
}
static VALUE io_spec_rb_io_open_descriptor(VALUE self, VALUE klass, VALUE descriptor, VALUE mode, VALUE path, VALUE timeout, VALUE internal_encoding, VALUE external_encoding, VALUE ecflags, VALUE ecopts) {
struct rb_io_encoding *io_encoding;
io_encoding = (struct rb_io_encoding *) malloc(sizeof(struct rb_io_encoding));
io_encoding->enc = rb_to_encoding(internal_encoding);
io_encoding->enc2 = rb_to_encoding(external_encoding);
io_encoding->ecflags = FIX2INT(ecflags);
io_encoding->ecopts = ecopts;
return rb_io_open_descriptor(klass, FIX2INT(descriptor), FIX2INT(mode), path, timeout, io_encoding);
}
static VALUE io_spec_rb_io_open_descriptor_without_encoding(VALUE self, VALUE klass, VALUE descriptor, VALUE mode, VALUE path, VALUE timeout) {
return rb_io_open_descriptor(klass, FIX2INT(descriptor), FIX2INT(mode), path, timeout, NULL);
}
#endif #endif
void Init_io_spec(void) { void Init_io_spec(void) {
@ -409,6 +430,14 @@ void Init_io_spec(void) {
#if defined(RUBY_VERSION_IS_3_3) || defined(TRUFFLERUBY) #if defined(RUBY_VERSION_IS_3_3) || defined(TRUFFLERUBY)
rb_define_method(cls, "rb_io_mode", io_spec_rb_io_mode, 1); rb_define_method(cls, "rb_io_mode", io_spec_rb_io_mode, 1);
rb_define_method(cls, "rb_io_path", io_spec_rb_io_path, 1); rb_define_method(cls, "rb_io_path", io_spec_rb_io_path, 1);
rb_define_method(cls, "rb_io_closed_p", io_spec_rb_io_closed_p, 1);
rb_define_method(cls, "rb_io_open_descriptor", io_spec_rb_io_open_descriptor, 9);
rb_define_method(cls, "rb_io_open_descriptor_without_encoding", io_spec_rb_io_open_descriptor_without_encoding, 5);
rb_define_const(cls, "FMODE_READABLE", INT2FIX(FMODE_READABLE));
rb_define_const(cls, "FMODE_WRITABLE", INT2FIX(FMODE_WRITABLE));
rb_define_const(cls, "FMODE_BINMODE", INT2FIX(FMODE_BINMODE));
rb_define_const(cls, "FMODE_TEXTMODE", INT2FIX(FMODE_TEXTMODE));
rb_define_const(cls, "ECONV_UNIVERSAL_NEWLINE_DECORATOR", INT2FIX(ECONV_UNIVERSAL_NEWLINE_DECORATOR));
#endif #endif
} }

View File

@ -67,11 +67,20 @@ VALUE kernel_spec_rb_block_call_no_func(VALUE self, VALUE ary) {
return rb_block_call(ary, rb_intern("map"), 0, NULL, (rb_block_call_func_t)NULL, Qnil); return rb_block_call(ary, rb_intern("map"), 0, NULL, (rb_block_call_func_t)NULL, Qnil);
} }
VALUE kernel_spec_rb_frame_this_func(VALUE self) { VALUE kernel_spec_rb_frame_this_func(VALUE self) {
return ID2SYM(rb_frame_this_func()); return ID2SYM(rb_frame_this_func());
} }
VALUE kernel_spec_rb_category_warn_deprecated(VALUE self) {
rb_category_warn(RB_WARN_CATEGORY_DEPRECATED, "foo");
return Qnil;
}
VALUE kernel_spec_rb_category_warn_deprecated_with_integer_extra_value(VALUE self, VALUE value) {
rb_category_warn(RB_WARN_CATEGORY_DEPRECATED, "foo %d", FIX2INT(value));
return Qnil;
}
VALUE kernel_spec_rb_ensure(VALUE self, VALUE main_proc, VALUE arg, VALUE kernel_spec_rb_ensure(VALUE self, VALUE main_proc, VALUE arg,
VALUE ensure_proc, VALUE arg2) { VALUE ensure_proc, VALUE arg2) {
VALUE main_array, ensure_array; VALUE main_array, ensure_array;
@ -242,6 +251,13 @@ VALUE kernel_spec_rb_syserr_fail(VALUE self, VALUE err, VALUE msg) {
return Qnil; return Qnil;
} }
VALUE kernel_spec_rb_syserr_fail_str(VALUE self, VALUE err, VALUE msg) {
if (self != Qundef) {
rb_syserr_fail_str(NUM2INT(err), msg);
}
return Qnil;
}
VALUE kernel_spec_rb_warn(VALUE self, VALUE msg) { VALUE kernel_spec_rb_warn(VALUE self, VALUE msg) {
rb_warn("%s", StringValuePtr(msg)); rb_warn("%s", StringValuePtr(msg));
return Qnil; return Qnil;
@ -323,6 +339,10 @@ static VALUE kernel_spec_rb_f_sprintf(VALUE self, VALUE ary) {
return rb_f_sprintf((int)RARRAY_LEN(ary), RARRAY_PTR(ary)); return rb_f_sprintf((int)RARRAY_LEN(ary), RARRAY_PTR(ary));
} }
static VALUE kernel_spec_rb_str_format(VALUE self, VALUE count, VALUE ary, VALUE format) {
return rb_str_format(FIX2INT(count), RARRAY_PTR(ary), format);
}
static VALUE kernel_spec_rb_make_backtrace(VALUE self) { static VALUE kernel_spec_rb_make_backtrace(VALUE self) {
return rb_make_backtrace(); return rb_make_backtrace();
} }
@ -381,6 +401,8 @@ void Init_kernel_spec(void) {
rb_define_method(cls, "rb_block_lambda", kernel_spec_rb_block_lambda, 0); rb_define_method(cls, "rb_block_lambda", kernel_spec_rb_block_lambda, 0);
rb_define_method(cls, "rb_frame_this_func_test", kernel_spec_rb_frame_this_func, 0); rb_define_method(cls, "rb_frame_this_func_test", kernel_spec_rb_frame_this_func, 0);
rb_define_method(cls, "rb_frame_this_func_test_again", kernel_spec_rb_frame_this_func, 0); rb_define_method(cls, "rb_frame_this_func_test_again", kernel_spec_rb_frame_this_func, 0);
rb_define_method(cls, "rb_category_warn_deprecated", kernel_spec_rb_category_warn_deprecated, 0);
rb_define_method(cls, "rb_category_warn_deprecated_with_integer_extra_value", kernel_spec_rb_category_warn_deprecated_with_integer_extra_value, 1);
rb_define_method(cls, "rb_ensure", kernel_spec_rb_ensure, 4); rb_define_method(cls, "rb_ensure", kernel_spec_rb_ensure, 4);
rb_define_method(cls, "rb_eval_string", kernel_spec_rb_eval_string, 1); rb_define_method(cls, "rb_eval_string", kernel_spec_rb_eval_string, 1);
rb_define_method(cls, "rb_eval_cmd_kw", kernel_spec_rb_eval_cmd_kw, 3); rb_define_method(cls, "rb_eval_cmd_kw", kernel_spec_rb_eval_cmd_kw, 3);
@ -400,6 +422,7 @@ void Init_kernel_spec(void) {
rb_define_method(cls, "rb_catch_obj", kernel_spec_rb_catch_obj, 2); rb_define_method(cls, "rb_catch_obj", kernel_spec_rb_catch_obj, 2);
rb_define_method(cls, "rb_sys_fail", kernel_spec_rb_sys_fail, 1); rb_define_method(cls, "rb_sys_fail", kernel_spec_rb_sys_fail, 1);
rb_define_method(cls, "rb_syserr_fail", kernel_spec_rb_syserr_fail, 2); rb_define_method(cls, "rb_syserr_fail", kernel_spec_rb_syserr_fail, 2);
rb_define_method(cls, "rb_syserr_fail_str", kernel_spec_rb_syserr_fail_str, 2);
rb_define_method(cls, "rb_warn", kernel_spec_rb_warn, 1); rb_define_method(cls, "rb_warn", kernel_spec_rb_warn, 1);
rb_define_method(cls, "rb_yield", kernel_spec_rb_yield, 1); rb_define_method(cls, "rb_yield", kernel_spec_rb_yield, 1);
rb_define_method(cls, "rb_yield_indirected", kernel_spec_rb_yield_indirected, 1); rb_define_method(cls, "rb_yield_indirected", kernel_spec_rb_yield_indirected, 1);
@ -410,6 +433,7 @@ void Init_kernel_spec(void) {
rb_define_method(cls, "rb_exec_recursive", kernel_spec_rb_exec_recursive, 1); rb_define_method(cls, "rb_exec_recursive", kernel_spec_rb_exec_recursive, 1);
rb_define_method(cls, "rb_set_end_proc", kernel_spec_rb_set_end_proc, 1); rb_define_method(cls, "rb_set_end_proc", kernel_spec_rb_set_end_proc, 1);
rb_define_method(cls, "rb_f_sprintf", kernel_spec_rb_f_sprintf, 1); rb_define_method(cls, "rb_f_sprintf", kernel_spec_rb_f_sprintf, 1);
rb_define_method(cls, "rb_str_format", kernel_spec_rb_str_format, 3);
rb_define_method(cls, "rb_make_backtrace", kernel_spec_rb_make_backtrace, 0); rb_define_method(cls, "rb_make_backtrace", kernel_spec_rb_make_backtrace, 0);
rb_define_method(cls, "rb_funcallv", kernel_spec_rb_funcallv, 3); rb_define_method(cls, "rb_funcallv", kernel_spec_rb_funcallv, 3);
#ifdef RUBY_VERSION_IS_3_0 #ifdef RUBY_VERSION_IS_3_0

View File

@ -581,6 +581,11 @@ static VALUE string_spec_rb_enc_interned_str_cstr(VALUE self, VALUE str, VALUE e
return rb_enc_interned_str_cstr(RSTRING_PTR(str), e); return rb_enc_interned_str_cstr(RSTRING_PTR(str), e);
} }
static VALUE string_spec_rb_enc_interned_str(VALUE self, VALUE str, VALUE len, VALUE enc) {
rb_encoding *e = NIL_P(enc) ? 0 : rb_to_encoding(enc);
return rb_enc_interned_str(RSTRING_PTR(str), FIX2LONG(len), e);
}
static VALUE string_spec_rb_str_to_interned_str(VALUE self, VALUE str) { static VALUE string_spec_rb_str_to_interned_str(VALUE self, VALUE str) {
return rb_str_to_interned_str(str); return rb_str_to_interned_str(str);
} }
@ -687,6 +692,7 @@ void Init_string_spec(void) {
rb_define_method(cls, "rb_str_locktmp", string_spec_rb_str_locktmp, 1); rb_define_method(cls, "rb_str_locktmp", string_spec_rb_str_locktmp, 1);
rb_define_method(cls, "rb_str_unlocktmp", string_spec_rb_str_unlocktmp, 1); rb_define_method(cls, "rb_str_unlocktmp", string_spec_rb_str_unlocktmp, 1);
rb_define_method(cls, "rb_enc_interned_str_cstr", string_spec_rb_enc_interned_str_cstr, 2); rb_define_method(cls, "rb_enc_interned_str_cstr", string_spec_rb_enc_interned_str_cstr, 2);
rb_define_method(cls, "rb_enc_interned_str", string_spec_rb_enc_interned_str, 3);
rb_define_method(cls, "rb_str_to_interned_str", string_spec_rb_str_to_interned_str, 1); rb_define_method(cls, "rb_str_to_interned_str", string_spec_rb_str_to_interned_str, 1);
} }

View File

@ -194,6 +194,61 @@ describe "C-API Hash function" do
end end
end end
describe "rb_hash_bulk_insert" do
it 'inserts key-value pairs into the hash' do
arr = [:a, 1, :b, 2, :c, 3]
hash = {}
@s.rb_hash_bulk_insert(arr.length, arr, hash)
hash.should == {a: 1, b: 2, c: 3}
end
it 'overwrites existing keys' do
arr = [:a, 4, :b, 5, :c, 6]
hash = {a: 1, b: 2}
@s.rb_hash_bulk_insert(arr.length, arr, hash)
hash.should == {a: 4, b: 5, c: 6}
end
it 'uses the last key in the array if it appears multiple times' do
arr = [:a, 1, :b, 2, :a, 3]
hash = {}
@s.rb_hash_bulk_insert(arr.length, arr, hash)
hash.should == {a: 3, b: 2}
end
it 'allows the array to be NULL if the length is zero' do
hash = {}
@s.rb_hash_bulk_insert(0, nil, hash)
hash.should == {}
end
it 'does not include any keys after the given length' do
arr = [:a, 1, :b, 2, :c, 3, :d, 4]
hash = {}
@s.rb_hash_bulk_insert(arr.length - 2, arr, hash)
hash.should == {a: 1, b: 2, c: 3}
end
it 'does not modify the hash if the length is zero' do
arr = []
hash = {a: 1, b: 2}
@s.rb_hash_bulk_insert(arr.length, arr, hash)
hash.should == {a: 1, b: 2}
end
end
describe "rb_hash_size" do describe "rb_hash_size" do
it "returns the size of the hash" do it "returns the size of the hash" do
hsh = {fast: 'car', good: 'music'} hsh = {fast: 'car', good: 'music'}

View File

@ -516,6 +516,152 @@ describe "C-API IO function" do
@o.rb_io_path(@rw_io).should == @name @o.rb_io_path(@rw_io).should == @name
end end
end end
describe "rb_io_closed_p" do
it "returns false when io is not closed" do
@o.rb_io_closed_p(@r_io).should == false
@r_io.closed?.should == false
end
it "returns true when io is closed" do
@r_io.close
@o.rb_io_closed_p(@r_io).should == true
@r_io.closed?.should == true
end
end
quarantine! do # "Errno::EBADF: Bad file descriptor" at closing @r_io, @rw_io etc in the after :each hook
describe "rb_io_open_descriptor" do
it "creates a new IO instance" do
io = @o.rb_io_open_descriptor(File, @r_io.fileno, 0, "a.txt", 60, "US-ASCII", "UTF-8", 0, {})
io.should.is_a?(IO)
end
it "return an instance of the specified class" do
io = @o.rb_io_open_descriptor(File, @r_io.fileno, 0, "a.txt", 60, "US-ASCII", "UTF-8", 0, {})
io.class.should == File
io = @o.rb_io_open_descriptor(IO, @r_io.fileno, 0, "a.txt", 60, "US-ASCII", "UTF-8", 0, {})
io.class.should == IO
end
it "sets the specified file descriptor" do
io = @o.rb_io_open_descriptor(File, @r_io.fileno, 0, "a.txt", 60, "US-ASCII", "UTF-8", 0, {})
io.fileno.should == @r_io.fileno
end
it "sets the specified path" do
io = @o.rb_io_open_descriptor(File, @r_io.fileno, 0, "a.txt", 60, "US-ASCII", "UTF-8", 0, {})
io.path.should == "a.txt"
end
it "sets the specified mode" do
io = @o.rb_io_open_descriptor(File, @r_io.fileno, CApiIOSpecs::FMODE_BINMODE, "a.txt", 60, "US-ASCII", "UTF-8", 0, {})
io.should.binmode?
io = @o.rb_io_open_descriptor(File, @r_io.fileno, CApiIOSpecs::FMODE_TEXTMODE, "a.txt", 60, "US-ASCII", "UTF-8", 0, {})
io.should_not.binmode?
end
it "sets the specified timeout" do
io = @o.rb_io_open_descriptor(File, @r_io.fileno, 0, "a.txt", 60, "US-ASCII", "UTF-8", 0, {})
io.timeout.should == 60
end
it "sets the specified internal encoding" do
io = @o.rb_io_open_descriptor(File, @r_io.fileno, 0, "a.txt", 60, "US-ASCII", "UTF-8", 0, {})
io.internal_encoding.should == Encoding::US_ASCII
end
it "sets the specified external encoding" do
io = @o.rb_io_open_descriptor(File, @r_io.fileno, 0, "a.txt", 60, "US-ASCII", "UTF-8", 0, {})
io.external_encoding.should == Encoding::UTF_8
end
it "does not apply the specified encoding flags" do
name = tmp("rb_io_open_descriptor_specs")
File.write(name, "123\r\n456\n89")
file = File.open(name, "r")
io = @o.rb_io_open_descriptor(File, file.fileno, CApiIOSpecs::FMODE_READABLE, "a.txt", 60, "US-ASCII", "UTF-8", CApiIOSpecs::ECONV_UNIVERSAL_NEWLINE_DECORATOR, {})
io.read_nonblock(20).should == "123\r\n456\n89"
ensure
file.close
rm_r name
end
it "ignores the IO open options" do
io = @o.rb_io_open_descriptor(File, @r_io.fileno, 0, "a.txt", 60, "US-ASCII", "UTF-8", 0, {external_encoding: "windows-1251"})
io.external_encoding.should == Encoding::UTF_8
io = @o.rb_io_open_descriptor(File, @r_io.fileno, 0, "a.txt", 60, "US-ASCII", "UTF-8", 0, {internal_encoding: "windows-1251"})
io.internal_encoding.should == Encoding::US_ASCII
io = @o.rb_io_open_descriptor(File, @r_io.fileno, 0, "a.txt", 60, "US-ASCII", "UTF-8", 0, {encoding: "windows-1251:binary"})
io.external_encoding.should == Encoding::UTF_8
io.internal_encoding.should == Encoding::US_ASCII
io = @o.rb_io_open_descriptor(File, @r_io.fileno, 0, "a.txt", 60, "US-ASCII", "UTF-8", 0, {textmode: false})
io.should_not.binmode?
io = @o.rb_io_open_descriptor(File, @r_io.fileno, 0, "a.txt", 60, "US-ASCII", "UTF-8", 0, {binmode: true})
io.should_not.binmode?
io = @o.rb_io_open_descriptor(File, @r_io.fileno, 0, "a.txt", 60, "US-ASCII", "UTF-8", 0, {autoclose: false})
io.should.autoclose?
io = @o.rb_io_open_descriptor(File, @r_io.fileno, 0, "a.txt", 60, "US-ASCII", "UTF-8", 0, {path: "a.txt"})
io.path.should == "a.txt"
end
it "ignores the IO encoding options" do
io = @o.rb_io_open_descriptor(File, @w_io.fileno, CApiIOSpecs::FMODE_WRITABLE, "a.txt", 60, "US-ASCII", "UTF-8", 0, {crlf_newline: true})
io.write("123\r\n456\n89")
io.flush
@r_io.read_nonblock(20).should == "123\r\n456\n89"
end
it "allows wrong mode" do
io = @o.rb_io_open_descriptor(File, @w_io.fileno, CApiIOSpecs::FMODE_READABLE, "a.txt", 60, "US-ASCII", "UTF-8", 0, {})
io.should.is_a?(File)
platform_is_not :windows do
-> { io.read_nonblock(1) }.should raise_error(Errno::EBADF)
end
platform_is :windows do
-> { io.read_nonblock(1) }.should raise_error(IO::EWOULDBLOCKWaitReadable)
end
end
it "tolerates NULL as rb_io_encoding *encoding parameter" do
io = @o.rb_io_open_descriptor_without_encoding(File, @r_io.fileno, 0, "a.txt", 60)
io.should.is_a?(File)
end
it "deduplicates path String" do
path = "a.txt".dup
io = @o.rb_io_open_descriptor(File, @r_io.fileno, 0, path, 60, "US-ASCII", "UTF-8", 0, {})
io.path.should_not equal(path)
path = "a.txt".freeze
io = @o.rb_io_open_descriptor(File, @r_io.fileno, 0, path, 60, "US-ASCII", "UTF-8", 0, {})
io.path.should_not equal(path)
end
it "calls #to_str to convert a path to a String" do
path = Object.new
def path.to_str; "a.txt"; end
io = @o.rb_io_open_descriptor(File, @r_io.fileno, 0, path, 60, "US-ASCII", "UTF-8", 0, {})
io.path.should == "a.txt"
end
end
end
end end
ruby_version_is "3.4" do ruby_version_is "3.4" do

View File

@ -156,26 +156,16 @@ describe "C-API Kernel function" do
end end
describe "rb_warn" do describe "rb_warn" do
before :each do
@stderr, $stderr = $stderr, IOStub.new
@verbose = $VERBOSE
end
after :each do
$stderr = @stderr
$VERBOSE = @verbose
end
it "prints a message to $stderr if $VERBOSE evaluates to true" do it "prints a message to $stderr if $VERBOSE evaluates to true" do
$VERBOSE = true -> {
@s.rb_warn("This is a warning") @s.rb_warn("This is a warning")
$stderr.should =~ /This is a warning/ }.should complain(/warning: This is a warning/, verbose: true)
end end
it "prints a message to $stderr if $VERBOSE evaluates to false" do it "prints a message to $stderr if $VERBOSE evaluates to false" do
$VERBOSE = false -> {
@s.rb_warn("This is a warning") @s.rb_warn("This is a warning")
$stderr.should =~ /This is a warning/ }.should complain(/warning: This is a warning/, verbose: false)
end end
end end
@ -197,13 +187,47 @@ describe "C-API Kernel function" do
it "raises an exception from the given error" do it "raises an exception from the given error" do
-> do -> do
@s.rb_syserr_fail(Errno::EINVAL::Errno, "additional info") @s.rb_syserr_fail(Errno::EINVAL::Errno, "additional info")
end.should raise_error(Errno::EINVAL, /additional info/) end.should raise_error(Errno::EINVAL, "Invalid argument - additional info")
end end
it "can take a NULL message" do it "can take a NULL message" do
-> do -> do
@s.rb_syserr_fail(Errno::EINVAL::Errno, nil) @s.rb_syserr_fail(Errno::EINVAL::Errno, nil)
end.should raise_error(Errno::EINVAL) end.should raise_error(Errno::EINVAL, "Invalid argument")
end
it "uses an 'unknown error' message when errno is unknown" do
platform_is_not :windows do
-> { @s.rb_syserr_fail(-10, nil) }.should raise_error(SystemCallError, /Unknown error(:)? -10/)
end
platform_is :windows do
-> { @s.rb_syserr_fail(-1, nil) }.should raise_error(SystemCallError, "The operation completed successfully.")
end
end
end
describe "rb_syserr_fail_str" do
it "raises an exception from the given error" do
-> do
@s.rb_syserr_fail_str(Errno::EINVAL::Errno, "additional info")
end.should raise_error(Errno::EINVAL, "Invalid argument - additional info")
end
it "can take nil as a message" do
-> do
@s.rb_syserr_fail_str(Errno::EINVAL::Errno, nil)
end.should raise_error(Errno::EINVAL, "Invalid argument")
end
it "uses an 'unknown error' message when errno is unknown" do
platform_is_not :windows do
-> { @s.rb_syserr_fail_str(-10, nil) }.should raise_error(SystemCallError, /Unknown error(:)? -10/)
end
platform_is :windows do
-> { @s.rb_syserr_fail_str(-1, nil) }.should raise_error(SystemCallError, "The operation completed successfully.")
end
end end
end end
@ -530,6 +554,40 @@ describe "C-API Kernel function" do
end end
end end
describe "rb_category_warn" do
it "emits a warning into stderr" do
Warning[:deprecated] = true
-> {
@s.rb_category_warn_deprecated
}.should complain(/warning: foo/, verbose: true)
end
it "supports printf format modifiers" do
Warning[:deprecated] = true
-> {
@s.rb_category_warn_deprecated_with_integer_extra_value(42)
}.should complain(/warning: foo 42/, verbose: true)
end
it "does not emits a warning when a category is disabled" do
Warning[:deprecated] = false
-> {
@s.rb_category_warn_deprecated
}.should_not complain(verbose: true)
end
it "does not emits a warning when $VERBOSE is nil" do
Warning[:deprecated] = true
-> {
@s.rb_category_warn_deprecated
}.should_not complain(verbose: nil)
end
end
describe "rb_ensure" do describe "rb_ensure" do
it "executes passed function and returns its value" do it "executes passed function and returns its value" do
proc = -> x { x } proc = -> x { x }
@ -868,4 +926,10 @@ describe "C-API Kernel function" do
@s.rb_check_funcall(object, :protected_method, []).should == :protected @s.rb_check_funcall(object, :protected_method, []).should == :protected
end end
end end
describe "rb_str_format" do
it "returns a string according to format and arguments" do
@s.rb_str_format(3, [10, 2.5, "test"], "%d %f %s").should == "10 2.500000 test"
end
end
end end

View File

@ -1265,6 +1265,51 @@ end
end end
end end
describe "rb_enc_interned_str" do
it "returns a frozen string" do
str = "hello"
val = @s.rb_enc_interned_str(str, str.bytesize, Encoding::US_ASCII)
val.should.is_a?(String)
val.encoding.should == Encoding::US_ASCII
val.should.frozen?
end
it "returns the same frozen string" do
str = "hello"
result1 = @s.rb_enc_interned_str(str, str.bytesize, Encoding::US_ASCII)
result2 = @s.rb_enc_interned_str(str, str.bytesize, Encoding::US_ASCII)
result1.should.equal?(result2)
end
it "returns different frozen strings for different encodings" do
str = "hello"
result1 = @s.rb_enc_interned_str(str, str.bytesize, Encoding::US_ASCII)
result2 = @s.rb_enc_interned_str(str, str.bytesize, Encoding::UTF_8)
result1.should_not.equal?(result2)
end
it 'returns the same string when using non-ascii characters' do
str = 'こんにちは'
result1 = @s.rb_enc_interned_str(str, str.bytesize, Encoding::UTF_8)
result2 = @s.rb_enc_interned_str(str, str.bytesize, Encoding::UTF_8)
result1.should.equal?(result2)
end
it "returns the same string as String#-@" do
str = "hello"
@s.rb_enc_interned_str(str, str.bytesize, Encoding::UTF_8).should.equal?(-str)
end
ruby_bug "#20322", ""..."3.4" do
it "uses the default encoding if encoding is null" do
str = "hello"
val = @s.rb_enc_interned_str(str, str.bytesize, nil)
val.encoding.should == Encoding::ASCII_8BIT
end
end
end
describe "rb_str_to_interned_str" do describe "rb_str_to_interned_str" do
it "returns a frozen string" do it "returns a frozen string" do
str = "hello" str = "hello"

View File

@ -23,31 +23,31 @@ describe :process_fork, shared: true do
end end
it "returns status zero" do it "returns status zero" do
pid = Process.fork { exit! 0 } pid = @object.fork { exit! 0 }
_, result = Process.wait2(pid) _, result = Process.wait2(pid)
result.exitstatus.should == 0 result.exitstatus.should == 0
end end
it "returns status zero" do it "returns status zero" do
pid = Process.fork { exit 0 } pid = @object.fork { exit 0 }
_, result = Process.wait2(pid) _, result = Process.wait2(pid)
result.exitstatus.should == 0 result.exitstatus.should == 0
end end
it "returns status zero" do it "returns status zero" do
pid = Process.fork {} pid = @object.fork {}
_, result = Process.wait2(pid) _, result = Process.wait2(pid)
result.exitstatus.should == 0 result.exitstatus.should == 0
end end
it "returns status non-zero" do it "returns status non-zero" do
pid = Process.fork { exit! 42 } pid = @object.fork { exit! 42 }
_, result = Process.wait2(pid) _, result = Process.wait2(pid)
result.exitstatus.should == 42 result.exitstatus.should == 42
end end
it "returns status non-zero" do it "returns status non-zero" do
pid = Process.fork { exit 42 } pid = @object.fork { exit 42 }
_, result = Process.wait2(pid) _, result = Process.wait2(pid)
result.exitstatus.should == 42 result.exitstatus.should == 42
end end

View File

@ -55,7 +55,7 @@ describe :end_with, shared: true do
it "checks that we are starting to match at the head of a character" do it "checks that we are starting to match at the head of a character" do
"\xC3\xA9".send(@method).should_not.end_with?("\xA9") "\xC3\xA9".send(@method).should_not.end_with?("\xA9")
"\xe3\x81\x82".send(@method).should_not.end_with?("\x82") "\xe3\x81\x82".send(@method).should_not.end_with?("\x82")
"ab".dup.force_encoding("UTF-16BE").send(@method).should_not.end_with?( "\xd8\x00\xdc\x00".dup.force_encoding("UTF-16BE").send(@method).should_not.end_with?(
"b".dup.force_encoding("UTF-16BE")) "\xdc\x00".dup.force_encoding("UTF-16BE"))
end end
end end