summaryrefslogtreecommitdiff
path: root/spec/ruby/language
diff options
context:
space:
mode:
authorBenoit Daloze <eregontp@gmail.com>2020-03-28 00:22:51 +0100
committerBenoit Daloze <eregontp@gmail.com>2020-03-28 00:22:51 +0100
commitf234d51eaba861edea925eabb564a0bee41b96a0 (patch)
tree3334f36a91fe81ec704f2980ab169231f52c41d0 /spec/ruby/language
parent296f68816cf575b3ff920f92aec8a4109a7d81d4 (diff)
Update to ruby/spec@ec84479
Diffstat (limited to 'spec/ruby/language')
-rw-r--r--spec/ruby/language/predefined_spec.rb15
-rw-r--r--spec/ruby/language/regexp/encoding_spec.rb12
-rw-r--r--spec/ruby/language/string_spec.rb22
3 files changed, 29 insertions, 20 deletions
diff --git a/spec/ruby/language/predefined_spec.rb b/spec/ruby/language/predefined_spec.rb
index e9fce1c358..970071eccd 100644
--- a/spec/ruby/language/predefined_spec.rb
+++ b/spec/ruby/language/predefined_spec.rb
@@ -399,15 +399,18 @@ describe "Predefined global $!" do
end
it "should be cleared when an exception is rescued even when a non-local return from block" do
- [ 1 ].each do
- begin
- raise StandardError.new('err')
- rescue => e
- $!.should == e
- return
+ def foo
+ [ 1 ].each do
+ begin
+ raise StandardError.new('err')
+ rescue => e
+ $!.should == e
+ return
+ end
end
end
+ foo
$!.should == nil
end
diff --git a/spec/ruby/language/regexp/encoding_spec.rb b/spec/ruby/language/regexp/encoding_spec.rb
index b8559c6b27..2db09fdda8 100644
--- a/spec/ruby/language/regexp/encoding_spec.rb
+++ b/spec/ruby/language/regexp/encoding_spec.rb
@@ -116,4 +116,16 @@ describe "Regexps with encoding modifiers" do
it "raises Encoding::CompatibilityError when trying =~ against different encodings" do
-> { /\A[[:space:]]*\z/ =~ " ".encode("UTF-16LE") }.should raise_error(Encoding::CompatibilityError)
end
+
+ it "computes the Regexp Encoding for each interpolated Regexp instance" do
+ make_regexp = -> str { /#{str}/ }
+
+ r = make_regexp.call("été".force_encoding(Encoding::UTF_8))
+ r.fixed_encoding?.should == true
+ r.encoding.should == Encoding::UTF_8
+
+ r = make_regexp.call("abc".force_encoding(Encoding::UTF_8))
+ r.fixed_encoding?.should == false
+ r.encoding.should == Encoding::US_ASCII
+ end
end
diff --git a/spec/ruby/language/string_spec.rb b/spec/ruby/language/string_spec.rb
index d0f62ff3c9..68c5fd221b 100644
--- a/spec/ruby/language/string_spec.rb
+++ b/spec/ruby/language/string_spec.rb
@@ -260,24 +260,18 @@ describe "Ruby String literals" do
end
describe "Ruby String interpolation" do
- it "creates a String having an Encoding compatible with all components" do
- a = "\u3042"
- b = "abc".encode("binary")
-
- str = "#{a} x #{b}"
-
- str.should == "\xe3\x81\x82\x20\x78\x20\x61\x62\x63".force_encoding("utf-8")
- str.encoding.should == Encoding::UTF_8
+ it "returns a string with the source encoding by default" do
+ "a#{"b"}c".encoding.should == Encoding::BINARY
+ eval('"a#{"b"}c"'.force_encoding("us-ascii")).encoding.should == Encoding::US_ASCII
+ eval("# coding: US-ASCII \n 'a#{"b"}c'").encoding.should == Encoding::US_ASCII
end
- it "creates a String having the Encoding of the components when all are the same Encoding" do
+ it "returns a string with the source encoding, even if the components have another encoding" do
a = "abc".force_encoding("euc-jp")
- b = "def".force_encoding("euc-jp")
- str = '"#{a} x #{b}"'.force_encoding("euc-jp")
+ "#{a}".encoding.should == Encoding::BINARY
- result = eval(str)
- result.should == "\x61\x62\x63\x20\x78\x20\x64\x65\x66".force_encoding("euc-jp")
- result.encoding.should == Encoding::EUC_JP
+ b = "abc".encode("utf-8")
+ "#{b}".encoding.should == Encoding::BINARY
end
it "raises an Encoding::CompatibilityError if the Encodings are not compatible" do