summaryrefslogtreecommitdiff
path: root/spec/ruby/core/symbol
diff options
context:
space:
mode:
Diffstat (limited to 'spec/ruby/core/symbol')
-rw-r--r--spec/ruby/core/symbol/case_compare_spec.rb8
-rw-r--r--spec/ruby/core/symbol/element_reference_spec.rb261
-rw-r--r--spec/ruby/core/symbol/id2name_spec.rb5
-rw-r--r--spec/ruby/core/symbol/intern_spec.rb8
-rw-r--r--spec/ruby/core/symbol/length_spec.rb21
-rw-r--r--spec/ruby/core/symbol/next_spec.rb5
-rw-r--r--spec/ruby/core/symbol/shared/id2name.rb30
-rw-r--r--spec/ruby/core/symbol/shared/length.rb23
-rw-r--r--spec/ruby/core/symbol/shared/slice.rb262
-rw-r--r--spec/ruby/core/symbol/shared/succ.rb18
-rw-r--r--spec/ruby/core/symbol/size_spec.rb5
-rw-r--r--spec/ruby/core/symbol/slice_spec.rb5
-rw-r--r--spec/ruby/core/symbol/succ_spec.rb16
-rw-r--r--spec/ruby/core/symbol/to_s_spec.rb30
-rw-r--r--spec/ruby/core/symbol/to_sym_spec.rb2
15 files changed, 337 insertions, 362 deletions
diff --git a/spec/ruby/core/symbol/case_compare_spec.rb b/spec/ruby/core/symbol/case_compare_spec.rb
index 0c6bc1eda5..a296132c04 100644
--- a/spec/ruby/core/symbol/case_compare_spec.rb
+++ b/spec/ruby/core/symbol/case_compare_spec.rb
@@ -1,11 +1,7 @@
require_relative '../../spec_helper'
describe "Symbol#===" do
- it "returns true when the argument is a Symbol" do
- (Symbol === :ruby).should == true
- end
-
- it "returns false when the argument is a String" do
- (Symbol === 'ruby').should == false
+ it "is an alias of Symbol#==" do
+ Symbol.instance_method(:===).should == Symbol.instance_method(:==)
end
end
diff --git a/spec/ruby/core/symbol/element_reference_spec.rb b/spec/ruby/core/symbol/element_reference_spec.rb
index df6bc15ddb..360a661891 100644
--- a/spec/ruby/core/symbol/element_reference_spec.rb
+++ b/spec/ruby/core/symbol/element_reference_spec.rb
@@ -1,6 +1,263 @@
require_relative '../../spec_helper'
-require_relative 'shared/slice'
+require_relative 'fixtures/classes'
describe "Symbol#[]" do
- it_behaves_like :symbol_slice, :[]
+ describe "with an Integer index" do
+ it "returns the character code of the element at the index" do
+ :symbol[1].should == ?y
+ end
+
+ it "returns nil if the index starts from the end and is greater than the length" do
+ :symbol[-10].should == nil
+ end
+
+ it "returns nil if the index is greater than the length" do
+ :symbol[42].should == nil
+ end
+ end
+
+ describe "with an Integer index and length" do
+ describe "and a positive index and length" do
+ it "returns a slice" do
+ :symbol[1, 3].should == "ymb"
+ end
+
+ it "returns a blank slice if the length is 0" do
+ :symbol[0, 0].should == ""
+ :symbol[1, 0].should == ""
+ end
+
+ it "returns a slice of all remaining characters if the given length is greater than the actual length" do
+ :symbol[1, 100].should == "ymbol"
+ end
+
+ it "returns nil if the index is greater than the length" do
+ :symbol[10, 1].should == nil
+ end
+ end
+
+ describe "and a positive index and negative length" do
+ it "returns nil" do
+ :symbol[0, -1].should == nil
+ :symbol[1, -1].should == nil
+ end
+ end
+
+ describe "and a negative index and positive length" do
+ it "returns a slice starting from the end upto the length" do
+ :symbol[-3, 2].should == "bo"
+ end
+
+ it "returns a blank slice if the length is 0" do
+ :symbol[-1, 0].should == ""
+ end
+
+ it "returns a slice of all remaining characters if the given length is larger than the actual length" do
+ :symbol[-4, 100].should == "mbol"
+ end
+
+ it "returns nil if the index is past the start" do
+ :symbol[-10, 1].should == nil
+ end
+ end
+
+ describe "and a negative index and negative length" do
+ it "returns nil" do
+ :symbol[-1, -1].should == nil
+ end
+ end
+
+ describe "and a Float length" do
+ it "converts the length to an Integer" do
+ :symbol[2, 2.5].should == "mb"
+ end
+ end
+
+ describe "and a nil length" do
+ it "raises a TypeError" do
+ -> { :symbol[1, nil] }.should.raise(TypeError)
+ end
+ end
+
+ describe "and a length that cannot be converted into an Integer" do
+ it "raises a TypeError when given an Array" do
+ -> { :symbol[1, Array.new] }.should.raise(TypeError)
+ end
+
+ it "raises a TypeError when given an Hash" do
+ -> { :symbol[1, Hash.new] }.should.raise(TypeError)
+ end
+
+ it "raises a TypeError when given an Object" do
+ -> { :symbol[1, Object.new] }.should.raise(TypeError)
+ end
+ end
+ end
+
+ describe "with a Float index" do
+ it "converts the index to an Integer" do
+ :symbol[1.5].should == ?y
+ end
+ end
+
+ describe "with a nil index" do
+ it "raises a TypeError" do
+ -> { :symbol[nil] }.should.raise(TypeError)
+ end
+ end
+
+ describe "with an index that cannot be converted into an Integer" do
+ it "raises a TypeError when given an Array" do
+ -> { :symbol[Array.new] }.should.raise(TypeError)
+ end
+
+ it "raises a TypeError when given an Hash" do
+ -> { :symbol[Hash.new] }.should.raise(TypeError)
+ end
+
+ it "raises a TypeError when given an Object" do
+ -> { :symbol[Object.new] }.should.raise(TypeError)
+ end
+ end
+
+ describe "with a Range slice" do
+ describe "that is within bounds" do
+ it "returns a slice if both range values begin at the start and are within bounds" do
+ :symbol[1..4].should == "ymbo"
+ end
+
+ it "returns a slice if the first range value begins at the start and the last begins at the end" do
+ :symbol[1..-1].should == "ymbol"
+ end
+
+ it "returns a slice if the first range value begins at the end and the last begins at the end" do
+ :symbol[-4..-1].should == "mbol"
+ end
+ end
+
+ describe "that is out of bounds" do
+ it "returns nil if the first range value begins past the end" do
+ :symbol[10..12].should == nil
+ end
+
+ it "returns a blank string if the first range value is within bounds and the last range value is not" do
+ :symbol[-2..-10].should == ""
+ :symbol[2..-10].should == ""
+ end
+
+ it "returns nil if the first range value starts from the end and is within bounds and the last value starts from the end and is greater than the length" do
+ :symbol[-10..-12].should == nil
+ end
+
+ it "returns nil if the first range value starts from the end and is out of bounds and the last value starts from the end and is less than the length" do
+ :symbol[-10..-2].should == nil
+ end
+ end
+
+ describe "with Float values" do
+ it "converts the first value to an Integer" do
+ :symbol[0.5..2].should == "sym"
+ end
+
+ it "converts the last value to an Integer" do
+ :symbol[0..2.5].should == "sym"
+ end
+ end
+ end
+
+ describe "with a Range subclass slice" do
+ it "returns a slice" do
+ range = SymbolSpecs::MyRange.new(1, 4)
+ :symbol[range].should == "ymbo"
+ end
+ end
+
+ describe "with a Regex slice" do
+ describe "without a capture index" do
+ it "returns a string of the match" do
+ :symbol[/[^bol]+/].should == "sym"
+ end
+
+ it "returns nil if the expression does not match" do
+ :symbol[/0-9/].should == nil
+ end
+
+ it "sets $~ to the MatchData if there is a match" do
+ :symbol[/[^bol]+/]
+ $~[0].should == "sym"
+ end
+
+ it "does not set $~ if there if there is not a match" do
+ :symbol[/[0-9]+/]
+ $~.should == nil
+ end
+ end
+
+ describe "with a capture index" do
+ it "returns a string of the complete match if the capture index is 0" do
+ :symbol[/(sy)(mb)(ol)/, 0].should == "symbol"
+ end
+
+ it "returns a string for the matched capture at the given index" do
+ :symbol[/(sy)(mb)(ol)/, 1].should == "sy"
+ :symbol[/(sy)(mb)(ol)/, -1].should == "ol"
+ end
+
+ it "returns nil if there is no capture for the index" do
+ :symbol[/(sy)(mb)(ol)/, 4].should == nil
+ :symbol[/(sy)(mb)(ol)/, -4].should == nil
+ end
+
+ it "converts the index to an Integer" do
+ :symbol[/(sy)(mb)(ol)/, 1.5].should == "sy"
+ end
+
+ describe "and an index that cannot be converted to an Integer" do
+ it "raises a TypeError when given an Hash" do
+ -> { :symbol[/(sy)(mb)(ol)/, Hash.new] }.should.raise(TypeError)
+ end
+
+ it "raises a TypeError when given an Array" do
+ -> { :symbol[/(sy)(mb)(ol)/, Array.new] }.should.raise(TypeError)
+ end
+
+ it "raises a TypeError when given an Object" do
+ -> { :symbol[/(sy)(mb)(ol)/, Object.new] }.should.raise(TypeError)
+ end
+ end
+
+ it "raises a TypeError if the index is nil" do
+ -> { :symbol[/(sy)(mb)(ol)/, nil] }.should.raise(TypeError)
+ end
+
+ it "sets $~ to the MatchData if there is a match" do
+ :symbol[/(sy)(mb)(ol)/, 0]
+ $~[0].should == "symbol"
+ $~[1].should == "sy"
+ $~[2].should == "mb"
+ $~[3].should == "ol"
+ end
+
+ it "does not set $~ to the MatchData if there is not a match" do
+ :symbol[/0-9/, 0]
+ $~.should == nil
+ end
+ end
+ end
+
+ describe "with a String slice" do
+ it "does not set $~" do
+ $~ = nil
+ :symbol["sym"]
+ $~.should == nil
+ end
+
+ it "returns a string if there is match" do
+ :symbol["ymb"].should == "ymb"
+ end
+
+ it "returns nil if there is not a match" do
+ :symbol["foo"].should == nil
+ end
+ end
end
diff --git a/spec/ruby/core/symbol/id2name_spec.rb b/spec/ruby/core/symbol/id2name_spec.rb
index 2caa89fc37..abcbff65f4 100644
--- a/spec/ruby/core/symbol/id2name_spec.rb
+++ b/spec/ruby/core/symbol/id2name_spec.rb
@@ -1,6 +1,7 @@
require_relative '../../spec_helper'
-require_relative 'shared/id2name'
describe "Symbol#id2name" do
- it_behaves_like :symbol_id2name, :id2name
+ it "is an alias of Symbol#to_s" do
+ Symbol.instance_method(:id2name).should == Symbol.instance_method(:to_s)
+ end
end
diff --git a/spec/ruby/core/symbol/intern_spec.rb b/spec/ruby/core/symbol/intern_spec.rb
index 9d0914c7fb..746d313d40 100644
--- a/spec/ruby/core/symbol/intern_spec.rb
+++ b/spec/ruby/core/symbol/intern_spec.rb
@@ -1,11 +1,7 @@
require_relative '../../spec_helper'
describe "Symbol#intern" do
- it "returns self" do
- :foo.intern.should == :foo
- end
-
- it "returns a Symbol" do
- :foo.intern.should.is_a?(Symbol)
+ it "is an alias of Symbol#to_sym" do
+ Symbol.instance_method(:intern).should == Symbol.instance_method(:to_sym)
end
end
diff --git a/spec/ruby/core/symbol/length_spec.rb b/spec/ruby/core/symbol/length_spec.rb
index 27bee575ef..29dd4ad46b 100644
--- a/spec/ruby/core/symbol/length_spec.rb
+++ b/spec/ruby/core/symbol/length_spec.rb
@@ -1,6 +1,23 @@
require_relative '../../spec_helper'
-require_relative 'shared/length'
describe "Symbol#length" do
- it_behaves_like :symbol_length, :length
+ it "returns 0 for empty name" do
+ :''.length.should == 0
+ end
+
+ it "returns 1 for name formed by a NUL character" do
+ :"\x00".length.should == 1
+ end
+
+ it "returns 3 for name formed by 3 ASCII characters" do
+ :one.length.should == 3
+ end
+
+ it "returns 4 for name formed by 4 ASCII characters" do
+ :four.length.should == 4
+ end
+
+ it "returns 4 for name formed by 1 multibyte and 3 ASCII characters" do
+ :"\xC3\x9Cber".length.should == 4
+ end
end
diff --git a/spec/ruby/core/symbol/next_spec.rb b/spec/ruby/core/symbol/next_spec.rb
index 97fe913739..e80bbaa508 100644
--- a/spec/ruby/core/symbol/next_spec.rb
+++ b/spec/ruby/core/symbol/next_spec.rb
@@ -1,6 +1,7 @@
require_relative '../../spec_helper'
-require_relative 'shared/succ'
describe "Symbol#next" do
- it_behaves_like :symbol_succ, :next
+ it "is an alias of Symbol#succ" do
+ Symbol.instance_method(:next).should == Symbol.instance_method(:succ)
+ end
end
diff --git a/spec/ruby/core/symbol/shared/id2name.rb b/spec/ruby/core/symbol/shared/id2name.rb
deleted file mode 100644
index 00a9c7d7dc..0000000000
--- a/spec/ruby/core/symbol/shared/id2name.rb
+++ /dev/null
@@ -1,30 +0,0 @@
-describe :symbol_id2name, shared: true do
- it "returns the string corresponding to self" do
- :rubinius.send(@method).should == "rubinius"
- :squash.send(@method).should == "squash"
- :[].send(@method).should == "[]"
- :@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
-
- ruby_version_is "3.4" do
- it "warns about mutating returned string" do
- -> { :bad!.send(@method).upcase! }.should complain(/warning: string returned by :bad!.to_s will be frozen in the future/)
- end
-
- it "does not warn about mutation when Warning[:deprecated] is false" do
- deprecated = Warning[:deprecated]
- Warning[:deprecated] = false
- -> { :bad!.send(@method).upcase! }.should_not complain
- ensure
- Warning[:deprecated] = deprecated
- end
- end
-end
diff --git a/spec/ruby/core/symbol/shared/length.rb b/spec/ruby/core/symbol/shared/length.rb
deleted file mode 100644
index 692e8c57e3..0000000000
--- a/spec/ruby/core/symbol/shared/length.rb
+++ /dev/null
@@ -1,23 +0,0 @@
-# -*- encoding: utf-8 -*-
-
-describe :symbol_length, shared: true do
- it "returns 0 for empty name" do
- :''.send(@method).should == 0
- end
-
- it "returns 1 for name formed by a NUL character" do
- :"\x00".send(@method).should == 1
- end
-
- it "returns 3 for name formed by 3 ASCII characters" do
- :one.send(@method).should == 3
- end
-
- it "returns 4 for name formed by 4 ASCII characters" do
- :four.send(@method).should == 4
- end
-
- it "returns 4 for name formed by 1 multibyte and 3 ASCII characters" do
- :"\xC3\x9Cber".send(@method).should == 4
- end
-end
diff --git a/spec/ruby/core/symbol/shared/slice.rb b/spec/ruby/core/symbol/shared/slice.rb
deleted file mode 100644
index 4e3a35240c..0000000000
--- a/spec/ruby/core/symbol/shared/slice.rb
+++ /dev/null
@@ -1,262 +0,0 @@
-require_relative '../fixtures/classes'
-
-describe :symbol_slice, shared: true do
- describe "with an Integer index" do
- it "returns the character code of the element at the index" do
- :symbol.send(@method, 1).should == ?y
- end
-
- it "returns nil if the index starts from the end and is greater than the length" do
- :symbol.send(@method, -10).should == nil
- end
-
- it "returns nil if the index is greater than the length" do
- :symbol.send(@method, 42).should == nil
- end
- end
-
- describe "with an Integer index and length" do
- describe "and a positive index and length" do
- it "returns a slice" do
- :symbol.send(@method, 1,3).should == "ymb"
- end
-
- it "returns a blank slice if the length is 0" do
- :symbol.send(@method, 0,0).should == ""
- :symbol.send(@method, 1,0).should == ""
- end
-
- it "returns a slice of all remaining characters if the given length is greater than the actual length" do
- :symbol.send(@method, 1,100).should == "ymbol"
- end
-
- it "returns nil if the index is greater than the length" do
- :symbol.send(@method, 10,1).should == nil
- end
- end
-
- describe "and a positive index and negative length" do
- it "returns nil" do
- :symbol.send(@method, 0,-1).should == nil
- :symbol.send(@method, 1,-1).should == nil
- end
- end
-
- describe "and a negative index and positive length" do
- it "returns a slice starting from the end upto the length" do
- :symbol.send(@method, -3,2).should == "bo"
- end
-
- it "returns a blank slice if the length is 0" do
- :symbol.send(@method, -1,0).should == ""
- end
-
- it "returns a slice of all remaining characters if the given length is larger than the actual length" do
- :symbol.send(@method, -4,100).should == "mbol"
- end
-
- it "returns nil if the index is past the start" do
- :symbol.send(@method, -10,1).should == nil
- end
- end
-
- describe "and a negative index and negative length" do
- it "returns nil" do
- :symbol.send(@method, -1,-1).should == nil
- end
- end
-
- describe "and a Float length" do
- it "converts the length to an Integer" do
- :symbol.send(@method, 2,2.5).should == "mb"
- end
- end
-
- describe "and a nil length" do
- it "raises a TypeError" do
- -> { :symbol.send(@method, 1,nil) }.should.raise(TypeError)
- end
- end
-
- describe "and a length that cannot be converted into an Integer" do
- it "raises a TypeError when given an Array" do
- -> { :symbol.send(@method, 1,Array.new) }.should.raise(TypeError)
- end
-
- it "raises a TypeError when given an Hash" do
- -> { :symbol.send(@method, 1,Hash.new) }.should.raise(TypeError)
- end
-
- it "raises a TypeError when given an Object" do
- -> { :symbol.send(@method, 1,Object.new) }.should.raise(TypeError)
- end
- end
- end
-
- describe "with a Float index" do
- it "converts the index to an Integer" do
- :symbol.send(@method, 1.5).should == ?y
- end
- end
-
- describe "with a nil index" do
- it "raises a TypeError" do
- -> { :symbol.send(@method, nil) }.should.raise(TypeError)
- end
- end
-
- describe "with an index that cannot be converted into an Integer" do
- it "raises a TypeError when given an Array" do
- -> { :symbol.send(@method, Array.new) }.should.raise(TypeError)
- end
-
- it "raises a TypeError when given an Hash" do
- -> { :symbol.send(@method, Hash.new) }.should.raise(TypeError)
- end
-
- it "raises a TypeError when given an Object" do
- -> { :symbol.send(@method, Object.new) }.should.raise(TypeError)
- end
- end
-
- describe "with a Range slice" do
- describe "that is within bounds" do
- it "returns a slice if both range values begin at the start and are within bounds" do
- :symbol.send(@method, 1..4).should == "ymbo"
- end
-
- it "returns a slice if the first range value begins at the start and the last begins at the end" do
- :symbol.send(@method, 1..-1).should == "ymbol"
- end
-
- it "returns a slice if the first range value begins at the end and the last begins at the end" do
- :symbol.send(@method, -4..-1).should == "mbol"
- end
- end
-
- describe "that is out of bounds" do
- it "returns nil if the first range value begins past the end" do
- :symbol.send(@method, 10..12).should == nil
- end
-
- it "returns a blank string if the first range value is within bounds and the last range value is not" do
- :symbol.send(@method, -2..-10).should == ""
- :symbol.send(@method, 2..-10).should == ""
- end
-
- it "returns nil if the first range value starts from the end and is within bounds and the last value starts from the end and is greater than the length" do
- :symbol.send(@method, -10..-12).should == nil
- end
-
- it "returns nil if the first range value starts from the end and is out of bounds and the last value starts from the end and is less than the length" do
- :symbol.send(@method, -10..-2).should == nil
- end
- end
-
- describe "with Float values" do
- it "converts the first value to an Integer" do
- :symbol.send(@method, 0.5..2).should == "sym"
- end
-
- it "converts the last value to an Integer" do
- :symbol.send(@method, 0..2.5).should == "sym"
- end
- end
- end
-
- describe "with a Range subclass slice" do
- it "returns a slice" do
- range = SymbolSpecs::MyRange.new(1, 4)
- :symbol.send(@method, range).should == "ymbo"
- end
- end
-
- describe "with a Regex slice" do
- describe "without a capture index" do
- it "returns a string of the match" do
- :symbol.send(@method, /[^bol]+/).should == "sym"
- end
-
- it "returns nil if the expression does not match" do
- :symbol.send(@method, /0-9/).should == nil
- end
-
- it "sets $~ to the MatchData if there is a match" do
- :symbol.send(@method, /[^bol]+/)
- $~[0].should == "sym"
- end
-
- it "does not set $~ if there if there is not a match" do
- :symbol.send(@method, /[0-9]+/)
- $~.should == nil
- end
- end
-
- describe "with a capture index" do
- it "returns a string of the complete match if the capture index is 0" do
- :symbol.send(@method, /(sy)(mb)(ol)/, 0).should == "symbol"
- end
-
- it "returns a string for the matched capture at the given index" do
- :symbol.send(@method, /(sy)(mb)(ol)/, 1).should == "sy"
- :symbol.send(@method, /(sy)(mb)(ol)/, -1).should == "ol"
- end
-
- it "returns nil if there is no capture for the index" do
- :symbol.send(@method, /(sy)(mb)(ol)/, 4).should == nil
- :symbol.send(@method, /(sy)(mb)(ol)/, -4).should == nil
- end
-
- it "converts the index to an Integer" do
- :symbol.send(@method, /(sy)(mb)(ol)/, 1.5).should == "sy"
- 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(TypeError)
- end
-
- it "raises a TypeError when given an Array" do
- -> { :symbol.send(@method, /(sy)(mb)(ol)/, Array.new) }.should.raise(TypeError)
- end
-
- it "raises a TypeError when given an Object" do
- -> { :symbol.send(@method, /(sy)(mb)(ol)/, Object.new) }.should.raise(TypeError)
- end
- end
-
- it "raises a TypeError if the index is nil" do
- -> { :symbol.send(@method, /(sy)(mb)(ol)/, nil) }.should.raise(TypeError)
- end
-
- it "sets $~ to the MatchData if there is a match" do
- :symbol.send(@method, /(sy)(mb)(ol)/, 0)
- $~[0].should == "symbol"
- $~[1].should == "sy"
- $~[2].should == "mb"
- $~[3].should == "ol"
- end
-
- it "does not set $~ to the MatchData if there is not a match" do
- :symbol.send(@method, /0-9/, 0)
- $~.should == nil
- end
- end
- end
-
- describe "with a String slice" do
- it "does not set $~" do
- $~ = nil
- :symbol.send(@method, "sym")
- $~.should == nil
- end
-
- it "returns a string if there is match" do
- :symbol.send(@method, "ymb").should == "ymb"
- end
-
- it "returns nil if there is not a match" do
- :symbol.send(@method, "foo").should == nil
- end
- end
-end
diff --git a/spec/ruby/core/symbol/shared/succ.rb b/spec/ruby/core/symbol/shared/succ.rb
deleted file mode 100644
index dde298207e..0000000000
--- a/spec/ruby/core/symbol/shared/succ.rb
+++ /dev/null
@@ -1,18 +0,0 @@
-require_relative '../../../spec_helper'
-
-describe :symbol_succ, shared: true do
- it "returns a successor" do
- :abcd.send(@method).should == :abce
- :THX1138.send(@method).should == :THX1139
- end
-
- it "propagates a 'carry'" do
- :"1999zzz".send(@method).should == :"2000aaa"
- :ZZZ9999.send(@method).should == :AAAA0000
- end
-
- it "increments non-alphanumeric characters when no alphanumeric characters are present" do
- :"<<koala>>".send(@method).should == :"<<koalb>>"
- :"***".send(@method).should == :"**+"
- end
-end
diff --git a/spec/ruby/core/symbol/size_spec.rb b/spec/ruby/core/symbol/size_spec.rb
index 5e2aa8d4d2..b5d375b3aa 100644
--- a/spec/ruby/core/symbol/size_spec.rb
+++ b/spec/ruby/core/symbol/size_spec.rb
@@ -1,6 +1,7 @@
require_relative '../../spec_helper'
-require_relative 'shared/length'
describe "Symbol#size" do
- it_behaves_like :symbol_length, :size
+ it "is an alias of Symbol#length" do
+ Symbol.instance_method(:size).should == Symbol.instance_method(:length)
+ end
end
diff --git a/spec/ruby/core/symbol/slice_spec.rb b/spec/ruby/core/symbol/slice_spec.rb
index d2421c474c..050a2cf38c 100644
--- a/spec/ruby/core/symbol/slice_spec.rb
+++ b/spec/ruby/core/symbol/slice_spec.rb
@@ -1,6 +1,7 @@
require_relative '../../spec_helper'
-require_relative 'shared/slice'
describe "Symbol#slice" do
- it_behaves_like :symbol_slice, :slice
+ it "is an alias of Symbol#[]" do
+ Symbol.instance_method(:slice).should == Symbol.instance_method(:[])
+ end
end
diff --git a/spec/ruby/core/symbol/succ_spec.rb b/spec/ruby/core/symbol/succ_spec.rb
index 694bfff862..893164a2a6 100644
--- a/spec/ruby/core/symbol/succ_spec.rb
+++ b/spec/ruby/core/symbol/succ_spec.rb
@@ -1,6 +1,18 @@
require_relative '../../spec_helper'
-require_relative 'shared/succ'
describe "Symbol#succ" do
- it_behaves_like :symbol_succ, :succ
+ it "returns a successor" do
+ :abcd.succ.should == :abce
+ :THX1138.succ.should == :THX1139
+ end
+
+ it "propagates a 'carry'" do
+ :"1999zzz".succ.should == :"2000aaa"
+ :ZZZ9999.succ.should == :AAAA0000
+ end
+
+ it "increments non-alphanumeric characters when no alphanumeric characters are present" do
+ :"<<koala>>".succ.should == :"<<koalb>>"
+ :"***".succ.should == :"**+"
+ end
end
diff --git a/spec/ruby/core/symbol/to_s_spec.rb b/spec/ruby/core/symbol/to_s_spec.rb
index cd963faa28..2cb57c4cbc 100644
--- a/spec/ruby/core/symbol/to_s_spec.rb
+++ b/spec/ruby/core/symbol/to_s_spec.rb
@@ -1,6 +1,32 @@
require_relative '../../spec_helper'
-require_relative 'shared/id2name'
describe "Symbol#to_s" do
- it_behaves_like :symbol_id2name, :to_s
+ it "returns the string corresponding to self" do
+ :rubinius.to_s.should == "rubinius"
+ :squash.to_s.should == "squash"
+ :[].to_s.should == "[]"
+ :@ruby.to_s.should == "@ruby"
+ :@@ruby.to_s.should == "@@ruby"
+ end
+
+ it "returns a String in the same encoding as self" do
+ string = "ruby".encode("US-ASCII")
+ symbol = string.to_sym
+
+ symbol.to_s.encoding.should == Encoding::US_ASCII
+ end
+
+ ruby_version_is "3.4" do
+ it "warns about mutating returned string" do
+ -> { :bad!.to_s.upcase! }.should complain(/warning: string returned by :bad!.to_s will be frozen in the future/)
+ end
+
+ it "does not warn about mutation when Warning[:deprecated] is false" do
+ deprecated = Warning[:deprecated]
+ Warning[:deprecated] = false
+ -> { :bad!.to_s.upcase! }.should_not complain
+ ensure
+ Warning[:deprecated] = deprecated
+ end
+ end
end
diff --git a/spec/ruby/core/symbol/to_sym_spec.rb b/spec/ruby/core/symbol/to_sym_spec.rb
index e75f3d48a8..062daa3fc7 100644
--- a/spec/ruby/core/symbol/to_sym_spec.rb
+++ b/spec/ruby/core/symbol/to_sym_spec.rb
@@ -3,7 +3,7 @@ require_relative '../../spec_helper'
describe "Symbol#to_sym" do
it "returns self" do
[:rubinius, :squash, :[], :@ruby, :@@ruby].each do |sym|
- sym.to_sym.should == sym
+ sym.to_sym.should.equal?(sym)
end
end
end