Permalink
Browse files

Merge remote-tracking branch 'r-stu31/symbol_length'

  • Loading branch information...
2 parents b277ca6 + bee55ba commit 0a8b18c684b190c5799dd4fe75bb3c8aa33caed2 @brixen brixen committed Apr 25, 2012
View
6 kernel/common/symbol19.rb
@@ -45,6 +45,12 @@ def empty?
alias_method :intern, :to_sym
alias_method :id2name, :to_s
+ def length
+ to_s.length
+ end
+
+ alias_method :size, :length
+
def match(pattern)
str = to_s
View
3 spec/ruby/core/symbol/length_spec.rb
@@ -1,7 +1,8 @@
require File.expand_path('../../../spec_helper', __FILE__)
+require File.expand_path('../shared/length', __FILE__)
ruby_version_is "1.9" do
describe "Symbol#length" do
- it "needs to be reviewed for spec completeness"
+ it_behaves_like(:symbol_length, :length)
end
end
View
23 spec/ruby/core/symbol/shared/length.rb
@@ -0,0 +1,23 @@
+# coding: 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
View
3 spec/ruby/core/symbol/size_spec.rb
@@ -1,7 +1,8 @@
require File.expand_path('../../../spec_helper', __FILE__)
+require File.expand_path('../shared/length', __FILE__)
ruby_version_is "1.9" do
describe "Symbol#size" do
- it "needs to be reviewed for spec completeness"
+ it_behaves_like(:symbol_length, :size)
end
end
View
1 spec/tags/19/ruby/core/symbol/length_tags.txt
@@ -0,0 +1 @@
+fails:Symbol#length returns 4 for name formed by 1 multibyte and 3 ASCII characters
View
1 spec/tags/19/ruby/core/symbol/size_tags.txt
@@ -0,0 +1 @@
+fails:Symbol#size returns 4 for name formed by 1 multibyte and 3 ASCII characters

0 comments on commit 0a8b18c

Please sign in to comment.