-
Notifications
You must be signed in to change notification settings - Fork 605
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge remote-tracking branch 'origin' into codedb-ffi-io
Showing
22 changed files
with
467 additions
and
76 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -102,6 +102,10 @@ def file | |
def defined_line | ||
@block_env.line | ||
end | ||
|
||
def scope | ||
@block_env.scope | ||
end | ||
end | ||
|
||
def from_proc? | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -31,5 +31,9 @@ def parameters | |
def source_location | ||
@receiver.source_location | ||
end | ||
|
||
def scope | ||
nil | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -78,5 +78,9 @@ def defined_line | |
def active_path | ||
@file | ||
end | ||
|
||
def scope | ||
nil | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
require File.expand_path('../../../spec_helper', __FILE__) | ||
require File.expand_path('../shared/read', __FILE__) | ||
|
||
describe 'ARGF.read_nonblock' do | ||
it_behaves_like :argf_read, :read_nonblock | ||
|
||
before do | ||
@file1_name = fixture(__FILE__, 'file1.txt') | ||
@file2_name = fixture(__FILE__, 'file2.txt') | ||
|
||
@file1 = File.read(@file1_name) | ||
@file2 = File.read(@file2_name) | ||
|
||
@chunk1 = File.read(@file1_name, 4) | ||
@chunk2 = File.read(@file2_name, 4) | ||
end | ||
|
||
after do | ||
ARGF.close unless ARGF.closed? | ||
end | ||
|
||
it 'reads up to the given amount of bytes' do | ||
argv [@file1_name] do | ||
ARGF.read_nonblock(4).should == @chunk1 | ||
end | ||
end | ||
|
||
describe 'when using multiple files' do | ||
it 'reads up to the given amount of bytes from the first file' do | ||
argv [@file1_name, @file2_name] do | ||
ARGF.read_nonblock(4).should == @chunk1 | ||
end | ||
end | ||
|
||
it 'returns an empty String when reading after having read the first file in its entirety' do | ||
argv [@file1_name, @file2_name] do | ||
ARGF.read_nonblock(File.size(@file1_name)).should == @file1 | ||
ARGF.read_nonblock(4).should == '' | ||
end | ||
end | ||
end | ||
|
||
describe 'when ARGV is empty' do | ||
it 'raises EOFError' do | ||
proc { argv [] { ARGF.read_nonblock(4) } }.should raise_error(EOFError) | ||
end | ||
end | ||
|
||
it 'reads up to the given bytes from STDIN' do | ||
stdin = ruby_exe('print ARGF.read_nonblock(4)', :args => "< #{@file1_name}") | ||
|
||
stdin.should == @chunk1 | ||
end | ||
|
||
it 'reads up to the given bytes from a file when a file and STDIN are present' do | ||
stdin = ruby_exe("print ARGF.read_nonblock(4)", :args => "#{@file1_name} - < #{@file2_name}") | ||
|
||
stdin.should == @chunk1 | ||
end | ||
|
||
it 'raises IO::EAGAINWaitReadable when STDIN is empty' do | ||
input = 'ARGF.read_nonblock(4) rescue print $!.class' | ||
stdin = ruby_exe(input, escape: true) | ||
|
||
stdin.should == 'IO::EAGAINWaitReadable' | ||
end | ||
|
||
it 'returns :wait_readable when the :exception is set to false' do | ||
input = 'p ARGF.read_nonblock(4, nil, exception: false)' | ||
stdin = ruby_exe(input, escape: true) | ||
|
||
stdin.strip.should == ':wait_readable' | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
require File.expand_path('../../../spec_helper', __FILE__) | ||
|
||
describe 'Binding#local_variable_defined?' do | ||
it 'returns false when a variable is not defined' do | ||
binding.local_variable_defined?(:foo).should == false | ||
end | ||
|
||
it 'returns true when a regular local variable is defined' do | ||
foo = 10 | ||
|
||
binding.local_variable_defined?(:foo).should == true | ||
end | ||
|
||
it 'returns true when a local variable is defined using eval()' do | ||
bind = binding | ||
|
||
bind.eval('foo = 10') | ||
|
||
bind.local_variable_defined?(:foo).should == true | ||
end | ||
|
||
it 'returns true when a local variable is defined using Binding#local_variable_set' do | ||
bind = binding | ||
|
||
bind.local_variable_set(:foo, 10) | ||
|
||
bind.local_variable_defined?(:foo).should == true | ||
end | ||
|
||
it 'returns true when a local variable is defined in a parent scope' do | ||
foo = 10 | ||
|
||
proc { binding.local_variable_defined?(:foo) }.call.should == true | ||
end | ||
|
||
it 'allows usage of a String as the variable name' do | ||
foo = 10 | ||
|
||
binding.local_variable_defined?('foo').should == true | ||
end | ||
|
||
it 'allows usage of an object responding to #to_str as the variable name' do | ||
foo = 10 | ||
name = mock(:obj) | ||
|
||
name.stub!(:to_str).and_return('foo') | ||
|
||
binding.local_variable_defined?(name).should == true | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
require File.expand_path('../../../spec_helper', __FILE__) | ||
|
||
describe 'Binding#local_variable_get' do | ||
it 'gets a local variable defined before the Binding' do | ||
number = 10 | ||
|
||
binding.local_variable_get(:number).should == 10 | ||
end | ||
|
||
it 'gets a local variable defined in the Binding' do | ||
bind = binding | ||
|
||
bind.local_variable_set(:number, 10) | ||
bind.local_variable_get(:number).should == 10 | ||
end | ||
|
||
it 'gets a local variable defined using eval()' do | ||
bind = binding | ||
|
||
bind.eval('number = 10') | ||
|
||
bind.local_variable_get(:number).should == 10 | ||
end | ||
|
||
it 'gets a local variable defined in a parent scope' do | ||
number = 10 | ||
|
||
proc { binding.local_variable_get(:number) }.call.should == 10 | ||
end | ||
|
||
it 'raises NameError for an undefined local variable' do | ||
proc { binding.local_variable_get(:cats) }.should raise_error(NameError) | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
require File.expand_path('../../../spec_helper', __FILE__) | ||
|
||
describe 'Binding#local_variable_set' do | ||
it 'sets a new local variable' do | ||
bind = binding | ||
|
||
bind.local_variable_set(:number, 10) | ||
bind.local_variable_get(:number).should == 10 | ||
end | ||
|
||
it 'sets a local variable using a String as the variable name' do | ||
bind = binding | ||
|
||
bind.local_variable_set('number', 10) | ||
bind.local_variable_get('number').should == 10 | ||
end | ||
|
||
it 'sets a local variable using an object responding to #to_str as the variable name' do | ||
bind = binding | ||
name = mock(:obj) | ||
|
||
name.stub!(:to_str).and_return('number') | ||
|
||
bind.local_variable_set(name, 10) | ||
bind.local_variable_get(name).should == 10 | ||
end | ||
|
||
it 'scopes new local variables to the receiving Binding' do | ||
bind = binding | ||
|
||
bind.local_variable_set(:number, 10) | ||
|
||
proc { number }.should raise_error(NameError) | ||
end | ||
|
||
it 'overwrites an existing local variable defined before a Binding' do | ||
number = 10 | ||
bind = binding | ||
|
||
bind.local_variable_set(:number, 20) | ||
|
||
number.should == 20 | ||
end | ||
|
||
it 'overwrites a local variable defined using eval()' do | ||
bind = binding | ||
|
||
bind.eval('number = 10') | ||
|
||
bind.local_variable_set(:number, 20) | ||
|
||
bind.local_variable_get(:number).should == 20 | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
#include "ruby.h" | ||
|
||
void Init_class_id_under_autoload_spec(void) { | ||
rb_define_class_id_under(rb_cObject, rb_intern("ClassIdUnderAutoload"), 0); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters