[前][次][番号順一覧][スレッド一覧]

ruby-changes:58018

From: Benoit <ko1@a...>
Date: Mon, 30 Sep 2019 01:02:56 +0900 (JST)
Subject: [ruby-changes:58018] a17bc04d15 (master): Update to ruby/spec@e69a14c

https://git.ruby-lang.org/ruby.git/commit/?id=a17bc04d15

From a17bc04d159ec9839cc8cfb02dc0cdd2802110f4 Mon Sep 17 00:00:00 2001
From: Benoit Daloze <eregontp@g...>
Date: Sun, 29 Sep 2019 18:01:32 +0200
Subject: Update to ruby/spec@e69a14c


diff --git a/spec/ruby/core/enumerator/lazy/flat_map_spec.rb b/spec/ruby/core/enumerator/lazy/flat_map_spec.rb
index 6a3391a..5dcaa8b 100644
--- a/spec/ruby/core/enumerator/lazy/flat_map_spec.rb
+++ b/spec/ruby/core/enumerator/lazy/flat_map_spec.rb
@@ -5,4 +5,12 @@ require_relative 'shared/collect_concat' https://github.com/ruby/ruby/blob/trunk/spec/ruby/core/enumerator/lazy/flat_map_spec.rb#L5
 
 describe "Enumerator::Lazy#flat_map" do
   it_behaves_like :enumerator_lazy_collect_concat, :flat_map
+
+  it "properly unwraps nested yields" do
+    s = Enumerator.new do |y| loop do y << [1, 2] end end
+
+    expected = s.take(3).flat_map { |x| x }.to_a
+    actual = s.lazy.take(3).flat_map{ |x| x }.force
+    actual.should == expected
+  end
 end
diff --git a/spec/ruby/core/gc/stat_spec.rb b/spec/ruby/core/gc/stat_spec.rb
new file mode 100644
index 0000000..51bd00c
--- /dev/null
+++ b/spec/ruby/core/gc/stat_spec.rb
@@ -0,0 +1,16 @@ https://github.com/ruby/ruby/blob/trunk/spec/ruby/core/gc/stat_spec.rb#L1
+require_relative '../../spec_helper'
+
+describe "GC.stat" do
+  it "supports access by key" do
+    keys = [:heap_free_slots, :total_allocated_objects, :count]
+    keys.each do |key|
+      GC.stat(key).should be_kind_of(Integer)
+    end
+  end
+
+  it "returns hash of values" do
+    stat = GC.stat
+    stat.should be_kind_of(Hash)
+    stat.keys.should include(:count)
+  end
+end
diff --git a/spec/ruby/core/kernel/warn_spec.rb b/spec/ruby/core/kernel/warn_spec.rb
index d05a379..2a404a2 100644
--- a/spec/ruby/core/kernel/warn_spec.rb
+++ b/spec/ruby/core/kernel/warn_spec.rb
@@ -101,6 +101,16 @@ describe "Kernel#warn" do https://github.com/ruby/ruby/blob/trunk/spec/ruby/core/kernel/warn_spec.rb#L101
         -> { w.f4("foo", 3) }.should output(nil, %r|core/kernel/fixtures/classes.rb:#{w.f3_call_lineno}: warning: foo|)
       end
 
+      it "converts first arg using to_s" do
+        w = KernelSpecs::WarnInNestedCall.new
+
+        -> { w.f4(false, 0) }.should output(nil, %r|core/kernel/fixtures/classes.rb:#{w.warn_call_lineno}: warning: false|)
+        -> { w.f4(nil, 1) }.should output(nil, %r|core/kernel/fixtures/classes.rb:#{w.f1_call_lineno}: warning: |)
+        obj = mock("obj")
+        obj.should_receive(:to_s).and_return("to_s called")
+        -> { w.f4(obj, 2) }.should output(nil, %r|core/kernel/fixtures/classes.rb:#{w.f2_call_lineno}: warning: to_s called|)
+      end
+
       it "does not prepend caller information if line number is too big" do
         w = KernelSpecs::WarnInNestedCall.new
         -> { w.f4("foo", 100) }.should output(nil, "warning: foo\n")
@@ -136,5 +146,11 @@ describe "Kernel#warn" do https://github.com/ruby/ruby/blob/trunk/spec/ruby/core/kernel/warn_spec.rb#L146
         -> { warn "", uplevel: Object.new }.should raise_error(TypeError)
       end
     end
+
+    it "treats empty hash as no keyword argument" do
+      h = {}
+      -> { warn(**h) }.should_not complain(verbose: true)
+      -> { warn('foo', **h) }.should complain("foo\n")
+    end
   end
 end
diff --git a/spec/ruby/language/optional_assignments_spec.rb b/spec/ruby/language/optional_assignments_spec.rb
index 04abc24..3d9e0db 100644
--- a/spec/ruby/language/optional_assignments_spec.rb
+++ b/spec/ruby/language/optional_assignments_spec.rb
@@ -42,6 +42,18 @@ describe 'Optional variable assignments' do https://github.com/ruby/ruby/blob/trunk/spec/ruby/language/optional_assignments_spec.rb#L42
 
         a.should == 10
       end
+
+      it 'returns the new value if set to false' do
+        a = false
+
+        (a ||= 20).should == 20
+      end
+
+      it 'returns the original value if truthy' do
+        a = 10
+
+        (a ||= 20).should == 10
+      end
     end
 
     describe 'using a accessor' do
@@ -89,6 +101,49 @@ describe 'Optional variable assignments' do https://github.com/ruby/ruby/blob/trunk/spec/ruby/language/optional_assignments_spec.rb#L101
 
         @a.b.should == 10
       end
+
+      it 'returns the new value if set to false' do
+        def @a.b=(x)
+          :v
+        end
+
+        @a.b = false
+        (@a.b ||= 20).should == 20
+      end
+
+      it 'returns the original value if truthy' do
+        def @a.b=(x)
+          @b = x
+          :v
+        end
+
+        @a.b = 10
+        (@a.b ||= 20).should == 10
+      end
+
+      it 'works when writer is private' do
+        klass = Class.new do
+          def t
+            self.b = false
+            (self.b ||= 10).should == 10
+            (self.b ||= 20).should == 10
+          end
+
+          def b
+            @b
+          end
+
+          def b=(x)
+            @b = x
+            :v
+          end
+
+          private :b=
+        end
+
+        klass.new.t
+      end
+
     end
   end
 
diff --git a/spec/ruby/library/rubygems/gem/bin_path_spec.rb b/spec/ruby/library/rubygems/gem/bin_path_spec.rb
new file mode 100644
index 0000000..cdf9507
--- /dev/null
+++ b/spec/ruby/library/rubygems/gem/bin_path_spec.rb
@@ -0,0 +1,30 @@ https://github.com/ruby/ruby/blob/trunk/spec/ruby/library/rubygems/gem/bin_path_spec.rb#L1
+require_relative '../../../spec_helper'
+require 'rubygems'
+
+describe "Gem.bin_path" do
+  before :each do
+    @bundle_gemfile = ENV['BUNDLE_GEMFILE']
+    ENV['BUNDLE_GEMFILE'] = tmp("no-gemfile")
+  end
+
+  after :each do
+    ENV['BUNDLE_GEMFILE'] = @bundle_gemfile
+  end
+
+  it "finds executables of default gems, which are the only files shipped for default gems" do
+    # For instance, Gem.bin_path("bundler", "bundle") is used by rails new
+
+    if Gem.respond_to? :default_specifications_dir
+      default_specifications_dir = Gem.default_specifications_dir
+    else
+      default_specifications_dir = Gem::Specification.default_specifications_dir
+    end
+
+    Gem::Specification.each_spec([default_specifications_dir]) do |spec|
+      spec.executables.each do |exe|
+        path = Gem.bin_path(spec.name, exe)
+        File.exist?(path).should == true
+      end
+    end
+  end
+end
diff --git a/spec/ruby/optional/capi/ext/string_spec.c b/spec/ruby/optional/capi/ext/string_spec.c
index 6ad0b46..4976dc9 100644
--- a/spec/ruby/optional/capi/ext/string_spec.c
+++ b/spec/ruby/optional/capi/ext/string_spec.c
@@ -14,14 +14,9 @@ extern "C" { https://github.com/ruby/ruby/blob/trunk/spec/ruby/optional/capi/ext/string_spec.c#L14
  * On TruffleRuby RSTRING_PTR and the bytes remain in managed memory
  * until they must be written to native memory.
  * In some specs we want to test using the native memory. */
-char* NATIVE_RSTRING_PTR(VALUE str) {
-  char* ptr = RSTRING_PTR(str);
-  char** native = malloc(sizeof(char*));
-  *native = ptr;
-  ptr = *native;
-  free(native);
-  return ptr;
-}
+#ifndef NATIVE_RSTRING_PTR
+#define NATIVE_RSTRING_PTR(str) RSTRING_PTR(str)
+#endif
 
 VALUE string_spec_rb_cstr2inum(VALUE self, VALUE str, VALUE inum) {
   int num = FIX2INT(inum);
@@ -124,6 +119,10 @@ VALUE string_spec_rb_str_conv_enc_opts(VALUE self, VALUE str, VALUE from, VALUE https://github.com/ruby/ruby/blob/trunk/spec/ruby/optional/capi/ext/string_spec.c#L119
   return rb_str_conv_enc_opts(str, from_enc, to_enc, FIX2INT(ecflags), ecopts);
 }
 
+VALUE string_spec_rb_str_drop_bytes(VALUE self, VALUE str, VALUE len) {
+  return rb_str_drop_bytes(str, NUM2LONG(len));
+}
+
 VALUE string_spec_rb_str_export(VALUE self, VALUE str) {
   return rb_str_export(str);
 }
@@ -427,6 +426,7 @@ void Init_string_spec(void) { https://github.com/ruby/ruby/blob/trunk/spec/ruby/optional/capi/ext/string_spec.c#L426
   rb_define_method(cls, "rb_str_cmp", string_spec_rb_str_cmp, 2);
   rb_define_method(cls, "rb_str_conv_enc", string_spec_rb_str_conv_enc, 3);
   rb_define_method(cls, "rb_str_conv_enc_opts", string_spec_rb_str_conv_enc_opts, 5);
+  rb_define_method(cls, "rb_str_drop_bytes", string_spec_rb_str_drop_bytes, 2);
   rb_define_method(cls, "rb_str_export", string_spec_rb_str_export, 1);
   rb_define_method(cls, "rb_str_export_locale", string_spec_rb_str_export_locale, 1);
   rb_define_method(cls, "rb_str_dup", string_spec_rb_str_dup, 1);
diff --git a/spec/ruby/optional/capi/module_spec.rb b/spec/ruby/optional/capi/module_spec.rb
index 34e6db8..bf09e9d 100644
--- a/spec/ruby/optional/capi/module_spec.rb
+++ b/spec/ruby/optional/capi/module_spec.rb
@@ -322,6 +322,11 @@ describe "CApiModule" do https://github.com/ruby/ruby/blob/trunk/spec/ruby/optional/capi/module_spec.rb#L322
       @class.should_not have_instance_method(:ruby_test_method)
     end
 
+    it "undefines private methods also" do
+      @m.rb_undef_method @class, "initialize_copy"
+      -> { @class.new.dup }.should raise_error(NoMethodError)
+    end
+
     it "does not raise exceptions when passed a missing name" do
       -> { @m.rb_undef_method @class, "not_exist" }.should_not raise_error
     end
diff --git a/spec/ruby/optional/capi/string_spec.rb b/spec/ruby/optional/capi/string_spec.rb
index 469a190..1cfd590 100644
--- a/spec/ruby/optional/capi/string_spec.rb
+++ b/spec/ruby/optional/capi/string_spec.rb
@@ -977,4 +977,24 @@ end https://github.com/ruby/ruby/blob/trunk/spec/ruby/optional/capi/string_spec.rb#L977
     end
 
   end
+
+  describe "rb_str_drop_bytes" do
+    it "drops N characters for an ASCII string" do
+      str = "12345678".encode("US-ASCII")
+      @s.rb_str_drop_bytes(str, 4)
+      str.should == "5678".encode("US-ASCII")
+    end
+
+    it "drop N/2 characters for a UTF-16 string" do
+      str = "12345678".encode("UTF-16LE")
+      @s.rb_str_drop_bytes(str, 4)
+      str.should == "345678".encode("UTF-16LE")
+    end
+
+    it "drop N/4 characters for a UTF-32 string" do
+      str = "12345678".encode("UTF-32LE")
+      @s.rb_str_drop_bytes(str, 4)
+      str.should == "2345678".encode("UTF-32LE")
+    end
+  end
 end
-- 
cgit v0.10.2


--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]