Skip to content

Commit

Permalink
Update RubySpec to d7ff2bee090df4b254f7fcaa70bef6f0e6081dff
Browse files Browse the repository at this point in the history
git-svn-id: http://svn.macosforge.org/repository/ruby/MacRuby/trunk@4984 23306eb0-4c56-4727-a40e-e92c0eb68959
  • Loading branch information
alloy committed Dec 6, 2010
1 parent f751478 commit 2bb5ffb
Show file tree
Hide file tree
Showing 59 changed files with 1,263 additions and 70 deletions.
35 changes: 33 additions & 2 deletions spec/frozen/core/array/cycle_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@
ruby_version_is '1.8.7' do
it "returns nil and does nothing for non positive n or empty arrays" do
[1,2,3].cycle(0){ throw "ball"}.should be_nil
[].cycle(0){ throw "ball"}.should be_nil
[].cycle(6){ throw "ball"}.should be_nil
end

it "cycle as many times as requested" do
[1,2,3].cycle(2).to_a.should == [1,2,3,1,2,3]
end

it "loop indefinitely if no n" do
it "cycles indefinitely if called without argument" do
bomb = 10
[1,2,3].cycle do
bomb -= 1
Expand All @@ -18,6 +18,37 @@
bomb.should == 0
end

it "cycles indefinitely if argument is nil" do
bomb = 10
[1,2,3].cycle(nil) do
bomb -= 1
break 42 if bomb <= 0
end.should == 42
bomb.should == 0
end

it "doesn't rescue StopIteration" do
lambda {
[1,2,3].cycle do
raise StopIteration
end
}.should raise_error(StopIteration)
lambda {
[1,2,3].cycle(2) do
raise StopIteration
end
}.should raise_error(StopIteration)
end

it "raises a TypeError if passed a non-Numeric and non-nil argument" do
lambda {
[1,2,3].cycle("4"){}
}.should raise_error(TypeError)
lambda {
[1,2,3].cycle(false){}
}.should raise_error(TypeError)
end

it "yields successive elements of the array repeatedly" do
b = []
[1,2,3].cycle do |elem|
Expand Down
6 changes: 6 additions & 0 deletions spec/frozen/core/array/delete_if_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,18 @@
it "raises a TypeError on a frozen array" do
lambda { ArraySpecs.frozen_array.delete_if {} }.should raise_error(TypeError)
end
it "raises a TypeError on an empty frozen array" do
lambda { ArraySpecs.empty_frozen_array.delete_if {} }.should raise_error(TypeError)
end
end

ruby_version_is '1.9' do
it "raises a RuntimeError on a frozen array" do
lambda { ArraySpecs.frozen_array.delete_if {} }.should raise_error(RuntimeError)
end
it "raises a RuntimeError on an empty frozen array" do
lambda { ArraySpecs.empty_frozen_array.delete_if {} }.should raise_error(RuntimeError)
end
end

it "keeps tainted status" do
Expand Down
6 changes: 6 additions & 0 deletions spec/frozen/core/array/fill_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -47,12 +47,18 @@
it "raises a TypeError on a frozen array" do
lambda { ArraySpecs.frozen_array.fill('x') }.should raise_error(TypeError)
end
it "raises a TypeError on an empty frozen array" do
lambda { ArraySpecs.empty_frozen_array.fill('x') }.should raise_error(TypeError)
end
end

ruby_version_is '1.9' do
it "raises a RuntimeError on a frozen array" do
lambda { ArraySpecs.frozen_array.fill('x') }.should raise_error(RuntimeError)
end
it "raises a RuntimeError on an empty frozen array" do
lambda { ArraySpecs.empty_frozen_array.fill('x') }.should raise_error(RuntimeError)
end
end

it "raises an ArgumentError if 4 or more arguments are passed when no block given" do
Expand Down
6 changes: 6 additions & 0 deletions spec/frozen/core/array/fixtures/classes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,12 @@ def self.frozen_array
frozen_array
end

def self.empty_frozen_array
frozen_array = []
frozen_array.freeze
frozen_array
end

def self.recursive_array
a = [1, 'two', 3.0]
5.times { a << a }
Expand Down
1 change: 1 addition & 0 deletions spec/frozen/core/array/flatten_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,7 @@
# see [ruby-core:23663]
it "raises a RuntimeError on frozen arrays when the array would not be modified" do
lambda { ArraySpecs.frozen_array.flatten! }.should raise_error(RuntimeError)
lambda { ArraySpecs.empty_frozen_array.flatten! }.should raise_error(RuntimeError)
end
end
end
7 changes: 7 additions & 0 deletions spec/frozen/core/array/pop_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -42,13 +42,20 @@
it "raises a TypeError on a frozen array" do
lambda { ArraySpecs.frozen_array.pop }.should raise_error(TypeError)
end
it "raises a TypeError on an empty frozen array" do
lambda { ArraySpecs.empty_frozen_array.pop }.should raise_error(TypeError)
end
end

ruby_version_is '1.9' do
it "raises a RuntimeError on a frozen array" do
lambda { ArraySpecs.frozen_array.pop }.should raise_error(RuntimeError)
end

it "raises a RuntimeError on an empty frozen array" do
lambda { ArraySpecs.empty_frozen_array.pop }.should raise_error(RuntimeError)
end

it "keeps untrusted status" do
a = [1, 2].untrust
a.pop
Expand Down
6 changes: 6 additions & 0 deletions spec/frozen/core/array/reject_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -100,12 +100,18 @@
it "raises a TypeError on a frozen array" do
lambda { ArraySpecs.frozen_array.reject! {} }.should raise_error(TypeError)
end
it "raises a TypeError on an empty frozen array" do
lambda { ArraySpecs.empty_frozen_array.reject! {} }.should raise_error(TypeError)
end
end

ruby_version_is "1.9" do
it "raises a RuntimeError on a frozen array" do
lambda { ArraySpecs.frozen_array.reject! {} }.should raise_error(RuntimeError)
end
it "raises a RuntimeError on an empty frozen array" do
lambda { ArraySpecs.empty_frozen_array.reject! {} }.should raise_error(RuntimeError)
end
end

it_behaves_like :enumeratorize, :reject!
Expand Down
6 changes: 6 additions & 0 deletions spec/frozen/core/array/shift_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,18 @@
it "raises a TypeError on a frozen array" do
lambda { ArraySpecs.frozen_array.shift }.should raise_error(TypeError)
end
it "raises a TypeError on an empty frozen array" do
lambda { ArraySpecs.empty_frozen_array.shift }.should raise_error(TypeError)
end
end

ruby_version_is "1.9" do
it "raises a RuntimeError on a frozen array" do
lambda { ArraySpecs.frozen_array.shift }.should raise_error(RuntimeError)
end
it "raises a RuntimeError on an empty frozen array" do
lambda { ArraySpecs.empty_frozen_array.shift }.should raise_error(RuntimeError)
end
end

ruby_version_is '' ... '1.8.7' do
Expand Down
4 changes: 3 additions & 1 deletion spec/frozen/core/array/shuffle_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -45,13 +45,15 @@

ruby_version_is ""..."1.9" do
it "raises a TypeError on a frozen array" do
lambda { ArraySpecs.frozen_array.reverse! }.should raise_error(TypeError)
lambda { ArraySpecs.frozen_array.shuffle! }.should raise_error(TypeError)
lambda { ArraySpecs.empty_frozen_array.shuffle! }.should raise_error(TypeError)
end
end

ruby_version_is "1.9" do
it "raises a RuntimeError on a frozen array" do
lambda { ArraySpecs.frozen_array.shuffle! }.should raise_error(RuntimeError)
lambda { ArraySpecs.empty_frozen_array.shuffle! }.should raise_error(RuntimeError)
end
end
end
Expand Down
19 changes: 4 additions & 15 deletions spec/frozen/core/array/sort_by_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,23 +24,12 @@
a.should be_kind_of(Array)
end

ruby_version_is '' ... '1.9' do
it "raises a TypeError on a frozen array" do
lambda { ArraySpecs.frozen_array.sort_by! {} }.should raise_error(TypeError)
end

it "temporarily freezes self and recovers after sorted" do
a = [1, 2, 3]
a.sort_by! { |x,y| a.frozen?.should == true; x <=> y }
a.frozen?.should == false
end
it "raises a RuntimeError on a frozen array" do
lambda { ArraySpecs.frozen_array.sort_by! {}}.should raise_error(RuntimeError)
end

ruby_version_is '1.9' do
it "raises a RuntimeError on a frozen array" do
lambda { ArraySpecs.frozen_array.sort_by! {}}.should raise_error(RuntimeError)
end

it "raises a RuntimeError on an empty frozen array" do
lambda { ArraySpecs.empty_frozen_array.sort_by! {}}.should raise_error(RuntimeError)
end

it "returns the specified value when it would break in the given block" do
Expand Down
5 changes: 5 additions & 0 deletions spec/frozen/core/array/uniq_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,11 @@ def self.eql?(o) taint; o.taint; true; end
# see [ruby-core:23666]
it "raises a RuntimeError on a frozen array when the array would not be modified" do
lambda { ArraySpecs.frozen_array.uniq!}.should raise_error(RuntimeError)
lambda { ArraySpecs.empty_frozen_array.uniq!}.should raise_error(RuntimeError)
end

it "doesn't yield to the block on a frozen array" do
lambda { ArraySpecs.frozen_array.uniq!{ raise RangeError, "shouldn't yield"}}.should raise_error(RuntimeError)
end
end

Expand Down
6 changes: 6 additions & 0 deletions spec/frozen/core/enumerable/shared/find.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
before :each do
@elements = [2, 4, 6, 8, 10]
@numerous = EnumerableSpecs::Numerous.new(*@elements)
@empty = []
end

it "passes each entry in enum to block while block when block is false" do
Expand Down Expand Up @@ -40,6 +41,11 @@
@numerous.send(@method, fail_proc) {|e| false }.should == "cheeseburgers"
end

it "calls the ifnone proc when there are no elements" do
fail_proc = lambda { "yay" }
@empty.send(@method, fail_proc) {|e| true}.should == "yay"
end

ruby_version_is "" ... "1.8.7" do
it "raises a LocalJumpError if no block given" do
lambda { @numerous.send(@method) }.should raise_error(LocalJumpError)
Expand Down
7 changes: 7 additions & 0 deletions spec/frozen/core/env/shared/value.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,11 @@
it "returns false if ENV doesn't have the value" do
ENV.send(@method, "this_value_should_never_exist").should == false
end

platform_is :windows do
it "looks up values case-insensitively" do
ENV["FOO"] = "bar"
ENV.send(@method, "Foo").should == "bar"
end
end
end
11 changes: 4 additions & 7 deletions spec/frozen/core/file/stat/inspect_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,10 @@
after :each do
rm_r @file
end

it "produces a nicely formatted description of a File::Stat object" do
st = File.stat(@file)
#p "#<File::Stat dev=0x#{st.dev.to_s(16)}, ino=#{st.ino}, mode=#{sprintf("%06s", st.mode.to_s(8))}, nlink=#{st.nlink}, uid=#{st.uid}, gid=#{st.gid}, rdev=0x#{st.rdev.to_s(16)}, size=#{st.size}, blksize=#{st.blksize}, blocks=#{st.blocks}, atime=#{st.atime}, mtime=#{st.mtime}, ctime=#{st.ctime}>"
st.inspect.should == "#<File::Stat dev=0x#{st.dev.to_s(16)}, ino=#{st.ino}, mode=#{sprintf("%07d", st.mode.to_s(8).to_i)}, nlink=#{st.nlink}, uid=#{st.uid}, gid=#{st.gid}, rdev=0x#{st.rdev.to_s(16)}, size=#{st.size}, blksize=#{st.blksize}, blocks=#{st.blocks}, atime=#{st.atime}, mtime=#{st.mtime}, ctime=#{st.ctime}>"

st = File.stat(@file)
expected = "#<File::Stat dev=0x#{st.dev.to_s(16)}, ino=#{st.ino}, mode=#{sprintf("%07o", st.mode)}, nlink=#{st.nlink}, uid=#{st.uid}, gid=#{st.gid}, rdev=0x#{st.rdev.to_s(16)}, size=#{st.size}, blksize=#{st.blksize}, blocks=#{st.blocks}, atime=#{st.atime}, mtime=#{st.mtime}, ctime=#{st.ctime}>"
st.inspect.should == expected
end


end
1 change: 1 addition & 0 deletions spec/frozen/core/float/round_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,6 @@
0.4.round.should == 0
-2.8.round.should == -3
0.0.round.should == 0
0.49999999999999994.round.should == 0 # see http://jira.codehaus.org/browse/JRUBY-5048
end
end
11 changes: 11 additions & 0 deletions spec/frozen/core/io/foreach_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,17 @@
ScratchPad.record []
end

ruby_version_is "1.9" do
before :each do
Encoding.default_external = Encoding::UTF_8
@orig_exteenc = Encoding.default_external
end

after :each do
Encoding.default_external = @orig_exteenc
end
end

it "raises TypeError if the first parameter is nil" do
lambda { IO.foreach(nil) {} }.should raise_error(TypeError)
end
Expand Down
11 changes: 11 additions & 0 deletions spec/frozen/core/io/readlines_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,17 @@
@io.close unless @io.closed?
end

ruby_version_is "1.9" do
before :each do
Encoding.default_external = Encoding::UTF_8
@orig_exteenc = Encoding.default_external
end

after :each do
Encoding.default_external = @orig_exteenc
end
end

it "raises an IOError if the stream is closed" do
@io.close
lambda { @io.readlines }.should raise_error(IOError)
Expand Down
Loading

0 comments on commit 2bb5ffb

Please sign in to comment.