diff options
author | eregon <eregon@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2017-09-20 20:18:52 +0000 |
---|---|---|
committer | eregon <eregon@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2017-09-20 20:18:52 +0000 |
commit | 1d15d5f08032acf1b7bceacbb450d617ff6e0931 (patch) | |
tree | a3785a79899302bc149e4a6e72f624ac27dc1f10 /spec/ruby/language/numbers_spec.rb | |
parent | 75bfc6440d595bf339007f4fb280fd4d743e89c1 (diff) |
Move spec/rubyspec to spec/ruby for consistency
* Other ruby implementations use the spec/ruby directory.
[Misc #13792] [ruby-core:82287]
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@59979 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'spec/ruby/language/numbers_spec.rb')
-rw-r--r-- | spec/ruby/language/numbers_spec.rb | 97 |
1 files changed, 97 insertions, 0 deletions
diff --git a/spec/ruby/language/numbers_spec.rb b/spec/ruby/language/numbers_spec.rb new file mode 100644 index 0000000000..e8c82f09a7 --- /dev/null +++ b/spec/ruby/language/numbers_spec.rb @@ -0,0 +1,97 @@ +require File.expand_path('../../spec_helper', __FILE__) + +describe "A number literal" do + + it "can be a sequence of decimal digits" do + 435.should == 435 + end + + it "can have '_' characters between digits" do + 4_3_5_7.should == 4357 + end + + it "cannot have a leading underscore" do + lambda { eval("_4_2") }.should raise_error(NameError) + end + + it "can have a decimal point" do + 4.35.should == 4.35 + end + + it "must have a digit before the decimal point" do + 0.75.should == 0.75 + lambda { eval(".75") }.should raise_error(SyntaxError) + lambda { eval("-.75") }.should raise_error(SyntaxError) + end + + it "can have an exponent" do + 1.2e-3.should == 0.0012 + end + + it "can be a sequence of hexadecimal digits with a leading '0x'" do + 0xffff.should == 65535 + end + + it "can be a sequence of binary digits with a leading '0x'" do + 0b01011.should == 11 + end + + it "can be a sequence of octal digits with a leading '0'" do + 0377.should == 255 + end + + it "can be an integer literal with trailing 'r' to represent a Rational" do + eval('3r').should == Rational(3, 1) + eval('-3r').should == Rational(-3, 1) + end + + it "can be an bignum literal with trailing 'r' to represent a Rational" do + eval('1111111111111111111111111111111111111111111111r').should == Rational(1111111111111111111111111111111111111111111111, 1) + eval('-1111111111111111111111111111111111111111111111r').should == Rational(-1111111111111111111111111111111111111111111111, 1) + end + + it "can be a decimal literal with trailing 'r' to represent a Rational" do + eval('0.3r').should == Rational(3, 10) + eval('-0.3r').should == Rational(-3, 10) + end + + it "can be a hexadecimal literal with trailing 'r' to represent a Rational" do + eval('0xffr').should == Rational(255, 1) + eval('-0xffr').should == Rational(-255, 1) + end + + it "can be an octal literal with trailing 'r' to represent a Rational" do + eval('042r').should == Rational(34, 1) + eval('-042r').should == Rational(-34, 1) + end + + it "can be a binary literal with trailing 'r' to represent a Rational" do + eval('0b1111r').should == Rational(15, 1) + eval('-0b1111r').should == Rational(-15, 1) + end + + it "can be an integer literal with trailing 'i' to represent a Complex" do + eval('5i').should == Complex(0, 5) + eval('-5i').should == Complex(0, -5) + end + + it "can be a decimal literal with trailing 'i' to represent a Complex" do + eval('0.6i').should == Complex(0, 0.6) + eval('-0.6i').should == Complex(0, -0.6) + end + + it "can be a hexadecimal literal with trailing 'i' to represent a Complex" do + eval('0xffi').should == Complex(0, 255) + eval('-0xffi').should == Complex(0, -255) + end + + it "can be a octal literal with trailing 'i' to represent a Complex" do + eval("042i").should == Complex(0, 34) + eval("-042i").should == Complex(0, -34) + end + + it "can be a binary literal with trailing 'i' to represent a Complex" do + eval('0b1110i').should == Complex(0, 14) + eval('-0b1110i').should == Complex(0, -14) + end +end |