diff options
Diffstat (limited to 'spec/ruby/core/string/to_i_spec.rb')
| -rw-r--r-- | spec/ruby/core/string/to_i_spec.rb | 36 |
1 files changed, 24 insertions, 12 deletions
diff --git a/spec/ruby/core/string/to_i_spec.rb b/spec/ruby/core/string/to_i_spec.rb index a37be47778..629750bd73 100644 --- a/spec/ruby/core/string/to_i_spec.rb +++ b/spec/ruby/core/string/to_i_spec.rb @@ -10,6 +10,18 @@ describe "String#to_i" do "1_2_3asdf".to_i.should == 123 end + it "ignores multiple non-consecutive underscores when the first digit is 0" do + (2..16).each do |base| + "0_0_010".to_i(base).should == base; + end + end + + it "bails out at the first double underscore if the first digit is 0" do + (2..16).each do |base| + "010__1".to_i(base).should == base; + end + end + it "ignores leading whitespaces" do [ " 123", " 123", "\r\n\r\n123", "\t\t123", "\r\n\t\n123", " \t\n\r\t 123"].each do |str| @@ -126,34 +138,34 @@ describe "String#to_i" do end it "raises an ArgumentError for illegal bases (1, < 0 or > 36)" do - -> { "".to_i(1) }.should raise_error(ArgumentError) - -> { "".to_i(-1) }.should raise_error(ArgumentError) - -> { "".to_i(37) }.should raise_error(ArgumentError) + -> { "".to_i(1) }.should.raise(ArgumentError) + -> { "".to_i(-1) }.should.raise(ArgumentError) + -> { "".to_i(37) }.should.raise(ArgumentError) end - it "returns a Fixnum for long strings with trailing spaces" do + it "returns an Integer for long strings with trailing spaces" do "0 ".to_i.should == 0 - "0 ".to_i.should be_an_instance_of(Fixnum) + "0 ".to_i.should.instance_of?(Integer) "10 ".to_i.should == 10 - "10 ".to_i.should be_an_instance_of(Fixnum) + "10 ".to_i.should.instance_of?(Integer) "-10 ".to_i.should == -10 - "-10 ".to_i.should be_an_instance_of(Fixnum) + "-10 ".to_i.should.instance_of?(Integer) end - it "returns a Fixnum for long strings with leading spaces" do + it "returns an Integer for long strings with leading spaces" do " 0".to_i.should == 0 - " 0".to_i.should be_an_instance_of(Fixnum) + " 0".to_i.should.instance_of?(Integer) " 10".to_i.should == 10 - " 10".to_i.should be_an_instance_of(Fixnum) + " 10".to_i.should.instance_of?(Integer) " -10".to_i.should == -10 - " -10".to_i.should be_an_instance_of(Fixnum) + " -10".to_i.should.instance_of?(Integer) end - it "returns the correct Bignum for long strings" do + it "returns the correct Integer for long strings" do "245789127594125924165923648312749312749327482".to_i.should == 245789127594125924165923648312749312749327482 "-245789127594125924165923648312749312749327482".to_i.should == -245789127594125924165923648312749312749327482 end |
