Skip to content

Commit

Permalink
Update to ruby/spec@e69a14c
Browse files Browse the repository at this point in the history
  • Loading branch information
eregon committed Sep 29, 2019
1 parent f9a9f3c commit a17bc04
Show file tree
Hide file tree
Showing 8 changed files with 158 additions and 8 deletions.
8 changes: 8 additions & 0 deletions spec/ruby/core/enumerator/lazy/flat_map_spec.rb
Expand Up @@ -5,4 +5,12 @@

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
16 changes: 16 additions & 0 deletions spec/ruby/core/gc/stat_spec.rb
@@ -0,0 +1,16 @@
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
16 changes: 16 additions & 0 deletions spec/ruby/core/kernel/warn_spec.rb
Expand Up @@ -101,6 +101,16 @@
-> { 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")
Expand Down Expand Up @@ -136,5 +146,11 @@
-> { 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
55 changes: 55 additions & 0 deletions spec/ruby/language/optional_assignments_spec.rb
Expand Up @@ -42,6 +42,18 @@

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
Expand Down Expand Up @@ -89,6 +101,49 @@

@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

Expand Down
30 changes: 30 additions & 0 deletions spec/ruby/library/rubygems/gem/bin_path_spec.rb
@@ -0,0 +1,30 @@
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
16 changes: 8 additions & 8 deletions spec/ruby/optional/capi/ext/string_spec.c
Expand Up @@ -14,14 +14,9 @@ extern "C" {
* 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);
Expand Down Expand Up @@ -124,6 +119,10 @@ VALUE string_spec_rb_str_conv_enc_opts(VALUE self, VALUE str, VALUE from, VALUE
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);
}
Expand Down Expand Up @@ -427,6 +426,7 @@ void Init_string_spec(void) {
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);
Expand Down
5 changes: 5 additions & 0 deletions spec/ruby/optional/capi/module_spec.rb
Expand Up @@ -322,6 +322,11 @@ def ruby_test_method
@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
Expand Down
20 changes: 20 additions & 0 deletions spec/ruby/optional/capi/string_spec.rb
Expand Up @@ -977,4 +977,24 @@ def inspect
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

0 comments on commit a17bc04

Please sign in to comment.