ruby-changes:65075
From: Benoit <ko1@a...>
Date: Fri, 29 Jan 2021 01:09:44 +0900 (JST)
Subject: [ruby-changes:65075] 2e32b919b4 (master): Update to ruby/spec@8cafaa5
https://git.ruby-lang.org/ruby.git/commit/?id=2e32b919b4 From 2e32b919b4f2f5b7f2e1509d6fa985526ef1f61c Mon Sep 17 00:00:00 2001 From: Benoit Daloze <eregontp@g...> Date: Thu, 28 Jan 2021 17:08:57 +0100 Subject: Update to ruby/spec@8cafaa5 --- spec/ruby/core/integer/digits_spec.rb | 9 ++ spec/ruby/core/kernel/caller_locations_spec.rb | 8 ++ spec/ruby/core/kernel/caller_spec.rb | 8 ++ spec/ruby/core/kernel/lambda_spec.rb | 12 ++ spec/ruby/core/kernel/rand_spec.rb | 42 +++++++ spec/ruby/core/module/ruby2_keywords_spec.rb | 112 ++++++++++++++++++ spec/ruby/core/module/to_s_spec.rb | 23 ++++ spec/ruby/core/proc/ruby2_keywords_spec.rb | 64 +++++++++++ spec/ruby/core/range/shared/cover.rb | 42 +++++++ spec/ruby/core/range/shared/cover_and_include.rb | 7 ++ spec/ruby/core/range/to_a_spec.rb | 5 + spec/ruby/core/range/to_s_spec.rb | 7 ++ spec/ruby/core/string/scrub_spec.rb | 7 ++ spec/ruby/core/string/shared/slice.rb | 10 ++ spec/ruby/core/string/split_spec.rb | 8 ++ spec/ruby/core/struct/hash_spec.rb | 4 + spec/ruby/core/symbol/name_spec.rb | 19 ++++ spec/ruby/core/thread/backtrace_locations_spec.rb | 8 ++ spec/ruby/core/thread/handle_interrupt_spec.rb | 125 +++++++++++++++++++++ spec/ruby/core/thread/pending_interrupt_spec.rb | 32 ++++++ spec/ruby/core/time/inspect_spec.rb | 26 ++++- spec/ruby/language/constants_spec.rb | 19 +++- spec/ruby/language/fixtures/constant_visibility.rb | 18 ++- spec/ruby/language/fixtures/squiggly_heredoc.rb | 8 ++ spec/ruby/language/heredoc_spec.rb | 5 + spec/ruby/library/pathname/inspect_spec.rb | 10 ++ spec/ruby/library/socket/basicsocket/send_spec.rb | 8 ++ .../library/socket/tcpsocket/recv_nonblock_spec.rb | 14 +++ .../socket/udpsocket/recvfrom_nonblock_spec.rb | 7 ++ spec/ruby/optional/capi/debug_spec.rb | 68 +++++++++++ spec/ruby/optional/capi/ext/debug_spec.c | 93 +++++++++++++++ spec/ruby/optional/capi/ext/object_spec.c | 1 + spec/ruby/optional/capi/fixtures/module.rb | 4 + spec/ruby/optional/capi/module_spec.rb | 4 + spec/ruby/optional/capi/object_spec.rb | 5 + 35 files changed, 832 insertions(+), 10 deletions(-) create mode 100644 spec/ruby/core/module/ruby2_keywords_spec.rb create mode 100644 spec/ruby/core/proc/ruby2_keywords_spec.rb create mode 100644 spec/ruby/core/symbol/name_spec.rb create mode 100644 spec/ruby/core/thread/handle_interrupt_spec.rb create mode 100644 spec/ruby/core/thread/pending_interrupt_spec.rb create mode 100644 spec/ruby/library/pathname/inspect_spec.rb create mode 100644 spec/ruby/optional/capi/debug_spec.rb create mode 100644 spec/ruby/optional/capi/ext/debug_spec.c diff --git a/spec/ruby/core/integer/digits_spec.rb b/spec/ruby/core/integer/digits_spec.rb index 4a8e339..3d0a64c 100644 --- a/spec/ruby/core/integer/digits_spec.rb +++ b/spec/ruby/core/integer/digits_spec.rb @@ -29,4 +29,13 @@ describe "Integer#digits" do https://github.com/ruby/ruby/blob/trunk/spec/ruby/core/integer/digits_spec.rb#L29 it "raises Math::DomainError when calling digits on a negative number" do -> { -12345.digits(7) }.should raise_error(Math::DomainError) end + + it "returns integer values > 9 when base is above 10" do + 1234.digits(16).should == [2, 13, 4] + end + + it "can be used with base > 37" do + 1234.digits(100).should == [34, 12] + 980099.digits(100).should == [99, 0, 98] + end end diff --git a/spec/ruby/core/kernel/caller_locations_spec.rb b/spec/ruby/core/kernel/caller_locations_spec.rb index 8050b5b..bbb7e7b 100644 --- a/spec/ruby/core/kernel/caller_locations_spec.rb +++ b/spec/ruby/core/kernel/caller_locations_spec.rb @@ -36,6 +36,14 @@ describe 'Kernel#caller_locations' do https://github.com/ruby/ruby/blob/trunk/spec/ruby/core/kernel/caller_locations_spec.rb#L36 end end + ruby_version_is "2.7" do + it "works with beginless ranges" do + locations1 = caller_locations(0) + locations2 = caller_locations(eval("(...5)")) + locations2.map(&:to_s)[eval("(2..)")].should == locations1[eval("(...5)")].map(&:to_s)[eval("(2..)")] + end + end + it "can be called with a range whose end is negative" do locations1 = caller_locations(0) locations2 = caller_locations(2..-1) diff --git a/spec/ruby/core/kernel/caller_spec.rb b/spec/ruby/core/kernel/caller_spec.rb index 06e9ea6..6c17586 100644 --- a/spec/ruby/core/kernel/caller_spec.rb +++ b/spec/ruby/core/kernel/caller_spec.rb @@ -52,6 +52,14 @@ describe 'Kernel#caller' do https://github.com/ruby/ruby/blob/trunk/spec/ruby/core/kernel/caller_spec.rb#L52 end end + ruby_version_is "2.7" do + it "works with beginless ranges" do + locations1 = KernelSpecs::CallerTest.locations(0) + locations2 = KernelSpecs::CallerTest.locations(eval("(..5)")) + locations2.map(&:to_s)[eval("(2..)")].should == locations1[eval("(..5)")].map(&:to_s)[eval("(2..)")] + end + end + guard -> { Kernel.instance_method(:tap).source_location } do it "includes core library methods defined in Ruby" do file, line = Kernel.instance_method(:tap).source_location diff --git a/spec/ruby/core/kernel/lambda_spec.rb b/spec/ruby/core/kernel/lambda_spec.rb index 4dd34c6..9a960f3 100644 --- a/spec/ruby/core/kernel/lambda_spec.rb +++ b/spec/ruby/core/kernel/lambda_spec.rb @@ -123,4 +123,16 @@ describe "Kernel.lambda" do https://github.com/ruby/ruby/blob/trunk/spec/ruby/core/kernel/lambda_spec.rb#L123 it "allows long returns to flow through it" do KernelSpecs::Lambda.new.outer.should == :good end + + it "treats the block as a Proc when lambda is re-defined" do + klass = Class.new do + def lambda (&block); block; end + def ret + lambda { return 1 }.call + 2 + end + end + klass.new.lambda { 42 }.should be_an_instance_of Proc + klass.new.ret.should == 1 + end end diff --git a/spec/ruby/core/kernel/rand_spec.rb b/spec/ruby/core/kernel/rand_spec.rb index a82b4fb..481189d 100644 --- a/spec/ruby/core/kernel/rand_spec.rb +++ b/spec/ruby/core/kernel/rand_spec.rb @@ -117,6 +117,48 @@ describe "Kernel.rand" do https://github.com/ruby/ruby/blob/trunk/spec/ruby/core/kernel/rand_spec.rb#L117 end end + context "given an inclusive range between 0 and 1" do + it "returns an Integer between the two Integers" do + x = rand(0..1) + x.should be_kind_of(Integer) + (0..1).should include(x) + end + + it "returns a Float if at least one side is Float" do + seed = 42 + x1 = Random.new(seed).rand(0..1.0) + x2 = Random.new(seed).rand(0.0..1.0) + x3 = Random.new(seed).rand(0.0..1) + + x3.should be_kind_of(Float) + x1.should equal(x3) + x2.should equal(x3) + + (0.0..1.0).should include(x3) + end + end + + context "given an exclusive range between 0 and 1" do + it "returns zero as an Integer" do + x = rand(0...1) + x.should be_kind_of(Integer) + x.should eql(0) + end + + it "returns a Float if at least one side is Float" do + seed = 42 + x1 = Random.new(seed).rand(0...1.0) + x2 = Random.new(seed).rand(0.0...1.0) + x3 = Random.new(seed).rand(0.0...1) + + x3.should be_kind_of(Float) + x1.should equal(x3) + x2.should equal(x3) + + (0.0...1.0).should include(x3) + end + end + it "returns a numeric for an range argument where max is < 1" do rand(0.25..0.75).should be_kind_of(Numeric) end diff --git a/spec/ruby/core/module/ruby2_keywords_spec.rb b/spec/ruby/core/module/ruby2_keywords_spec.rb new file mode 100644 index 0000000..34c45cb --- /dev/null +++ b/spec/ruby/core/module/ruby2_keywords_spec.rb @@ -0,0 +1,112 @@ https://github.com/ruby/ruby/blob/trunk/spec/ruby/core/module/ruby2_keywords_spec.rb#L1 +require_relative '../../spec_helper' +require_relative 'fixtures/classes' + +ruby_version_is "2.7" do + describe "Module#ruby2_keywords" do + it "marks the final hash argument as keyword hash" do + obj = Object.new + + obj.singleton_class.class_exec do + def foo(*a) a.last end + ruby2_keywords :foo + end + + last = obj.foo(1, 2, a: "a") + Hash.ruby2_keywords_hash?(last).should == true + end + + ruby_version_is "2.7" ... "3.0" do + it "fixes delegation warnings when calling a method accepting keywords" do + obj = Object.new + + obj.singleton_class.class_exec do + def foo(*a) bar(*a) end + def bar(*a, **b) end + end + + -> { obj.foo(1, 2, {a: "a"}) }.should complain(/Using the last argument as keyword parameters is deprecated/) + + obj.singleton_class.class_exec do + ruby2_keywords :foo + end + + -> { obj.foo(1, 2, {a: "a"}) }.should_not complain + end + end + + it "returns nil" do + obj = Object.new + + obj.singleton_class.class_exec do + def foo(*a) end + + ruby2_keywords(:foo).should == nil + end + end + + it "raises NameError when passed not existing method name" do + obj = Object.new + + -> { + obj.singleton_class.class_exec do + ruby2_keywords :not_existing + end + }.should raise_error(NameError, /undefined method `not_existing'/) + end + + it "acceps String as well" do + obj = Object.new + + obj.singleton_class.class_exec do + def foo(*a) a.last end + ruby2_keywords "foo" + end + + last = obj.foo(1, 2, a: "a") + Hash.ruby2_keywords_hash?(last).should == true + end + + it "raises TypeError when passed not Symbol or String" do + obj = Object.new + + -> { + obj.singleton_class.class_exec do + ruby2_keywor (... truncated) -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/