diff options
author | eregon <eregon@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2017-12-01 15:41:50 +0000 |
---|---|---|
committer | eregon <eregon@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2017-12-01 15:41:50 +0000 |
commit | 4d7b0b9112f2adf9e87ef75056f930bf7c1f3dc4 (patch) | |
tree | 8d712e18a619a9720d181d0d44e8cc2474ff31ee /spec/ruby/core/kernel/shared/sprintf_encoding.rb | |
parent | 821d9a2d30f2e0d3f9009dc001b4b49aaa63c66e (diff) |
Update to ruby/spec@bacedc5
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@60973 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'spec/ruby/core/kernel/shared/sprintf_encoding.rb')
-rw-r--r-- | spec/ruby/core/kernel/shared/sprintf_encoding.rb | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/spec/ruby/core/kernel/shared/sprintf_encoding.rb b/spec/ruby/core/kernel/shared/sprintf_encoding.rb new file mode 100644 index 0000000000..a92f3c10cd --- /dev/null +++ b/spec/ruby/core/kernel/shared/sprintf_encoding.rb @@ -0,0 +1,28 @@ +describe :kernel_sprintf_encoding, shared: true do + def format(*args) + @method.call(*args) + end + + it "returns a String in the same encoding as the format String if compatible" do + string = "%s".force_encoding(Encoding::KOI8_U) + result = format(string, "dogs") + result.encoding.should equal(Encoding::KOI8_U) + end + + it "returns a String in the argument's encoding if format encoding is more restrictive" do + string = "foo %s".force_encoding(Encoding::US_ASCII) + argument = "b\303\274r".force_encoding(Encoding::UTF_8) + + result = format(string, argument) + result.encoding.should equal(Encoding::UTF_8) + end + + it "raises Encoding::CompatibilityError if both encodings are ASCII compatible and there ano not ASCII characters" do + string = "Ä %s".encode('windows-1252') + argument = "Ђ".encode('windows-1251') + + -> () { + format(string, argument) + }.should raise_error(Encoding::CompatibilityError) + end +end |