ruby-changes:62743
From: Benoit <ko1@a...>
Date: Sat, 29 Aug 2020 03:28:05 +0900 (JST)
Subject: [ruby-changes:62743] b49307c701 (master): Update to ruby/spec@335eb9b
https://git.ruby-lang.org/ruby.git/commit/?id=b49307c701 From b49307c701911a713cbdb48367833d3661a4880a Mon Sep 17 00:00:00 2001 From: Benoit Daloze <eregontp@g...> Date: Fri, 28 Aug 2020 20:26:02 +0200 Subject: Update to ruby/spec@335eb9b diff --git a/spec/ruby/README.md b/spec/ruby/README.md index df3b991..ec744c1 100644 --- a/spec/ruby/README.md +++ b/spec/ruby/README.md @@ -120,6 +120,16 @@ MSpec can automatically add new top-level constants in this file with: https://github.com/ruby/ruby/blob/trunk/spec/ruby/README.md#L120 See [CONTRIBUTING.md](https://github.com/ruby/spec/blob/master/CONTRIBUTING.md) for documentation about contributing and writing specs (guards, matchers, etc). +### Dependencies + +These command-line executables are needed to run the specs. + +* `echo` +* `stat` for `core/file/*time_spec.rb` +* `find` for `core/file/fixtures/file_types.rb` (package `findutils`, not needed on Windows) + +The file `/etc/services` is required for socket specs (package `netbase` on Debian, not needed on Windows). + ### Socket specs from rubysl-socket Most specs under `library/socket` were imported from [the rubysl-socket project](https://github.com/rubysl/rubysl-socket). diff --git a/spec/ruby/core/file/absolute_path_spec.rb b/spec/ruby/core/file/absolute_path_spec.rb index 52839cf..9f39923 100644 --- a/spec/ruby/core/file/absolute_path_spec.rb +++ b/spec/ruby/core/file/absolute_path_spec.rb @@ -73,6 +73,12 @@ describe "File.absolute_path" do https://github.com/ruby/ruby/blob/trunk/spec/ruby/core/file/absolute_path_spec.rb#L73 File.absolute_path('~').should_not == File.expand_path('~') end + platform_is_not :windows do + it "does not expand '~' when given dir argument" do + File.absolute_path('~', '/').should == '/~' + end + end + it "does not expand '~user' to a home directory." do path = File.dirname(@abs) Dir.chdir(path) do diff --git a/spec/ruby/core/float/inspect_spec.rb b/spec/ruby/core/float/inspect_spec.rb new file mode 100644 index 0000000..4be1927 --- /dev/null +++ b/spec/ruby/core/float/inspect_spec.rb @@ -0,0 +1,6 @@ https://github.com/ruby/ruby/blob/trunk/spec/ruby/core/float/inspect_spec.rb#L1 +require_relative '../../spec_helper' +require_relative 'shared/to_s' + +describe "Float#inspect" do + it_behaves_like :float_to_s, :inspect +end diff --git a/spec/ruby/core/float/negative_spec.rb b/spec/ruby/core/float/negative_spec.rb new file mode 100644 index 0000000..511d92a --- /dev/null +++ b/spec/ruby/core/float/negative_spec.rb @@ -0,0 +1,33 @@ https://github.com/ruby/ruby/blob/trunk/spec/ruby/core/float/negative_spec.rb#L1 +require_relative '../../spec_helper' + +describe "Float#negative?" do + describe "on positive numbers" do + it "returns false" do + 0.1.negative?.should be_false + end + end + + describe "on zero" do + it "returns false" do + 0.0.negative?.should be_false + end + end + + describe "on negative zero" do + it "returns false" do + -0.0.negative?.should be_false + end + end + + describe "on negative numbers" do + it "returns true" do + -0.1.negative?.should be_true + end + end + + describe "on NaN" do + it "returns false" do + nan_value.negative?.should be_false + end + end +end diff --git a/spec/ruby/core/float/positive_spec.rb b/spec/ruby/core/float/positive_spec.rb new file mode 100644 index 0000000..575f92a --- /dev/null +++ b/spec/ruby/core/float/positive_spec.rb @@ -0,0 +1,33 @@ https://github.com/ruby/ruby/blob/trunk/spec/ruby/core/float/positive_spec.rb#L1 +require_relative '../../spec_helper' + +describe "Float#positive?" do + describe "on positive numbers" do + it "returns true" do + 0.1.positive?.should be_true + end + end + + describe "on zero" do + it "returns false" do + 0.0.positive?.should be_false + end + end + + describe "on negative zero" do + it "returns false" do + -0.0.positive?.should be_false + end + end + + describe "on negative numbers" do + it "returns false" do + -0.1.positive?.should be_false + end + end + + describe "on NaN" do + it "returns false" do + nan_value.positive?.should be_false + end + end +end diff --git a/spec/ruby/core/float/round_spec.rb b/spec/ruby/core/float/round_spec.rb index e143682..4bd2dc4 100644 --- a/spec/ruby/core/float/round_spec.rb +++ b/spec/ruby/core/float/round_spec.rb @@ -114,4 +114,17 @@ describe "Float#round" do https://github.com/ruby/ruby/blob/trunk/spec/ruby/core/float/round_spec.rb#L114 it "raise for a non-existent round mode" do -> { 14.2.round(half: :nonsense) }.should raise_error(ArgumentError, "invalid rounding mode: nonsense") end + + describe "when 0.0 is given" do + it "returns self for positive ndigits" do + (0.0).round(5).inspect.should == "0.0" + (-0.0).round(1).inspect.should == "-0.0" + end + + it "returns 0 for 0 or undefined ndigits" do + (0.0).round.should == 0 + (-0.0).round(0).should == 0 + (0.0).round(half: :up) == 0 + end + end end diff --git a/spec/ruby/core/float/shared/to_s.rb b/spec/ruby/core/float/shared/to_s.rb new file mode 100644 index 0000000..0925efc --- /dev/null +++ b/spec/ruby/core/float/shared/to_s.rb @@ -0,0 +1,308 @@ https://github.com/ruby/ruby/blob/trunk/spec/ruby/core/float/shared/to_s.rb#L1 +describe :float_to_s, shared: true do + it "returns 'NaN' for NaN" do + nan_value().send(@method).should == 'NaN' + end + + it "returns 'Infinity' for positive infinity" do + infinity_value().send(@method).should == 'Infinity' + end + + it "returns '-Infinity' for negative infinity" do + (-infinity_value()).send(@method).should == '-Infinity' + end + + it "returns '0.0' for 0.0" do + 0.0.send(@method).should == "0.0" + end + + platform_is_not :openbsd do + it "emits '-' for -0.0" do + -0.0.send(@method).should == "-0.0" + end + end + + it "emits a '-' for negative values" do + -3.14.send(@method).should == "-3.14" + end + + it "emits a trailing '.0' for a whole number" do + 50.0.send(@method).should == "50.0" + end + + it "emits a trailing '.0' for the mantissa in e format" do + 1.0e20.send(@method).should == "1.0e+20" + end + + it "uses non-e format for a positive value with fractional part having 5 significant figures" do + 0.0001.send(@method).should == "0.0001" + end + + it "uses non-e format for a negative value with fractional part having 5 significant figures" do + -0.0001.send(@method).should == "-0.0001" + end + + it "uses e format for a positive value with fractional part having 6 significant figures" do + 0.00001.send(@method).should == "1.0e-05" + end + + it "uses e format for a negative value with fractional part having 6 significant figures" do + -0.00001.send(@method).should == "-1.0e-05" + end + + it "uses non-e format for a positive value with whole part having 15 significant figures" do + 10000000000000.0.send(@method).should == "10000000000000.0" + end + + it "uses non-e format for a negative value with whole part having 15 significant figures" do + -10000000000000.0.send(@method).should == "-10000000000000.0" + end + + it "uses non-e format for a positive value with whole part having 16 significant figures" do + 100000000000000.0.send(@method).should == "100000000000000.0" + end + + it "uses non-e format for a negative value with whole part having 16 significant figures" do + -100000000000000.0.send(@method).should == "-100000000000000.0" + end + + it "uses e format for a positive value with whole part having 18 significant figures" do + 10000000000000000.0.send(@method).should == "1.0e+16" + end + + it "uses e format for a negative value with whole part having 18 significant figures" do + -10000000000000000.0.send(@method).should == "-1.0e+16" + end + + it "uses e format for a positive value with whole part having 17 significant figures" do + 1000000000000000.0.send(@method).should == "1.0e+15" + end + + it "uses e format for a negative value with whole part having 17 significant figures" do + -1000000000000000.0.send(@method).should == "-1.0e+15" + end + + # #3273 + it "outputs the minimal, unique form necessary to recreate the value" do + value = 0.21611564636388508 + string = "0.21611564636388508" + + value.send(@method).should == string + string.to_f.should == value + end + + it "outputs the minimal, unique form to represent the value" do + 0.56.send(@method).should == "0.56" + end + + describe "matches" do + it "random examples in all ranges" do + # 50.times do + # bytes = (0...8).map { rand(256) } + # string = bytes.pack('C8') + # float = string.unpack('D').first + # puts "#{'%.20g' % float}.send(@method).should == #{float.send(@method).inspect}" + # end + + 2.5540217314354050325e+163.send(@method).should == "2.554021731435405e+163" + 2.5492588360356597544e-172.send(@method).should == "2.5492588360356598e-172" + 1.742770260934704852e-82.send(@method).should == "1.7427702609347049e-82" + 6.2108093676180883209e-104.send(@method).should == "6.210809367618088e-104" + -3.3448803488331067402e-143.send(@method).should == "-3.3448803488331067e-143" + -2.2740074343500832557e-168.send(@method).should == "-2.2740074343500833e-168" + 7.0587971678048535732e+191.send(@method).should == "7.058797167804854e+191" + -284438.88327586348169.send(@method).should == "-284438.8832758635" + 3.953272468476091301e+105.send(@method).should == "3.9532724684760913e+105" + -3.6361359552959847853e+100.send(@method).should == "-3.636135955295985e+100" + -1.3222325865575206185e-31.send(@method).should == "-1.3222325865575206e-31" + 1.1440138916932761366e+130.send(@method).should == "1.1440138916932761e+130" + 4.8750891560387561157e-286.send(@method).should == "4.875089156038756e-286" + 5.6101113356591453525e-257.send(@method).should == "5.610111335659145e-257" + -3.829644279545809 (... truncated) -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/