diff options
Diffstat (limited to 'spec/ruby/core/symbol')
-rw-r--r-- | spec/ruby/core/symbol/casecmp_spec.rb | 8 | ||||
-rw-r--r-- | spec/ruby/core/symbol/end_with_spec.rb | 6 | ||||
-rw-r--r-- | spec/ruby/core/symbol/inspect_spec.rb | 2 | ||||
-rw-r--r-- | spec/ruby/core/symbol/name_spec.rb | 24 | ||||
-rw-r--r-- | spec/ruby/core/symbol/shared/id2name.rb | 7 | ||||
-rw-r--r-- | spec/ruby/core/symbol/shared/slice.rb | 20 | ||||
-rw-r--r-- | spec/ruby/core/symbol/start_with_spec.rb | 6 | ||||
-rw-r--r-- | spec/ruby/core/symbol/to_proc_spec.rb | 62 |
8 files changed, 68 insertions, 67 deletions
diff --git a/spec/ruby/core/symbol/casecmp_spec.rb b/spec/ruby/core/symbol/casecmp_spec.rb index 80ea51e910..662a29a284 100644 --- a/spec/ruby/core/symbol/casecmp_spec.rb +++ b/spec/ruby/core/symbol/casecmp_spec.rb @@ -56,6 +56,10 @@ describe "Symbol#casecmp with Symbol" do lower_a_tilde.casecmp(upper_a_tilde).should == 1 lower_a_umlaut.casecmp(upper_a_umlaut).should == 1 end + + it "returns 0 for empty strings in different encodings" do + ''.to_sym.casecmp(''.encode("UTF-32LE").to_sym).should == 0 + end end describe "Symbol#casecmp" do @@ -141,4 +145,8 @@ describe 'Symbol#casecmp?' do upper_a_tilde.casecmp?(lower_a_tilde).should == nil lower_a_tilde.casecmp?(upper_a_tilde).should == nil end + + it "returns true for empty symbols in different encodings" do + ''.to_sym.should.casecmp?(''.encode("UTF-32LE").to_sym) + end end diff --git a/spec/ruby/core/symbol/end_with_spec.rb b/spec/ruby/core/symbol/end_with_spec.rb index 77dc4caf71..4b9f5a4996 100644 --- a/spec/ruby/core/symbol/end_with_spec.rb +++ b/spec/ruby/core/symbol/end_with_spec.rb @@ -3,8 +3,6 @@ require_relative '../../spec_helper' require_relative '../../shared/string/end_with' -ruby_version_is "2.7" do - describe "Symbol#end_with?" do - it_behaves_like :end_with, :to_sym - end +describe "Symbol#end_with?" do + it_behaves_like :end_with, :to_sym end diff --git a/spec/ruby/core/symbol/inspect_spec.rb b/spec/ruby/core/symbol/inspect_spec.rb index 58402ab261..6dbb36c2ad 100644 --- a/spec/ruby/core/symbol/inspect_spec.rb +++ b/spec/ruby/core/symbol/inspect_spec.rb @@ -5,6 +5,8 @@ describe "Symbol#inspect" do fred: ":fred", :fred? => ":fred?", :fred! => ":fred!", + :BAD! => ":BAD!", + :_BAD! => ":_BAD!", :$ruby => ":$ruby", :@ruby => ":@ruby", :@@ruby => ":@@ruby", diff --git a/spec/ruby/core/symbol/name_spec.rb b/spec/ruby/core/symbol/name_spec.rb index 15b9aa75e9..f9b631266c 100644 --- a/spec/ruby/core/symbol/name_spec.rb +++ b/spec/ruby/core/symbol/name_spec.rb @@ -1,19 +1,17 @@ require_relative '../../spec_helper' -ruby_version_is "3.0" do - describe "Symbol#name" do - it "returns string" do - :ruby.name.should == "ruby" - :ルビー.name.should == "ルビー" - end +describe "Symbol#name" do + it "returns string" do + :ruby.name.should == "ruby" + :ルビー.name.should == "ルビー" + end - it "returns same string instance" do - :"ruby_3".name.should.equal?(:ruby_3.name) - :"ruby_#{1+2}".name.should.equal?(:ruby_3.name) - end + it "returns same string instance" do + :"ruby_3".name.should.equal?(:ruby_3.name) + :"ruby_#{1+2}".name.should.equal?(:ruby_3.name) + end - it "returns frozen string" do - :symbol.name.should.frozen? - end + it "returns frozen string" do + :symbol.name.should.frozen? end end diff --git a/spec/ruby/core/symbol/shared/id2name.rb b/spec/ruby/core/symbol/shared/id2name.rb index 47f97bd332..d012b7634e 100644 --- a/spec/ruby/core/symbol/shared/id2name.rb +++ b/spec/ruby/core/symbol/shared/id2name.rb @@ -6,4 +6,11 @@ describe :symbol_id2name, shared: true do :@ruby.send(@method).should == "@ruby" :@@ruby.send(@method).should == "@@ruby" end + + it "returns a String in the same encoding as self" do + string = "ruby".encode("US-ASCII") + symbol = string.to_sym + + symbol.send(@method).encoding.should == Encoding::US_ASCII + end end diff --git a/spec/ruby/core/symbol/shared/slice.rb b/spec/ruby/core/symbol/shared/slice.rb index 3f07f6aedb..0df87e183d 100644 --- a/spec/ruby/core/symbol/shared/slice.rb +++ b/spec/ruby/core/symbol/shared/slice.rb @@ -190,16 +190,6 @@ describe :symbol_slice, shared: true do :symbol.send(@method, /[0-9]+/) $~.should be_nil end - - ruby_version_is ''...'2.7' do - it "returns a tainted string if the regexp is tainted" do - :symbol.send(@method, /./.taint).tainted?.should be_true - end - - it "returns an untrusted string if the regexp is untrusted" do - :symbol.send(@method, /./.untrust).untrusted?.should be_true - end - end end describe "with a capture index" do @@ -221,16 +211,6 @@ describe :symbol_slice, shared: true do :symbol.send(@method, /(sy)(mb)(ol)/, 1.5).should == "sy" end - ruby_version_is ''...'2.7' do - it "returns a tainted string if the regexp is tainted" do - :symbol.send(@method, /(.)/.taint, 1).tainted?.should be_true - end - - it "returns an untrusted string if the regexp is untrusted" do - :symbol.send(@method, /(.)/.untrust, 1).untrusted?.should be_true - end - end - describe "and an index that cannot be converted to an Integer" do it "raises a TypeError when given an Hash" do -> { :symbol.send(@method, /(sy)(mb)(ol)/, Hash.new) }.should raise_error(TypeError) diff --git a/spec/ruby/core/symbol/start_with_spec.rb b/spec/ruby/core/symbol/start_with_spec.rb index f54b3e499e..cd43279003 100644 --- a/spec/ruby/core/symbol/start_with_spec.rb +++ b/spec/ruby/core/symbol/start_with_spec.rb @@ -3,8 +3,6 @@ require_relative '../../spec_helper' require_relative 'fixtures/classes' require_relative '../../shared/string/start_with' -ruby_version_is "2.7" do - describe "Symbol#start_with?" do - it_behaves_like :start_with, :to_sym - end +describe "Symbol#start_with?" do + it_behaves_like :start_with, :to_sym end diff --git a/spec/ruby/core/symbol/to_proc_spec.rb b/spec/ruby/core/symbol/to_proc_spec.rb index e9261e6cdf..54eccdba11 100644 --- a/spec/ruby/core/symbol/to_proc_spec.rb +++ b/spec/ruby/core/symbol/to_proc_spec.rb @@ -12,42 +12,52 @@ describe "Symbol#to_proc" do :to_s.to_proc.call(obj).should == "Received #to_s" end - ruby_version_is ""..."3.0" do - it "returns a Proc with #lambda? false" do - pr = :to_s.to_proc - pr.should_not.lambda? - end + it "returns a Proc with #lambda? true" do + pr = :to_s.to_proc + pr.should.lambda? + end - it "produces a Proc with arity -1" do - pr = :to_s.to_proc - pr.arity.should == -1 - end + it "produces a Proc with arity -2" do + pr = :to_s.to_proc + pr.arity.should == -2 + end - it "produces a Proc that always returns [[:rest]] for #parameters" do - pr = :to_s.to_proc - pr.parameters.should == [[:rest]] - end + it "produces a Proc that always returns [[:req], [:rest]] for #parameters" do + pr = :to_s.to_proc + pr.parameters.should == [[:req], [:rest]] end - ruby_version_is "3.0" do - it "returns a Proc with #lambda? true" do - pr = :to_s.to_proc - pr.should.lambda? - end + ruby_version_is "3.2" do + it "only calls public methods" do + body = proc do + public def pub; @a << :pub end + protected def pro; @a << :pro end + private def pri; @a << :pri end + attr_reader :a + end - it "produces a Proc with arity -2" do - pr = :to_s.to_proc - pr.arity.should == -2 - end + @a = [] + singleton_class.class_eval(&body) + tap(&:pub) + proc{tap(&:pro)}.should raise_error(NoMethodError, /protected method [`']pro' called/) + proc{tap(&:pri)}.should raise_error(NoMethodError, /private method [`']pri' called/) + @a.should == [:pub] - it "produces a Proc that always returns [[:req], [:rest]] for #parameters" do - pr = :to_s.to_proc - pr.parameters.should == [[:req], [:rest]] + @a = [] + c = Class.new(&body) + o = c.new + o.instance_variable_set(:@a, []) + o.tap(&:pub) + proc{tap(&:pro)}.should raise_error(NoMethodError, /protected method [`']pro' called/) + proc{o.tap(&:pri)}.should raise_error(NoMethodError, /private method [`']pri' called/) + o.a.should == [:pub] end end it "raises an ArgumentError when calling #call on the Proc without receiver" do - -> { :object_id.to_proc.call }.should raise_error(ArgumentError, "no receiver given") + -> { + :object_id.to_proc.call + }.should raise_error(ArgumentError, /no receiver given|wrong number of arguments \(given 0, expected 1\+\)/) end it "passes along the block passed to Proc#call" do |