aboutsummaryrefslogtreecommitdiffstats
path: root/spec/rubyspec/core/symbol
diff options
context:
space:
mode:
Diffstat (limited to 'spec/rubyspec/core/symbol')
-rw-r--r--spec/rubyspec/core/symbol/all_symbols_spec.rb14
-rw-r--r--spec/rubyspec/core/symbol/capitalize_spec.rb49
-rw-r--r--spec/rubyspec/core/symbol/case_compare_spec.rb11
-rw-r--r--spec/rubyspec/core/symbol/casecmp_spec.rb74
-rw-r--r--spec/rubyspec/core/symbol/comparison_spec.rb51
-rw-r--r--spec/rubyspec/core/symbol/downcase_spec.rb26
-rw-r--r--spec/rubyspec/core/symbol/element_reference_spec.rb6
-rw-r--r--spec/rubyspec/core/symbol/empty_spec.rb11
-rw-r--r--spec/rubyspec/core/symbol/encoding_spec.rb23
-rw-r--r--spec/rubyspec/core/symbol/equal_value_spec.rb14
-rw-r--r--spec/rubyspec/core/symbol/fixtures/classes.rb3
-rw-r--r--spec/rubyspec/core/symbol/id2name_spec.rb6
-rw-r--r--spec/rubyspec/core/symbol/inspect_spec.rb105
-rw-r--r--spec/rubyspec/core/symbol/intern_spec.rb11
-rw-r--r--spec/rubyspec/core/symbol/length_spec.rb6
-rw-r--r--spec/rubyspec/core/symbol/match_spec.rb70
-rw-r--r--spec/rubyspec/core/symbol/next_spec.rb6
-rw-r--r--spec/rubyspec/core/symbol/shared/id2name.rb9
-rw-r--r--spec/rubyspec/core/symbol/shared/length.rb23
-rw-r--r--spec/rubyspec/core/symbol/shared/slice.rb278
-rw-r--r--spec/rubyspec/core/symbol/shared/succ.rb18
-rw-r--r--spec/rubyspec/core/symbol/size_spec.rb6
-rw-r--r--spec/rubyspec/core/symbol/slice_spec.rb6
-rw-r--r--spec/rubyspec/core/symbol/succ_spec.rb6
-rw-r--r--spec/rubyspec/core/symbol/swapcase_spec.rb34
-rw-r--r--spec/rubyspec/core/symbol/symbol_spec.rb7
-rw-r--r--spec/rubyspec/core/symbol/to_proc_spec.rb41
-rw-r--r--spec/rubyspec/core/symbol/to_s_spec.rb6
-rw-r--r--spec/rubyspec/core/symbol/to_sym_spec.rb9
-rw-r--r--spec/rubyspec/core/symbol/upcase_spec.rb22
30 files changed, 951 insertions, 0 deletions
diff --git a/spec/rubyspec/core/symbol/all_symbols_spec.rb b/spec/rubyspec/core/symbol/all_symbols_spec.rb
new file mode 100644
index 0000000000..d18d58ba48
--- /dev/null
+++ b/spec/rubyspec/core/symbol/all_symbols_spec.rb
@@ -0,0 +1,14 @@
+require File.expand_path('../../../spec_helper', __FILE__)
+
+describe "Symbol.all_symbols" do
+ it "returns an array containing all the Symbols in the symbol table" do
+ all_symbols = Symbol.all_symbols
+ all_symbols.should be_an_instance_of(Array)
+ all_symbols.all? { |s| s.is_a?(Symbol) ? true : (p s; false) }.should == true
+ end
+
+ it "returns an Array containing Symbols that have been created" do
+ symbol = "symbol_specs_#{rand(5_000_000)}".to_sym
+ Symbol.all_symbols.should include(symbol)
+ end
+end
diff --git a/spec/rubyspec/core/symbol/capitalize_spec.rb b/spec/rubyspec/core/symbol/capitalize_spec.rb
new file mode 100644
index 0000000000..cf7e8a007f
--- /dev/null
+++ b/spec/rubyspec/core/symbol/capitalize_spec.rb
@@ -0,0 +1,49 @@
+# -*- encoding: utf-8 -*-
+require File.expand_path('../../../spec_helper', __FILE__)
+
+describe "Symbol#capitalize" do
+ it "returns a Symbol" do
+ :glark.capitalize.should be_an_instance_of(Symbol)
+ end
+
+ it "converts the first character to uppercase if it is ASCII" do
+ :lower.capitalize.should == :Lower
+ end
+
+ it "leaves the first character alone if it is not an alphabetical character" do
+ :"£1.20".capitalize.should == :"£1.20"
+ end
+
+ ruby_version_is ''...'2.4' do
+ it "leaves the first character alone if it is not an alphabetical ASCII character" do
+ "\u{00DE}c".to_sym.capitalize.should == :"Þc"
+ "\u{00DF}C".to_sym.capitalize.should == :"ßc"
+ end
+ end
+
+ it "converts subsequent uppercase ASCII characters to their lowercase equivalents" do
+ :lOWER.capitalize.should == :Lower
+ end
+
+ it "leaves ASCII characters already in the correct case as they were" do
+ :Title.capitalize.should == :Title
+ end
+
+ it "works with both upper- and lowercase ASCII characters in the same Symbol" do
+ :mIxEd.capitalize.should == :Mixed
+ end
+
+ ruby_version_is ''...'2.4' do
+ it "leaves uppercase Unicode characters as they were" do
+ "a\u{00DE}c".to_sym.capitalize.should == :"AÞc"
+ end
+ end
+
+ it "leaves lowercase Unicode characters (except in first position) as they were" do
+ "a\u{00DF}C".to_sym.capitalize.should == :"Aßc"
+ end
+
+ it "leaves non-alphabetic ASCII characters as they were" do
+ "Glark?!?".to_sym.capitalize.should == :"Glark?!?"
+ end
+end
diff --git a/spec/rubyspec/core/symbol/case_compare_spec.rb b/spec/rubyspec/core/symbol/case_compare_spec.rb
new file mode 100644
index 0000000000..5c705c0b04
--- /dev/null
+++ b/spec/rubyspec/core/symbol/case_compare_spec.rb
@@ -0,0 +1,11 @@
+require File.expand_path('../../../spec_helper', __FILE__)
+
+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
+ end
+end
diff --git a/spec/rubyspec/core/symbol/casecmp_spec.rb b/spec/rubyspec/core/symbol/casecmp_spec.rb
new file mode 100644
index 0000000000..942bd15998
--- /dev/null
+++ b/spec/rubyspec/core/symbol/casecmp_spec.rb
@@ -0,0 +1,74 @@
+# -*- encoding: binary -*-
+require File.expand_path('../../../spec_helper', __FILE__)
+
+describe "Symbol#casecmp with Symbol" do
+ it "compares symbols without regard to case" do
+ :abcdef.casecmp(:abcde).should == 1
+ :aBcDeF.casecmp(:abcdef).should == 0
+ :abcdef.casecmp(:abcdefg).should == -1
+ :abcdef.casecmp(:ABCDEF).should == 0
+ end
+
+ it "doesn't consider non-ascii characters equal that aren't" do
+ # -- Latin-1 --
+ upper_a_tilde = :"\xC3"
+ upper_a_umlaut = :"\xC4"
+ lower_a_tilde = :"\xE3"
+ lower_a_umlaut = :"\xE4"
+
+ lower_a_tilde.casecmp(lower_a_umlaut).should_not == 0
+ lower_a_umlaut.casecmp(lower_a_tilde).should_not == 0
+ upper_a_tilde.casecmp(upper_a_umlaut).should_not == 0
+ upper_a_umlaut.casecmp(upper_a_tilde).should_not == 0
+
+ # -- UTF-8 --
+ upper_a_tilde = :"\xC3\x83"
+ upper_a_umlaut = :"\xC3\x84"
+ lower_a_tilde = :"\xC3\xA3"
+ lower_a_umlaut = :"\xC3\xA4"
+
+ lower_a_tilde.casecmp(lower_a_umlaut).should_not == 0
+ lower_a_umlaut.casecmp(lower_a_tilde).should_not == 0
+ upper_a_tilde.casecmp(upper_a_umlaut).should_not == 0
+ upper_a_umlaut.casecmp(upper_a_tilde).should_not == 0
+ end
+
+ it "doesn't do case mapping for non-ascii characters" do
+ # -- Latin-1 --
+ upper_a_tilde = :"\xC3"
+ upper_a_umlaut = :"\xC4"
+ lower_a_tilde = :"\xE3"
+ lower_a_umlaut = :"\xE4"
+
+ upper_a_tilde.casecmp(lower_a_tilde).should == -1
+ upper_a_umlaut.casecmp(lower_a_umlaut).should == -1
+ lower_a_tilde.casecmp(upper_a_tilde).should == 1
+ lower_a_umlaut.casecmp(upper_a_umlaut).should == 1
+
+ # -- UTF-8 --
+ upper_a_tilde = :"\xC3\x83"
+ upper_a_umlaut = :"\xC3\x84"
+ lower_a_tilde = :"\xC3\xA3"
+ lower_a_umlaut = :"\xC3\xA4"
+
+ upper_a_tilde.casecmp(lower_a_tilde).should == -1
+ upper_a_umlaut.casecmp(lower_a_umlaut).should == -1
+ lower_a_tilde.casecmp(upper_a_tilde).should == 1
+ lower_a_umlaut.casecmp(upper_a_umlaut).should == 1
+ end
+end
+
+describe "Symbol#casecmp" do
+ it "returns nil if other is a String" do
+ :abc.casecmp("abc").should be_nil
+ end
+
+ it "returns nil if other is a Fixnum" do
+ :abc.casecmp(1).should be_nil
+ end
+
+ it "returns nil if other is an object" do
+ obj = mock("string <=>")
+ :abc.casecmp(obj).should be_nil
+ end
+end
diff --git a/spec/rubyspec/core/symbol/comparison_spec.rb b/spec/rubyspec/core/symbol/comparison_spec.rb
new file mode 100644
index 0000000000..91edd1f0d9
--- /dev/null
+++ b/spec/rubyspec/core/symbol/comparison_spec.rb
@@ -0,0 +1,51 @@
+require File.expand_path('../../../spec_helper', __FILE__)
+
+describe "Symbol#<=> with Symbol" do
+ it "compares individual characters based on their ascii value" do
+ ascii_order = Array.new(256) { |x| x.chr.to_sym }
+ sort_order = ascii_order.sort
+ sort_order.should == ascii_order
+ end
+
+ it "returns -1 when self is less than other" do
+ (:this <=> :those).should == -1
+ end
+
+ it "returns 0 when self is equal to other" do
+ (:yep <=> :yep).should == 0
+ end
+
+ it "returns 1 when self is greater than other" do
+ (:yoddle <=> :griddle).should == 1
+ end
+
+ it "considers symbol that comes lexicographically first to be less if the symbols have same size" do
+ (:aba <=> :abc).should == -1
+ (:abc <=> :aba).should == 1
+ end
+
+ it "doesn't consider shorter string to be less if longer string starts with shorter one" do
+ (:abc <=> :abcd).should == -1
+ (:abcd <=> :abc).should == 1
+ end
+
+ it "compares shorter string with corresponding number of first chars of longer string" do
+ (:abx <=> :abcd).should == 1
+ (:abcd <=> :abx).should == -1
+ end
+end
+
+describe "Symbol#<=>" do
+ it "returns nil if other is a String" do
+ (:abc <=> "abc").should be_nil
+ end
+
+ it "returns nil if other is a Fixnum" do
+ (:abc <=> 1).should be_nil
+ end
+
+ it "returns nil if other is an object" do
+ obj = mock("string <=>")
+ (:abc <=> obj).should be_nil
+ end
+end
diff --git a/spec/rubyspec/core/symbol/downcase_spec.rb b/spec/rubyspec/core/symbol/downcase_spec.rb
new file mode 100644
index 0000000000..0b2422ad3e
--- /dev/null
+++ b/spec/rubyspec/core/symbol/downcase_spec.rb
@@ -0,0 +1,26 @@
+# -*- encoding: utf-8 -*-
+require File.expand_path('../../../spec_helper', __FILE__)
+
+describe "Symbol#downcase" do
+ it "returns a Symbol" do
+ :glark.downcase.should be_an_instance_of(Symbol)
+ end
+
+ it "converts uppercase ASCII characters to their lowercase equivalents" do
+ :lOwEr.downcase.should == :lower
+ end
+
+ it "leaves lowercase Unicode characters as they were" do
+ "\u{E0}Bc".to_sym.downcase.should == :"àbc"
+ end
+
+ ruby_version_is ''...'2.4' do
+ it "leaves uppercase Unicode characters as they were" do
+ "\u{DE}Bc".to_sym.downcase.should == :"Þbc"
+ end
+ end
+
+ it "leaves non-alphabetic ASCII characters as they were" do
+ "Glark?!?".to_sym.downcase.should == :"glark?!?"
+ end
+end
diff --git a/spec/rubyspec/core/symbol/element_reference_spec.rb b/spec/rubyspec/core/symbol/element_reference_spec.rb
new file mode 100644
index 0000000000..4116274ee0
--- /dev/null
+++ b/spec/rubyspec/core/symbol/element_reference_spec.rb
@@ -0,0 +1,6 @@
+require File.expand_path('../../../spec_helper', __FILE__)
+require File.expand_path('../shared/slice.rb', __FILE__)
+
+describe "Symbol#[]" do
+ it_behaves_like(:symbol_slice, :[])
+end
diff --git a/spec/rubyspec/core/symbol/empty_spec.rb b/spec/rubyspec/core/symbol/empty_spec.rb
new file mode 100644
index 0000000000..7be0007355
--- /dev/null
+++ b/spec/rubyspec/core/symbol/empty_spec.rb
@@ -0,0 +1,11 @@
+require File.expand_path('../../../spec_helper', __FILE__)
+
+describe "Symbol#empty?" do
+ it "returns true if self is empty" do
+ :"".empty?.should be_true
+ end
+
+ it "returns false if self is non-empty" do
+ :"a".empty?.should be_false
+ end
+end
diff --git a/spec/rubyspec/core/symbol/encoding_spec.rb b/spec/rubyspec/core/symbol/encoding_spec.rb
new file mode 100644
index 0000000000..b6128562b9
--- /dev/null
+++ b/spec/rubyspec/core/symbol/encoding_spec.rb
@@ -0,0 +1,23 @@
+# encoding: utf-8
+
+require File.expand_path('../../../spec_helper', __FILE__)
+
+describe "Symbol#encoding for ASCII symbols" do
+ it "is US-ASCII" do
+ :foo.encoding.name.should == "US-ASCII"
+ end
+
+ it "is US-ASCII after converting to string" do
+ :foo.to_s.encoding.name.should == "US-ASCII"
+ end
+end
+
+describe "Symbol#encoding for UTF-8 symbols" do
+ it "is UTF-8" do
+ :åäö.encoding.name.should == "UTF-8"
+ end
+
+ it "is UTF-8 after converting to string" do
+ :åäö.to_s.encoding.name.should == "UTF-8"
+ end
+end
diff --git a/spec/rubyspec/core/symbol/equal_value_spec.rb b/spec/rubyspec/core/symbol/equal_value_spec.rb
new file mode 100644
index 0000000000..7c305fab39
--- /dev/null
+++ b/spec/rubyspec/core/symbol/equal_value_spec.rb
@@ -0,0 +1,14 @@
+require File.expand_path('../../../spec_helper', __FILE__)
+
+describe "Symbol#==" do
+ it "only returns true when the other is exactly the same symbol" do
+ (:ruby == :ruby).should == true
+ (:ruby == :"ruby").should == true
+ (:ruby == :'ruby').should == true
+ (:@ruby == :@ruby).should == true
+
+ (:ruby == :@ruby).should == false
+ (:foo == :bar).should == false
+ (:ruby == 'ruby').should == false
+ end
+end
diff --git a/spec/rubyspec/core/symbol/fixtures/classes.rb b/spec/rubyspec/core/symbol/fixtures/classes.rb
new file mode 100644
index 0000000000..6552f6ee38
--- /dev/null
+++ b/spec/rubyspec/core/symbol/fixtures/classes.rb
@@ -0,0 +1,3 @@
+module SymbolSpecs
+ class MyRange < Range; end
+end
diff --git a/spec/rubyspec/core/symbol/id2name_spec.rb b/spec/rubyspec/core/symbol/id2name_spec.rb
new file mode 100644
index 0000000000..932dd7171d
--- /dev/null
+++ b/spec/rubyspec/core/symbol/id2name_spec.rb
@@ -0,0 +1,6 @@
+require File.expand_path('../../../spec_helper', __FILE__)
+require File.expand_path('../shared/id2name', __FILE__)
+
+describe "Symbol#id2name" do
+ it_behaves_like(:symbol_id2name, :id2name)
+end
diff --git a/spec/rubyspec/core/symbol/inspect_spec.rb b/spec/rubyspec/core/symbol/inspect_spec.rb
new file mode 100644
index 0000000000..dead6e34fc
--- /dev/null
+++ b/spec/rubyspec/core/symbol/inspect_spec.rb
@@ -0,0 +1,105 @@
+require File.expand_path('../../../spec_helper', __FILE__)
+
+describe "Symbol#inspect" do
+ symbols = {
+ fred: ":fred",
+ :fred? => ":fred?",
+ :fred! => ":fred!",
+ :$ruby => ":$ruby",
+ :@ruby => ":@ruby",
+ :@@ruby => ":@@ruby",
+ :"$ruby!" => ":\"$ruby!\"",
+ :"$ruby?" => ":\"$ruby?\"",
+ :"@ruby!" => ":\"@ruby!\"",
+ :"@ruby?" => ":\"@ruby?\"",
+ :"@@ruby!" => ":\"@@ruby!\"",
+ :"@@ruby?" => ":\"@@ruby?\"",
+
+ :$-w => ":$-w",
+ :"$-ww" => ":\"$-ww\"",
+ :"$+" => ":$+",
+ :"$~" => ":$~",
+ :"$:" => ":$:",
+ :"$?" => ":$?",
+ :"$<" => ":$<",
+ :"$_" => ":$_",
+ :"$/" => ":$/",
+ :"$'" => ":$'",
+ :"$\"" => ":$\"",
+ :"$$" => ":$$",
+ :"$." => ":$.",
+ :"$," => ":$,",
+ :"$`" => ":$`",
+ :"$!" => ":$!",
+ :"$;" => ":$;",
+ :"$\\" => ":$\\",
+ :"$=" => ":$=",
+ :"$*" => ":$*",
+ :"$>" => ":$>",
+ :"$&" => ":$&",
+ :"$@" => ":$@",
+ :"$1234" => ":$1234",
+
+ :-@ => ":-@",
+ :+@ => ":+@",
+ :% => ":%",
+ :& => ":&",
+ :* => ":*",
+ :** => ":**",
+ :"/" => ":/", # lhs quoted for emacs happiness
+ :< => ":<",
+ :<= => ":<=",
+ :<=> => ":<=>",
+ :== => ":==",
+ :=== => ":===",
+ :=~ => ":=~",
+ :> => ":>",
+ :>= => ":>=",
+ :>> => ":>>",
+ :[] => ":[]",
+ :[]= => ":[]=",
+ :"\<\<" => ":\<\<",
+ :^ => ":^",
+ :"`" => ":`", # for emacs, and justice!
+ :~ => ":~",
+ :| => ":|",
+
+ :"!" => [":\"!\"", ":!" ],
+ :"!=" => [":\"!=\"", ":!="],
+ :"!~" => [":\"!~\"", ":!~"],
+ :"\$" => ":\"$\"", # for justice!
+ :"&&" => ":\"&&\"",
+ :"'" => ":\"\'\"",
+ :"," => ":\",\"",
+ :"." => ":\".\"",
+ :".." => ":\"..\"",
+ :"..." => ":\"...\"",
+ :":" => ":\":\"",
+ :"::" => ":\"::\"",
+ :";" => ":\";\"",
+ :"=" => ":\"=\"",
+ :"=>" => ":\"=>\"",
+ :"\?" => ":\"?\"", # rawr!
+ :"@" => ":\"@\"",
+ :"||" => ":\"||\"",
+ :"|||" => ":\"|||\"",
+ :"++" => ":\"++\"",
+
+ :"\"" => ":\"\\\"\"",
+ :"\"\"" => ":\"\\\"\\\"\"",
+
+ :"9" => ":\"9\"",
+ :"foo bar" => ":\"foo bar\"",
+ :"*foo" => ":\"*foo\"",
+ :"foo " => ":\"foo \"",
+ :" foo" => ":\" foo\"",
+ :" " => ":\" \"",
+ }
+
+ symbols.each do |input, expected|
+ expected = expected[1] if expected.is_a?(Array)
+ it "returns self as a symbol literal for #{expected}" do
+ input.inspect.should == expected
+ end
+ end
+end
diff --git a/spec/rubyspec/core/symbol/intern_spec.rb b/spec/rubyspec/core/symbol/intern_spec.rb
new file mode 100644
index 0000000000..c1ac5aeac1
--- /dev/null
+++ b/spec/rubyspec/core/symbol/intern_spec.rb
@@ -0,0 +1,11 @@
+require File.expand_path('../../../spec_helper', __FILE__)
+
+describe "Symbol#intern" do
+ it "returns self" do
+ :foo.intern.should == :foo
+ end
+
+ it "returns a Symbol" do
+ :foo.intern.should be_kind_of(Symbol)
+ end
+end
diff --git a/spec/rubyspec/core/symbol/length_spec.rb b/spec/rubyspec/core/symbol/length_spec.rb
new file mode 100644
index 0000000000..e7e0700d5a
--- /dev/null
+++ b/spec/rubyspec/core/symbol/length_spec.rb
@@ -0,0 +1,6 @@
+require File.expand_path('../../../spec_helper', __FILE__)
+require File.expand_path('../shared/length', __FILE__)
+
+describe "Symbol#length" do
+ it_behaves_like :symbol_length, :length
+end
diff --git a/spec/rubyspec/core/symbol/match_spec.rb b/spec/rubyspec/core/symbol/match_spec.rb
new file mode 100644
index 0000000000..768e3b00da
--- /dev/null
+++ b/spec/rubyspec/core/symbol/match_spec.rb
@@ -0,0 +1,70 @@
+require File.expand_path('../../../spec_helper', __FILE__)
+
+describe :symbol_match, shared: true do
+ it "returns the index of the beginning of the match" do
+ :abc.send(@method, /b/).should == 1
+ end
+
+ it "returns nil if there is no match" do
+ :a.send(@method, /b/).should be_nil
+ end
+
+ it "sets the last match pseudo-variables" do
+ :a.send(@method, /(.)/).should == 0
+ $1.should == "a"
+ end
+end
+
+describe "Symbol#=~" do
+ it_behaves_like :symbol_match, :=~
+end
+
+ruby_version_is ""..."2.4" do
+ describe "Symbol#match" do
+ it_behaves_like :symbol_match, :match
+ end
+end
+
+ruby_version_is "2.4" do
+ describe "Symbol#match" do
+ it "returns the MatchData" do
+ result = :abc.match(/b/)
+ result.should be_kind_of(MatchData)
+ result[0].should == 'b'
+ end
+
+ it "returns nil if there is no match" do
+ :a.match(/b/).should be_nil
+ end
+
+ it "sets the last match pseudo-variables" do
+ :a.match(/(.)/)[0].should == 'a'
+ $1.should == "a"
+ end
+ end
+end
+
+ruby_version_is "2.4" do
+ describe "Symbol#match?" do
+ before :each do
+ # Resetting Regexp.last_match
+ /DONTMATCH/.match ''
+ end
+
+ context "when matches the given regex" do
+ it "returns true but does not set Regexp.last_match" do
+ :string.match?(/string/i).should be_true
+ Regexp.last_match.should be_nil
+ end
+ end
+
+ it "returns false when does not match the given regex" do
+ :string.match?(/STRING/).should be_false
+ end
+
+ it "takes matching position as the 2nd argument" do
+ :string.match?(/str/i, 0).should be_true
+ :string.match?(/str/i, 1).should be_false
+ end
+ end
+end
diff --git a/spec/rubyspec/core/symbol/next_spec.rb b/spec/rubyspec/core/symbol/next_spec.rb
new file mode 100644
index 0000000000..65ffbebd40
--- /dev/null
+++ b/spec/rubyspec/core/symbol/next_spec.rb
@@ -0,0 +1,6 @@
+require File.expand_path('../../../spec_helper', __FILE__)
+require File.expand_path('../shared/succ', __FILE__)
+
+describe "Symbol#next" do
+ it_behaves_like :symbol_succ, :next
+end
diff --git a/spec/rubyspec/core/symbol/shared/id2name.rb b/spec/rubyspec/core/symbol/shared/id2name.rb
new file mode 100644
index 0000000000..47f97bd332
--- /dev/null
+++ b/spec/rubyspec/core/symbol/shared/id2name.rb
@@ -0,0 +1,9 @@
+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
+end
diff --git a/spec/rubyspec/core/symbol/shared/length.rb b/spec/rubyspec/core/symbol/shared/length.rb
new file mode 100644
index 0000000000..692e8c57e3
--- /dev/null
+++ b/spec/rubyspec/core/symbol/shared/length.rb
@@ -0,0 +1,23 @@
+# -*- 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/rubyspec/core/symbol/shared/slice.rb b/spec/rubyspec/core/symbol/shared/slice.rb
new file mode 100644
index 0000000000..d39b02f319
--- /dev/null
+++ b/spec/rubyspec/core/symbol/shared/slice.rb
@@ -0,0 +1,278 @@
+require File.expand_path('../../fixtures/classes.rb', __FILE__)
+
+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 be_nil
+ end
+
+ it "returns nil if the index is greater than the length" do
+ :symbol.send(@method, 42).should be_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 be_nil
+ end
+ end
+
+ describe "and a positive index and negative length" do
+ it "returns nil" do
+ :symbol.send(@method, 0,-1).should be_nil
+ :symbol.send(@method, 1,-1).should be_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 be_nil
+ end
+ end
+
+ describe "and a negative index and negative length" do
+ it "returns nil" do
+ :symbol.send(@method, -1,-1).should be_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
+ lambda { :symbol.send(@method, 1,nil) }.should raise_error(TypeError)
+ end
+ end
+
+ describe "and a length that cannot be converted into an Integer" do
+ it "raises a TypeError when given an Array" do
+ lambda { :symbol.send(@method, 1,Array.new) }.should raise_error(TypeError)
+ end
+
+ it "raises a TypeError when given an Hash" do
+ lambda { :symbol.send(@method, 1,Hash.new) }.should raise_error(TypeError)
+ end
+
+ it "raises a TypeError when given an Object" do
+ lambda { :symbol.send(@method, 1,Object.new) }.should raise_error(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
+ lambda { :symbol.send(@method, nil) }.should raise_error(TypeError)
+ end
+ end
+
+ describe "with an index that cannot be converted into an Integer" do
+ it "raises a TypeError when given an Array" do
+ lambda { :symbol.send(@method, Array.new) }.should raise_error(TypeError)
+ end
+
+ it "raises a TypeError when given an Hash" do
+ lambda { :symbol.send(@method, Hash.new) }.should raise_error(TypeError)
+ end
+
+ it "raises a TypeError when given an Object" do
+ lambda { :symbol.send(@method, Object.new) }.should raise_error(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 be_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 be_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 be_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 be_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 be_nil
+ end
+
+ 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
+
+ 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 be_nil
+ :symbol.send(@method, /(sy)(mb)(ol)/, -4).should be_nil
+ end
+
+ it "converts the index to an Integer" do
+ :symbol.send(@method, /(sy)(mb)(ol)/, 1.5).should == "sy"
+ end
+
+ 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
+
+ describe "and an index that cannot be converted to an Integer" do
+ it "raises a TypeError when given an Hash" do
+ lambda { :symbol.send(@method, /(sy)(mb)(ol)/, Hash.new) }.should raise_error(TypeError)
+ end
+
+ it "raises a TypeError when given an Array" do
+ lambda { :symbol.send(@method, /(sy)(mb)(ol)/, Array.new) }.should raise_error(TypeError)
+ end
+
+ it "raises a TypeError when given an Object" do
+ lambda { :symbol.send(@method, /(sy)(mb)(ol)/, Object.new) }.should raise_error(TypeError)
+ end
+ end
+
+ it "raises a TypeError if the index is nil" do
+ lambda { :symbol.send(@method, /(sy)(mb)(ol)/, nil) }.should raise_error(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 be_nil
+ end
+ end
+ end
+
+ describe "with a String slice" do
+ it "does not set $~" do
+ $~ = nil
+ :symbol.send(@method, "sym")
+ $~.should be_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 be_nil
+ end
+ end
+end
diff --git a/spec/rubyspec/core/symbol/shared/succ.rb b/spec/rubyspec/core/symbol/shared/succ.rb
new file mode 100644
index 0000000000..0e371490f9
--- /dev/null
+++ b/spec/rubyspec/core/symbol/shared/succ.rb
@@ -0,0 +1,18 @@
+require File.expand_path('../../../../spec_helper', __FILE__)
+
+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/rubyspec/core/symbol/size_spec.rb b/spec/rubyspec/core/symbol/size_spec.rb
new file mode 100644
index 0000000000..a6dfe092ec
--- /dev/null
+++ b/spec/rubyspec/core/symbol/size_spec.rb
@@ -0,0 +1,6 @@
+require File.expand_path('../../../spec_helper', __FILE__)
+require File.expand_path('../shared/length', __FILE__)
+
+describe "Symbol#size" do
+ it_behaves_like :symbol_length, :size
+end
diff --git a/spec/rubyspec/core/symbol/slice_spec.rb b/spec/rubyspec/core/symbol/slice_spec.rb
new file mode 100644
index 0000000000..3c535ac4b0
--- /dev/null
+++ b/spec/rubyspec/core/symbol/slice_spec.rb
@@ -0,0 +1,6 @@
+require File.expand_path('../../../spec_helper', __FILE__)
+require File.expand_path('../shared/slice.rb', __FILE__)
+
+describe "Symbol#slice" do
+ it_behaves_like(:symbol_slice, :slice)
+end
diff --git a/spec/rubyspec/core/symbol/succ_spec.rb b/spec/rubyspec/core/symbol/succ_spec.rb
new file mode 100644
index 0000000000..21bfb7e4aa
--- /dev/null
+++ b/spec/rubyspec/core/symbol/succ_spec.rb
@@ -0,0 +1,6 @@
+require File.expand_path('../../../spec_helper', __FILE__)
+require File.expand_path('../shared/succ', __FILE__)
+
+describe "Symbol#succ" do
+ it_behaves_like :symbol_succ, :succ
+end
diff --git a/spec/rubyspec/core/symbol/swapcase_spec.rb b/spec/rubyspec/core/symbol/swapcase_spec.rb
new file mode 100644
index 0000000000..fdc42ec477
--- /dev/null
+++ b/spec/rubyspec/core/symbol/swapcase_spec.rb
@@ -0,0 +1,34 @@
+# -*- encoding: utf-8 -*-
+require File.expand_path('../../../spec_helper', __FILE__)
+
+describe "Symbol#swapcase" do
+ it "returns a Symbol" do
+ :glark.swapcase.should be_an_instance_of(Symbol)
+ end
+
+ it "converts lowercase ASCII characters to their uppercase equivalents" do
+ :lower.swapcase.should == :LOWER
+ end
+
+ it "converts uppercase ASCII characters to their lowercase equivalents" do
+ :UPPER.swapcase.should == :upper
+ end
+
+ it "works with both upper- and lowercase ASCII characters in the same Symbol" do
+ :mIxEd.swapcase.should == :MiXeD
+ end
+
+ ruby_version_is ''...'2.4' do
+ it "leaves uppercase Unicode characters as they were" do
+ "\u{00DE}Bc".to_sym.swapcase.should == :"ÞbC"
+ end
+
+ it "leaves lowercase Unicode characters as they were" do
+ "\u{00DF}Bc".to_sym.swapcase.should == :"ßbC"
+ end
+ end
+
+ it "leaves non-alphabetic ASCII characters as they were" do
+ "Glark?!?".to_sym.swapcase.should == :"gLARK?!?"
+ end
+end
diff --git a/spec/rubyspec/core/symbol/symbol_spec.rb b/spec/rubyspec/core/symbol/symbol_spec.rb
new file mode 100644
index 0000000000..bb95211ba0
--- /dev/null
+++ b/spec/rubyspec/core/symbol/symbol_spec.rb
@@ -0,0 +1,7 @@
+require File.expand_path('../../../spec_helper', __FILE__)
+
+describe "Symbol" do
+ it "includes Comparable" do
+ Symbol.include?(Comparable).should == true
+ end
+end
diff --git a/spec/rubyspec/core/symbol/to_proc_spec.rb b/spec/rubyspec/core/symbol/to_proc_spec.rb
new file mode 100644
index 0000000000..be625994d9
--- /dev/null
+++ b/spec/rubyspec/core/symbol/to_proc_spec.rb
@@ -0,0 +1,41 @@
+require File.expand_path('../../../spec_helper', __FILE__)
+
+describe "Symbol#to_proc" do
+ it "returns a new Proc" do
+ proc = :to_s.to_proc
+ proc.should be_kind_of(Proc)
+ end
+
+ it "sends self to arguments passed when calling #call on the Proc" do
+ obj = mock("Receiving #to_s")
+ obj.should_receive(:to_s).and_return("Received #to_s")
+ :to_s.to_proc.call(obj).should == "Received #to_s"
+ end
+
+ it "raises an ArgumentError when calling #call on the Proc without receiver" do
+ lambda { :object_id.to_proc.call }.should raise_error(ArgumentError)
+ end
+
+ it "produces a proc that always returns [[:rest]] for #parameters" do
+ pr = :to_s.to_proc
+ pr.parameters.should == [[:rest]]
+ end
+end
+
+describe "Symbol#to_proc" do
+ before :all do
+ @klass = Class.new do
+ def m
+ yield
+ end
+
+ def to_proc
+ :m.to_proc.call(self) { :value }
+ end
+ end
+ end
+
+ it "passes along the block passed to Proc#call" do
+ @klass.new.to_proc.should == :value
+ end
+end
diff --git a/spec/rubyspec/core/symbol/to_s_spec.rb b/spec/rubyspec/core/symbol/to_s_spec.rb
new file mode 100644
index 0000000000..40c13675b3
--- /dev/null
+++ b/spec/rubyspec/core/symbol/to_s_spec.rb
@@ -0,0 +1,6 @@
+require File.expand_path('../../../spec_helper', __FILE__)
+require File.expand_path('../shared/id2name', __FILE__)
+
+describe "Symbol#to_s" do
+ it_behaves_like(:symbol_id2name, :to_s)
+end
diff --git a/spec/rubyspec/core/symbol/to_sym_spec.rb b/spec/rubyspec/core/symbol/to_sym_spec.rb
new file mode 100644
index 0000000000..7f26684850
--- /dev/null
+++ b/spec/rubyspec/core/symbol/to_sym_spec.rb
@@ -0,0 +1,9 @@
+require File.expand_path('../../../spec_helper', __FILE__)
+
+describe "Symbol#to_sym" do
+ it "returns self" do
+ [:rubinius, :squash, :[], :@ruby, :@@ruby].each do |sym|
+ sym.to_sym.should == sym
+ end
+ end
+end
diff --git a/spec/rubyspec/core/symbol/upcase_spec.rb b/spec/rubyspec/core/symbol/upcase_spec.rb
new file mode 100644
index 0000000000..fce62af100
--- /dev/null
+++ b/spec/rubyspec/core/symbol/upcase_spec.rb
@@ -0,0 +1,22 @@
+# -*- encoding: utf-8 -*-
+require File.expand_path('../../../spec_helper', __FILE__)
+
+describe "Symbol#upcase" do
+ it "returns a Symbol" do
+ :glark.upcase.should be_an_instance_of(Symbol)
+ end
+
+ it "converts lowercase ASCII characters to their uppercase equivalents" do
+ :lOwEr.upcase.should == :LOWER
+ end
+
+ ruby_version_is ''...'2.4' do
+ it "leaves lowercase Unicode characters as they were" do
+ "\u{E0}Bc".to_sym.upcase.should == :"àBC"
+ end
+ end
+
+ it "leaves non-alphabetic ASCII characters as they were" do
+ "Glark?!?".to_sym.upcase.should == :"GLARK?!?"
+ end
+end