[macruby-changes] [2147] MacRuby/branches/experimental/spec/frozen
source_changes at macosforge.org
source_changes at macosforge.org
Sun Aug 2 06:12:25 PDT 2009
Revision: 2147
http://trac.macosforge.org/projects/ruby/changeset/2147
Author: eloy.de.enige at gmail.com
Date: 2009-08-02 06:12:21 -0700 (Sun, 02 Aug 2009)
Log Message:
-----------
Updated RubySpec to f4a506d2e78447c34f1e1ac28b948a20532c8e67
Modified Paths:
--------------
MacRuby/branches/experimental/spec/frozen/TODO
MacRuby/branches/experimental/spec/frozen/core/array/each_index_spec.rb
MacRuby/branches/experimental/spec/frozen/core/array/each_spec.rb
MacRuby/branches/experimental/spec/frozen/core/array/equal_value_spec.rb
MacRuby/branches/experimental/spec/frozen/core/array/fixtures/classes.rb
MacRuby/branches/experimental/spec/frozen/core/array/join_spec.rb
MacRuby/branches/experimental/spec/frozen/core/array/multiply_spec.rb
MacRuby/branches/experimental/spec/frozen/core/array/reverse_each_spec.rb
MacRuby/branches/experimental/spec/frozen/core/array/rindex_spec.rb
MacRuby/branches/experimental/spec/frozen/core/bignum/bit_and_spec.rb
MacRuby/branches/experimental/spec/frozen/core/bignum/bit_or_spec.rb
MacRuby/branches/experimental/spec/frozen/core/bignum/bit_xor_spec.rb
MacRuby/branches/experimental/spec/frozen/core/bignum/divmod_spec.rb
MacRuby/branches/experimental/spec/frozen/core/class/new_spec.rb
MacRuby/branches/experimental/spec/frozen/core/comparable/equal_value_spec.rb
MacRuby/branches/experimental/spec/frozen/core/complex/real_spec.rb
MacRuby/branches/experimental/spec/frozen/core/dir/chdir_spec.rb
MacRuby/branches/experimental/spec/frozen/core/dir/shared/exists.rb
MacRuby/branches/experimental/spec/frozen/core/enumerable/collect_spec.rb
MacRuby/branches/experimental/spec/frozen/core/enumerable/map_spec.rb
MacRuby/branches/experimental/spec/frozen/core/enumerable/shared/collect.rb
MacRuby/branches/experimental/spec/frozen/core/env/each_key_spec.rb
MacRuby/branches/experimental/spec/frozen/core/env/each_value_spec.rb
MacRuby/branches/experimental/spec/frozen/core/env/element_reference_spec.rb
MacRuby/branches/experimental/spec/frozen/core/env/fetch_spec.rb
MacRuby/branches/experimental/spec/frozen/core/env/keys_spec.rb
MacRuby/branches/experimental/spec/frozen/core/env/shared/each.rb
MacRuby/branches/experimental/spec/frozen/core/env/to_a_spec.rb
MacRuby/branches/experimental/spec/frozen/core/env/values_at_spec.rb
MacRuby/branches/experimental/spec/frozen/core/env/values_spec.rb
MacRuby/branches/experimental/spec/frozen/core/file/expand_path_spec.rb
MacRuby/branches/experimental/spec/frozen/core/file/join_spec.rb
MacRuby/branches/experimental/spec/frozen/core/float/divmod_spec.rb
MacRuby/branches/experimental/spec/frozen/core/hash/element_reference_spec.rb
MacRuby/branches/experimental/spec/frozen/core/hash/inspect_spec.rb
MacRuby/branches/experimental/spec/frozen/core/hash/shared/to_s.rb
MacRuby/branches/experimental/spec/frozen/core/io/inspect_spec.rb
MacRuby/branches/experimental/spec/frozen/core/io/print_spec.rb
MacRuby/branches/experimental/spec/frozen/core/io/read_spec.rb
MacRuby/branches/experimental/spec/frozen/core/io/reopen_spec.rb
MacRuby/branches/experimental/spec/frozen/core/io/shared/new.rb
MacRuby/branches/experimental/spec/frozen/core/kernel/caller_spec.rb
MacRuby/branches/experimental/spec/frozen/core/kernel/eval_spec.rb
MacRuby/branches/experimental/spec/frozen/core/kernel/fixtures/classes.rb
MacRuby/branches/experimental/spec/frozen/core/kernel/freeze_spec.rb
MacRuby/branches/experimental/spec/frozen/core/kernel/instance_eval_spec.rb
MacRuby/branches/experimental/spec/frozen/core/kernel/lambda_spec.rb
MacRuby/branches/experimental/spec/frozen/core/kernel/load_spec.rb
MacRuby/branches/experimental/spec/frozen/core/kernel/methods_spec.rb
MacRuby/branches/experimental/spec/frozen/core/kernel/proc_spec.rb
MacRuby/branches/experimental/spec/frozen/core/kernel/puts_spec.rb
MacRuby/branches/experimental/spec/frozen/core/kernel/require_spec.rb
MacRuby/branches/experimental/spec/frozen/core/kernel/send_spec.rb
MacRuby/branches/experimental/spec/frozen/core/kernel/shared/lambda.rb
MacRuby/branches/experimental/spec/frozen/core/kernel/sprintf_spec.rb
MacRuby/branches/experimental/spec/frozen/core/kernel/tap_spec.rb
MacRuby/branches/experimental/spec/frozen/core/marshal/load_spec.rb
MacRuby/branches/experimental/spec/frozen/core/math/acos_spec.rb
MacRuby/branches/experimental/spec/frozen/core/method/clone_spec.rb
MacRuby/branches/experimental/spec/frozen/core/method/fixtures/classes.rb
MacRuby/branches/experimental/spec/frozen/core/method/source_location_spec.rb
MacRuby/branches/experimental/spec/frozen/core/module/autoload_spec.rb
MacRuby/branches/experimental/spec/frozen/core/module/const_defined_spec.rb
MacRuby/branches/experimental/spec/frozen/core/module/fixtures/classes.rb
MacRuby/branches/experimental/spec/frozen/core/module/instance_methods_spec.rb
MacRuby/branches/experimental/spec/frozen/core/module/name_spec.rb
MacRuby/branches/experimental/spec/frozen/core/module/shared/class_eval.rb
MacRuby/branches/experimental/spec/frozen/core/numeric/angle_spec.rb
MacRuby/branches/experimental/spec/frozen/core/numeric/arg_spec.rb
MacRuby/branches/experimental/spec/frozen/core/numeric/conj_spec.rb
MacRuby/branches/experimental/spec/frozen/core/numeric/conjugate_spec.rb
MacRuby/branches/experimental/spec/frozen/core/numeric/div_spec.rb
MacRuby/branches/experimental/spec/frozen/core/numeric/divmod_spec.rb
MacRuby/branches/experimental/spec/frozen/core/numeric/imag_spec.rb
MacRuby/branches/experimental/spec/frozen/core/numeric/imaginary_spec.rb
MacRuby/branches/experimental/spec/frozen/core/numeric/modulo_spec.rb
MacRuby/branches/experimental/spec/frozen/core/numeric/phase_spec.rb
MacRuby/branches/experimental/spec/frozen/core/numeric/polar_spec.rb
MacRuby/branches/experimental/spec/frozen/core/numeric/quo_spec.rb
MacRuby/branches/experimental/spec/frozen/core/numeric/real_spec.rb
MacRuby/branches/experimental/spec/frozen/core/proc/block_pass_spec.rb
MacRuby/branches/experimental/spec/frozen/core/proc/equal_value_spec.rb
MacRuby/branches/experimental/spec/frozen/core/proc/fixtures/procs.rb
MacRuby/branches/experimental/spec/frozen/core/string/element_set_spec.rb
MacRuby/branches/experimental/spec/frozen/core/string/tr_spec.rb
MacRuby/branches/experimental/spec/frozen/core/struct/inspect_spec.rb
MacRuby/branches/experimental/spec/frozen/core/thread/inspect_spec.rb
MacRuby/branches/experimental/spec/frozen/core/thread/status_spec.rb
MacRuby/branches/experimental/spec/frozen/language/block_spec.rb
MacRuby/branches/experimental/spec/frozen/language/class_spec.rb
MacRuby/branches/experimental/spec/frozen/language/defined_spec.rb
MacRuby/branches/experimental/spec/frozen/language/file_spec.rb
MacRuby/branches/experimental/spec/frozen/language/super_spec.rb
MacRuby/branches/experimental/spec/frozen/language/versions/block_1.9.rb
MacRuby/branches/experimental/spec/frozen/library/complex/Complex_spec.rb
MacRuby/branches/experimental/spec/frozen/library/complex/hash_spec.rb
MacRuby/branches/experimental/spec/frozen/library/complex/imag_spec.rb
MacRuby/branches/experimental/spec/frozen/library/complex/image_spec.rb
MacRuby/branches/experimental/spec/frozen/library/complex/inspect_spec.rb
MacRuby/branches/experimental/spec/frozen/library/complex/math/acos_spec.rb
MacRuby/branches/experimental/spec/frozen/library/complex/math/acosh_spec.rb
MacRuby/branches/experimental/spec/frozen/library/complex/math/asin_spec.rb
MacRuby/branches/experimental/spec/frozen/library/complex/math/asinh_spec.rb
MacRuby/branches/experimental/spec/frozen/library/complex/math/atan2_spec.rb
MacRuby/branches/experimental/spec/frozen/library/complex/math/atan_spec.rb
MacRuby/branches/experimental/spec/frozen/library/complex/math/atanh_spec.rb
MacRuby/branches/experimental/spec/frozen/library/complex/math/cos_spec.rb
MacRuby/branches/experimental/spec/frozen/library/complex/math/cosh_spec.rb
MacRuby/branches/experimental/spec/frozen/library/complex/math/exp_spec.rb
MacRuby/branches/experimental/spec/frozen/library/complex/math/log10_spec.rb
MacRuby/branches/experimental/spec/frozen/library/complex/math/log_spec.rb
MacRuby/branches/experimental/spec/frozen/library/complex/math/shared/acosh.rb
MacRuby/branches/experimental/spec/frozen/library/complex/math/sin_spec.rb
MacRuby/branches/experimental/spec/frozen/library/complex/math/sinh_spec.rb
MacRuby/branches/experimental/spec/frozen/library/complex/math/sqrt_spec.rb
MacRuby/branches/experimental/spec/frozen/library/complex/math/tan_spec.rb
MacRuby/branches/experimental/spec/frozen/library/complex/math/tanh_spec.rb
MacRuby/branches/experimental/spec/frozen/library/complex/minus_spec.rb
MacRuby/branches/experimental/spec/frozen/library/complex/numeric/angle_spec.rb
MacRuby/branches/experimental/spec/frozen/library/complex/numeric/arg_spec.rb
MacRuby/branches/experimental/spec/frozen/library/complex/numeric/conj_spec.rb
MacRuby/branches/experimental/spec/frozen/library/complex/numeric/conjugate_spec.rb
MacRuby/branches/experimental/spec/frozen/library/complex/numeric/imag_spec.rb
MacRuby/branches/experimental/spec/frozen/library/complex/numeric/image_spec.rb
MacRuby/branches/experimental/spec/frozen/library/complex/numeric/polar_spec.rb
MacRuby/branches/experimental/spec/frozen/library/complex/numeric/real_spec.rb
MacRuby/branches/experimental/spec/frozen/library/prime/prime_division_spec.rb
MacRuby/branches/experimental/spec/frozen/shared/complex/equal_value.rb
MacRuby/branches/experimental/spec/frozen/shared/complex/exponent.rb
MacRuby/branches/experimental/spec/frozen/tags/1.9/core/io/reopen_tags.txt
MacRuby/branches/experimental/spec/frozen/tags/1.9/core/kernel/freeze_tags.txt
MacRuby/branches/experimental/spec/frozen/tags/1.9/core/kernel/puts_tags.txt
MacRuby/branches/experimental/spec/frozen/upstream
Added Paths:
-----------
MacRuby/branches/experimental/spec/frozen/core/basicobject/fixtures/
MacRuby/branches/experimental/spec/frozen/core/basicobject/fixtures/classes.rb
MacRuby/branches/experimental/spec/frozen/core/basicobject/instance_exec_spec.rb
MacRuby/branches/experimental/spec/frozen/core/complex/Complex_spec.rb
MacRuby/branches/experimental/spec/frozen/core/complex/fdiv_spec.rb
MacRuby/branches/experimental/spec/frozen/core/complex/hash_spec.rb
MacRuby/branches/experimental/spec/frozen/core/complex/imag_spec.rb
MacRuby/branches/experimental/spec/frozen/core/complex/inspect_spec.rb
MacRuby/branches/experimental/spec/frozen/core/complex/minus_spec.rb
MacRuby/branches/experimental/spec/frozen/core/enumerable/join_spec.rb
MacRuby/branches/experimental/spec/frozen/core/kernel/public_send_spec.rb
MacRuby/branches/experimental/spec/frozen/core/kernel/shared/send.rb
MacRuby/branches/experimental/spec/frozen/core/module/fixtures/name.rb
MacRuby/branches/experimental/spec/frozen/core/proc/case_compare_spec.rb
MacRuby/branches/experimental/spec/frozen/core/proc/curry_spec.rb
MacRuby/branches/experimental/spec/frozen/core/proc/eql_spec.rb
MacRuby/branches/experimental/spec/frozen/core/proc/hash_spec.rb
MacRuby/branches/experimental/spec/frozen/core/proc/lambda_spec.rb
MacRuby/branches/experimental/spec/frozen/core/proc/parameters_spec.rb
MacRuby/branches/experimental/spec/frozen/core/proc/shared/equal.rb
MacRuby/branches/experimental/spec/frozen/core/proc/source_location_spec.rb
MacRuby/branches/experimental/spec/frozen/core/proc/versions/
MacRuby/branches/experimental/spec/frozen/core/proc/versions/parameters_1.9.rb
MacRuby/branches/experimental/spec/frozen/core/proc/yield_spec.rb
MacRuby/branches/experimental/spec/frozen/core/random/
MacRuby/branches/experimental/spec/frozen/core/random/bytes_spec.rb
MacRuby/branches/experimental/spec/frozen/core/random/equal_value_spec.rb
MacRuby/branches/experimental/spec/frozen/core/random/float_spec.rb
MacRuby/branches/experimental/spec/frozen/core/random/int_spec.rb
MacRuby/branches/experimental/spec/frozen/core/random/new_seed_spec.rb
MacRuby/branches/experimental/spec/frozen/core/random/new_spec.rb
MacRuby/branches/experimental/spec/frozen/core/random/rand_spec.rb
MacRuby/branches/experimental/spec/frozen/core/random/seed_spec.rb
MacRuby/branches/experimental/spec/frozen/core/random/srand_spec.rb
MacRuby/branches/experimental/spec/frozen/core/string/encode_spec.rb
MacRuby/branches/experimental/spec/frozen/core/symbol/intern_spec.rb
MacRuby/branches/experimental/spec/frozen/language/literal_lambda_spec.rb
MacRuby/branches/experimental/spec/frozen/language/versions/literal_lambda_1.9.rb
MacRuby/branches/experimental/spec/frozen/shared/array/
MacRuby/branches/experimental/spec/frozen/shared/array/join.rb
MacRuby/branches/experimental/spec/frozen/shared/complex/Complex.rb
MacRuby/branches/experimental/spec/frozen/shared/complex/hash.rb
MacRuby/branches/experimental/spec/frozen/shared/complex/image.rb
MacRuby/branches/experimental/spec/frozen/shared/complex/inspect.rb
MacRuby/branches/experimental/spec/frozen/shared/complex/minus.rb
MacRuby/branches/experimental/spec/frozen/shared/complex/numeric/
MacRuby/branches/experimental/spec/frozen/shared/complex/numeric/arg.rb
MacRuby/branches/experimental/spec/frozen/shared/complex/numeric/conj.rb
MacRuby/branches/experimental/spec/frozen/shared/complex/numeric/imag.rb
MacRuby/branches/experimental/spec/frozen/shared/complex/numeric/polar.rb
MacRuby/branches/experimental/spec/frozen/shared/complex/numeric/real.rb
MacRuby/branches/experimental/spec/frozen/tags/1.9/core/enumerable/join_tags.txt
Removed Paths:
-------------
MacRuby/branches/experimental/spec/frozen/core/array/shared/join.rb
MacRuby/branches/experimental/spec/frozen/core/complex/modulo_spec.rb
MacRuby/branches/experimental/spec/frozen/core/numeric/shared/conj.rb
MacRuby/branches/experimental/spec/frozen/core/numeric/shared/imag.rb
MacRuby/branches/experimental/spec/frozen/core/numeric/shared/phase.rb
MacRuby/branches/experimental/spec/frozen/library/complex/numeric/shared/arg.rb
MacRuby/branches/experimental/spec/frozen/library/complex/numeric/shared/conjugate.rb
MacRuby/branches/experimental/spec/frozen/library/complex/numeric/shared/image.rb
MacRuby/branches/experimental/spec/frozen/library/complex/shared/image.rb
MacRuby/branches/experimental/spec/frozen/tags/1.9/core/hash/element_reference_tags.txt
MacRuby/branches/experimental/spec/frozen/tags/1.9/core/kernel/caller_tags.txt
MacRuby/branches/experimental/spec/frozen/tags/1.9/core/module/attr_writer_tags.txt
MacRuby/branches/experimental/spec/frozen/tags/1.9/core/module/autoload_tags.txt
MacRuby/branches/experimental/spec/frozen/tags/1.9/core/module/class_eval_tags.txt
MacRuby/branches/experimental/spec/frozen/tags/1.9/core/module/class_variable_defined_tags.txt
MacRuby/branches/experimental/spec/frozen/tags/1.9/core/module/class_variable_get_tags.txt
MacRuby/branches/experimental/spec/frozen/tags/1.9/core/module/class_variable_set_tags.txt
MacRuby/branches/experimental/spec/frozen/tags/1.9/core/module/class_variables_tags.txt
MacRuby/branches/experimental/spec/frozen/tags/1.9/core/module/const_defined_tags.txt
MacRuby/branches/experimental/spec/frozen/tags/1.9/core/module/const_missing_tags.txt
MacRuby/branches/experimental/spec/frozen/tags/1.9/core/module/define_method_tags.txt
MacRuby/branches/experimental/spec/frozen/tags/1.9/core/module/freeze_tags.txt
MacRuby/branches/experimental/spec/frozen/tags/1.9/core/module/include_tags.txt
MacRuby/branches/experimental/spec/frozen/tags/1.9/core/module/instance_methods_tags.txt
MacRuby/branches/experimental/spec/frozen/tags/1.9/core/module/module_eval_tags.txt
MacRuby/branches/experimental/spec/frozen/tags/1.9/core/module/name_tags.txt
MacRuby/branches/experimental/spec/frozen/tags/1.9/core/module/private_method_defined_tags.txt
MacRuby/branches/experimental/spec/frozen/tags/1.9/core/module/protected_instance_methods_tags.txt
MacRuby/branches/experimental/spec/frozen/tags/1.9/core/module/protected_method_defined_tags.txt
MacRuby/branches/experimental/spec/frozen/tags/1.9/core/module/public_instance_methods_tags.txt
MacRuby/branches/experimental/spec/frozen/tags/1.9/core/module/public_method_defined_tags.txt
MacRuby/branches/experimental/spec/frozen/tags/1.9/core/range/inspect_tags.txt
MacRuby/branches/experimental/spec/frozen/tags/1.9/core/range/to_s_tags.txt
Modified: MacRuby/branches/experimental/spec/frozen/TODO
===================================================================
--- MacRuby/branches/experimental/spec/frozen/TODO 2009-08-02 08:57:05 UTC (rev 2146)
+++ MacRuby/branches/experimental/spec/frozen/TODO 2009-08-02 13:12:21 UTC (rev 2147)
@@ -23,6 +23,7 @@
we handle ruby_bug guards that pass on HEAD, but fail on earlier versions.
* Replace Infinity/NaN hacks with the new helpers.
* Think about how we can support exhaustive tests of certain features.
+* Specify 'public' and 'protected' keywords.
# Windows
==========
@@ -52,3 +53,11 @@
* Ask Ruby core about what Array#pack should do to encoding; citing failing
tests as example questions.
* Spec Ripper.
+* 1.9 defines methods such as instance_eval on BasicObject; not Kernel as in
+ 1.8. Do we need to share these specs so that the methods are specified in
+ the correct place?
+* #public_send and #send could share some common functionality, but shared
+ specs use #send internally. Ask brixen what to do.
+* Determine how we're going to specify the vast Gem module...
+* Specify require_relative
+* Share Enumerable#join with Hash#join once Enumerable#join is more stable.
Modified: MacRuby/branches/experimental/spec/frozen/core/array/each_index_spec.rb
===================================================================
--- MacRuby/branches/experimental/spec/frozen/core/array/each_index_spec.rb 2009-08-02 08:57:05 UTC (rev 2146)
+++ MacRuby/branches/experimental/spec/frozen/core/array/each_index_spec.rb 2009-08-02 13:12:21 UTC (rev 2147)
@@ -1,31 +1,24 @@
require File.dirname(__FILE__) + '/../../spec_helper'
require File.dirname(__FILE__) + '/fixtures/classes'
+# Modifying a collection while the contents are being iterated
+# gives undefined behavior. See
+# http://blade.nagaokaut.ac.jp/cgi-bin/scat.rb/ruby/ruby-core/23633
+
describe "Array#each_index" do
- it "passes the index of each element to the block" do
- a = []
- x = ['a', 'b', 'c', 'd']
- x.each_index { |i| a << i }.should equal(x)
- a.should == [0, 1, 2, 3]
+ before :each do
+ ScratchPad.record []
end
- it "passes the index of each element to the block even if the array is changed during iteration" do
- a = []
- x = [10, 11, 12, 13,]
- x.each_index {|i| a << i; x << x[i]+5 if (x[i]%2).zero? }.should equal(x)
- a.should == [0, 1, 2, 3, 4, 5]
+ it "passes the index of each element to the block" do
+ a = ['a', 'b', 'c', 'd']
+ a.each_index { |i| ScratchPad << i }
+ ScratchPad.recorded.should == [0, 1, 2, 3]
end
- it "passes the index from 0..size even if size changes" do
- a = []
- x = [10, 11, 12, 13, 14]
- x.each_index {|i| a << i; x.pop if (x[i]%2).zero? }.should equal(x)
- a.should == [0, 1, 2]
-
- a = []
- x = [10, 11, 12, 13, 14]
- x.each_index {|i| a << i; x.shift if (x[i]%2).zero? }.should equal(x)
- a.should == [0, 1, 2]
+ it "returns self" do
+ a = [:a, :b, :c]
+ a.each_index { |i| }.should equal(a)
end
ruby_version_is '' ... '1.8.7' do
@@ -33,6 +26,7 @@
lambda{ [1,2].each_index }.should raise_error(LocalJumpError)
end
end
+
ruby_version_is '1.8.7' do
it 'returns an Enumerator if no block given' do
[1,2].each_index.should be_kind_of(enumerator_class)
Modified: MacRuby/branches/experimental/spec/frozen/core/array/each_spec.rb
===================================================================
--- MacRuby/branches/experimental/spec/frozen/core/array/each_spec.rb 2009-08-02 08:57:05 UTC (rev 2146)
+++ MacRuby/branches/experimental/spec/frozen/core/array/each_spec.rb 2009-08-02 13:12:21 UTC (rev 2147)
@@ -1,6 +1,10 @@
require File.dirname(__FILE__) + '/../../spec_helper'
require File.dirname(__FILE__) + '/fixtures/classes'
+# Modifying a collection while the contents are being iterated
+# gives undefined behavior. See
+# http://blade.nagaokaut.ac.jp/cgi-bin/scat.rb/ruby/ruby-core/23633
+
describe "Array#each" do
it "yields each element to the block" do
a = []
@@ -9,27 +13,6 @@
a.should == [1, 2, 3]
end
- it "yields each element to the block even if the array is changed during iteration" do
- a = [1, 2, 3, 4, 5]
- b = []
- a.each {|x| b << x; a << x+5 if (x%2).zero? }
- b.should == [1, 2, 3, 4, 5, 7, 9]
- end
-
- it "yields only elements that are still in the array" do
- a = [0, 1, 2, 3, 4]
- b = []
- a.each {|x| b << x; a.pop if (x%2).zero? }
- b.should == [0, 1, 2]
- end
-
- it "yields elements based on an internal index" do
- a = [0, 1, 2, 3, 4]
- b = []
- a.each {|x| b << x; a.shift if (x%2).zero? }
- b.should == [0, 2, 4]
- end
-
it "yields each element to a block that takes multiple arguments" do
a = [[1, 2], :a, [3, 4]]
b = []
@@ -47,6 +30,7 @@
lambda{ [1,2].each }.should raise_error(LocalJumpError)
end
end
+
ruby_version_is '1.8.7' do
it 'returns an Enumerator if no block given' do
[1,2].each.should be_kind_of(enumerator_class)
Modified: MacRuby/branches/experimental/spec/frozen/core/array/equal_value_spec.rb
===================================================================
--- MacRuby/branches/experimental/spec/frozen/core/array/equal_value_spec.rb 2009-08-02 08:57:05 UTC (rev 2146)
+++ MacRuby/branches/experimental/spec/frozen/core/array/equal_value_spec.rb 2009-08-02 13:12:21 UTC (rev 2147)
@@ -25,4 +25,9 @@
obj.should_receive(:==).and_return(true)
[obj].should == [5]
end
+
+ # As per bug #1720
+ it "returns false for [NaN] == [NaN]" do
+ [nan_value].should_not == [nan_value]
+ end
end
Modified: MacRuby/branches/experimental/spec/frozen/core/array/fixtures/classes.rb
===================================================================
--- MacRuby/branches/experimental/spec/frozen/core/array/fixtures/classes.rb 2009-08-02 08:57:05 UTC (rev 2146)
+++ MacRuby/branches/experimental/spec/frozen/core/array/fixtures/classes.rb 2009-08-02 13:12:21 UTC (rev 2147)
@@ -144,4 +144,13 @@
nil
end
end
+
+ # Useful for shared specs where you pass in an object as the third argument.
+ # @object.new(a,b,c) creates an Array-like object with elements a, b, and c.
+ # This class allows a similar constructor for Array
+ class NewArray
+ def self.new(*args)
+ args
+ end
+ end
end
Modified: MacRuby/branches/experimental/spec/frozen/core/array/join_spec.rb
===================================================================
--- MacRuby/branches/experimental/spec/frozen/core/array/join_spec.rb 2009-08-02 08:57:05 UTC (rev 2146)
+++ MacRuby/branches/experimental/spec/frozen/core/array/join_spec.rb 2009-08-02 13:12:21 UTC (rev 2147)
@@ -1,10 +1,11 @@
require File.dirname(__FILE__) + '/../../spec_helper'
require File.dirname(__FILE__) + '/fixtures/classes'
-require File.dirname(__FILE__) + '/shared/join'
+require File.dirname(__FILE__) + '/../../shared/array/join'
describe "Array#join" do
- it_behaves_like :array_join, :join
+ it_behaves_like :array_join, :join, ArraySpecs::NewArray
+
it "does not separates elements when the passed separator is nil" do
[1, 2, 3].join(nil).should == '123'
end
Modified: MacRuby/branches/experimental/spec/frozen/core/array/multiply_spec.rb
===================================================================
--- MacRuby/branches/experimental/spec/frozen/core/array/multiply_spec.rb 2009-08-02 08:57:05 UTC (rev 2146)
+++ MacRuby/branches/experimental/spec/frozen/core/array/multiply_spec.rb 2009-08-02 13:12:21 UTC (rev 2147)
@@ -1,6 +1,6 @@
require File.dirname(__FILE__) + '/../../spec_helper'
require File.dirname(__FILE__) + '/fixtures/classes'
-require File.dirname(__FILE__) + '/shared/join'
+require File.dirname(__FILE__) + '/../../shared/array/join'
describe "Array#*" do
it "tries to convert the passed argument to a String using #to_str" do
@@ -126,5 +126,5 @@
end
describe "Array#* with a string" do
- it_behaves_like :array_join, :*
+ it_behaves_like :array_join, :*, ArraySpecs::NewArray
end
Modified: MacRuby/branches/experimental/spec/frozen/core/array/reverse_each_spec.rb
===================================================================
--- MacRuby/branches/experimental/spec/frozen/core/array/reverse_each_spec.rb 2009-08-02 08:57:05 UTC (rev 2146)
+++ MacRuby/branches/experimental/spec/frozen/core/array/reverse_each_spec.rb 2009-08-02 13:12:21 UTC (rev 2147)
@@ -1,50 +1,46 @@
require File.dirname(__FILE__) + '/../../spec_helper'
require File.dirname(__FILE__) + '/fixtures/classes'
+# Modifying a collection while the contents are being iterated
+# gives undefined behavior. See
+# http://blade.nagaokaut.ac.jp/cgi-bin/scat.rb/ruby/ruby-core/23633
+
describe "Array#reverse_each" do
+ before :each do
+ ScratchPad.record []
+ end
+
it "traverses array in reverse order and pass each element to block" do
- a = []
- [1, 3, 4, 6].reverse_each { |i| a << i }
- a.should == [6, 4, 3, 1]
+ [1, 3, 4, 6].reverse_each { |i| ScratchPad << i }
+ ScratchPad.recorded.should == [6, 4, 3, 1]
end
- it "properly handles recursive arrays" do
- res = []
+ it "returns self" do
+ a = [:a, :b, :c]
+ a.reverse_each { |x| }.should equal(a)
+ end
+
+ it "yields only the top level element of an empty recursive arrays" do
empty = ArraySpecs.empty_recursive_array
- empty.reverse_each { |i| res << i }
- res.should == [empty]
+ empty.reverse_each { |i| ScratchPad << i }
+ ScratchPad.recorded.should == [empty]
+ end
- res = []
+ it "yields only the top level element of a recursive array" do
array = ArraySpecs.recursive_array
- array.reverse_each { |i| res << i }
- res.should == [array, array, array, array, array, 3.0, 'two', 1]
+ array.reverse_each { |i| ScratchPad << i }
+ ScratchPad.recorded.should == [array, array, array, array, array, 3.0, 'two', 1]
end
- it "does not fail when removing elements from block" do
- ary = [0, 0, 1, 1, 3, 2, 1, :x]
-
- count = 0
-
- ary.reverse_each do |item|
- count += 1
-
- if item == :x then
- ary.slice!(1..-1)
- end
- end
-
- count.should == 2
- end
-
ruby_version_is '' ... '1.8.7' do
it 'raises a LocalJumpError if no block given' do
lambda{ [1,2].reverse_each }.should raise_error(LocalJumpError)
end
end
+
ruby_version_is '1.8.7' do
it 'returns an Enumerator if no block given' do
[1,2].reverse_each.should be_kind_of(enumerator_class)
end
end
-
end
Modified: MacRuby/branches/experimental/spec/frozen/core/array/rindex_spec.rb
===================================================================
--- MacRuby/branches/experimental/spec/frozen/core/array/rindex_spec.rb 2009-08-02 08:57:05 UTC (rev 2146)
+++ MacRuby/branches/experimental/spec/frozen/core/array/rindex_spec.rb 2009-08-02 13:12:21 UTC (rev 2147)
@@ -1,6 +1,10 @@
require File.dirname(__FILE__) + '/../../spec_helper'
require File.dirname(__FILE__) + '/fixtures/classes'
+# Modifying a collection while the contents are being iterated
+# gives undefined behavior. See
+# http://blade.nagaokaut.ac.jp/cgi-bin/scat.rb/ruby/ruby-core/23633
+
describe "Array#rindex" do
it "returns the first index backwards from the end where element == to object" do
key = 3
@@ -27,26 +31,18 @@
[1, 1, 3, 2, 1, 3].rindex(4).should == nil
end
- it "does not fail when removing elements from block" do
- sentinel = mock('sentinel')
- ary = [0, 0, 1, 1, 3, 2, 1, sentinel]
-
- sentinel.instance_variable_set(:@ary, ary)
- def sentinel.==(o) @ary.slice!(1..-1); false; end
-
- ary.rindex(0).should == 0
- end
-
- it "properly handles recursive arrays" do
+ it "properly handles empty recursive arrays" do
empty = ArraySpecs.empty_recursive_array
empty.rindex(empty).should == 0
empty.rindex(1).should be_nil
+ end
+ it "properly handles recursive arrays" do
array = ArraySpecs.recursive_array
array.rindex(1).should == 0
array.rindex(array).should == 7
end
-
+
ruby_version_is "1.8.7" do
it "accepts a block instead of an argument" do
[4, 2, 1, 5, 1, 3].rindex{|x| x < 2}.should == 4
Deleted: MacRuby/branches/experimental/spec/frozen/core/array/shared/join.rb
===================================================================
--- MacRuby/branches/experimental/spec/frozen/core/array/shared/join.rb 2009-08-02 08:57:05 UTC (rev 2146)
+++ MacRuby/branches/experimental/spec/frozen/core/array/shared/join.rb 2009-08-02 13:12:21 UTC (rev 2147)
@@ -1,124 +0,0 @@
-describe :array_join, :shared => true do
- it "returns an empty string if the Array is empty" do
- a = []
- a.send(@method, ':').should == ''
- end
-
- it "returns a string formed by concatenating each element.to_s separated by separator without trailing separator" do
- obj = mock('foo')
- def obj.to_s() 'foo' end
- [1, 2, 3, 4, obj].send(@method, ' | ').should == '1 | 2 | 3 | 4 | foo'
-
- obj = mock('o')
- class << obj; undef :to_s; end
- obj.should_receive(:method_missing).with(:to_s).and_return("o")
- [1, obj].send(@method, ":").should == "1:o"
- end
-
- it "raises a NoMethodError if an element does not respond to #to_s" do
- obj = mock('o')
- class << obj; undef :to_s; end
- lambda{ [1,obj].send(@method, ':') }.should raise_error(NoMethodError)
- end
-
- it "uses the same separator with nested arrays" do
- [1, [2, [3, 4], 5], 6].send(@method, ":").should == "1:2:3:4:5:6"
- [1, [2, ArraySpecs::MyArray[3, 4], 5], 6].send(@method, ":").should == "1:2:3:4:5:6"
- end
-
- it "tries to convert the passed separator to a String using #to_str" do
- obj = mock('::')
- obj.should_receive(:to_str).and_return("::")
- [1, 2, 3, 4].send(@method, obj).should == '1::2::3::4'
- end
-
- # detail of joining recursive arrays is implementation depended. [ruby-dev:37021]
- it "handles recursive arrays" do
- x = []
- x << x
- x.send(@method, ':').should be_kind_of(String)
-
- x = ["one", "two"]
- x << x
- str = x.send(@method, '/')
- str.should include("one/two")
-
- x << "three"
- x << "four"
- str = x.send(@method, '/')
- str.should include("one/two")
- str.should include("three/four")
-
- # nested and recursive
- x = [["one", "two"], ["three", "four"]]
- x << x
- str = x.send(@method, '/')
- str.should include("one/two")
- str.should include("three/four")
-
- x = []
- y = []
- y << 9 << x << 8 << y << 7
- x << 1 << x << 2 << y << 3
- # representations when recursing from x
- # these are here to make it easier to understand what is happening
- str = x.send(@method, ':')
- str.should include('1')
- str.should include('2')
- str.should include('3')
- end
-
- it "does not consider taint of either the array or the separator when the array is empty" do
- [].send(@method, ":").tainted?.should == false
- [].taint.send(@method, ":").tainted?.should == false
- [].send(@method, ":".taint).tainted?.should == false
- [].taint.send(@method, ":".taint).tainted?.should == false
- end
-
- it "returns a string which would be infected with taint of the array, its elements or the separator when the array is not empty" do
- ["a", "b"].send(@method, ":").tainted?.should == false
- ["a", "b"].send(@method, ":".taint).tainted?.should == true
- ["a", "b"].taint.send(@method, ":").tainted?.should == true
- ["a", "b"].taint.send(@method, ":".taint).tainted?.should == true
- ["a", "b".taint].send(@method, ":").tainted?.should == true
- ["a", "b".taint].send(@method, ":".taint).tainted?.should == true
- ["a", "b".taint].taint.send(@method, ":").tainted?.should == true
- ["a", "b".taint].taint.send(@method, ":".taint).tainted?.should == true
- ["a".taint, "b"].send(@method, ":").tainted?.should == true
- ["a".taint, "b"].send(@method, ":".taint).tainted?.should == true
- ["a".taint, "b"].taint.send(@method, ":").tainted?.should == true
- ["a".taint, "b"].taint.send(@method, ":".taint).tainted?.should == true
- ["a".taint, "b".taint].send(@method, ":").tainted?.should == true
- ["a".taint, "b".taint].send(@method, ":".taint).tainted?.should == true
- ["a".taint, "b".taint].taint.send(@method, ":").tainted?.should == true
- ["a".taint, "b".taint].taint.send(@method, ":".taint).tainted?.should == true
- end
-
- ruby_version_is '1.9' do
- it "does not consider untrustworthiness of either the array or the separator when the array is empty" do
- [].send(@method, ":").untrusted?.should == false
- [].untrust.send(@method, ":").untrusted?.should == false
- [].send(@method, ":".untrust).untrusted?.should == false
- [].untrust.send(@method, ":".untrust).untrusted?.should == false
- end
-
- it "returns a string which would be infected with untrustworthiness of the array, its elements or the separator when the array is not empty" do
- ["a", "b"].send(@method, ":").untrusted?.should == false
- ["a", "b"].send(@method, ":".untrust).untrusted?.should == true
- ["a", "b"].untrust.send(@method, ":").untrusted?.should == true
- ["a", "b"].untrust.send(@method, ":".untrust).untrusted?.should == true
- ["a", "b".untrust].send(@method, ":").untrusted?.should == true
- ["a", "b".untrust].send(@method, ":".untrust).untrusted?.should == true
- ["a", "b".untrust].untrust.send(@method, ":").untrusted?.should == true
- ["a", "b".untrust].untrust.send(@method, ":".untrust).untrusted?.should == true
- ["a".untrust, "b"].send(@method, ":").untrusted?.should == true
- ["a".untrust, "b"].send(@method, ":".untrust).untrusted?.should == true
- ["a".untrust, "b"].untrust.send(@method, ":").untrusted?.should == true
- ["a".untrust, "b"].untrust.send(@method, ":".untrust).untrusted?.should == true
- ["a".untrust, "b".untrust].send(@method, ":").untrusted?.should == true
- ["a".untrust, "b".untrust].send(@method, ":".untrust).untrusted?.should == true
- ["a".untrust, "b".untrust].untrust.send(@method, ":").untrusted?.should == true
- ["a".untrust, "b".untrust].untrust.send(@method, ":".untrust).untrusted?.should == true
- end
- end
-end
Added: MacRuby/branches/experimental/spec/frozen/core/basicobject/fixtures/classes.rb
===================================================================
--- MacRuby/branches/experimental/spec/frozen/core/basicobject/fixtures/classes.rb (rev 0)
+++ MacRuby/branches/experimental/spec/frozen/core/basicobject/fixtures/classes.rb 2009-08-02 13:12:21 UTC (rev 2147)
@@ -0,0 +1,17 @@
+module BasicObjectSpecs
+ class IVars
+ def initialize
+ @secret = 99
+ end
+ end
+
+ module InstExec
+ def self.included(base)
+ base.instance_exec { @@count = 2 }
+ end
+ end
+
+ module InstExecIncluded
+ include InstExec
+ end
+end
Added: MacRuby/branches/experimental/spec/frozen/core/basicobject/instance_exec_spec.rb
===================================================================
--- MacRuby/branches/experimental/spec/frozen/core/basicobject/instance_exec_spec.rb (rev 0)
+++ MacRuby/branches/experimental/spec/frozen/core/basicobject/instance_exec_spec.rb 2009-08-02 13:12:21 UTC (rev 2147)
@@ -0,0 +1,92 @@
+require File.dirname(__FILE__) + '/../../spec_helper'
+
+ruby_version_is "1.9" do
+
+ require File.dirname(__FILE__) + '/fixtures/classes'
+
+ describe "BasicObject#instance_exec" do
+ it "raises a LocalJumpError unless given a block" do
+ lambda { "hola".instance_exec }.should raise_error(LocalJumpError)
+ end
+
+ it "has an arity of -1" do
+ Object.new.method(:instance_exec).arity.should == -1
+ end
+
+ it "accepts arguments with a block" do
+ lambda { "hola".instance_exec(4, 5) { |a,b| a + b } }.should_not raise_error
+ end
+
+ it "doesn't pass self to the block as an argument" do
+ "hola".instance_exec { |o| o }.should be_nil
+ end
+
+ it "passes any arguments to the block" do
+ Object.new.instance_exec(1,2) {|one, two| one + two}.should == 3
+ end
+
+ it "only binds the exec to the receiver" do
+ f = Object.new
+ f.instance_exec do
+ def foo
+ 1
+ end
+ end
+ f.foo.should == 1
+ lambda { Object.new.foo }.should raise_error(NoMethodError)
+ end
+
+ # TODO: This should probably be replaced with a "should behave like" that uses
+ # the many scoping/binding specs from kernel/eval_spec, since most of those
+ # behaviors are the same for instance_exec. See also module_eval/class_eval.
+
+ it "binds self to the receiver" do
+ s = "hola"
+ (s == s.instance_exec { self }).should == true
+ end
+
+ it "executes in the context of the receiver" do
+ "Ruby-fu".instance_exec { size }.should == 7
+ Object.class_eval { "Ruby-fu".instance_exec{ to_s } }.should == "Ruby-fu"
+ end
+
+ it "has access to receiver's instance variables" do
+ BasicObjectSpecs::IVars.new.instance_exec { @secret }.should == 99
+ end
+
+ it "sets class variables in the receiver" do
+ BasicObjectSpecs::InstExec.class_variables.should include(:@@count)
+ BasicObjectSpecs::InstExec.send(:class_variable_get, :@@count).should == 2
+ end
+
+ it "raises a TypeError when defining methods on an immediate" do
+ lambda do
+ 1.instance_exec { def foo; end }
+ end.should raise_error(TypeError)
+ lambda do
+ :foo.instance_exec { def foo; end }
+ end.should raise_error(TypeError)
+ end
+
+ quarantine! do # Not clean, leaves cvars lying around to break other specs
+ it "scopes class var accesses in the caller when called on a Fixnum" do
+ # Fixnum can take instance vars
+ Fixnum.class_eval "@@__tmp_instance_exec_spec = 1"
+ (defined? @@__tmp_instance_exec_spec).should == nil
+
+ @@__tmp_instance_exec_spec = 2
+ 1.instance_exec { @@__tmp_instance_exec_spec }.should == 2
+ Fixnum.__send__(:remove_class_variable, :@@__tmp_instance_exec_spec)
+ end
+ end
+
+ it "raises a TypeError when defining methods on numerics" do
+ lambda do
+ (1.0).instance_exec { def foo; end }
+ end.should raise_error(TypeError)
+ lambda do
+ (1 << 64).instance_exec { def foo; end }
+ end.should raise_error(TypeError)
+ end
+ end
+end
Modified: MacRuby/branches/experimental/spec/frozen/core/bignum/bit_and_spec.rb
===================================================================
--- MacRuby/branches/experimental/spec/frozen/core/bignum/bit_and_spec.rb 2009-08-02 08:57:05 UTC (rev 2146)
+++ MacRuby/branches/experimental/spec/frozen/core/bignum/bit_and_spec.rb 2009-08-02 13:12:21 UTC (rev 2147)
@@ -15,12 +15,24 @@
((2*bignum_value) & -1).should == 18446744073709551616
((4*bignum_value) & -1).should == 36893488147419103232
((2*bignum_value) & (2*bignum_value)).should == 18446744073709551616
- (bignum_value & bignum_value(0xffff).to_f).should == 9223372036854775808
end
+ ruby_version_is ""..."1.9" do
+ it "coerces Float arguments into Integers" do
+ (@bignum & 3.4).should == 1
+ (bignum_value & bignum_value(0xffff).to_f).should == 9223372036854775808
+ end
+ end
+
+ ruby_version_is "1.9" do
+ it "raises a TypeError when passed a Float" do
+ lambda { (@bignum & 3.4) }.should raise_error(TypeError)
+ lambda {(bignum_value & bignum_value(0xffff).to_f)}.should
+ raise_error(TypeError)
+ end
+ end
+
it "tries to convert the given argument to an Integer using to_int" do
- (@bignum & 3.4).should == 1
-
(obj = mock('3')).should_receive(:to_int).and_return(3)
(@bignum & obj).should == 1
end
Modified: MacRuby/branches/experimental/spec/frozen/core/bignum/bit_or_spec.rb
===================================================================
--- MacRuby/branches/experimental/spec/frozen/core/bignum/bit_or_spec.rb 2009-08-02 08:57:05 UTC (rev 2146)
+++ MacRuby/branches/experimental/spec/frozen/core/bignum/bit_or_spec.rb 2009-08-02 13:12:21 UTC (rev 2147)
@@ -9,12 +9,24 @@
(@bignum | 2).should == 9223372036854775819
(@bignum | 9).should == 9223372036854775819
(@bignum | bignum_value).should == 9223372036854775819
- (bignum_value | bignum_value(0xffff).to_f).should == 9223372036854841344
end
+ ruby_version_is ""..."1.9" do
+ it "coerces Float arguments to Integers" do
+ (bignum_value | bignum_value(0xffff).to_f).should == 9223372036854841344
+ (@bignum | 9.9).should == 9223372036854775819
+ end
+ end
+
+ ruby_version_is "1.9" do
+ it "raises a TypeError when passed a Float" do
+ lambda { bignum_value | bignum_value(0xffff).to_f }.should
+ raise_error(TypeError)
+ lambda { @bignum | 9.9 }.should raise_error(TypeError)
+ end
+ end
+
it "tries to convert the given argument to an Integer using to_int" do
- (@bignum | 9.9).should == 9223372036854775819
-
(obj = mock('2')).should_receive(:to_int).and_return(2)
(@bignum | obj).should == 9223372036854775819
end
Modified: MacRuby/branches/experimental/spec/frozen/core/bignum/bit_xor_spec.rb
===================================================================
--- MacRuby/branches/experimental/spec/frozen/core/bignum/bit_xor_spec.rb 2009-08-02 08:57:05 UTC (rev 2146)
+++ MacRuby/branches/experimental/spec/frozen/core/bignum/bit_xor_spec.rb 2009-08-02 13:12:21 UTC (rev 2147)
@@ -9,12 +9,24 @@
(@bignum ^ 2).should == 9223372036854775824
(@bignum ^ @bignum).should == 0
(@bignum ^ 14).should == 9223372036854775836
- (bignum_value ^ bignum_value(0xffff).to_f).should == 65536
end
+ ruby_version_is ""..."1.9" do
+ it "coerces Float arguments into Integers" do
+ (@bignum ^ 14.5).should == 9223372036854775836
+ (bignum_value ^ bignum_value(0xffff).to_f).should == 65536
+ end
+ end
+
+ ruby_version_is "1.9" do
+ it "raises a TypeError when passed a Float" do
+ lambda { @bignum ^ 14.5 }.should raise_error(TypeError)
+ lambda { bignum_value ^ bignum_value(0xffff).to_f }.should
+ raise_error(TypeError)
+ end
+ end
+
it "tries to convert the given argument to an Integer using to_int" do
- (@bignum ^ 14.5).should == 9223372036854775836
-
(obj = mock('2')).should_receive(:to_int).and_return(2)
(@bignum ^ obj).should == 9223372036854775824
end
Modified: MacRuby/branches/experimental/spec/frozen/core/bignum/divmod_spec.rb
===================================================================
--- MacRuby/branches/experimental/spec/frozen/core/bignum/divmod_spec.rb 2009-08-02 08:57:05 UTC (rev 2146)
+++ MacRuby/branches/experimental/spec/frozen/core/bignum/divmod_spec.rb 2009-08-02 13:12:21 UTC (rev 2147)
@@ -32,6 +32,11 @@
lambda { (- at bignum).divmod(0) }.should raise_error(ZeroDivisionError)
end
+ # Behaviour established as correct in r23953
+ it "raises a FloatDomainError if other is NaN" do
+ lambda { @bignum.divmod(nan_value) }.should raise_error(FloatDomainError)
+ end
+
ruby_version_is ""..."1.9" do
it "raises a FloatDomainError when the given argument is 0 and a Float" do
lambda { @bignum.divmod(0.0) }.should raise_error(FloatDomainError)
Modified: MacRuby/branches/experimental/spec/frozen/core/class/new_spec.rb
===================================================================
--- MacRuby/branches/experimental/spec/frozen/core/class/new_spec.rb 2009-08-02 08:57:05 UTC (rev 2146)
+++ MacRuby/branches/experimental/spec/frozen/core/class/new_spec.rb 2009-08-02 13:12:21 UTC (rev 2147)
@@ -63,8 +63,8 @@
end
it "creates a class that can be given a name by assigning it to a constant" do
- MyClass = Class.new
- MyClass.name.should == "MyClass"
+ ::MyClass = Class.new
+ ::MyClass.name.should == "MyClass"
a = Class.new
MyClass::NestedClass = a
MyClass::NestedClass.name.should == "MyClass::NestedClass"
Modified: MacRuby/branches/experimental/spec/frozen/core/comparable/equal_value_spec.rb
===================================================================
--- MacRuby/branches/experimental/spec/frozen/core/comparable/equal_value_spec.rb 2009-08-02 08:57:05 UTC (rev 2146)
+++ MacRuby/branches/experimental/spec/frozen/core/comparable/equal_value_spec.rb 2009-08-02 13:12:21 UTC (rev 2147)
@@ -34,30 +34,65 @@
(a == b).should == false
end
- it "returns nil if calling #<=> on self returns nil or a non-Integer" do
- a = ComparableSpecs::Weird.new(0)
- b = ComparableSpecs::Weird.new(10)
+ ruby_version_is ""..."1.9" do
+ it "returns nil if calling #<=> on self returns nil or a non-Integer" do
+ a = ComparableSpecs::Weird.new(0)
+ b = ComparableSpecs::Weird.new(10)
- a.should_receive(:<=>).any_number_of_times.and_return(nil)
- (a == b).should == nil
+ a.should_receive(:<=>).any_number_of_times.and_return(nil)
+ (a == b).should == nil
- a = ComparableSpecs::Weird.new(0)
- a.should_receive(:<=>).any_number_of_times.and_return("abc")
- (a == b).should == nil
+ a = ComparableSpecs::Weird.new(0)
+ a.should_receive(:<=>).any_number_of_times.and_return("abc")
+ (a == b).should == nil
+ end
end
- it "returns nil if calling #<=> on self raises a StandardError" do
- a = ComparableSpecs::Weird.new(0)
- b = ComparableSpecs::Weird.new(10)
-
- def a.<=>(b) raise StandardError, "test"; end
- (a == b).should == nil
+ ruby_version_is "1.9" do
+ it "returns false if calling #<=> on self returns nil or a non-Integer" do
+ a = ComparableSpecs::Weird.new(0)
+ b = ComparableSpecs::Weird.new(10)
- # TypeError < StandardError
- def a.<=>(b) raise TypeError, "test"; end
- (a == b).should == nil
+ a.should_receive(:<=>).any_number_of_times.and_return(nil)
+ (a == b).should be_false
- def a.<=>(b) raise Exception, "test"; end
- lambda { (a == b).should == nil }.should raise_error(Exception)
+ a = ComparableSpecs::Weird.new(0)
+ a.should_receive(:<=>).any_number_of_times.and_return("abc")
+ (a == b).should be_false
+ end
end
+
+ ruby_version_is ""..."1.9" do
+ it "returns nil if calling #<=> on self raises a StandardError" do
+ a = ComparableSpecs::Weird.new(0)
+ b = ComparableSpecs::Weird.new(10)
+
+ def a.<=>(b) raise StandardError, "test"; end
+ (a == b).should == nil
+
+ # TypeError < StandardError
+ def a.<=>(b) raise TypeError, "test"; end
+ (a == b).should == nil
+
+ def a.<=>(b) raise Exception, "test"; end
+ lambda { (a == b).should == nil }.should raise_error(Exception)
+ end
+ end
+
+ ruby_version_is "1.9" do
+ # Behaviour confirmed by MRI test suite
+ it "returns false if calling #<=> on self raises an Exception" do
+ a = ComparableSpecs::Weird.new(0)
+ b = ComparableSpecs::Weird.new(10)
+
+ def a.<=>(b) raise StandardError, "test"; end
+ (a == b).should be_false
+
+ def a.<=>(b) raise TypeError, "test"; end
+ (a == b).should be_false
+
+ def a.<=>(b) raise Exception, "test"; end
+ lambda { (a == b).should be_false }.should raise_error(Exception)
+ end
+ end
end
Added: MacRuby/branches/experimental/spec/frozen/core/complex/Complex_spec.rb
===================================================================
--- MacRuby/branches/experimental/spec/frozen/core/complex/Complex_spec.rb (rev 0)
+++ MacRuby/branches/experimental/spec/frozen/core/complex/Complex_spec.rb 2009-08-02 13:12:21 UTC (rev 2147)
@@ -0,0 +1,20 @@
+require File.dirname(__FILE__) + '/../../spec_helper'
+require File.dirname(__FILE__) + '/../../shared/complex/Complex'
+
+ruby_version_is "1.9" do
+ describe "Complex when passed [Complex, Complex]" do
+ it_behaves_like(:complex_Complex_complex_complex, :Complex)
+ end
+
+ describe "Complex when passed [Complex]" do
+ it_behaves_like(:complex_Complex_complex, :Complex)
+ end
+
+ describe "Complex when passed [Integer, Integer]" do
+ it_behaves_like(:complex_Complex_integer_integer, :Complex)
+ end
+
+ describe "Complex when passed [Integer]" do
+ it_behaves_like(:complex_Complex_integer, :Complex)
+ end
+end
Added: MacRuby/branches/experimental/spec/frozen/core/complex/fdiv_spec.rb
===================================================================
--- MacRuby/branches/experimental/spec/frozen/core/complex/fdiv_spec.rb (rev 0)
+++ MacRuby/branches/experimental/spec/frozen/core/complex/fdiv_spec.rb 2009-08-02 13:12:21 UTC (rev 2147)
@@ -0,0 +1,131 @@
+require File.dirname(__FILE__) + '/../../spec_helper'
+
+ruby_version_is "1.9" do
+ describe "Complex#fdiv" do
+ it "accepts a numeric argument" do
+ lambda { Complex(20).fdiv(2) }.should_not raise_error(TypeError)
+ lambda { Complex(20).fdiv(2.0) }.should_not raise_error(TypeError)
+ lambda { Complex(20).fdiv(bignum_value) }.should_not raise_error(TypeError)
+ end
+
+ it "accepts a negative numeric argument" do
+ lambda { Complex(20).fdiv(-2) }.should_not raise_error(TypeError)
+ lambda { Complex(20).fdiv(-2.0) }.should_not raise_error(TypeError)
+ lambda { Complex(20).fdiv(-bignum_value) }.should_not raise_error(TypeError)
+ end
+
+ it "raises a TypeError if passed a non-numeric argument" do
+ lambda { Complex(20).fdiv([]) }.should raise_error(TypeError)
+ lambda { Complex(20).fdiv(:sym) }.should raise_error(TypeError)
+ lambda { Complex(20).fdiv('s') }.should raise_error(TypeError)
+ end
+
+ it "sets the real part to NaN if self's real part is NaN" do
+ Complex(nan_value).fdiv(2).real.nan?.should be_true
+ end
+
+ it "sets the imaginary part to NaN if self's imaginary part is NaN" do
+ Complex(2, nan_value).fdiv(2).imag.nan?.should be_true
+ end
+
+ it "sets the real and imaginary part to NaN if self's real and imaginary parts are NaN" do
+ Complex(nan_value, nan_value).fdiv(2).imag.nan?.should be_true
+ Complex(nan_value, nan_value).fdiv(2).real.nan?.should be_true
+ end
+
+ it "sets the real and imaginary part to NaN if self's real part and the argument are both NaN" do
+ Complex(nan_value, 2).fdiv(nan_value).imag.nan?.should be_true
+ Complex(nan_value, 2).fdiv(nan_value).real.nan?.should be_true
+ end
+
+ it "sets the real and imaginary part to NaN if self's real part, self's imaginary part, and the argument are NaN" do
+ Complex(nan_value, nan_value).fdiv(nan_value).imag.nan?.should be_true
+ Complex(nan_value, nan_value).fdiv(nan_value).real.nan?.should be_true
+ end
+
+ it "sets the real part to Infinity if self's real part is Infinity" do
+ Complex(infinity_value).fdiv(2).real.infinite?.should == 1
+ Complex(infinity_value,2).fdiv(2).real.infinite?.should == 1
+ end
+
+ it "sets the imaginary part to Infinity if self's imaginary part is Infinity" do
+ Complex(2, infinity_value).fdiv(2).imag.infinite?.should == 1
+ Complex(2, infinity_value).fdiv(2).imag.infinite?.should == 1
+ end
+
+ it "sets the imaginary and real part to Infinity if self's imaginary and real parts are Infinity" do
+ Complex(infinity_value, infinity_value).fdiv(2).real.infinite?.should == 1
+ Complex(infinity_value, infinity_value).fdiv(2).imag.infinite?.should == 1
+ end
+
+ it "sets the real part to NaN and the imaginary part to NaN if self's imaginary part, self's real part, and the argument are Infinity" do
+ Complex(infinity_value, infinity_value).fdiv(infinity_value).real.nan?.should be_true
+ Complex(infinity_value, infinity_value).fdiv(infinity_value).imag.nan?.should be_true
+ end
+ end
+
+ describe "Complex#fdiv with no imaginary part" do
+ before(:each) do
+ @numbers = [1, 5.43, 10, bignum_value, 99872.2918710].map{|n| [n,-n]}.flatten
+ end
+
+ it "returns a Complex number" do
+ @numbers.each do |real|
+ @numbers.each do |other|
+ Complex(real).fdiv(other).should be_an_instance_of(Complex)
+ end
+ end
+ end
+
+ it "sets the real part to self's real part fdiv'd with the argument" do
+ @numbers.each do |real|
+ @numbers.each do |other|
+ Complex(real).fdiv(other).real.should == real.fdiv(other)
+ end
+ end
+ end
+
+ it "sets the imaginary part to 0.0" do
+ @numbers.each do |real|
+ @numbers.each do |other|
+ Complex(real).fdiv(other).imaginary.should == 0.0
+ end
+ end
+ end
+ end
+
+ describe "Complex#fdiv with an imaginary part" do
+ before(:each) do
+ @numbers = [1, 5.43, 10, bignum_value, 99872.2918710].map{|n| [n,-n]}.flatten
+ end
+
+ it "returns a Complex number" do
+ @numbers.each do |real|
+ @numbers.each_with_index do |other,idx|
+ Complex(
+ real, at numbers[idx == 0 ? -1 : idx-1]
+ ).fdiv(other).should be_an_instance_of(Complex)
+ end
+ end
+ end
+
+ it "sets the real part to self's real part fdiv'd with the argument" do
+ @numbers.each do |real|
+ @numbers.each_with_index do |other,idx|
+ Complex(
+ real, at numbers[idx == 0 ? -1 : idx-1]
+ ).fdiv(other).real.should == real.fdiv(other)
+ end
+ end
+ end
+
+ it "sets the imaginary part to the imaginary part fdiv'd with the argument" do
+ @numbers.each do |real|
+ @numbers.each_with_index do |other,idx|
+ im = @numbers[idx == 0 ? -1 : idx-1]
+ Complex(real, im).fdiv(other).imag.should == im.fdiv(other)
+ end
+ end
+ end
+ end
+end
Added: MacRuby/branches/experimental/spec/frozen/core/complex/hash_spec.rb
===================================================================
--- MacRuby/branches/experimental/spec/frozen/core/complex/hash_spec.rb (rev 0)
+++ MacRuby/branches/experimental/spec/frozen/core/complex/hash_spec.rb 2009-08-02 13:12:21 UTC (rev 2147)
@@ -0,0 +1,8 @@
+require File.dirname(__FILE__) + '/../../spec_helper'
+require File.dirname(__FILE__) + '/../../shared/complex/hash'
+
+ruby_version_is "1.9" do
+ describe "Complex#hash" do
+ it_behaves_like(:complex_hash, :hash)
+ end
+end
Added: MacRuby/branches/experimental/spec/frozen/core/complex/imag_spec.rb
===================================================================
--- MacRuby/branches/experimental/spec/frozen/core/complex/imag_spec.rb (rev 0)
+++ MacRuby/branches/experimental/spec/frozen/core/complex/imag_spec.rb 2009-08-02 13:12:21 UTC (rev 2147)
@@ -0,0 +1,7 @@
+require File.dirname(__FILE__) + '/../../shared/complex/image'
+
+ruby_version_is "1.9" do
+ describe "Complex#imag" do
+ it_behaves_like(:complex_image, :imag)
+ end
+end
Added: MacRuby/branches/experimental/spec/frozen/core/complex/inspect_spec.rb
===================================================================
--- MacRuby/branches/experimental/spec/frozen/core/complex/inspect_spec.rb (rev 0)
+++ MacRuby/branches/experimental/spec/frozen/core/complex/inspect_spec.rb 2009-08-02 13:12:21 UTC (rev 2147)
@@ -0,0 +1,7 @@
+require File.dirname(__FILE__) + '/../../shared/complex/inspect'
+
+ruby_version_is "1.9" do
+ describe "Complex#inspect" do
+ it_behaves_like(:complex_inspect, :inspect)
+ end
+end
Added: MacRuby/branches/experimental/spec/frozen/core/complex/minus_spec.rb
===================================================================
--- MacRuby/branches/experimental/spec/frozen/core/complex/minus_spec.rb (rev 0)
+++ MacRuby/branches/experimental/spec/frozen/core/complex/minus_spec.rb 2009-08-02 13:12:21 UTC (rev 2147)
@@ -0,0 +1,15 @@
+require File.dirname(__FILE__) + '/../../shared/complex/minus'
+
+ruby_version_is "1.9" do
+ describe "Complex#- with Complex" do
+ it_behaves_like(:complex_minus_complex, :-)
+ end
+
+ describe "Complex#- with Integer" do
+ it_behaves_like(:complex_minus_integer, :-)
+ end
+
+ describe "Complex#- with Object" do
+ it_behaves_like(:complex_minus_object, :-)
+ end
+end
Deleted: MacRuby/branches/experimental/spec/frozen/core/complex/modulo_spec.rb
===================================================================
--- MacRuby/branches/experimental/spec/frozen/core/complex/modulo_spec.rb 2009-08-02 08:57:05 UTC (rev 2146)
+++ MacRuby/branches/experimental/spec/frozen/core/complex/modulo_spec.rb 2009-08-02 13:12:21 UTC (rev 2147)
@@ -1,17 +0,0 @@
-require File.dirname(__FILE__) + '/../../shared/complex/modulo'
-
-=begin # Looks like Complex#% doesn't work even with ruby 1.9.2
-ruby_version_is "1.9" do
- describe "Complex#% with Complex" do
- it_behaves_like(:complex_modulo_complex, :%)
- end
-
- describe "Complex#% with Integer" do
- it_behaves_like(:complex_modulo_integer, :%)
- end
-
- describe "Complex#% with Object" do
- it_behaves_like(:complex_modulo_object, :%)
- end
-end
-=end
Modified: MacRuby/branches/experimental/spec/frozen/core/complex/real_spec.rb
===================================================================
--- MacRuby/branches/experimental/spec/frozen/core/complex/real_spec.rb 2009-08-02 08:57:05 UTC (rev 2146)
+++ MacRuby/branches/experimental/spec/frozen/core/complex/real_spec.rb 2009-08-02 13:12:21 UTC (rev 2147)
@@ -5,4 +5,22 @@
describe "Complex#real" do
it_behaves_like(:complex_real, :real)
end
+
+ describe "Complex#real?" do
+ it "returns false if there is an imaginary part" do
+ Complex(2,3).real?.should be_false
+ end
+
+ it "returns false if there is not an imaginary part" do
+ Complex(2).real?.should be_false
+ end
+
+ it "returns false if the real part is Infinity" do
+ Complex(infinity_value).real?.should be_false
+ end
+
+ it "returns false if the real part is NaN" do
+ Complex(nan_value).real?.should be_false
+ end
+ end
end
Modified: MacRuby/branches/experimental/spec/frozen/core/dir/chdir_spec.rb
===================================================================
--- MacRuby/branches/experimental/spec/frozen/core/dir/chdir_spec.rb 2009-08-02 08:57:05 UTC (rev 2146)
+++ MacRuby/branches/experimental/spec/frozen/core/dir/chdir_spec.rb 2009-08-02 13:12:21 UTC (rev 2147)
@@ -29,10 +29,37 @@
Dir.chdir(@original).should == 0
end
+ it "calls #to_str on the argument if it's not a String" do
+ obj = mock('path')
+ obj.should_receive(:to_str).and_return(Dir.pwd)
+ Dir.chdir(obj)
+ end
+
+ ruby_version_is "1.9" do
+ it "calls #to_path on the argument if it's not a String" do
+ obj = mock('path')
+ obj.should_receive(:to_path).and_return(Dir.pwd)
+ Dir.chdir(obj)
+ end
+
+ it "prefers #to_str over #to_path" do
+ obj = Class.new do
+ def to_path; DirSpecs.mock_dir; end
+ def to_str; Dir.pwd; end
+ end
+ Dir.chdir(obj.new)
+ Dir.pwd.should == @original
+ end
+ end
+
it "returns the value of the block when a block is given" do
Dir.chdir(@original) { :block_value }.should == :block_value
end
+ it "defaults to the home directory when given a block but no argument" do
+ Dir.chdir { Dir.pwd.should == ENV['HOME'] }
+ end
+
it "changes to the specified directory for the duration of the block" do
ar = Dir.chdir(DirSpecs.mock_dir) { |dir| [dir, DirSpecs.pwd] }
ar.should == [DirSpecs.mock_dir, DirSpecs.mock_dir]
Modified: MacRuby/branches/experimental/spec/frozen/core/dir/shared/exists.rb
===================================================================
--- MacRuby/branches/experimental/spec/frozen/core/dir/shared/exists.rb 2009-08-02 08:57:05 UTC (rev 2146)
+++ MacRuby/branches/experimental/spec/frozen/core/dir/shared/exists.rb 2009-08-02 13:12:21 UTC (rev 2147)
@@ -33,9 +33,9 @@
Dir.send(@method, dir).should be_true
end
- it "doesn't expand paths" do
+ it "expands paths" do
Dir.send(@method, File.expand_path('~')).should be_true
- Dir.send(@method, '~').should be_false
+ Dir.send(@method, '~').should be_true
end
it "returns false if the argument exists but is a file" do
Modified: MacRuby/branches/experimental/spec/frozen/core/enumerable/collect_spec.rb
===================================================================
--- MacRuby/branches/experimental/spec/frozen/core/enumerable/collect_spec.rb 2009-08-02 08:57:05 UTC (rev 2146)
+++ MacRuby/branches/experimental/spec/frozen/core/enumerable/collect_spec.rb 2009-08-02 13:12:21 UTC (rev 2147)
@@ -5,3 +5,7 @@
describe "Enumerable#collect" do
it_behaves_like(:enumerable_collect , :collect)
end
+
+describe "Enumerable#collect with implicit to_proc [each(&obj) form]" do
+ it_behaves_like(:enumerable_collect_to_proc , :collect)
+end
Added: MacRuby/branches/experimental/spec/frozen/core/enumerable/join_spec.rb
===================================================================
--- MacRuby/branches/experimental/spec/frozen/core/enumerable/join_spec.rb (rev 0)
+++ MacRuby/branches/experimental/spec/frozen/core/enumerable/join_spec.rb 2009-08-02 13:12:21 UTC (rev 2147)
@@ -0,0 +1,22 @@
+require File.dirname(__FILE__) + '/../../shared/array/join'
+require File.dirname(__FILE__) + '/../array/fixtures/classes'
+
+ruby_version_is "1.9" do
+ describe "Enumerable#join" do
+ class Enum
+ include Enumerable
+ def initialize(*args)
+ @elements = args
+ end
+ def each
+ @elements.each {|e| yield e}
+ end
+ def <<(e)
+ @elements << e
+ self
+ end
+ end
+
+ it_behaves_like(:array_join, :join, Enum)
+ end
+end
Modified: MacRuby/branches/experimental/spec/frozen/core/enumerable/map_spec.rb
===================================================================
--- MacRuby/branches/experimental/spec/frozen/core/enumerable/map_spec.rb 2009-08-02 08:57:05 UTC (rev 2146)
+++ MacRuby/branches/experimental/spec/frozen/core/enumerable/map_spec.rb 2009-08-02 13:12:21 UTC (rev 2147)
@@ -5,3 +5,7 @@
describe "Enumerable#map" do
it_behaves_like(:enumerable_collect , :map)
end
+
+describe "Enumerable#map with implicit to_proc [each(&obj) form]" do
+ it_behaves_like(:enumerable_collect_to_proc , :map)
+end
Modified: MacRuby/branches/experimental/spec/frozen/core/enumerable/shared/collect.rb
===================================================================
--- MacRuby/branches/experimental/spec/frozen/core/enumerable/shared/collect.rb 2009-08-02 08:57:05 UTC (rev 2146)
+++ MacRuby/branches/experimental/spec/frozen/core/enumerable/shared/collect.rb 2009-08-02 13:12:21 UTC (rev 2147)
@@ -25,6 +25,7 @@
EnumerableSpecs::Numerous.new.send(@method).should == [2, 5, 3, 6, 1, 4]
end
end
+
ruby_version_is "1.9" do
it "returns an enumerator when no block given" do
enum = EnumerableSpecs::Numerous.new.send(@method)
@@ -32,6 +33,32 @@
enum.each { |i| -i }.should == [-2, -5, -3, -6, -1, -4]
end
end
+end
+describe :enumerable_collect_to_proc, :shared => true do
+ ruby_version_is "1.8.7" do
+ it "calls obj.to_proc" do
+ EnumerableSpecs::Numerous.new.send(@method, &:succ).should == [3, 6, 4, 7, 2, 5]
+ end
+ it "does not call obj.to_proc if obj is a lambda" do
+ f = lambda{ |x| x + 1 }
+ class << f
+ def to_proc
+ lambda{ |x| 42 }
+ end
+ end
+ EnumerableSpecs::Numerous.new.send(@method, &f).should == [3, 6, 4, 7, 2, 5]
+ end
+
+ it "does not call obj.to_proc if obj is a Proc" do
+ myproc = Class.new Proc do
+ def to_proc
+ lambda{ |x| 42 }
+ end
+ end
+ inc = myproc.new{ |x| x + 1 }
+ EnumerableSpecs::Numerous.new.send(@method, &inc).should == [3, 6, 4, 7, 2, 5]
+ end
+ end
end
Modified: MacRuby/branches/experimental/spec/frozen/core/env/each_key_spec.rb
===================================================================
--- MacRuby/branches/experimental/spec/frozen/core/env/each_key_spec.rb 2009-08-02 08:57:05 UTC (rev 2146)
+++ MacRuby/branches/experimental/spec/frozen/core/env/each_key_spec.rb 2009-08-02 13:12:21 UTC (rev 2147)
@@ -29,4 +29,11 @@
end
end
+ ruby_version_is "1.9" do
+ it "returns keys in the locale encoding" do
+ ENV.each_key do |key|
+ key.encoding.should == Encoding.find('locale')
+ end
+ end
+ end
end
Modified: MacRuby/branches/experimental/spec/frozen/core/env/each_value_spec.rb
===================================================================
--- MacRuby/branches/experimental/spec/frozen/core/env/each_value_spec.rb 2009-08-02 08:57:05 UTC (rev 2146)
+++ MacRuby/branches/experimental/spec/frozen/core/env/each_value_spec.rb 2009-08-02 13:12:21 UTC (rev 2147)
@@ -28,5 +28,12 @@
ENV.each_value.should be_kind_of(enumerator_class)
end
end
-
+
+ ruby_version_is "1.9" do
+ it "uses the locale encoding" do
+ ENV.each_value do |value|
+ value.encoding.should == Encoding.find('locale')
+ end
+ end
+ end
end
Modified: MacRuby/branches/experimental/spec/frozen/core/env/element_reference_spec.rb
===================================================================
--- MacRuby/branches/experimental/spec/frozen/core/env/element_reference_spec.rb 2009-08-02 08:57:05 UTC (rev 2146)
+++ MacRuby/branches/experimental/spec/frozen/core/env/element_reference_spec.rb 2009-08-02 13:12:21 UTC (rev 2147)
@@ -15,4 +15,10 @@
it "returns nil if the variable isn't found" do
ENV["this_var_is_never_set"].should == nil
end
+
+ ruby_version_is "1.9" do
+ it "uses the locale encoding" do
+ ENV[@variable_name].encoding.should == Encoding.find('locale')
+ end
+ end
end
Modified: MacRuby/branches/experimental/spec/frozen/core/env/fetch_spec.rb
===================================================================
--- MacRuby/branches/experimental/spec/frozen/core/env/fetch_spec.rb 2009-08-02 08:57:05 UTC (rev 2146)
+++ MacRuby/branches/experimental/spec/frozen/core/env/fetch_spec.rb 2009-08-02 13:12:21 UTC (rev 2147)
@@ -26,4 +26,9 @@
end.should complain(/block supersedes default value argument/)
end
+ ruby_version_is "1.9" do
+ it "uses the locale encoding" do
+ ENV.fetch(ENV.keys.first).encoding.should == Encoding.find('locale')
+ end
+ end
end
Modified: MacRuby/branches/experimental/spec/frozen/core/env/keys_spec.rb
===================================================================
--- MacRuby/branches/experimental/spec/frozen/core/env/keys_spec.rb 2009-08-02 08:57:05 UTC (rev 2146)
+++ MacRuby/branches/experimental/spec/frozen/core/env/keys_spec.rb 2009-08-02 13:12:21 UTC (rev 2147)
@@ -5,4 +5,12 @@
it "returns all the keys" do
ENV.keys.sort.should == ENV.to_hash.keys.sort
end
+
+ ruby_version_is "1.9" do
+ it "returns the keys in the locale encoding" do
+ ENV.keys.each do |key|
+ key.encoding.should == Encoding.find('locale')
+ end
+ end
+ end
end
Modified: MacRuby/branches/experimental/spec/frozen/core/env/shared/each.rb
===================================================================
--- MacRuby/branches/experimental/spec/frozen/core/env/shared/each.rb 2009-08-02 08:57:05 UTC (rev 2146)
+++ MacRuby/branches/experimental/spec/frozen/core/env/shared/each.rb 2009-08-02 13:12:21 UTC (rev 2147)
@@ -25,4 +25,13 @@
ENV.send(@method).should be_kind_of(enumerator_class)
end
end
+
+ ruby_version_is "1.9" do
+ it "uses the locale encoding" do
+ ENV.send(@method) do |key, value|
+ key.encoding.should == Encoding.find('locale')
+ value.encoding.should == Encoding.find('locale')
+ end
+ end
+ end
end
Modified: MacRuby/branches/experimental/spec/frozen/core/env/to_a_spec.rb
===================================================================
--- MacRuby/branches/experimental/spec/frozen/core/env/to_a_spec.rb 2009-08-02 08:57:05 UTC (rev 2146)
+++ MacRuby/branches/experimental/spec/frozen/core/env/to_a_spec.rb 2009-08-02 13:12:21 UTC (rev 2147)
@@ -9,4 +9,13 @@
a.find { |e| e.first == "foo" }.should == ["foo", "bar"]
ENV.delete "foo"
end
+
+ ruby_version_is "1.9" do
+ it "returns the entries in the locale encoding" do
+ ENV.to_a.each do |key, value|
+ key.encoding.should == Encoding.find('locale')
+ value.encoding.should == Encoding.find('locale')
+ end
+ end
+ end
end
Modified: MacRuby/branches/experimental/spec/frozen/core/env/values_at_spec.rb
===================================================================
--- MacRuby/branches/experimental/spec/frozen/core/env/values_at_spec.rb 2009-08-02 08:57:05 UTC (rev 2146)
+++ MacRuby/branches/experimental/spec/frozen/core/env/values_at_spec.rb 2009-08-02 13:12:21 UTC (rev 2147)
@@ -10,4 +10,10 @@
ENV.delete "foo"
ENV.delete "bar"
end
+
+ ruby_version_is "1.9" do
+ it "uses the locale encoding" do
+ ENV.values_at(ENV.keys.first).first.encoding.should == Encoding.find('locale')
+ end
+ end
end
Modified: MacRuby/branches/experimental/spec/frozen/core/env/values_spec.rb
===================================================================
--- MacRuby/branches/experimental/spec/frozen/core/env/values_spec.rb 2009-08-02 08:57:05 UTC (rev 2146)
+++ MacRuby/branches/experimental/spec/frozen/core/env/values_spec.rb 2009-08-02 13:12:21 UTC (rev 2147)
@@ -12,4 +12,12 @@
ENV.replace orig
end
end
+
+ ruby_version_is "1.9" do
+ it "uses the locale encoding" do
+ ENV.values.each do |value|
+ value.encoding.should == Encoding.find('locale')
+ end
+ end
+ end
end
Modified: MacRuby/branches/experimental/spec/frozen/core/file/expand_path_spec.rb
===================================================================
--- MacRuby/branches/experimental/spec/frozen/core/file/expand_path_spec.rb 2009-08-02 08:57:05 UTC (rev 2146)
+++ MacRuby/branches/experimental/spec/frozen/core/file/expand_path_spec.rb 2009-08-02 13:12:21 UTC (rev 2147)
@@ -105,4 +105,14 @@
it "expands /./dir to /dir" do
File.expand_path("/./dir").should == "/dir"
end
+
+ ruby_version_is "1.9" do
+ it "produces a String in the default external encoding" do
+ old_external = Encoding.default_external
+ Encoding.default_external = Encoding::SHIFT_JIS
+ File.expand_path("./a").encoding.should == Encoding::SHIFT_JIS
+ File.expand_path("./\u{9876}").encoding.should == Encoding::SHIFT_JIS
+ Encoding.default_external = old_external
+ end
+ end
end
Modified: MacRuby/branches/experimental/spec/frozen/core/file/join_spec.rb
===================================================================
--- MacRuby/branches/experimental/spec/frozen/core/file/join_spec.rb 2009-08-02 08:57:05 UTC (rev 2146)
+++ MacRuby/branches/experimental/spec/frozen/core/file/join_spec.rb 2009-08-02 13:12:21 UTC (rev 2147)
@@ -66,6 +66,15 @@
File.join("usr/", "", "/bin").should == "usr/bin"
end
+ it "gives priority to existing separators in the rightmost argument" do
+ File.join("usr/", "bin") .should == "usr/bin"
+ File.join("usr/", "/bin") .should == "usr/bin"
+ File.join("usr//", "/bin") .should == "usr/bin"
+ File.join("usr//", "//bin") .should == "usr//bin"
+ File.join("usr//", "///bin").should == "usr///bin"
+ File.join("usr///", "//bin") .should == "usr//bin"
+ end
+
# TODO: See MRI svn r23306. Add patchlevel when there is a release.
ruby_bug "redmine #1418", "1.8.8" do
it "raises an ArgumentError if passed a recursive array" do
Modified: MacRuby/branches/experimental/spec/frozen/core/float/divmod_spec.rb
===================================================================
--- MacRuby/branches/experimental/spec/frozen/core/float/divmod_spec.rb 2009-08-02 08:57:05 UTC (rev 2146)
+++ MacRuby/branches/experimental/spec/frozen/core/float/divmod_spec.rb 2009-08-02 13:12:21 UTC (rev 2147)
@@ -13,6 +13,21 @@
values[1].should be_close(9223372036854775808.000, TOLERANCE)
end
+ # Behaviour established as correct in r23953
+ it "raises a FloatDomainError if self is NaN" do
+ lambda { nan_value.divmod(1) }.should raise_error(FloatDomainError)
+ end
+
+ # Behaviour established as correct in r23953
+ it "raises a FloatDomainError if other is NaN" do
+ lambda { 1.divmod(nan_value) }.should raise_error(FloatDomainError)
+ end
+
+ # Behaviour established as correct in r23953
+ it "raises a FloatDomainError if self is Infinity" do
+ lambda { infinity_value.divmod(1) }.should raise_error(FloatDomainError)
+ end
+
ruby_version_is ""..."1.9" do
it "raises FloatDomainError if other is zero" do
lambda { 1.0.divmod(0) }.should raise_error(FloatDomainError)
Modified: MacRuby/branches/experimental/spec/frozen/core/hash/element_reference_spec.rb
===================================================================
--- MacRuby/branches/experimental/spec/frozen/core/hash/element_reference_spec.rb 2009-08-02 08:57:05 UTC (rev 2146)
+++ MacRuby/branches/experimental/spec/frozen/core/hash/element_reference_spec.rb 2009-08-02 13:12:21 UTC (rev 2147)
@@ -75,7 +75,10 @@
x = mock('0')
x.should_receive(:hash).and_return(0)
- new_hash[x].should == nil
+ h = new_hash
+ # 1.9 only calls #hash if the hash had at least one entry beforehand.
+ h[:foo] = :bar
+ h[x].should == nil
end
it "does not compare key with unknown hash codes via eql?" do
Modified: MacRuby/branches/experimental/spec/frozen/core/hash/inspect_spec.rb
===================================================================
--- MacRuby/branches/experimental/spec/frozen/core/hash/inspect_spec.rb 2009-08-02 08:57:05 UTC (rev 2146)
+++ MacRuby/branches/experimental/spec/frozen/core/hash/inspect_spec.rb 2009-08-02 13:12:21 UTC (rev 2147)
@@ -4,42 +4,4 @@
describe "Hash#inspect" do
it_behaves_like :to_s, :inspect
-
- # FIXME: When http://redmine.ruby-lang.org/issues/show/1533 is fixed, this
- # block can be removed, as the behaviour will then be shared with to_s
- # completely.
- it "handles recursive hashes" do
- x = new_hash
- x[0] = x
- x.inspect.should == '{0=>{...}}'
-
- x = new_hash
- x[x] = 0
- x.inspect.should == '{{...}=>0}'
-
- x = new_hash
- x[x] = x
- x.inspect.should == '{{...}=>{...}}'
-
- x = new_hash
- y = new_hash
- x[0] = y
- y[1] = x
- x.inspect.should == "{0=>{1=>{...}}}"
- y.inspect.should == "{1=>{0=>{...}}}"
-
- x = new_hash
- y = new_hash
- x[y] = 0
- y[x] = 1
- x.inspect.should == "{{{...}=>1}=>0}"
- y.inspect.should == "{{{...}=>0}=>1}"
-
- x = new_hash
- y = new_hash
- x[y] = x
- y[x] = y
- x.inspect.should == "{{{...}=>{...}}=>{...}}"
- y.inspect.should == "{{{...}=>{...}}=>{...}}"
- end
end
Modified: MacRuby/branches/experimental/spec/frozen/core/hash/shared/to_s.rb
===================================================================
--- MacRuby/branches/experimental/spec/frozen/core/hash/shared/to_s.rb 2009-08-02 08:57:05 UTC (rev 2146)
+++ MacRuby/branches/experimental/spec/frozen/core/hash/shared/to_s.rb 2009-08-02 13:12:21 UTC (rev 2147)
@@ -24,15 +24,22 @@
new_hash(key => val).send(@method).should == '{key=>val}'
end
- # There is an inconsistency in the behaviour of #to_s/#inspect on 1.9.1.
- # ujihisa fixed it and we're waiting for his patch to be committed. See
- # http://redmine.ruby-lang.org/issues/show/1533 for details.
- ruby_bug "1533", "1.9.1.154" do
- it "handles recursive hashes" do
- x = new_hash
- x[0] = x
- x.send(@method).should == '{0=>{...}}'
+ it "handles hashes with recursive values" do
+ x = new_hash
+ x[0] = x
+ x.send(@method).should == '{0=>{...}}'
+ x = new_hash
+ y = new_hash
+ x[0] = y
+ y[1] = x
+ x.send(@method).should == "{0=>{1=>{...}}}"
+ y.send(@method).should == "{1=>{0=>{...}}}"
+ end
+
+ # Recursive hash keys are disallowed on 1.9
+ ruby_version_is ""..."1.9" do
+ it "handles hashes with recursive keys" do
x = new_hash
x[x] = 0
x.send(@method).should == '{{...}=>0}'
@@ -41,12 +48,6 @@
x[x] = x
x.send(@method).should == '{{...}=>{...}}'
- x = new_hash
- y = new_hash
- x[0] = y
- y[1] = x
- x.send(@method).should == "{0=>{1=>{...}}}"
- y.send(@method).should == "{1=>{0=>{...}}}"
x = new_hash
y = new_hash
@@ -61,6 +62,6 @@
y[x] = y
x.send(@method).should == "{{{...}=>{...}}=>{...}}"
y.send(@method).should == "{{{...}=>{...}}=>{...}}"
- end
- end
+ end
+ end
end
Modified: MacRuby/branches/experimental/spec/frozen/core/io/inspect_spec.rb
===================================================================
--- MacRuby/branches/experimental/spec/frozen/core/io/inspect_spec.rb 2009-08-02 08:57:05 UTC (rev 2146)
+++ MacRuby/branches/experimental/spec/frozen/core/io/inspect_spec.rb 2009-08-02 13:12:21 UTC (rev 2147)
@@ -14,6 +14,6 @@
it "returns a string describing a stream" do
# don't hardcode the tmp path
@file.inspect.should =~ /#<File.*inspect_spec>/
- IO.new(@file.to_i).inspect.should =~ /<IO:[\w\d]+>/
+ IO.new(@file.to_i).inspect.should =~ /<IO:[\w\s?\d]+>/
end
end
Modified: MacRuby/branches/experimental/spec/frozen/core/io/print_spec.rb
===================================================================
--- MacRuby/branches/experimental/spec/frozen/core/io/print_spec.rb 2009-08-02 08:57:05 UTC (rev 2146)
+++ MacRuby/branches/experimental/spec/frozen/core/io/print_spec.rb 2009-08-02 13:12:21 UTC (rev 2147)
@@ -34,10 +34,13 @@
end
it "does not call obj.to_str" do
- o = Object.new
- def o.to_str(); 'Haha!'; end
+ o = mock('o')
+ o.should_not_receive(:to_str)
+ o.should_receive(:to_s)
+
+ require 'stringio'
- lambda { $stdout.print(o) }.should output("#{o.to_s}#{$\}")
+ StringIO.new.print(o)
end
it "writes each obj.to_s to the stream and appends $\\ (if any) given multiple objects" do
Modified: MacRuby/branches/experimental/spec/frozen/core/io/read_spec.rb
===================================================================
--- MacRuby/branches/experimental/spec/frozen/core/io/read_spec.rb 2009-08-02 08:57:05 UTC (rev 2146)
+++ MacRuby/branches/experimental/spec/frozen/core/io/read_spec.rb 2009-08-02 13:12:21 UTC (rev 2147)
@@ -88,10 +88,18 @@
end
after :each do
- @io.close
File.delete(@fname) if File.exists?(@fname)
end
+ after :all do
+ # We originally closed @io after every example, but on 1.9 that led to a
+ # particularly bizarre bug where #close would raise an Errno::EBADF under
+ # certain conditions. I can't determine what these conditions are,
+ # unfortunately. I believe it's safe to only close @io here because it's
+ # instantiated anew before each example.
+ @io.close
+ end
+
it "can be read from consecutively" do
@io.read(1).should == '1'
@io.read(2).should == '23'
Modified: MacRuby/branches/experimental/spec/frozen/core/io/reopen_spec.rb
===================================================================
--- MacRuby/branches/experimental/spec/frozen/core/io/reopen_spec.rb 2009-08-02 08:57:05 UTC (rev 2146)
+++ MacRuby/branches/experimental/spec/frozen/core/io/reopen_spec.rb 2009-08-02 13:12:21 UTC (rev 2147)
@@ -107,7 +107,7 @@
File.readlines(@name2_w).should == ["line1-F2\n"]
end
- it "reassociates self with new a new stream after some reads" do
+ it "reassociates self with a new stream after some reads" do
@file1.reopen(@file2)
@file1.gets
@file1.gets
Modified: MacRuby/branches/experimental/spec/frozen/core/io/shared/new.rb
===================================================================
--- MacRuby/branches/experimental/spec/frozen/core/io/shared/new.rb 2009-08-02 08:57:05 UTC (rev 2146)
+++ MacRuby/branches/experimental/spec/frozen/core/io/shared/new.rb 2009-08-02 13:12:21 UTC (rev 2147)
@@ -68,24 +68,14 @@
lambda { IO.send(@method, fd, 'w') }.should raise_error(Errno::EBADF)
end
- ruby_version_is "" ... "1.9" do
- it "raises EINVAL if mode is not compatible with the descriptor's current mode" do
- lambda { IO.send(@method, @file.fileno, 'r') }.
- should raise_error(Errno::EINVAL)
- lambda { io = IO.send(@method, @file.fileno, 'w'); io.close }.
- should_not raise_error
- end
+ # (1.9 behaviour verified as correct in bug #1582)
+ it "raises EINVAL if mode is not compatible with the descriptor's current mode" do
+ lambda { IO.send(@method, @file.fileno, 'r') }.
+ should raise_error(Errno::EINVAL)
+ lambda { io = IO.send(@method, @file.fileno, 'w'); io.close }.
+ should_not raise_error
end
- ruby_version_is "1.9" do
- it "does not raise EINVAL even if mode is not compatible with the descriptor's current mode" do
- lambda { IO.send(@method, @file.fileno, 'r') }.
- should_not raise_error(Errno::EINVAL)
- lambda { io = IO.send(@method, @file.fileno, 'w'); io.close }.
- should_not raise_error
- end
- end
-
it "raises IOError on closed stream" do
lambda { IO.new(IOSpecs.closed_file.fileno, 'w') }.should raise_error(IOError)
end
@@ -119,15 +109,8 @@
io.close
end
- ruby_version_is "" ... "1.9" do
- it "cannot open an IO with incompatible flags" do
- lambda { IO.new(@file.fileno, "r") }.should raise_error
- end
+ # (1.9 behaviour verified as correct in bug #1582)
+ it "cannot open an IO with incompatible flags" do
+ lambda { IO.new(@file.fileno, "r") }.should raise_error(Errno::EINVAL)
end
-
- ruby_version_is "1.9" do
- it "can open an IO with incompatible flags" do
- lambda { IO.new(@file.fileno, "r") }.should_not raise_error
- end
- end
end
Modified: MacRuby/branches/experimental/spec/frozen/core/kernel/caller_spec.rb
===================================================================
--- MacRuby/branches/experimental/spec/frozen/core/kernel/caller_spec.rb 2009-08-02 08:57:05 UTC (rev 2146)
+++ MacRuby/branches/experimental/spec/frozen/core/kernel/caller_spec.rb 2009-08-02 13:12:21 UTC (rev 2147)
@@ -43,48 +43,108 @@
end
describe "Kernel#caller in a Proc or eval" do
- it "returns the definition trace of a block when evaluated in a Proc binding" do
- stack = CallerFixture.caller_of(CallerFixture.block)
- stack[0].should =~ /caller_fixture1\.rb:4/
- stack[1].should =~ /caller_fixture1\.rb:4:in `.+'/
- end
+ ruby_version_is ""..."1.9" do
+ it "returns the definition trace of a block when evaluated in a Proc binding" do
+ stack = CallerFixture.caller_of(CallerFixture.block)
+ stack[0].should =~ /caller_fixture1\.rb:4/
+ stack[1].should =~ /caller_fixture1\.rb:4:in `.+'/
+ end
- it "returns the definition trace of a Proc" do
- stack = CallerFixture.caller_of(CallerFixture.example_proc)
- stack[0].should =~ /caller_fixture1\.rb:14:in `example_proc'/
- stack[1].should =~ /caller_fixture1\.rb:14/
- end
+ it "returns the definition trace of a Proc" do
+ stack = CallerFixture.caller_of(CallerFixture.example_proc)
+ stack[0].should =~ /caller_fixture1\.rb:14:in `example_proc'/
+ stack[1].should =~ /caller_fixture1\.rb:14/
+ end
- it "returns the correct caller line from a called Proc" do
- stack = CallerFixture.entry_point.call
- stack[0].should =~ /caller_fixture1\.rb:31:in `(block in )?third'/
- stack[1].should =~ /caller_spec\.rb:59/
- end
+ it "returns the correct caller line from a called Proc" do
+ stack = CallerFixture.entry_point.call
+ stack[0].should =~ /caller_fixture1\.rb:31:in `(block in )?third'/
+ stack[1].should =~ /caller_spec\.rb:60/
+ end
- it "returns the correct definition line for a complex Proc trace" do
- stack = CallerFixture.caller_of(CallerFixture.entry_point)
- stack[0].should =~ /caller_fixture1\.rb:29:in `third'/
- ruby_bug("http://redmine.ruby-lang.org/issues/show/146", "1.8.7") do
- stack[1].should =~ /caller_fixture1\.rb:25:in `second'/
+ it "returns the correct definition line for a complex Proc trace" do
+ stack = CallerFixture.caller_of(CallerFixture.entry_point)
+ stack[0].should =~ /caller_fixture1\.rb:29:in `third'/
+ ruby_bug("http://redmine.ruby-lang.org/issues/show/146", "1.8.7") do
+ stack[1].should =~ /caller_fixture1\.rb:25:in `second'/
+ end
end
- end
- it "begins with (eval) for caller(0) in eval" do
- stack = CallerFixture.eval_caller(0)
- stack[0].should == "(eval):1:in `eval_caller'"
- stack[1].should =~ /caller_spec\.rb:73/
- end
+ it "begins with (eval) for caller(0) in eval" do
+ stack = CallerFixture.eval_caller(0)
+ stack[0].should == "(eval):1:in `eval_caller'"
+ stack[1].should =~ /caller_spec\.rb:74/
+ end
- it "begins with the eval's sender's sender for caller(1) in eval" do
- stack = CallerFixture.eval_caller(1)
- stack[0].should =~ /caller_spec\.rb:79/
+ it "begins with the eval's sender's sender for caller(1) in eval" do
+ stack = CallerFixture.eval_caller(1)
+ stack[0].should =~ /caller_spec\.rb:80/
+ end
+
+ it "shows the current line in the calling block twice when evaled" do
+ stack = CallerFixture.eval_caller(0)
+ stack[0].should == "(eval):1:in `eval_caller'"
+ stack[1].should =~/caller_spec\.rb:85/
+ stack[2].should =~/caller_fixture2\.rb:23/
+ stack[3].should =~/caller_spec\.rb:85/
+ end
end
+
+ ruby_version_is "1.9" do
+ it "returns the definition trace of a block when evaluated in a Proc binding" do
+ stack = CallerFixture.caller_of(CallerFixture.block)
+ stack[0].should == "(eval):1:in `<top (required)>'"
+ stack[1].should =~ /caller_fixture2\.rb:18:in `eval'/
+ stack[2].should =~ /caller_fixture2\.rb:18:in `caller_of'/
+ stack[3].should =~ /caller_spec\.rb:95:in `block \(3 levels\) in <top \(required\)>'/
+ end
- it "shows the current line in the calling block twice when evaled" do
- stack = CallerFixture.eval_caller(0)
- stack[0].should == "(eval):1:in `eval_caller'"
- stack[1].should =~/caller_spec\.rb:84/
- stack[2].should =~/caller_fixture2\.rb:23/
- stack[3].should =~/caller_spec\.rb:84/
+ it "returns the definition trace of a Proc" do
+ stack = CallerFixture.caller_of(CallerFixture.example_proc)
+ stack[0].should == "(eval):1:in `example_proc'"
+ stack[1].should =~ /caller_fixture2\.rb:18:in `eval'/
+ stack[2].should =~ /caller_fixture2\.rb:18:in `caller_of'/
+ stack[3].should =~ /caller_spec\.rb:103:in `block \(3 levels\) in <top \(required\)>'/
+ end
+
+ it "returns the correct caller line from a called Proc" do
+ stack = CallerFixture.entry_point.call
+ stack[0].should =~ /caller_fixture1\.rb:31:in `block in third'/
+ stack[1].should =~ /caller_spec\.rb:111:in `call'/
+ stack[2].should =~ /caller_spec\.rb:111:in `block \(3 levels\) in <top \(required\)>'/
+ end
+
+ # On 1.8 this expectation is marred by bug #146. I don't understand 1.9's
+ # output to ascertain whether the same bug occurs here, and if so what is
+ # the correct behaviour
+ it "returns the correct definition line for a complex Proc trace" do
+ stack = CallerFixture.caller_of(CallerFixture.entry_point)
+ stack[0].should == "(eval):1:in `third'"
+ stack[1].should =~ /caller_fixture2\.rb:18:in `eval'/
+ stack[2].should =~ /caller_fixture2\.rb:18:in `caller_of'/
+ stack[3].should =~ /caller_spec.rb:121:in `block \(3 levels\) in <top \(required\)>'/
+ end
+
+ it "begins with (eval) for caller(0) in eval" do
+ stack = CallerFixture.eval_caller(0)
+ stack[0].should == "(eval):1:in `eval_caller'"
+ stack[1].should =~ /caller_fixture2\.rb:23:in `eval'/
+ stack[2].should =~ /caller_fixture2\.rb:23:in `eval_caller'/
+ stack[3].should =~ /caller_spec\.rb:129:in `block \(3 levels\) in <top \(required\)>'/
+ end
+
+ it "begins with the eval's sender's sender for caller(4) in eval" do
+ stack = CallerFixture.eval_caller(4)
+ stack[0].should =~ /caller_spec\.rb:137:in `block \(3 levels\) in <top \(required\)>'/
+ end
+
+ it "shows the current line in the calling block twice when evaled" do
+ stack = CallerFixture.eval_caller(0)
+
+ stack[0].should == "(eval):1:in `eval_caller'"
+ stack[1].should =~/caller_fixture2\.rb:23:in `eval'/
+ stack[2].should =~/caller_fixture2\.rb:23:in `eval_caller'/
+ stack[3].should =~/caller_spec\.rb:142:in `block \(3 levels\) in <top \(required\)>/
+ end
end
end
Modified: MacRuby/branches/experimental/spec/frozen/core/kernel/eval_spec.rb
===================================================================
--- MacRuby/branches/experimental/spec/frozen/core/kernel/eval_spec.rb 2009-08-02 08:57:05 UTC (rev 2146)
+++ MacRuby/branches/experimental/spec/frozen/core/kernel/eval_spec.rb 2009-08-02 13:12:21 UTC (rev 2147)
@@ -31,107 +31,176 @@
A::C.name.should == "A::C"
end
- it "accepts a Proc object as a binding" do
- x = 1
- bind = proc {}
+ ruby_version_is ""..."1.9" do
+ it "accepts a Proc object as a binding" do
+ x = 1
+ bind = proc {}
- eval("x", bind).should == 1
- eval("y = 2", bind).should == 2
- eval("y", bind).should == 2
+ eval("x", bind).should == 1
+ eval("y = 2", bind).should == 2
+ eval("y", bind).should == 2
- eval("z = 3").should == 3
- eval("z", bind).should == 3
+ eval("z = 3").should == 3
+ eval("z", bind).should == 3
+ end
end
+ ruby_version_is "1.9" do
+ it "doesn't accept a Proc object as a binding" do
+ x = 1
+ bind = proc {}
+
+ lambda { eval("x", bind) }.should raise_error(TypeError)
+ end
+ end
+
it "does not make Proc locals visible to evaluated code" do
bind = proc { inner = 4 }
- lambda { eval("inner", bind) }.should raise_error(NameError)
+ lambda { eval("inner", bind.binding) }.should raise_error(NameError)
end
- it "allows a binding to be captured inside an eval" do
- outer_binding = binding
- level1 = eval("binding", outer_binding)
- level2 = eval("binding", level1)
+ ruby_version_is ""..."1.9" do
+ it "allows a binding to be captured inside an eval" do
+ outer_binding = binding
+ level1 = eval("binding", outer_binding)
+ level2 = eval("binding", level1)
- eval("w = 1")
- eval("x = 2", outer_binding)
- eval("y = 3", level1)
+ eval("w = 1")
+ eval("x = 2", outer_binding)
+ eval("y = 3", level1)
- eval("w").should == 1
- eval("w", outer_binding).should == 1
- eval("w", level1).should == 1
- eval("w", level2).should == 1
+ eval("w").should == 1
+ eval("w", outer_binding).should == 1
+ eval("w", level1).should == 1
+ eval("w", level2).should == 1
- eval("x").should == 2
- eval("x", outer_binding).should == 2
- eval("x", level1).should == 2
- eval("x", level2).should == 2
+ eval("x").should == 2
+ eval("x", outer_binding).should == 2
+ eval("x", level1).should == 2
+ eval("x", level2).should == 2
- eval("y").should == 3
- eval("y", outer_binding).should == 3
- eval("y", level1).should == 3
- eval("y", level2).should == 3
+ eval("y").should == 3
+ eval("y", outer_binding).should == 3
+ eval("y", level1).should == 3
+ eval("y", level2).should == 3
+ end
end
- it "allows Proc and binding to be nested in horrible ways" do
- outer_binding = binding
- proc_binding = eval("proc {l = 5; binding}.call", outer_binding)
- inner_binding = eval("proc {k = 6; binding}.call", proc_binding)
+ ruby_version_is "1.9" do
+ # This differs from the 1.8 example because 1.9 doesn't share scope across
+ # sibling evals
+ it "allows a binding to be captured inside an eval" do
+ outer_binding = binding
+ level1 = eval("binding", outer_binding)
+ level2 = eval("binding", level1)
- eval("w = 1")
- eval("x = 2", outer_binding)
- eval("yy = 3", proc_binding)
- eval("z = 4", inner_binding)
+ eval("x = 2", outer_binding)
+ eval("y = 3", level1)
- eval("w").should == 1
- eval("w", outer_binding).should == 1
- eval("w", proc_binding).should == 1
- eval("w", inner_binding).should == 1
+ eval("w=1", outer_binding)
+ eval("w", outer_binding).should == 1
+ eval("w=1", level1).should == 1
+ eval("w", level1).should == 1
+ eval("w=1", level2).should == 1
+ eval("w", level2).should == 1
- eval("x").should == 2
- eval("x", outer_binding).should == 2
- eval("x", proc_binding).should == 2
- eval("x", inner_binding).should == 2
+ eval("x", outer_binding).should == 2
+ eval("x=2", level1)
+ eval("x", level1).should == 2
+ eval("x=2", level2)
+ eval("x", level2).should == 2
- lambda { eval("yy") }.should raise_error(NameError)
- lambda { eval("yy", outer_binding) }.should raise_error(NameError)
- eval("yy", proc_binding).should == 3
- eval("yy", inner_binding).should == 3
+ eval("y=3", outer_binding)
+ eval("y", outer_binding).should == 3
+ eval("y=3", level1)
+ eval("y", level1).should == 3
+ eval("y=3", level2)
+ eval("y", level2).should == 3
+ end
+ end
- lambda { eval("z") }.should raise_error(NameError)
- lambda { eval("z", outer_binding) }.should raise_error(NameError)
- lambda { eval("z", proc_binding) }.should raise_error(NameError)
- eval("z", inner_binding).should == 4
+ ruby_version_is ""..."1.9" do
+ it "allows Proc and binding to be nested in horrible ways" do
+ outer_binding = binding
+ proc_binding = eval("proc {l = 5; binding}.call", outer_binding)
+ inner_binding = eval("proc {k = 6; binding}.call", proc_binding)
- lambda { eval("l") }.should raise_error(NameError)
- lambda { eval("l", outer_binding) }.should raise_error(NameError)
- eval("l", proc_binding).should == 5
- eval("l", inner_binding).should == 5
+ eval("w = 1")
+ eval("x = 2", outer_binding)
+ eval("yy = 3", proc_binding)
+ eval("z = 4", inner_binding)
- lambda { eval("k") }.should raise_error(NameError)
- lambda { eval("k", outer_binding) }.should raise_error(NameError)
- lambda { eval("k", proc_binding) }.should raise_error(NameError)
- eval("k", inner_binding).should == 6
- end
+ eval("w").should == 1
+ eval("w", outer_binding).should == 1
+ eval("w", proc_binding).should == 1
+ eval("w", inner_binding).should == 1
- it "allows creating a new class in a binding" do
- bind = proc {}
- eval "class A; end", bind
- eval("A.name", bind).should == "A"
+ eval("x").should == 2
+ eval("x", outer_binding).should == 2
+ eval("x", proc_binding).should == 2
+ eval("x", inner_binding).should == 2
+
+ lambda { eval("yy") }.should raise_error(NameError)
+ lambda { eval("yy", outer_binding) }.should raise_error(NameError)
+ eval("yy", proc_binding).should == 3
+ eval("yy", inner_binding).should == 3
+
+ lambda { eval("z") }.should raise_error(NameError)
+ lambda { eval("z", outer_binding) }.should raise_error(NameError)
+ lambda { eval("z", proc_binding) }.should raise_error(NameError)
+ eval("z", inner_binding).should == 4
+
+ lambda { eval("l") }.should raise_error(NameError)
+ lambda { eval("l", outer_binding) }.should raise_error(NameError)
+ eval("l", proc_binding).should == 5
+ eval("l", inner_binding).should == 5
+
+ lambda { eval("k") }.should raise_error(NameError)
+ lambda { eval("k", outer_binding) }.should raise_error(NameError)
+ lambda { eval("k", proc_binding) }.should raise_error(NameError)
+ eval("k", inner_binding).should == 6
+ end
end
- it "allows creating a new class in a binding created by #eval" do
- bind = eval "binding"
- eval "class A; end", bind
- eval("A.name").should == "A"
+ ruby_version_is ""..."1.9" do
+ it "allows creating a new class in a binding" do
+ bind = proc {}
+ eval "class A; end", bind.binding
+ eval("A.name", bind.binding).should == "A"
+ end
+
+ it "allows creating a new class in a binding created by #eval" do
+ bind = eval "binding"
+ eval "class A; end", bind
+ eval("A.name").should == "A"
+ end
+
+ it "allows creating a new class in a binding returned by a method defined with #eval" do
+ bind = eval "def spec_binding; binding; end; spec_binding"
+ eval "class A; end", bind
+ eval("A.name").should == "A"
+ end
end
- it "allows creating a new class in a binding returned by a method defined with #eval" do
- bind = eval "def spec_binding; binding; end; spec_binding"
- eval "class A; end", bind
- eval("A.name").should == "A"
+ ruby_version_is "1.9" do
+ it "allows creating a new class in a binding" do
+ bind = proc {}
+ eval("class A; end; A.name", bind.binding).should =~ /A$/
+ end
+
+ it "allows creating a new class in a binding created by #eval" do
+ bind = eval "binding"
+ eval("class A; end; A.name", bind).should =~ /A$/
+ end
+
+ it "allows creating a new class in a binding returned by a method defined with #eval" do
+ bind = eval "def spec_binding; binding; end; spec_binding"
+ eval("class A; end; A.name", bind).should =~ /A$/
+ end
end
+
+
it "includes file and line information in syntax error" do
expected = 'speccing.rb'
lambda {
@@ -142,22 +211,36 @@
end
it "should perform top level evaluations from inside a block" do
- [1].each { eval "Const = 1"}
- Const.should ==1
+ # The class Object bit is needed to workaround some mspec oddness
class Object
+ [1].each { eval "Const = 1"}
+ Const.should == 1
remove_const :Const
end
end
- it "uses the filename of the binding if none is provided" do
- eval("__FILE__").should == "(eval)"
- eval("__FILE__", binding).should == __FILE__
- eval("__FILE__", binding, "success").should == "success"
- eval("eval '__FILE__', binding").should == "(eval)"
- eval("eval '__FILE__', binding", binding).should == __FILE__
- eval("eval '__FILE__', binding", binding, 'success').should == 'success'
+ ruby_version_is ""..."1.9" do
+ it "uses the filename of the binding if none is provided" do
+ eval("__FILE__").should == "(eval)"
+ eval("__FILE__", binding).should == __FILE__
+ eval("__FILE__", binding, "success").should == "success"
+ eval("eval '__FILE__', binding").should == "(eval)"
+ eval("eval '__FILE__', binding", binding).should == __FILE__
+ eval("eval '__FILE__', binding", binding, 'success').should == 'success'
+ end
end
+ ruby_version_is "1.9" do
+ it "uses a filename of (eval) if none is provided" do
+ eval("__FILE__").should == "(eval)"
+ eval("__FILE__", binding).should == "(eval)"
+ eval("__FILE__", binding, "success").should == "success"
+ eval("eval '__FILE__', binding").should == "(eval)"
+ eval("eval '__FILE__', binding", binding).should == "(eval)"
+ eval("eval '__FILE__', binding", binding, 'success').should == '(eval)'
+ end
+ end
+
it "can be aliased" do
alias aliased_eval eval
x = 2
Modified: MacRuby/branches/experimental/spec/frozen/core/kernel/fixtures/classes.rb
===================================================================
--- MacRuby/branches/experimental/spec/frozen/core/kernel/fixtures/classes.rb 2009-08-02 08:57:05 UTC (rev 2146)
+++ MacRuby/branches/experimental/spec/frozen/core/kernel/fixtures/classes.rb 2009-08-02 13:12:21 UTC (rev 2147)
@@ -157,6 +157,10 @@
end
end
+ module InstEvalCVar
+ instance_eval { @@count = 2 }
+ end
+
module InstEval
def self.included(base)
base.instance_eval { @@count = 2 }
@@ -198,6 +202,24 @@
ScratchPad.record object_id
end
end
+
+ module ParentMixin
+ def parent_mixin_method; end
+ end
+
+ class Parent
+ include ParentMixin
+ def parent_method; end
+ def another_parent_method; end
+ end
+
+ class Child < Parent
+ undef_method :parent_method
+ end
+
+ class Grandchild < Child
+ undef_method :parent_mixin_method
+ end
end
# for Kernel#sleep to have Channel in it's specs
Modified: MacRuby/branches/experimental/spec/frozen/core/kernel/freeze_spec.rb
===================================================================
--- MacRuby/branches/experimental/spec/frozen/core/kernel/freeze_spec.rb 2009-08-02 08:57:05 UTC (rev 2146)
+++ MacRuby/branches/experimental/spec/frozen/core/kernel/freeze_spec.rb 2009-08-02 13:12:21 UTC (rev 2147)
@@ -9,6 +9,7 @@
o.frozen?.should == true
end
+ # 1.9 allows immediate's to be frozen; reported as bug #1747
it "has no effect on immediate values" do
a = nil
b = true
Modified: MacRuby/branches/experimental/spec/frozen/core/kernel/instance_eval_spec.rb
===================================================================
--- MacRuby/branches/experimental/spec/frozen/core/kernel/instance_eval_spec.rb 2009-08-02 08:57:05 UTC (rev 2146)
+++ MacRuby/branches/experimental/spec/frozen/core/kernel/instance_eval_spec.rb 2009-08-02 13:12:21 UTC (rev 2147)
@@ -10,10 +10,18 @@
lambda { "hola".instance_eval(4, 5) { |a,b| a + b } }.should raise_error(ArgumentError)
end
- it "passes the object to the block" do
- "hola".instance_eval { |o| o.size }.should == 4
+ ruby_version_is ""..."1.9" do
+ it "passes the object to the block" do
+ "hola".instance_eval { |o| o.size }.should == 4
+ end
end
+ ruby_version_is "1.9" do
+ it "doesn't pass the object to the block" do
+ "hola".instance_eval { |o| o }.should be_nil
+ end
+ end
+
it "only binds the eval to the receiver" do
f = Object.new
f.instance_eval do
@@ -28,15 +36,19 @@
# TODO: This should probably be replaced with a "should behave like" that uses
# the many scoping/binding specs from kernel/eval_spec, since most of those
# behaviors are the same for instance_eval. See also module_eval/class_eval.
- it "shares a scope across sibling evals" do
- a, b = Object.new, Object.new
+
+ # Feature removed in 1.9
+ ruby_version_is ""..."1.9" do
+ it "shares a scope across sibling evals" do
+ a, b = Object.new, Object.new
- result = nil
- a.instance_eval "x = 1"
- lambda do
- b.instance_eval "result = x"
- end.should_not raise_error
- result.should == 1
+ result = nil
+ a.instance_eval "x = 1"
+ lambda do
+ b.instance_eval "result = x"
+ end.should_not raise_error
+ result.should == 1
+ end
end
it "binds self to the receiver" do
@@ -75,11 +87,22 @@
prc.call(false, prc).should == 1
end
- it "sets class variables in the receiver" do
- KernelSpecs::IncludesInstEval.class_variables.should include("@@count")
- KernelSpecs::IncludesInstEval.send(:class_variable_get, :@@count).should == 2
+ ruby_version_is ""..."1.9" do
+ it "sets class variables in the receiver" do
+ KernelSpecs::IncludesInstEval.class_variables.should include("@@count")
+ KernelSpecs::IncludesInstEval.send(:class_variable_get, :@@count).should == 2
+ end
end
+ ruby_version_is "1.9" do
+ # On 1.9 class variables aren't inherited so we have to modify the test
+ # from 1.8
+ it "sets class variables in the receiver" do
+ KernelSpecs::InstEvalCVar.class_variables.should include(:@@count)
+ KernelSpecs::InstEvalCVar.send(:class_variable_get, :@@count).should == 2
+ end
+ end
+
it "raises a TypeError when defining methods on an immediate" do
lambda do
1.instance_eval { def foo; end }
Modified: MacRuby/branches/experimental/spec/frozen/core/kernel/lambda_spec.rb
===================================================================
--- MacRuby/branches/experimental/spec/frozen/core/kernel/lambda_spec.rb 2009-08-02 08:57:05 UTC (rev 2146)
+++ MacRuby/branches/experimental/spec/frozen/core/kernel/lambda_spec.rb 2009-08-02 13:12:21 UTC (rev 2147)
@@ -2,12 +2,16 @@
require File.dirname(__FILE__) + '/fixtures/classes'
require File.dirname(__FILE__) + '/shared/lambda'
+# The functionality of lambdas is specified in core/proc
+
describe "Kernel.lambda" do
it "is a private method" do
Kernel.should have_private_instance_method(:lambda)
end
it_behaves_like(:kernel_lambda, :lambda)
+ it_behaves_like(:kernel_lambda_return_like_method, :lambda)
+
end
describe "Kernel#lambda" do
Modified: MacRuby/branches/experimental/spec/frozen/core/kernel/load_spec.rb
===================================================================
--- MacRuby/branches/experimental/spec/frozen/core/kernel/load_spec.rb 2009-08-02 08:57:05 UTC (rev 2146)
+++ MacRuby/branches/experimental/spec/frozen/core/kernel/load_spec.rb 2009-08-02 13:12:21 UTC (rev 2147)
@@ -111,10 +111,31 @@
$LOADED_FEATURES.grep(/load_spec_3.rb/).should == []
end
+ ruby_version_is ""..."1.8.7" do
+ it "returns __FILE__ as a relative path" do
+ Dir.chdir($load_fixture_dir) do |dir|
+ load('load_spec_4.rb')
+ $load_spec_4.first.first.should == './load_spec_4.rb'
+ end
+ end
+ end
+
+ ruby_version_is "1.8.7" do
+ it "returns __FILE__ as an absolute path" do
+ Dir.chdir($load_fixture_dir) do |dir|
+ load('load_spec_4.rb')
+ $load_spec_4.first.first.should == File.expand_path('./load_spec_4.rb')
+ end
+ end
+ end
+
it "produces __FILE__ as the given filename and __LINE__ as the source line number" do
Dir.chdir($load_fixture_dir) do |dir|
load('load_spec_4.rb').should == true
- $load_spec_4.should == [['./load_spec_4.rb', 1], ['./load_spec_4.rb', 10]]
+ $load_spec_4.first.first.should =~ /load_spec_4\.rb$/
+ $load_spec_4.first.last.should == 1
+ $load_spec_4.last.first.should =~ /load_spec_4\.rb$/
+ $load_spec_4.last.last.should == 10
extended_on :rubinius do
`rm load_spec_4.rbc`
Modified: MacRuby/branches/experimental/spec/frozen/core/kernel/methods_spec.rb
===================================================================
--- MacRuby/branches/experimental/spec/frozen/core/kernel/methods_spec.rb 2009-08-02 08:57:05 UTC (rev 2146)
+++ MacRuby/branches/experimental/spec/frozen/core/kernel/methods_spec.rb 2009-08-02 13:12:21 UTC (rev 2147)
@@ -1,158 +1,126 @@
require File.dirname(__FILE__) + '/../../spec_helper'
require File.dirname(__FILE__) + '/fixtures/classes'
-module KernelSpecs
- class MethodsUndefd
- def all; end
- end
-
- class MethodsUndefdParent
- def parent_method; end
- end
-
- class MethodsUndefdChild < MethodsUndefdParent
- undef_method :parent_method
- end
-end
-
# On Ruby < 1.9 #methods returns an Array of Strings
ruby_version_is ""..."1.9" do
describe "Kernel#methods" do
-
- it "picks up methods added via self.meth" do
+ it "returns singleton methods defined by obj.meth" do
KernelSpecs::Methods.methods(false).should include("ichi")
end
- it "picks up methods added inside 'class << self'" do
+ it "returns singleton methods defined in 'class << self'" do
KernelSpecs::Methods.methods(false).should include("san")
end
- it "picks up private methods added via self.meth" do
+ it "returns private singleton methods defined by obj.meth" do
KernelSpecs::Methods.methods(false).should include("shi")
end
- it "picks up methods added inside 'class << self' after private" do
+ it "returns singleton methods defined in 'class << self' when it follows 'private'" do
KernelSpecs::Methods.methods(false).should include("roku")
end
- it "doesn't pick up methods added inside 'class << self; private'" do
+ it "does not return private singleton methods defined in 'class << self'" do
KernelSpecs::Methods.methods(false).should_not include("shichi")
end
- it "returns a list of the names of publicly accessible methods in the object" do
+ it "returns the publicly accessible methods of the object" do
meths = KernelSpecs::Methods.methods(false)
+ meths.should include("hachi", "ichi", "juu", "juu_ichi",
+ "juu_ni", "roku", "san", "shi")
- ["hachi", "ichi", "juu", "juu_ichi", "juu_ni", "roku", "san", "shi"].each do|m|
- meths.should include(m)
- end
-
KernelSpecs::Methods.new.methods(false).should == []
end
- it "returns a list of the names of publicly accessible methods in the object and its ancestors and mixed-in modules" do
+ it "returns the publicly accessible methods in the object, its ancestors and mixed-in modules" do
meths = KernelSpecs::Methods.methods(false) & KernelSpecs::Methods.methods
- ["hachi", "ichi", "juu", "juu_ichi", "juu_ni", "roku", "san", "shi"].each do |m|
- meths.should include(m)
- end
+ meths.should include("hachi", "ichi", "juu", "juu_ichi",
+ "juu_ni", "roku", "san", "shi")
- m = KernelSpecs::Methods.new.methods
- m.should include('ku')
- m.should include('ni')
- m.should include('juu_san')
+ KernelSpecs::Methods.new.methods.should include("ku", "ni", "juu_san")
end
- it "does not include any .undef'd methods" do
- o = KernelSpecs::MethodsUndefd.new
-
+ it "does not return undefined singleton methods defined by obj.meth" do
+ o = KernelSpecs::Child.new
def o.single; end
-
- o.methods.should include("all")
o.methods.should include("single")
- KernelSpecs::MethodsUndefd.send :undef_method, :all
-
- o.methods.should_not include("all")
-
class << o; self; end.send :undef_method, :single
-
o.methods.should_not include("single")
end
- it "does not include any .undef'd methods even if method is inherited" do
- o = KernelSpecs::MethodsUndefdChild.new
- o.methods.should_not include("inh")
+ it "does not return superclass methods undefined in the object's class" do
+ KernelSpecs::Child.new.methods.should_not include("parent_method")
end
+ it "does not return superclass methods undefined in a superclass" do
+ KernelSpecs::Grandchild.new.methods.should_not include("parent_method")
+ end
+
+ it "does not return included module methods undefined in the object's class" do
+ KernelSpecs::Grandchild.new.methods.should_not include("parent_mixin_method")
+ end
end
end
# On MRI >= 1.9 #methods returns an Array of Symbols.
ruby_version_is "1.9" do
describe "Kernel#methods" do
-
- it "picks up methods added via self.meth" do
+ it "returns singleton methods defined by obj.meth" do
KernelSpecs::Methods.methods(false).should include(:ichi)
end
- it "picks up methods added inside 'class << self'" do
+ it "returns singleton methods defined in 'class << self'" do
KernelSpecs::Methods.methods(false).should include(:san)
end
- it "picks up private methods added via self.meth" do
+ it "returns private singleton methods defined by obj.meth" do
KernelSpecs::Methods.methods(false).should include(:shi)
end
- it "picks up methods added inside 'class << self' after private" do
+ it "returns singleton methods defined in 'class << self' when it follows 'private'" do
KernelSpecs::Methods.methods(false).should include(:roku)
end
- it "doesn't pick up methods added inside 'class << self; private'" do
+ it "does not return private singleton methods defined in 'class << self'" do
KernelSpecs::Methods.methods(false).should_not include(:shichi)
end
- it "returns a list of the names of publicly accessible methods in the object" do
+ it "returns the publicly accessible methods of the object" do
meths = KernelSpecs::Methods.methods(false)
+ meths.should include(:hachi, :ichi, :juu, :juu_ichi,
+ :juu_ni, :roku, :san, :shi)
- [:hachi, :ichi, :juu, :juu_ichi, :juu_ni, :roku, :san, :shi].each do|m|
- meths.should include(m)
- end
-
KernelSpecs::Methods.new.methods(false).should == []
end
- it "returns a list of the names of publicly accessible methods in the object and its ancestors and mixed-in modules" do
+ it "returns the publicly accessible methods in the object, its ancestors and mixed-in modules" do
meths = KernelSpecs::Methods.methods(false) & KernelSpecs::Methods.methods
- [:hachi, :ichi, :juu, :juu_ichi, :juu_ni, :roku, :san, :shi].each do |m|
- meths.should include(m)
- end
+ meths.should include(:hachi, :ichi, :juu, :juu_ichi,
+ :juu_ni, :roku, :san, :shi)
- m = KernelSpecs::Methods.new.methods
- m.should include(:ku)
- m.should include(:ni)
- m.should include(:juu_san)
+ KernelSpecs::Methods.new.methods.should include(:ku, :ni, :juu_san)
end
- it "does not include any .undef'd methods" do
- o = KernelSpecs::MethodsUndefd.new
-
+ it "does not return undefined singleton methods defined by obj.meth" do
+ o = KernelSpecs::Child.new
def o.single; end
-
- o.methods.should include(:all)
o.methods.should include(:single)
- KernelSpecs::MethodsUndefd.send :undef_method, :all
-
- o.methods.should_not include(:all)
-
class << o; self; end.send :undef_method, :single
-
o.methods.should_not include(:single)
end
- it "does not include any .undef'd methods even if method is inherited" do
- o = KernelSpecs::MethodsUndefdChild.new
- o.methods.should_not include(:inh)
+ it "does not return superclass methods undefined in the object's class" do
+ KernelSpecs::Child.new.methods.should_not include(:parent_method)
end
+ it "does not return superclass methods undefined in a superclass" do
+ KernelSpecs::Grandchild.new.methods.should_not include(:parent_method)
+ end
+
+ it "does not return included module methods undefined in the object's class" do
+ KernelSpecs::Grandchild.new.methods.should_not include(:parent_mixin_method)
+ end
end
end
Modified: MacRuby/branches/experimental/spec/frozen/core/kernel/proc_spec.rb
===================================================================
--- MacRuby/branches/experimental/spec/frozen/core/kernel/proc_spec.rb 2009-08-02 08:57:05 UTC (rev 2146)
+++ MacRuby/branches/experimental/spec/frozen/core/kernel/proc_spec.rb 2009-08-02 13:12:21 UTC (rev 2147)
@@ -2,12 +2,30 @@
require File.dirname(__FILE__) + '/fixtures/classes'
require File.dirname(__FILE__) + '/shared/lambda'
+# The functionality of Proc objects is specified in core/proc
+
describe "Kernel.proc" do
it "is a private method" do
Kernel.should have_private_instance_method(:proc)
end
it_behaves_like(:kernel_lambda, :proc)
+
+ ruby_version_is ""..."1.9" do
+ it_behaves_like(:kernel_lambda_return_like_method, :proc)
+ end
+
+ ruby_version_is "1.9" do
+ it "returns from the creation site of the proc, not just the proc itself" do
+ @reached_end_of_method = nil
+ def test
+ proc { return }.call
+ @reached_end_of_method = true
+ end
+ test
+ @reached_end_of_method.should be_nil
+ end
+ end
end
describe "Kernel#proc" do
Added: MacRuby/branches/experimental/spec/frozen/core/kernel/public_send_spec.rb
===================================================================
--- MacRuby/branches/experimental/spec/frozen/core/kernel/public_send_spec.rb (rev 0)
+++ MacRuby/branches/experimental/spec/frozen/core/kernel/public_send_spec.rb 2009-08-02 13:12:21 UTC (rev 2147)
@@ -0,0 +1,73 @@
+require File.dirname(__FILE__) + '/../../spec_helper'
+require File.dirname(__FILE__) + '/fixtures/classes'
+require File.dirname(__FILE__) + '/shared/send'
+
+ruby_version_is "1.9" do
+ describe "Kernel#public_send" do
+ it "invokes the named public method" do
+ class KernelSpecs::Foo
+ def bar
+ 'done'
+ end
+ end
+ KernelSpecs::Foo.new.public_send(:bar).should == 'done'
+ end
+
+ it "invokes the named alias of a public method" do
+ class KernelSpecs::Foo
+ alias :aka :bar
+ def bar
+ 'done'
+ end
+ end
+ KernelSpecs::Foo.new.public_send(:aka).should == 'done'
+ end
+
+ it "raises a NoMethodError if the method is protected" do
+ class KernelSpecs::Foo
+ protected
+ def bar
+ 'done'
+ end
+ end
+ lambda { KernelSpecs::Foo.new.public_send(:bar)}.should raise_error(NoMethodError)
+ end
+
+ it "raises a NoMethodError if the named method is private" do
+ class KernelSpecs::Foo
+ private
+ def bar
+ 'done2'
+ end
+ end
+ lambda { KernelSpecs::Foo.new.public_send(:bar) }.should
+ raise_error(NoMethodError)
+ end
+
+ it "raises a NoMethodError if the named method is an alias of a private method" do
+ class KernelSpecs::Foo
+ alias :aka :bar
+ private
+ def bar
+ 'done2'
+ end
+ end
+ lambda { KernelSpecs::Foo.new.public_send(:aka) }.should
+ raise_error(NoMethodError)
+ end
+
+ it "raises a NoMethodError if the named method is an alias of a protected method" do
+ class KernelSpecs::Foo
+ alias :aka :bar
+ protected
+ def bar
+ 'done2'
+ end
+ end
+ lambda { KernelSpecs::Foo.new.public_send(:aka) }.should
+ raise_error(NoMethodError)
+ end
+
+ it_behaves_like(:kernel_send, :public_send)
+ end
+end
Modified: MacRuby/branches/experimental/spec/frozen/core/kernel/puts_spec.rb
===================================================================
--- MacRuby/branches/experimental/spec/frozen/core/kernel/puts_spec.rb 2009-08-02 08:57:05 UTC (rev 2146)
+++ MacRuby/branches/experimental/spec/frozen/core/kernel/puts_spec.rb 2009-08-02 13:12:21 UTC (rev 2147)
@@ -20,12 +20,24 @@
Kernel.puts.should == nil
end
- it "writes nil with a newline when given nil as an arg" do
- $stdout.should_receive(:write).with("nil")
- $stdout.should_receive(:write).with("\n")
- Kernel.puts(nil).should == nil
+ ruby_version_is ""..."1.9" do
+ it "writes nil with a newline when given nil as an arg" do
+ $stdout.should_receive(:write).with("nil")
+ $stdout.should_receive(:write).with("\n")
+ Kernel.puts(nil).should == nil
+ end
end
+ # Declared intentional in
+ # http://redmine.ruby-lang.org/issues/show/1748
+ ruby_version_is "1.9" do
+ it "writes a newline when given nil as an arg" do
+ $stdout.should_receive(:write).with('')
+ $stdout.should_receive(:write).with("\n")
+ Kernel.puts(nil).should == nil
+ end
+ end
+
it "calls to_s before writing non-string objects" do
object = mock('hola')
object.should_receive(:to_s).and_return("hola")
Modified: MacRuby/branches/experimental/spec/frozen/core/kernel/require_spec.rb
===================================================================
--- MacRuby/branches/experimental/spec/frozen/core/kernel/require_spec.rb 2009-08-02 08:57:05 UTC (rev 2146)
+++ MacRuby/branches/experimental/spec/frozen/core/kernel/require_spec.rb 2009-08-02 13:12:21 UTC (rev 2147)
@@ -63,6 +63,34 @@
end
end
+ ruby_version_is "1.9" do
+ # This expectation is necessarily long-winded because the conditions are
+ # particularly specific. Namely:
+ #
+ # * The directory containing the file isn't in $LOAD_PATH
+ # * The filename has no path components prepended
+ # * The file hasn't already been required
+ # * The file exists
+ #
+ # For reference see [ruby-core:24155] in which matz confirms this feature is
+ # intentional for security reasons.
+ it "does not resolve completely unqualified filenames against the current working directory unless it appears in $LOAD_PATH" do
+ dir = File.join($require_tmp_dir, $$.to_s)
+ $LOAD_PATH.include?(dir).should be_false
+ File.directory?(dir).should be_false
+ Dir.mkdir(dir)
+ File.directory?(dir).should be_true
+ Dir.chdir(dir) do |tmp_dir|
+ file = "#{$$}_#{Process.times.utime}.rb"
+ FileUtils.touch file
+ File.exist?(file).should be_true
+ lambda { require file }.should raise_error(LoadError)
+ File.unlink(file)
+ end
+ Dir.rmdir(dir)
+ end
+ end
+
it "does not expand/resolve qualified files against $LOAD_PATH" do
num_features = $LOADED_FEATURES.size
Dir.chdir($require_fixture_dir + '/../') do |dir|
Modified: MacRuby/branches/experimental/spec/frozen/core/kernel/send_spec.rb
===================================================================
--- MacRuby/branches/experimental/spec/frozen/core/kernel/send_spec.rb 2009-08-02 08:57:05 UTC (rev 2146)
+++ MacRuby/branches/experimental/spec/frozen/core/kernel/send_spec.rb 2009-08-02 13:12:21 UTC (rev 2147)
@@ -1,102 +1,68 @@
require File.dirname(__FILE__) + '/../../spec_helper'
require File.dirname(__FILE__) + '/fixtures/classes'
+require File.dirname(__FILE__) + '/shared/send'
describe "Kernel#send" do
- it "invokes the named method" do
+ it "invokes the named public method" do
class KernelSpecs::Foo
def bar
'done'
end
-
- private
- def bar2
- 'done2'
- end
end
KernelSpecs::Foo.new.send(:bar).should == 'done'
- KernelSpecs::Foo.new.send(:bar2).should == 'done2'
end
- it "invokes a class method if called on a class" do
+ it "invokes the named alias of a public method" do
class KernelSpecs::Foo
- def self.bar
+ alias :aka :bar
+ def bar
'done'
end
end
- KernelSpecs::Foo.send(:bar).should == 'done'
+ KernelSpecs::Foo.new.send(:aka).should == 'done'
end
- it "raises a NoMethodError if the corresponding method can't be found" do
+ it "invokes the named protected method" do
class KernelSpecs::Foo
+ protected
def bar
'done'
end
end
- lambda { KernelSpecs::Foo.new.send(:baz) }.should raise_error(NameError)
+ KernelSpecs::Foo.new.send(:bar).should == 'done'
end
- it "raises a NoMethodError if the corresponding singleton method can't be found" do
+ it "invokes the named private method" do
class KernelSpecs::Foo
- def self.bar
- 'done'
+ private
+ def bar
+ 'done2'
end
end
- lambda { KernelSpecs::Foo.send(:baz) }.should raise_error(NameError)
+ KernelSpecs::Foo.new.send(:bar).should == 'done2'
end
- it "raises an ArgumentError if called with more arguments than available parameters" do
+ it "invokes the named alias of a private method" do
class KernelSpecs::Foo
- def bar; end
+ alias :aka :bar
+ private
+ def bar
+ 'done2'
+ end
end
-
- lambda { KernelSpecs::Foo.new.send(:bar, :arg) }.should raise_error(ArgumentError)
+ KernelSpecs::Foo.new.send(:aka).should == 'done2'
end
- it "raises an ArgumentError if called with fewer arguments than required parameters" do
+ it "invokes the named alias of a protected method" do
class KernelSpecs::Foo
- def foo(arg); end
+ alias :aka :bar
+ protected
+ def bar
+ 'done2'
+ end
end
-
- lambda { KernelSpecs::Foo.new.send(:foo) }.should raise_error(ArgumentError)
+ KernelSpecs::Foo.new.send(:aka).should == 'done2'
end
- it "succeeds if passed an arbitrary number of arguments as a splat parameter" do
- class KernelSpecs::Foo
- def baz(*args) args end
- end
-
- begin
- KernelSpecs::Foo.new.send(:baz).should == []
- KernelSpecs::Foo.new.send(:baz, :quux).should == [:quux]
- KernelSpecs::Foo.new.send(:baz, :quux, :foo).should == [:quux, :foo]
- rescue
- fail
- end
- end
-
- it "succeeds when passing 1 or more arguments as a required and a splat parameter" do
- class KernelSpecs::Foo
- def foo(first, *rest) [first, *rest] end
- end
-
- begin
- KernelSpecs::Foo.new.send(:baz, :quux).should == [:quux]
- KernelSpecs::Foo.new.send(:baz, :quux, :foo).should == [:quux, :foo]
- rescue
- fail
- end
- end
-
- it "succeeds when passing 0 arguments to a method with one parameter with a default" do
- class KernelSpecs::Foo
- def foo(first = true) first end
- end
-
- begin
- KernelSpecs::Foo.new.send(:foo).should == true
- KernelSpecs::Foo.new.send(:foo, :arg).should == :arg
- rescue
- fail
- end
- end
+ it_behaves_like(:kernel_send, :send)
end
Modified: MacRuby/branches/experimental/spec/frozen/core/kernel/shared/lambda.rb
===================================================================
--- MacRuby/branches/experimental/spec/frozen/core/kernel/shared/lambda.rb 2009-08-02 08:57:05 UTC (rev 2146)
+++ MacRuby/branches/experimental/spec/frozen/core/kernel/shared/lambda.rb 2009-08-02 13:12:21 UTC (rev 2147)
@@ -7,33 +7,16 @@
lambda { send(@method) }.should raise_error(ArgumentError)
end
- it "raises an ArgumentError when given too many arguments" do
- lambda {
- send(@method) { |a, b| a + b }.call(1, 2, 5)
- }.should raise_error(ArgumentError)
- end
+end
- it "raises an ArgumentError when given too few arguments" do
- lambda {
- send(@method) { |a, b| a + b }.call(1)
- }.should raise_error(ArgumentError)
- end
-
- it "returns from block into caller block" do
- # More info in the pickaxe book pg. 359
- def some_method(cmd)
- p = send(cmd) { return 99 }
- res = p.call
- "returned #{res}"
+describe :kernel_lambda_return_like_method, :shared => true do
+ it "returns from the #{@method} itself; not the creation site of the #{@method}" do
+ @reached_end_of_method = nil
+ def test
+ send(@method) { return }.call
+ @reached_end_of_method = true
end
-
- # Have to pass in the @method errors otherwise
- some_method(@method).should == "returned 99"
-
- def some_method2(&b) b end
- a_proc = send(@method) { return true }
- res = some_method2(&a_proc)
-
- res.call.should == true
+ test
+ @reached_end_of_method.should be_true
end
end
Copied: MacRuby/branches/experimental/spec/frozen/core/kernel/shared/send.rb (from rev 2146, MacRuby/branches/experimental/spec/frozen/core/kernel/send_spec.rb)
===================================================================
--- MacRuby/branches/experimental/spec/frozen/core/kernel/shared/send.rb (rev 0)
+++ MacRuby/branches/experimental/spec/frozen/core/kernel/shared/send.rb 2009-08-02 13:12:21 UTC (rev 2147)
@@ -0,0 +1,98 @@
+describe :kernel_send, :shared => true do
+ it "invokes the named method" do
+ class KernelSpecs::Foo
+ def bar
+ 'done'
+ end
+ end
+ KernelSpecs::Foo.new.send(@method, :bar).should == 'done'
+ end
+
+ it "invokes a class method if called on a class" do
+ class KernelSpecs::Foo
+ def self.bar
+ 'done'
+ end
+ end
+ KernelSpecs::Foo.send(@method, :bar).should == 'done'
+ end
+
+ it "raises a NameError if the corresponding method can't be found" do
+ class KernelSpecs::Foo
+ def bar
+ 'done'
+ end
+ end
+ lambda { KernelSpecs::Foo.new.send(@method, :syegsywhwua) }.should raise_error(NameError)
+ end
+
+ it "raises a NameError if the corresponding singleton method can't be found" do
+ class KernelSpecs::Foo
+ def self.bar
+ 'done'
+ end
+ end
+ lambda { KernelSpecs::Foo.send(@method, :baz) }.should raise_error(NameError)
+ end
+
+ it "raises an ArgumentError if called with more arguments than available parameters" do
+ class KernelSpecs::Foo
+ def bar; end
+ end
+
+ lambda { KernelSpecs::Foo.new.send(:bar, :arg) }.should raise_error(ArgumentError)
+ end
+
+ it "raises an ArgumentError if called with fewer arguments than required parameters" do
+ class KernelSpecs::Foo
+ def foo(arg); end
+ end
+
+ lambda { KernelSpecs::Foo.new.send(@method, :foo) }.should raise_error(ArgumentError)
+ end
+
+ it "succeeds if passed an arbitrary number of arguments as a splat parameter" do
+ class KernelSpecs::Foo
+ def baz(*args) args end
+ end
+
+ begin
+ KernelSpecs::Foo.new.send(@method, :baz).should == []
+ KernelSpecs::Foo.new.send(@method, :baz, :quux).should == [:quux]
+ KernelSpecs::Foo.new.send(@method, :baz, :quux, :foo).should == [:quux, :foo]
+ rescue
+ fail
+ end
+ end
+
+ it "succeeds when passing 1 or more arguments as a required and a splat parameter" do
+ class KernelSpecs::Foo
+ def foo(first, *rest) [first, *rest] end
+ end
+
+ begin
+ KernelSpecs::Foo.new.send(@method, :baz, :quux).should == [:quux]
+ KernelSpecs::Foo.new.send(@method, :baz, :quux, :foo).should == [:quux, :foo]
+ rescue
+ fail
+ end
+ end
+
+ it "succeeds when passing 0 arguments to a method with one parameter with a default" do
+ class KernelSpecs::Foo
+ def foo(first = true) first end
+ end
+
+ begin
+ KernelSpecs::Foo.new.send(@method, :foo).should == true
+ KernelSpecs::Foo.new.send(@method, :foo, :arg).should == :arg
+ rescue
+ fail
+ end
+ end
+
+ # Confirm commit r24306
+ it "has an arity of -1" do
+ method(:__send__).arity.should == -1
+ end
+end
Modified: MacRuby/branches/experimental/spec/frozen/core/kernel/sprintf_spec.rb
===================================================================
--- MacRuby/branches/experimental/spec/frozen/core/kernel/sprintf_spec.rb 2009-08-02 08:57:05 UTC (rev 2146)
+++ MacRuby/branches/experimental/spec/frozen/core/kernel/sprintf_spec.rb 2009-08-02 13:12:21 UTC (rev 2147)
@@ -10,8 +10,10 @@
sprintf("%s%d%s%s", nil, 4, 'a', 'b').should == '4ab'
end
- it "treats nil arguments as zeroes in %d slots" do
- sprintf("%d%d%s%s", nil, 4, 'a', 'b').should == '04ab'
+ ruby_version_is ""..."1.9" do
+ it "treats nil arguments as zeroes in %d slots" do
+ sprintf("%d%d%s%s", nil, 4, 'a', 'b').should == '04ab'
+ end
end
end
Modified: MacRuby/branches/experimental/spec/frozen/core/kernel/tap_spec.rb
===================================================================
--- MacRuby/branches/experimental/spec/frozen/core/kernel/tap_spec.rb 2009-08-02 08:57:05 UTC (rev 2146)
+++ MacRuby/branches/experimental/spec/frozen/core/kernel/tap_spec.rb 2009-08-02 13:12:21 UTC (rev 2147)
@@ -1,7 +1,7 @@
require File.dirname(__FILE__) + '/../../spec_helper'
require File.dirname(__FILE__) + '/fixtures/classes'
-ruby_version_is "1.8.7".."" do
+ruby_version_is "1.8.7" do
describe "Kernel#tap" do
it "always yields self and returns self" do
a = KernelSpecs::A.new
Modified: MacRuby/branches/experimental/spec/frozen/core/marshal/load_spec.rb
===================================================================
--- MacRuby/branches/experimental/spec/frozen/core/marshal/load_spec.rb 2009-08-02 08:57:05 UTC (rev 2146)
+++ MacRuby/branches/experimental/spec/frozen/core/marshal/load_spec.rb 2009-08-02 13:12:21 UTC (rev 2147)
@@ -112,53 +112,147 @@
obj
end
- it "loads a array containing objects having _dump method, and with proc" do
- arr = []
- proc = Proc.new { |o| arr << o }
- o1 = UserDefined.new; o2 = UserDefinedWithIvar.new
- obj = [o1, o2, o1, o2]
+ ruby_version_is "1.9" do
+ it "returns the value of the proc when called with a proc" do
+ Marshal.load(Marshal.dump([1,2]), proc { [3,4] }).should == [3,4]
+ end
+ end
- Marshal.load "\004\b[\tu:\020UserDefined\022\004\b[\a\"\nstuff@\006u:\030UserDefinedWithIvar5\004\b[\bI\"\nstuff\006:\t at foo:\030UserDefinedWithIvar\"\tmore@\a@\006@\a", proc
+ ruby_version_is ""..."1.9" do
+ it "ignores the value of the proc when called with a proc" do
+ Marshal.load(Marshal.dump([1,2]), proc { [3,4] }).should == [1,2]
+ end
+ end
- arr.should == [o1, o2, obj]
+ ruby_version_is "1.9" do
+ it "calls the proc for recursively visited data" do
+ a = [1]
+ a << a
+ ret = []
+ Marshal.load(Marshal.dump(a), proc { |arg| ret << arg; arg })
+ ret.first.should == 1
+ ret[1].should == [1,a]
+ ret[2].should == a
+ ret.size.should == 3
+ end
end
- it "loads an array containing objects having marshal_dump method, and with proc" do
- arr = []
- proc = Proc.new { |o| arr << o }
- o1 = UserMarshal.new
- o2 = UserMarshalWithIvar.new
- obj = [o1, o2, o1, o2]
+ ruby_version_is ""..."1.9" do
+ it "doesn't call the proc for recursively visited data" do
+ a = [1]
+ a << a
+ ret = []
+ Marshal.load(Marshal.dump(a), proc { |arg| ret << arg })
+ ret.first.should == 1
+ ret.size.should == 2
+ end
+ end
- Marshal.load "\004\b[\tU:\020UserMarshal\"\nstuffU:\030UserMarshalWithIvar[\006\"\fmy data@\006@\b", proc
+ ruby_version_is ""..."1.9" do
+ it "loads a array containing objects having _dump method, and with proc" do
+ arr = []
+ proc = Proc.new { |o| arr << o }
+ o1 = UserDefined.new;
+ o2 = UserDefinedWithIvar.new
+ obj = [o1, o2, o1, o2]
- arr.should == ['stuff', o1, 'my data', ['my data'], o2, obj]
+ Marshal.load "\004\b[\tu:\020UserDefined\022\004\b[\a\"\nstuff@\006u:\030UserDefinedWithIvar5\004\b[\bI\"\nstuff\006:\t at foo:\030UserDefinedWithIvar\"\tmore@\a@\006@\a", proc
+
+ arr.should == [o1, o2, obj]
+ end
end
- it "loads an Array with proc" do
- arr = []
- s = 'hi'
- s.instance_variable_set(:@foo, 5)
- st = Struct.new("Brittle", :a).new
- st.instance_variable_set(:@clue, 'none')
- st.a = 0.0
- h = Hash.new('def')
- h['nine'] = 9
- a = [:a, :b, :c]
- a.instance_variable_set(:@two, 2)
- obj = [s, 10, s, s, st, h, a]
- obj.instance_variable_set(:@zoo, 'ant')
+ ruby_version_is "1.9" do
+ it "loads a array containing objects having _dump method, and with proc" do
+ arr = []
+ myproc = Proc.new { |o| arr << o; o }
+ o1 = UserDefined.new;
+ o2 = UserDefinedWithIvar.new
+ obj = [o1, o2, o1, o2]
- proc = Proc.new { |o| arr << o }
- new_obj = Marshal.load "\004\bI[\fI\"\ahi\006:\t at fooi\ni\017@\006@\006IS:\024Struct::Brittle\006:\006af\0060\006:\n at clue\"\tnone}\006\"\tninei\016\"\bdefI[\b;\a:\006b:\006c\006:\t at twoi\a\006:\t at zoo\"\bant", proc
+ Marshal.load "\x04\b[\tu:\x10UserDefined\x18\x04\b[\aI\"\nstuff\x06:\x06EF@\x06u:\x18UserDefinedWithIvar>\x04\b[\bI\"\nstuff\a:\x06EF:\t at foo:\x18UserDefinedWithIvarI\"\tmore\x06;\x00F@\a@\x06@\a", myproc
- new_obj.should == obj
- new_obj.instance_variable_get(:@zoo).should == 'ant'
+ arr.should == [o1, o2, o1, o2, obj]
+ end
+ end
- arr.should ==
- [5, s, 10, 0.0, 'none', st, 'nine', 9, 'def', h, :b, :c, 2, a, 'ant', obj]
+ ruby_version_is ""..."1.9" do
+ it "loads an array containing objects having marshal_dump method, and with proc" do
+ arr = []
+ proc = Proc.new { |o| arr << o }
+ o1 = UserMarshal.new
+ o2 = UserMarshalWithIvar.new
+ obj = [o1, o2, o1, o2]
+
+ Marshal.load "\004\b[\tU:\020UserMarshal\"\nstuffU:\030UserMarshalWithIvar[\006\"\fmy data@\006@\b", proc
+
+ arr.should == ['stuff', o1, 'my data', ['my data'], o2, obj]
+ end
end
+ ruby_version_is "1.9" do
+ it "loads an array containing objects having marshal_dump method, and with proc" do
+ arr = []
+ proc = Proc.new { |o| arr << o; o }
+ o1 = UserMarshal.new
+ o2 = UserMarshalWithIvar.new
+ obj = [o1, o2, o1, o2]
+
+ Marshal.load "\004\b[\tU:\020UserMarshal\"\nstuffU:\030UserMarshalWithIvar[\006\"\fmy data@\006@\b", proc
+
+ arr.should == ['stuff', o1, 'my data', ['my data'], o2, o1, o2, obj]
+ end
+ end
+
+ ruby_version_is ""..."1.9" do
+ it "loads an Array with proc" do
+ arr = []
+ s = 'hi'
+ s.instance_variable_set(:@foo, 5)
+ st = Struct.new("Brittle", :a).new
+ st.instance_variable_set(:@clue, 'none')
+ st.a = 0.0
+ h = Hash.new('def')
+ h['nine'] = 9
+ a = [:a, :b, :c]
+ a.instance_variable_set(:@two, 2)
+ obj = [s, 10, s, s, st, h, a]
+ obj.instance_variable_set(:@zoo, 'ant')
+ proc = Proc.new { |o| arr << o }
+
+ new_obj = Marshal.load "\004\bI[\fI\"\ahi\006:\t at fooi\ni\017@\006@\006IS:\024Struct::Brittle\006:\006af\0060\006:\n at clue\"\tnone}\006\"\tninei\016\"\bdefI[\b;\a:\006b:\006c\006:\t at twoi\a\006:\t at zoo\"\bant", proc
+
+ new_obj.should == obj
+ new_obj.instance_variable_get(:@zoo).should == 'ant'
+
+ arr.should ==
+ [5, s, 10, 0.0, 'none', st, 'nine', 9, 'def', h, :b, :c, 2, a, 'ant', obj]
+ end
+ end
+
+ ruby_version_is "1.9" do
+ it "loads an Array with proc" do
+ arr = []
+ s = 'hi'
+ s.instance_variable_set(:@foo, 5)
+ st = Struct.new("Brittle", :a).new
+ st.instance_variable_set(:@clue, 'none')
+ st.a = 0.0
+ h = Hash.new('def')
+ h['nine'] = 9
+ a = [:a, :b, :c]
+ a.instance_variable_set(:@two, 2)
+ obj = [s, 10, s, s, st, a]
+ obj.instance_variable_set(:@zoo, 'ant')
+ proc = Proc.new { |o| arr << o; o}
+
+ Marshal.load("\x04\bI[\vI\"\ahi\a:\x06EF:\t at fooi\ni\x0F@\x06@\x06IS:\x14Struct::Brittle\x06:\x06af\x060\x06:\n at clueI\"\tnone\x06;\x00FI[\b;\b:\x06b:\x06c\x06:\t at twoi\a\x06:\t at zooI\"\bant\x06;\x00F", proc)
+
+ arr.should == ["hi", false, 5, 10, "hi", "hi", 0.0, st, "none", false,
+ :b, :c, a, 2, ["hi", 10, "hi", "hi", st, [:a, :b, :c]], "ant", false]
+ end
+ end
+
it "loads a array containing the same objects" do
s = 'oh'; b = 'hi'; r = //; d = [b, :no, s, :go]; c = String; f = 1.0
o1 = UserMarshalWithIvar.new; o2 = UserMarshal.new
Modified: MacRuby/branches/experimental/spec/frozen/core/math/acos_spec.rb
===================================================================
--- MacRuby/branches/experimental/spec/frozen/core/math/acos_spec.rb 2009-08-02 08:57:05 UTC (rev 2146)
+++ MacRuby/branches/experimental/spec/frozen/core/math/acos_spec.rb 2009-08-02 13:12:21 UTC (rev 2147)
@@ -54,11 +54,13 @@
Math.acos(MathSpecs::Float.new(0.5)).should be_close(Math.acos(0.5), TOLERANCE)
end
- it "coerces string argument with Float() without calling to_f" do
- s = MathSpecs::StringSubClass.new("0.5")
- s.should_not_receive(:to_f)
- Math.acos(s).should be_close(Math.acos(0.5), TOLERANCE)
- end
+ ruby_version_is ""..."1.9" do
+ it "coerces string argument with Float() without calling to_f" do
+ s = MathSpecs::StringSubClass.new("0.5")
+ s.should_not_receive(:to_f)
+ Math.acos(s).should be_close(Math.acos(0.5), TOLERANCE)
+ end
+ end
end
describe "Math#acos" do
Modified: MacRuby/branches/experimental/spec/frozen/core/method/clone_spec.rb
===================================================================
--- MacRuby/branches/experimental/spec/frozen/core/method/clone_spec.rb 2009-08-02 08:57:05 UTC (rev 2146)
+++ MacRuby/branches/experimental/spec/frozen/core/method/clone_spec.rb 2009-08-02 13:12:21 UTC (rev 2147)
@@ -7,7 +7,7 @@
m2 = m1.clone
m1.should == m2
- m1.should_not eql(m2)
+ m1.should_not equal(m2)
m1.call.should == m2.call
end
Modified: MacRuby/branches/experimental/spec/frozen/core/method/fixtures/classes.rb
===================================================================
--- MacRuby/branches/experimental/spec/frozen/core/method/fixtures/classes.rb 2009-08-02 08:57:05 UTC (rev 2146)
+++ MacRuby/branches/experimental/spec/frozen/core/method/fixtures/classes.rb 2009-08-02 13:12:21 UTC (rev 2147)
@@ -13,6 +13,11 @@
def self.redefined
:last
end
+
+ def original
+ end
+
+ alias :aka :original
end
class Methods
Modified: MacRuby/branches/experimental/spec/frozen/core/method/source_location_spec.rb
===================================================================
--- MacRuby/branches/experimental/spec/frozen/core/method/source_location_spec.rb 2009-08-02 08:57:05 UTC (rev 2146)
+++ MacRuby/branches/experimental/spec/frozen/core/method/source_location_spec.rb 2009-08-02 13:12:21 UTC (rev 2147)
@@ -30,5 +30,9 @@
it "returns the last place the method was defined" do
MethodSpecs::SourceLocation.method(:redefined).source_location.last.should == 13
end
+
+ it "returns the location of the original method even if it was aliased" do
+ MethodSpecs::SourceLocation.new.method(:aka).source_location.last.should == 17
+ end
end
end
Modified: MacRuby/branches/experimental/spec/frozen/core/module/autoload_spec.rb
===================================================================
--- MacRuby/branches/experimental/spec/frozen/core/module/autoload_spec.rb 2009-08-02 08:57:05 UTC (rev 2146)
+++ MacRuby/branches/experimental/spec/frozen/core/module/autoload_spec.rb 2009-08-02 13:12:21 UTC (rev 2147)
@@ -199,21 +199,41 @@
ModuleSpecs::Autoload::U::V::X.should == :autoload_uvx
end
- # [ruby-core:19127]
- it "raises a NameError when the autoload file did not define the constant and a module is opened with the same name" do
- lambda do
- module ModuleSpecs::Autoload
- class W
- autoload :Y, fixture(__FILE__, "autoload_w.rb")
+ # TODO: Remove duplicate specs (this one and that which follows it) when ruby_bug is fixed
+ ruby_bug "#1745", "1.9" do
+ # [ruby-core:19127]
+ it "raises a NameError when the autoload file did not define the constant and a module is opened with the same name" do
+ lambda do
+ module ModuleSpecs::Autoload
+ class W
+ autoload :Y, fixture(__FILE__, "autoload_w.rb")
- class Y
+ class Y
+ end
end
end
- end
- end.should raise_error(NameError)
- ScratchPad.recorded.should == :loaded
+ end.should raise_error(NameError)
+ ScratchPad.recorded.should == :loaded
+ end
end
+ ruby_version_is ""..."1.9" do
+ # [ruby-core:19127]
+ it "raises a NameError when the autoload file did not define the constant and a module is opened with the same name" do
+ lambda do
+ module ModuleSpecs::Autoload
+ class W
+ autoload :Y, fixture(__FILE__, "autoload_w.rb")
+
+ class Y
+ end
+ end
+ end
+ end.should raise_error(NameError)
+ ScratchPad.recorded.should == :loaded
+ end
+ end
+
it "raises an ArgumentError when an empty filename is given" do
lambda { ModuleSpecs.autoload :A, "" }.should raise_error(ArgumentError)
end
Modified: MacRuby/branches/experimental/spec/frozen/core/module/const_defined_spec.rb
===================================================================
--- MacRuby/branches/experimental/spec/frozen/core/module/const_defined_spec.rb 2009-08-02 08:57:05 UTC (rev 2146)
+++ MacRuby/branches/experimental/spec/frozen/core/module/const_defined_spec.rb 2009-08-02 13:12:21 UTC (rev 2147)
@@ -9,6 +9,18 @@
ConstantSpecs::ContainerA.const_defined?(:ChildA).should == true
end
+ ruby_version_is "1.9" do
+ it "returns true if the constant is defined in the reciever's superclass" do
+ # CS_CONST4 is defined in the superclass of ChildA
+ ConstantSpecs::ContainerA::ChildA.const_defined?(:CS_CONST4).should be_true
+ end
+
+ it "returns true if the constant is defined in a mixed-in module of the reciever" do
+ # CS_CONST10 is defined in a module included by ChildA
+ ConstantSpecs::ContainerA::ChildA.const_defined?(:CS_CONST10).should be_true
+ end
+ end
+
it "returns true if the given String names a constant defined in the receiver" do
ConstantSpecs.const_defined?("CS_CONST2").should == true
ConstantSpecs.const_defined?("ModuleA").should == true
@@ -16,11 +28,23 @@
ConstantSpecs::ContainerA.const_defined?("ChildA").should == true
end
- it "returns false if the constant is not defined in the receiver" do
- ConstantSpecs::ContainerA::ChildA.const_defined?(:CS_CONST4).should == false
- ConstantSpecs::ParentA.const_defined?(:CS_CONST12).should == false
+ ruby_version_is ""..."1.9" do
+ it "returns false if the constant is not defined in the receiver" do
+ ConstantSpecs::ContainerA::ChildA.const_defined?(:CS_CONST4).should == false
+ ConstantSpecs::ParentA.const_defined?(:CS_CONST12).should == false
+ end
end
+ ruby_version_is "1.9" do
+ it "returns false if the constant is not defined in the receiver, its superclass, or any included modules" do
+ # The following constant isn't defined at all.
+ ConstantSpecs::ContainerA::ChildA.const_defined?(:CS_CONST4726).should be_false
+ # DETATCHED_CONSTANT is defined in ConstantSpecs::Detatched, which isn't
+ # included by or inherited from ParentA
+ ConstantSpecs::ParentA.const_defined?(:DETATCHED_CONSTANT).should be_false
+ end
+ end
+
it "does not call #const_missing if the constant is not defined in the receiver" do
ConstantSpecs::ClassA.should_not_receive(:const_missing)
ConstantSpecs::ClassA.const_defined?(:CS_CONSTX).should == false
Modified: MacRuby/branches/experimental/spec/frozen/core/module/fixtures/classes.rb
===================================================================
--- MacRuby/branches/experimental/spec/frozen/core/module/fixtures/classes.rb 2009-08-02 08:57:05 UTC (rev 2146)
+++ MacRuby/branches/experimental/spec/frozen/core/module/fixtures/classes.rb 2009-08-02 13:12:21 UTC (rev 2147)
@@ -33,6 +33,9 @@
def undefed_method() end
undef_method :undefed_method
+ def parent_method; end
+ def another_parent_method; end
+
# For public_class_method spec
private
def self.public_method; end
@@ -69,6 +72,8 @@
private
def private_super_module() end
+ def super_included_method; end
+
class SuperChild
end
end
@@ -88,6 +93,9 @@
def public_child() end
+ undef_method :parent_method
+ undef_method :another_parent_method
+
protected
def protected_child() end
@@ -95,6 +103,10 @@
def private_child() end
end
+ class Grandchild < Child
+ undef_method :super_included_method
+ end
+
class Child2 < Parent
attr_reader :foo
end
@@ -309,6 +321,12 @@
module Autoload
end
+
+ # This class isn't inherited from or included in anywhere. It exists to test
+ # 1.9's constant scoping rules
+ class Detached
+ DETATCHED_CONSTANT = :d
+ end
end
ModuleSpecs::Nesting[:root_level] = Module.nesting
Added: MacRuby/branches/experimental/spec/frozen/core/module/fixtures/name.rb
===================================================================
--- MacRuby/branches/experimental/spec/frozen/core/module/fixtures/name.rb (rev 0)
+++ MacRuby/branches/experimental/spec/frozen/core/module/fixtures/name.rb 2009-08-02 13:12:21 UTC (rev 2147)
@@ -0,0 +1,10 @@
+# encoding: utf-8
+module ModuleSpecs
+ class NameEncoding
+ class Cß
+ end
+ def name
+ Cß.name
+ end
+ end
+end
Modified: MacRuby/branches/experimental/spec/frozen/core/module/instance_methods_spec.rb
===================================================================
--- MacRuby/branches/experimental/spec/frozen/core/module/instance_methods_spec.rb 2009-08-02 08:57:05 UTC (rev 2146)
+++ MacRuby/branches/experimental/spec/frozen/core/module/instance_methods_spec.rb 2009-08-02 13:12:21 UTC (rev 2147)
@@ -4,17 +4,27 @@
# Prior to MRI 1.9 #instance_methods returned an Array of Strings
ruby_version_is ""..."1.9" do
describe "Module#instance_methods" do
- it "does not return undefined methods" do
+ it "does not return methods undefined in a superclass" do
methods = ModuleSpecs::Parent.instance_methods(false)
methods.should_not include("undefed_method")
+ end
+ it "does not return methods undefined in a subclass" do
+ methods = ModuleSpecs::Grandchild.instance_methods
+ methods.should_not include("parent_method", "another_parent_method")
+ end
+
+ it "does not return methods undefined in the current class" do
ModuleSpecs::Child.send(:undef_method, 'undefed_child')
methods = ModuleSpecs::Child.instance_methods
- methods.should_not include("undefed_method")
- methods.should_not include("undefed_child")
+ methods.should_not include("undefed_method", "undefed_child")
end
- it "returns an array containing the public and protected methods of self if include_super is false" do
+ it "does not return methods from an included module that are undefined in the class" do
+ ModuleSpecs::Grandchild.instance_methods.should_not include("super_included_method")
+ end
+
+ it "returns the public and protected methods of self if include_super is false" do
methods = ModuleSpecs::Parent.instance_methods(false)
methods.should include("protected_parent", "public_parent")
@@ -22,32 +32,42 @@
methods.should include("protected_child", "public_child")
end
- it "returns an array containing the public and protected methods of self and it's ancestors" do
+ it "returns the public and protected methods of self and it's ancestors" do
methods = ModuleSpecs::Basic.instance_methods
methods.should include("protected_module", "public_module")
methods = ModuleSpecs::Super.instance_methods
methods.should include("protected_module", "protected_super_module",
- "public_module", "public_super_module")
+ "public_module", "public_super_module")
end
end
-end
+end
# As of MRI 1.9 #instance_methods returns an Array of Symbols
ruby_version_is "1.9" do
describe "Module#instance_methods" do
- it "does not return undefined methods" do
+ it "does not return methods undefined in a superclass" do
methods = ModuleSpecs::Parent.instance_methods(false)
methods.should_not include(:undefed_method)
+ end
- ModuleSpecs::Child.send(:undef_method, :undefed_child)
+ it "does not return methods undefined in a subclass" do
+ methods = ModuleSpecs::Grandchild.instance_methods
+ methods.should_not include(:parent_method, :another_parent_method)
+ end
+
+ it "does not return methods undefined in the current class" do
+ ModuleSpecs::Child.send(:undef_method, 'undefed_child')
methods = ModuleSpecs::Child.instance_methods
- methods.should_not include(:undefed_method)
- methods.should_not include(:undefed_child)
+ methods.should_not include(:undefed_method, :undefed_child)
end
- it "returns an array containing the public and protected methods of self if include_super is false" do
+ it "does not return methods from an included module that are undefined in the class" do
+ ModuleSpecs::Grandchild.instance_methods.should_not include(:super_included_method)
+ end
+
+ it "returns the public and protected methods of self if include_super is false" do
methods = ModuleSpecs::Parent.instance_methods(false)
methods.should include(:protected_parent, :public_parent)
@@ -55,13 +75,13 @@
methods.should include(:protected_child, :public_child)
end
- it "returns an array containing the public and protected methods of self and it's ancestors" do
+ it "returns the public and protected methods of self and it's ancestors" do
methods = ModuleSpecs::Basic.instance_methods
methods.should include(:protected_module, :public_module)
methods = ModuleSpecs::Super.instance_methods
methods.should include(:protected_module, :protected_super_module,
- :public_module, :public_super_module)
+ :public_module, :public_super_module)
end
end
-end
+end
Modified: MacRuby/branches/experimental/spec/frozen/core/module/name_spec.rb
===================================================================
--- MacRuby/branches/experimental/spec/frozen/core/module/name_spec.rb 2009-08-02 08:57:05 UTC (rev 2146)
+++ MacRuby/branches/experimental/spec/frozen/core/module/name_spec.rb 2009-08-02 13:12:21 UTC (rev 2147)
@@ -2,10 +2,28 @@
require File.dirname(__FILE__) + '/fixtures/classes'
describe "Module#name" do
+ ruby_version_is ""..."1.9" do
+ it "returns an empty String by default" do
+ Module.new.name.should == ""
+ Class.new.name.should == ""
+ end
+ end
+
+ ruby_version_is "1.9" do
+ it "returns nil by default" do
+ Module.new.name.should be_nil
+ Class.new.name.should be_nil
+ end
+
+ require File.dirname(__FILE__) + '/fixtures/name'
+ # http://redmine.ruby-lang.org/issues/show/1833
+ it "preserves the encoding in which the class was defined" do
+ ModuleSpecs::NameEncoding.new.name.encoding.should == Encoding::UTF_8
+ end
+ end
+
it "returns the name of self" do
- Module.new.name.should == ""
- Class.new.name.should == ""
-
+
ModuleSpecs.name.should == "ModuleSpecs"
ModuleSpecs::Child.name.should == "ModuleSpecs::Child"
ModuleSpecs::Parent.name.should == "ModuleSpecs::Parent"
Modified: MacRuby/branches/experimental/spec/frozen/core/module/shared/class_eval.rb
===================================================================
--- MacRuby/branches/experimental/spec/frozen/core/module/shared/class_eval.rb 2009-08-02 08:57:05 UTC (rev 2146)
+++ MacRuby/branches/experimental/spec/frozen/core/module/shared/class_eval.rb 2009-08-02 13:12:21 UTC (rev 2147)
@@ -2,17 +2,7 @@
# TODO: This should probably be replaced with a "should behave like" that uses
# the many scoping/binding specs from kernel/eval_spec, since most of those
# behaviors are the same for instance_eval. See also module_eval/class_eval.
- it "shares a scope across sibling evals" do
- a, b = Object.new, Object.new
- result = nil
- a.instance_eval "x = 1"
- lambda do
- b.instance_eval "result = x"
- end.should_not raise_error
- result.should == 1
- end
-
it "evaluates a given string in the context of self" do
ModuleSpecs.send(@method, "self").should == ModuleSpecs
ModuleSpecs.send(@method, "1 + 1").should == 2
Modified: MacRuby/branches/experimental/spec/frozen/core/numeric/angle_spec.rb
===================================================================
--- MacRuby/branches/experimental/spec/frozen/core/numeric/angle_spec.rb 2009-08-02 08:57:05 UTC (rev 2146)
+++ MacRuby/branches/experimental/spec/frozen/core/numeric/angle_spec.rb 2009-08-02 13:12:21 UTC (rev 2147)
@@ -1,8 +1,8 @@
require File.dirname(__FILE__) + '/../../spec_helper'
-require File.dirname(__FILE__) + '/shared/phase'
+require File.dirname(__FILE__) + '/../../shared/complex/numeric/arg'
ruby_version_is "1.9" do
describe "Numeric#angle" do
- it_behaves_like(:numeric_phase, :angle)
+ it_behaves_like(:numeric_arg, :angle)
end
end
Modified: MacRuby/branches/experimental/spec/frozen/core/numeric/arg_spec.rb
===================================================================
--- MacRuby/branches/experimental/spec/frozen/core/numeric/arg_spec.rb 2009-08-02 08:57:05 UTC (rev 2146)
+++ MacRuby/branches/experimental/spec/frozen/core/numeric/arg_spec.rb 2009-08-02 13:12:21 UTC (rev 2147)
@@ -1,8 +1,8 @@
require File.dirname(__FILE__) + '/../../spec_helper'
-require File.dirname(__FILE__) + '/shared/phase'
+require File.dirname(__FILE__) + '/../../shared/complex/numeric/arg'
ruby_version_is "1.9" do
describe "Numeric#arg" do
- it_behaves_like(:numeric_phase, :arg)
+ it_behaves_like(:numeric_arg, :arg)
end
end
Modified: MacRuby/branches/experimental/spec/frozen/core/numeric/conj_spec.rb
===================================================================
--- MacRuby/branches/experimental/spec/frozen/core/numeric/conj_spec.rb 2009-08-02 08:57:05 UTC (rev 2146)
+++ MacRuby/branches/experimental/spec/frozen/core/numeric/conj_spec.rb 2009-08-02 13:12:21 UTC (rev 2147)
@@ -1,5 +1,5 @@
require File.dirname(__FILE__) + '/../../spec_helper'
-require File.dirname(__FILE__) + '/shared/conj'
+require File.dirname(__FILE__) + '/../../shared/complex/numeric/conj'
ruby_version_is "1.9" do
describe "Numeric#conj" do
Modified: MacRuby/branches/experimental/spec/frozen/core/numeric/conjugate_spec.rb
===================================================================
--- MacRuby/branches/experimental/spec/frozen/core/numeric/conjugate_spec.rb 2009-08-02 08:57:05 UTC (rev 2146)
+++ MacRuby/branches/experimental/spec/frozen/core/numeric/conjugate_spec.rb 2009-08-02 13:12:21 UTC (rev 2147)
@@ -1,5 +1,5 @@
require File.dirname(__FILE__) + '/../../spec_helper'
-require File.dirname(__FILE__) + '/shared/conj'
+require File.dirname(__FILE__) + '/../../shared/complex/numeric/conj'
ruby_version_is "1.9" do
describe "Numeric#conjugate" do
Modified: MacRuby/branches/experimental/spec/frozen/core/numeric/div_spec.rb
===================================================================
--- MacRuby/branches/experimental/spec/frozen/core/numeric/div_spec.rb 2009-08-02 08:57:05 UTC (rev 2146)
+++ MacRuby/branches/experimental/spec/frozen/core/numeric/div_spec.rb 2009-08-02 13:12:21 UTC (rev 2147)
@@ -6,11 +6,23 @@
@obj = NumericSub.new
end
- it "calls self#/ with other, converts the result to a Float (using #to_f) and returns the #floor'ed result" do
- result = mock("Numeric#div result")
- result.should_receive(:to_f).and_return(13 - TOLERANCE)
- @obj.should_receive(:/).with(10).and_return(result)
-
- @obj.div(10).should == 12
+ ruby_version_is ""..."1.9" do
+ it "calls self#/ with other, converts the result to a Float (using #to_f) and returns the #floor'ed result" do
+ result = mock("Numeric#div result")
+ result.should_receive(:to_f).and_return(13 - TOLERANCE)
+ @obj.should_receive(:/).with(10).and_return(result)
+
+ @obj.div(10).should == 12
+ end
end
+
+ ruby_version_is "1.9" do
+ it "calls self#/ with other, then returns the #floor'ed result" do
+ result = mock("Numeric#div result")
+ result.should_receive(:floor).and_return(12)
+ @obj.should_receive(:/).with(10).and_return(result)
+
+ @obj.div(10).should == 12
+ end
+ end
end
Modified: MacRuby/branches/experimental/spec/frozen/core/numeric/divmod_spec.rb
===================================================================
--- MacRuby/branches/experimental/spec/frozen/core/numeric/divmod_spec.rb 2009-08-02 08:57:05 UTC (rev 2146)
+++ MacRuby/branches/experimental/spec/frozen/core/numeric/divmod_spec.rb 2009-08-02 13:12:21 UTC (rev 2147)
@@ -6,10 +6,21 @@
@obj = NumericSub.new
end
- it "returns [quotient, modulus], with quotient being obtained as in Numeric#div and modulus being obtained by calling self#% with other" do
- @obj.should_receive(:/).with(10).and_return(13 - TOLERANCE)
- @obj.should_receive(:%).with(10).and_return(3)
-
- @obj.divmod(10).should == [12, 3]
+ ruby_version_is ""..."1.9" do
+ it "returns [quotient, modulus], with quotient being obtained as in Numeric#div and modulus being obtained by calling self#% with other" do
+ @obj.should_receive(:/).with(10).and_return(13 - TOLERANCE)
+ @obj.should_receive(:%).with(10).and_return(3)
+
+ @obj.divmod(10).should == [12, 3]
+ end
end
+
+ ruby_version_is "1.9" do
+ it "returns [quotient, modulus], with quotient being obtained as in Numeric#div then #floor and modulus being obtained by calling self#- with quotient * other" do
+ @obj.should_receive(:/).twice.with(10).and_return(13 - TOLERANCE, 13 - TOLERANCE)
+ @obj.should_receive(:-).with(120).and_return(3)
+
+ @obj.divmod(10).should == [12, 3]
+ end
+ end
end
Modified: MacRuby/branches/experimental/spec/frozen/core/numeric/imag_spec.rb
===================================================================
--- MacRuby/branches/experimental/spec/frozen/core/numeric/imag_spec.rb 2009-08-02 08:57:05 UTC (rev 2146)
+++ MacRuby/branches/experimental/spec/frozen/core/numeric/imag_spec.rb 2009-08-02 13:12:21 UTC (rev 2147)
@@ -1,5 +1,5 @@
require File.dirname(__FILE__) + '/../../spec_helper'
-require File.dirname(__FILE__) + '/shared/imag'
+require File.dirname(__FILE__) + '/../../shared/complex/numeric/imag'
ruby_version_is "1.9" do
describe "Numeric#imag" do
Modified: MacRuby/branches/experimental/spec/frozen/core/numeric/imaginary_spec.rb
===================================================================
--- MacRuby/branches/experimental/spec/frozen/core/numeric/imaginary_spec.rb 2009-08-02 08:57:05 UTC (rev 2146)
+++ MacRuby/branches/experimental/spec/frozen/core/numeric/imaginary_spec.rb 2009-08-02 13:12:21 UTC (rev 2147)
@@ -1,5 +1,5 @@
require File.dirname(__FILE__) + '/../../spec_helper'
-require File.dirname(__FILE__) + '/shared/imag'
+require File.dirname(__FILE__) + '/../../shared/complex/numeric/imag'
ruby_version_is "1.9" do
describe "Numeric#imaginary" do
Modified: MacRuby/branches/experimental/spec/frozen/core/numeric/modulo_spec.rb
===================================================================
--- MacRuby/branches/experimental/spec/frozen/core/numeric/modulo_spec.rb 2009-08-02 08:57:05 UTC (rev 2146)
+++ MacRuby/branches/experimental/spec/frozen/core/numeric/modulo_spec.rb 2009-08-02 13:12:21 UTC (rev 2147)
@@ -2,10 +2,22 @@
require File.dirname(__FILE__) + '/fixtures/classes'
describe "Numeric#modulo" do
- it "returns the result of calling self#% with other" do
- obj = NumericSub.new
- obj.should_receive(:%).with(20).and_return(:result)
-
- obj.modulo(20).should == :result
+ ruby_version_is "".."1.9" do
+ it "returns the result of calling self#% with other" do
+ obj = NumericSub.new
+ obj.should_receive(:%).with(20).and_return(:result)
+
+ obj.modulo(20).should == :result
+ end
end
+
+ ruby_version_is "1.9" do
+ it "returns the result of self#- (self#/ other) * other" do
+ obj = NumericSub.new
+ obj.should_receive(:/).with(15).and_return(13)
+ obj.should_receive(:-).with(195).and_return(5)
+ # 200 % 15 == 5
+ obj.modulo(15).should == 5
+ end
+ end
end
Modified: MacRuby/branches/experimental/spec/frozen/core/numeric/phase_spec.rb
===================================================================
--- MacRuby/branches/experimental/spec/frozen/core/numeric/phase_spec.rb 2009-08-02 08:57:05 UTC (rev 2146)
+++ MacRuby/branches/experimental/spec/frozen/core/numeric/phase_spec.rb 2009-08-02 13:12:21 UTC (rev 2147)
@@ -1,8 +1,8 @@
require File.dirname(__FILE__) + '/../../spec_helper'
-require File.dirname(__FILE__) + '/shared/phase'
+require File.dirname(__FILE__) + '/../../shared/complex/numeric/arg'
ruby_version_is "1.9" do
describe "Numeric#phase" do
- it_behaves_like(:numeric_phase, :phase)
+ it_behaves_like(:numeric_arg, :phase)
end
end
Modified: MacRuby/branches/experimental/spec/frozen/core/numeric/polar_spec.rb
===================================================================
--- MacRuby/branches/experimental/spec/frozen/core/numeric/polar_spec.rb 2009-08-02 08:57:05 UTC (rev 2146)
+++ MacRuby/branches/experimental/spec/frozen/core/numeric/polar_spec.rb 2009-08-02 13:12:21 UTC (rev 2147)
@@ -1,54 +1,8 @@
require File.dirname(__FILE__) + '/../../spec_helper'
+require File.dirname(__FILE__) + '/../../shared/complex/numeric/polar'
ruby_version_is "1.9" do
describe "Numeric#polar" do
- before(:each) do
- @pos_numbers = [
- 1,
- 3898172610**9,
- 987.18273,
- Float::MAX,
- Rational(13,7),
- 1/0.0,
- ]
- @neg_numbers = @pos_numbers.map {|n| -n}
- @numbers = @pos_numbers + @neg_numbers
- @numbers.push(0, 0.0)
- end
-
- it "returns a two-element Array" do
- @numbers.each do |number|
- number.polar.should be_an_instance_of(Array)
- number.polar.size.should == 2
- end
- end
-
- it "sets the first value to the absolute value of self" do
- @numbers.each do |number|
- number.polar.first.should == number.abs
- end
- end
-
- it "sets the last value to 0 if self is positive" do
- (@numbers - @neg_numbers).each do |number|
- number.should >= 0
- number.polar.last.should == 0
- end
- end
-
- it "sets the last value to Pi if self is negative" do
- @neg_numbers.each do |number|
- number.should < 0
- number.polar.last.should == Math::PI
- end
- end
-
- it "treats NaN like a positive number" do
- nan = 0/0.0
- nan.nan?.should be_true
- nan.polar.size.should == 2
- nan.polar.first.nan?.should be_true
- nan.polar.last.should == 0
- end
+ it_behaves_like(:numeric_polar, :polar)
end
end
Modified: MacRuby/branches/experimental/spec/frozen/core/numeric/quo_spec.rb
===================================================================
--- MacRuby/branches/experimental/spec/frozen/core/numeric/quo_spec.rb 2009-08-02 08:57:05 UTC (rev 2146)
+++ MacRuby/branches/experimental/spec/frozen/core/numeric/quo_spec.rb 2009-08-02 13:12:21 UTC (rev 2147)
@@ -2,10 +2,23 @@
require File.dirname(__FILE__) + '/fixtures/classes'
describe "Numeric#quo" do
- it "returns the result of calling self#/ with other" do
- obj = NumericSub.new
- obj.should_receive(:/).with(19).and_return(:result)
-
- obj.quo(19).should == :result
+ ruby_version_is ""..."1.9" do
+ it "returns the result of calling self#/ with other" do
+ obj = NumericSub.new
+ obj.should_receive(:/).with(19).and_return(:result)
+
+ obj.quo(19).should == :result
+ end
end
+
+ ruby_version_is "1.9" do
+ it "returns the result of calling self#/ with other" do
+ obj = NumericSub.new
+ obj.should_receive(:coerce).twice.and_return([19,19])
+ obj.should_receive(:<=>).any_number_of_times.and_return(1)
+ obj.should_receive(:/).and_return(20)
+
+ obj.quo(19).should == 20
+ end
+ end
end
Modified: MacRuby/branches/experimental/spec/frozen/core/numeric/real_spec.rb
===================================================================
--- MacRuby/branches/experimental/spec/frozen/core/numeric/real_spec.rb 2009-08-02 08:57:05 UTC (rev 2146)
+++ MacRuby/branches/experimental/spec/frozen/core/numeric/real_spec.rb 2009-08-02 13:12:21 UTC (rev 2147)
@@ -1,32 +1,8 @@
require File.dirname(__FILE__) + '/../../spec_helper'
+require File.dirname(__FILE__) + '/../../shared/complex/numeric/real'
ruby_version_is "1.9" do
describe "Numeric#real" do
- before(:each) do
- @numbers = [
- 20, # Integer
- 398.72, # Float
- Rational(3, 4), # Rational
- 99999999**99, # Bignum
- Float::MAX * 2, # Infinity
- 0/0.0 # NaN
- ]
- end
-
- it "returns self" do
- @numbers.each do |number|
- if number.to_f.nan?
- number.real.nan?.should be_true
- else
- number.real.should == number
- end
- end
- end
-
- it "raises an ArgumentError if given any arguments" do
- @numbers.each do |number|
- lambda { number.real(number) }.should raise_error(ArgumentError)
- end
- end
+ it_behaves_like(:numeric_real, :real)
end
end
Deleted: MacRuby/branches/experimental/spec/frozen/core/numeric/shared/conj.rb
===================================================================
--- MacRuby/branches/experimental/spec/frozen/core/numeric/shared/conj.rb 2009-08-02 08:57:05 UTC (rev 2146)
+++ MacRuby/branches/experimental/spec/frozen/core/numeric/shared/conj.rb 2009-08-02 13:12:21 UTC (rev 2147)
@@ -1,26 +0,0 @@
-require File.dirname(__FILE__) + '/../../../spec_helper'
-
-describe :numeric_conj, :shared => true do
- before(:each) do
- @numbers = [
- 20, # Integer
- 398.72, # Float
- Rational(3, 4), # Rational
- 99999999**99, # Bignum
- Float::MAX * 2, # Infinity
- 0/0.0 # NaN
- ]
- end
-
- it "returns self" do
- @numbers.each do |number|
- number.send(@method).to_s.should == number.to_s
- end
- end
-
- it "raises an ArgumentError if given any arguments" do
- @numbers.each do |number|
- lambda { number.send(@method, number) }.should raise_error(ArgumentError)
- end
- end
-end
Deleted: MacRuby/branches/experimental/spec/frozen/core/numeric/shared/imag.rb
===================================================================
--- MacRuby/branches/experimental/spec/frozen/core/numeric/shared/imag.rb 2009-08-02 08:57:05 UTC (rev 2146)
+++ MacRuby/branches/experimental/spec/frozen/core/numeric/shared/imag.rb 2009-08-02 13:12:21 UTC (rev 2147)
@@ -1,26 +0,0 @@
-require File.dirname(__FILE__) + '/../../../spec_helper'
-
-describe :numeric_imag, :shared => true do
- before(:each) do
- @numbers = [
- 20, # Integer
- 398.72, # Float
- Rational(3, 4), # Rational
- 99999999**99, # Bignum
- Float::MAX * 2, # Infinity
- 0/0.0 # NaN
- ]
- end
-
- it "returns 0" do
- @numbers.each do |number|
- number.send(@method).should == 0
- end
- end
-
- it "raises an ArgumentError if given any arguments" do
- @numbers.each do |number|
- lambda { number.send(@method, number) }.should raise_error(ArgumentError)
- end
- end
-end
Deleted: MacRuby/branches/experimental/spec/frozen/core/numeric/shared/phase.rb
===================================================================
--- MacRuby/branches/experimental/spec/frozen/core/numeric/shared/phase.rb 2009-08-02 08:57:05 UTC (rev 2146)
+++ MacRuby/branches/experimental/spec/frozen/core/numeric/shared/phase.rb 2009-08-02 13:12:21 UTC (rev 2147)
@@ -1,34 +0,0 @@
-require File.dirname(__FILE__) + '/../../../spec_helper'
-
-describe :numeric_phase, :shared => true do
- before(:each) do
- @numbers = [
- 20, # Integer
- 398.72, # Float
- Rational(3, 4), # Rational
- 99999999**99, # Bignum
- Float::MAX * 2, # Infinity
- 0/0.0 # NaN
- ]
- end
-
- it "returns 0 if positive" do
- @numbers.each do |number|
- number.send(@method).should == 0
- end
- end
-
- it "returns Pi if negative" do
- @numbers.each do |number|
- # NaN can't be negated
- next if number.to_f.nan?
- (0-number).send(@method).should == Math::PI
- end
- end
-
- it "raises an ArgumentError if given any arguments" do
- @numbers.each do |number|
- lambda { number.send(@method, number) }.should raise_error(ArgumentError)
- end
- end
-end
Modified: MacRuby/branches/experimental/spec/frozen/core/proc/block_pass_spec.rb
===================================================================
--- MacRuby/branches/experimental/spec/frozen/core/proc/block_pass_spec.rb 2009-08-02 08:57:05 UTC (rev 2146)
+++ MacRuby/branches/experimental/spec/frozen/core/proc/block_pass_spec.rb 2009-08-02 13:12:21 UTC (rev 2147)
@@ -19,3 +19,23 @@
p.should == p2
end
end
+
+describe "Proc as an implicit block pass argument" do
+ def revivify
+ Proc::new
+ end
+
+ it "remains the same object if re-vivified by the target method" do
+ p = Proc.new {}
+ p2 = revivify(&p)
+ p.object_id.should == p2.object_id
+ p.should == p2
+ end
+
+ it "remains the same object if reconstructed with Proc.new" do
+ p = Proc.new {}
+ p2 = Proc.new(&p)
+ p.object_id.should == p2.object_id
+ p.should == p2
+ end
+end
Added: MacRuby/branches/experimental/spec/frozen/core/proc/case_compare_spec.rb
===================================================================
--- MacRuby/branches/experimental/spec/frozen/core/proc/case_compare_spec.rb (rev 0)
+++ MacRuby/branches/experimental/spec/frozen/core/proc/case_compare_spec.rb 2009-08-02 13:12:21 UTC (rev 2147)
@@ -0,0 +1,16 @@
+require File.dirname(__FILE__) + '/../../spec_helper'
+require File.dirname(__FILE__) + '/shared/call'
+
+ruby_version_is "1.9" do
+ describe "Proc#===" do
+ it_behaves_like :proc_call, :===
+ end
+
+ describe "Proc#=== on a Proc created with Proc.new" do
+ it_behaves_like :proc_call_on_proc_new, :===
+ end
+
+ describe "Proc#=== on a Proc created with Kernel#lambda or Kernel#proc" do
+ it_behaves_like :proc_call_on_proc_or_lambda, :===
+ end
+end
Added: MacRuby/branches/experimental/spec/frozen/core/proc/curry_spec.rb
===================================================================
--- MacRuby/branches/experimental/spec/frozen/core/proc/curry_spec.rb (rev 0)
+++ MacRuby/branches/experimental/spec/frozen/core/proc/curry_spec.rb 2009-08-02 13:12:21 UTC (rev 2147)
@@ -0,0 +1,144 @@
+require File.dirname(__FILE__) + '/../../spec_helper'
+
+ruby_version_is "1.9" do
+ describe "Proc#curry" do
+ before(:each) do
+ @proc_add = proc {|x,y,z| (x||0) + (y||0) + (z||0) }
+ @lambda_add = lambda {|x,y,z| (x||0) + (y||0) + (z||0) }
+ end
+
+ it "returns a Proc when called on a proc" do
+ p = proc { true }
+ p.curry.should be_an_instance_of(Proc)
+ end
+
+ it "returns a Proc when called on a lambda" do
+ p = lambda { true }
+ p.curry.should be_an_instance_of(Proc)
+ end
+
+ it "calls the curried proc with the arguments if sufficient arguments have been given" do
+ @proc_add.curry[1][2][3].should == 6
+ @lambda_add.curry[1][2][3].should == 6
+ end
+
+ it "returns a Proc that consumes the remainder of the arguments unless sufficient arguments have been given" do
+ proc2 = @proc_add.curry[1][2]
+ proc2.should be_an_instance_of(Proc)
+ proc2.call(3).should == 6
+
+ lambda2 = @lambda_add.curry[1][2]
+ lambda2.should be_an_instance_of(Proc)
+ lambda2.call(3).should == 6
+
+ @proc_add.curry.call(1,2,3).should == 6
+ @lambda_add.curry.call(1,2,3).should == 6
+ end
+
+ it "can be called multiple times on the same Proc" do
+ @proc_add.curry
+ lambda { @proc_add.curry }.should_not raise_error
+
+ @lambda_add.curry
+ lambda { @lambda_add.curry }.should_not raise_error
+ end
+
+ it "can be passed superfluous arguments if created from a proc" do
+ lambda { @proc_add.curry[1,2,3,4].should == 6 }.should_not
+ raise_error(ArgumentError)
+ lambda { @proc_add.curry[1,2].curry[3,4,5,6].should == 6 }.should_not
+ raise_error(ArgumentError)
+ end
+
+ it "raises an ArgumentError if passed superfluous arguments when created from a lambda" do
+ lambda { @lambda_add.curry[1,2,3,4] }.should raise_error(ArgumentError)
+ lambda { @lambda_add.curry[1,2].curry[3,4,5,6] }.should raise_error(ArgumentError)
+ end
+
+ it "returns Procs with arities of -1" do
+ @proc_add.curry.arity.should == -1
+ @lambda_add.curry.arity.should == -1
+ l = lambda { |*a| }
+ l.curry.arity.should == -1
+ end
+ end
+
+ describe "Proc#curry with arity argument" do
+ before(:each) do
+ @proc_add = proc {|x,y,z| (x||0) + (y||0) + (z||0) }
+ @lambda_add = lambda {|x,y,z| (x||0) + (y||0) + (z||0) }
+ end
+
+ it "accepts an optional Integer argument for the arity" do
+ lambda { @proc_add.curry(3) }.should_not raise_error
+ lambda { @lambda_add.curry(3) }.should_not raise_error
+ end
+
+ it "returns a Proc when called on a proc" do
+ @proc_add.curry(3).should be_an_instance_of(Proc)
+ end
+
+ it "returns a Proc when called on a lambda" do
+ @lambda_add.curry(3).should be_an_instance_of(Proc)
+ end
+
+ # [ruby-core:24127]
+ it "retains the lambda-ness of the Proc on which its called" do
+ @lambda_add.curry(3).lambda?.should be_true
+ @proc_add.curry(3).lambda?.should be_false
+ end
+
+ it "raises an ArgumentError if called on a lambda that requires more than _arity_ arguments" do
+ p = lambda { true }
+ lambda { p.curry(2) }.should raise_error(ArgumentError)
+ end
+
+ it "raises an ArgumentError if called on a lambda that requires fewer than _arity_ arguments" do
+ p = lambda { true }
+ lambda { p.curry(4) }.should raise_error(ArgumentError)
+ end
+
+ it "calls the curried proc with the arguments if _arity_ arguments have been given" do
+ @proc_add.curry(3)[1][2][3].should == 6
+ @lambda_add.curry(3)[1][2][3].should == 6
+ end
+
+ it "returns a Proc that consumes the remainder of the arguments when fewer than _arity_ arguments are given" do
+ proc2 = @proc_add.curry(3)[1][2]
+ proc2.should be_an_instance_of(Proc)
+ proc2.call(3).should == 6
+
+ lambda2 = @lambda_add.curry(3)[1][2]
+ lambda2.should be_an_instance_of(Proc)
+ lambda2.call(3).should == 6
+ end
+
+ it "can be specified multiple times on the same Proc" do
+ @proc_add.curry(2)
+ lambda { @proc_add.curry(1) }.should_not raise_error
+
+ @lambda_add.curry(3)
+ lambda { @lambda_add.curry(3) }.should_not raise_error
+ end
+
+ it "can be passed more than _arity_ arguments if created from a proc" do
+ lambda { @proc_add.curry(3)[1,2,3,4].should == 6 }.should_not
+ raise_error(ArgumentError)
+ lambda { @proc_add.curry(1)[1,2].curry(3)[3,4,5,6].should == 6 }.should_not
+ raise_error(ArgumentError)
+ end
+
+ it "raises an ArgumentError if passed more than _arity_ arguments when created from a lambda" do
+ lambda { @lambda_add.curry(3)[1,2,3,4] }.should raise_error(ArgumentError)
+ lambda { @lambda_add.curry(1)[1,2].curry(3)[3,4,5,6] }.should raise_error(ArgumentError)
+ end
+
+ it "returns Procs with arities of -1 regardless of the value of _arity_" do
+ @proc_add.curry(1).arity.should == -1
+ @proc_add.curry(2).arity.should == -1
+ @lambda_add.curry(3).arity.should == -1
+ l = lambda { |*a| }
+ l.curry(3).arity.should == -1
+ end
+ end
+end
Added: MacRuby/branches/experimental/spec/frozen/core/proc/eql_spec.rb
===================================================================
--- MacRuby/branches/experimental/spec/frozen/core/proc/eql_spec.rb (rev 0)
+++ MacRuby/branches/experimental/spec/frozen/core/proc/eql_spec.rb 2009-08-02 13:12:21 UTC (rev 2147)
@@ -0,0 +1,8 @@
+require File.dirname(__FILE__) + '/../../spec_helper'
+require File.dirname(__FILE__) + '/shared/equal'
+
+ruby_version_is "1.9" do
+ describe "Proc#eql?" do
+ it_behaves_like(:proc_equal, :eql?)
+ end
+end
Modified: MacRuby/branches/experimental/spec/frozen/core/proc/equal_value_spec.rb
===================================================================
--- MacRuby/branches/experimental/spec/frozen/core/proc/equal_value_spec.rb 2009-08-02 08:57:05 UTC (rev 2146)
+++ MacRuby/branches/experimental/spec/frozen/core/proc/equal_value_spec.rb 2009-08-02 13:12:21 UTC (rev 2147)
@@ -1,14 +1,6 @@
require File.dirname(__FILE__) + '/../../spec_helper'
+require File.dirname(__FILE__) + '/shared/equal'
describe "Proc#==" do
- it "returns true when the given value is self or a copy of self" do
- a = lambda { "hello" }
-
- a.should == a
- a.should == a.dup
-
- a.should_not == lambda { "hello" }
- a.should_not == Proc.new {}
- a.should_not == nil
- end
-end
\ No newline at end of file
+ it_behaves_like(:proc_equal, :==)
+end
Modified: MacRuby/branches/experimental/spec/frozen/core/proc/fixtures/procs.rb
===================================================================
--- MacRuby/branches/experimental/spec/frozen/core/proc/fixtures/procs.rb 2009-08-02 08:57:05 UTC (rev 2146)
+++ MacRuby/branches/experimental/spec/frozen/core/proc/fixtures/procs.rb 2009-08-02 13:12:21 UTC (rev 2147)
@@ -2,4 +2,53 @@
def self.new_proc_in_method
Proc.new
end
+ class SourceLocation
+ def self.my_proc
+ proc { true }
+ end
+
+ def self.my_lambda
+ lambda { true }
+ end
+
+ def self.my_proc_new
+ Proc.new { true }
+ end
+
+ def self.my_multiline_proc
+ proc do
+ 'a'.upcase
+ 1 + 22
+ end
+ end
+
+ def self.my_multiline_lambda
+ lambda do
+ 'a'.upcase
+ 1 + 22
+ end
+ end
+
+ def self.my_multiline_proc_new
+ Proc.new do
+ 'a'.upcase
+ 1 + 22
+ end
+ end
+
+ def self.my_detached_proc
+ body = proc { true }
+ proc &body
+ end
+
+ def self.my_detached_lambda
+ body = lambda { true }
+ lambda &body
+ end
+
+ def self.my_detached_proc_new
+ body = Proc.new { true }
+ Proc.new &body
+ end
+ end
end
Added: MacRuby/branches/experimental/spec/frozen/core/proc/hash_spec.rb
===================================================================
--- MacRuby/branches/experimental/spec/frozen/core/proc/hash_spec.rb (rev 0)
+++ MacRuby/branches/experimental/spec/frozen/core/proc/hash_spec.rb 2009-08-02 13:12:21 UTC (rev 2147)
@@ -0,0 +1,24 @@
+require File.dirname(__FILE__) + '/../../spec_helper'
+
+ruby_version_is "1.9" do
+ describe "Proc#hash" do
+ it "is provided" do
+ proc {}.respond_to?(:hash).should be_true
+ lambda {}.respond_to?(:hash).should be_true
+ end
+
+ it "returns an Integer" do
+ proc { 1 + 489 }.hash.should be_kind_of(Integer)
+ end
+
+ it "is stable" do
+ body = proc { :foo }
+ (proc &body).hash.should == (proc &body).hash
+ end
+
+ it "does not depend on whether self is a proc or lambda" do
+ body = proc { :foo }
+ (proc &body).hash.should == (lambda &body).hash
+ end
+ end
+end
Added: MacRuby/branches/experimental/spec/frozen/core/proc/lambda_spec.rb
===================================================================
--- MacRuby/branches/experimental/spec/frozen/core/proc/lambda_spec.rb (rev 0)
+++ MacRuby/branches/experimental/spec/frozen/core/proc/lambda_spec.rb 2009-08-02 13:12:21 UTC (rev 2147)
@@ -0,0 +1,23 @@
+require File.dirname(__FILE__) + '/../../spec_helper'
+
+ruby_version_is "1.9" do
+ describe "Proc#lambda?" do
+ it "returns true if the object was created with the lambda keyword" do
+ lambda { true }.lambda?.should be_true
+ end
+
+ it "returns false if the object was created with the proc keyword" do
+ proc { true }.lambda?.should be_false
+ end
+
+ it "returns false if the object was created with Proc.new" do
+ Proc.new { true }.lambda?.should be_false
+ end
+
+ # [ruby-core:24127]
+ it "returns true if the object was created with Proc#curry" do
+ l = lambda { true }
+ l.curry.lambda?.should be_true
+ end
+ end
+end
Added: MacRuby/branches/experimental/spec/frozen/core/proc/parameters_spec.rb
===================================================================
--- MacRuby/branches/experimental/spec/frozen/core/proc/parameters_spec.rb (rev 0)
+++ MacRuby/branches/experimental/spec/frozen/core/proc/parameters_spec.rb 2009-08-02 13:12:21 UTC (rev 2147)
@@ -0,0 +1,2 @@
+language_version __FILE__, "parameters"
+
Added: MacRuby/branches/experimental/spec/frozen/core/proc/shared/equal.rb
===================================================================
--- MacRuby/branches/experimental/spec/frozen/core/proc/shared/equal.rb (rev 0)
+++ MacRuby/branches/experimental/spec/frozen/core/proc/shared/equal.rb 2009-08-02 13:12:21 UTC (rev 2147)
@@ -0,0 +1,93 @@
+require File.dirname(__FILE__) + '/../../../spec_helper'
+
+describe :proc_equal, :shared => true do
+ it "returns true if self and other are the same object" do
+ p = proc { :foo }
+ p.send(@method, p.dup).should be_true
+
+ p = Proc.new { :foo }
+ p.send(@method, p.dup).should be_true
+
+ p = lambda { :foo }
+ p.send(@method, p.dup).should be_true
+ end
+
+ it "returns true if self and other are both procs with the same body" do
+ body = proc { :foo }
+ p = proc &body
+ p2 = proc &body
+ p.send(@method, p2).should be_true
+
+ body = lambda { :foo }
+ p = proc &body
+ p2 = proc &body
+ p.send(@method, p2).should be_true
+ end
+
+ it "returns true if self and other are both lambdas with the same body" do
+ body = proc { :foo }
+ p = lambda &body
+ p2 = lambda &body
+ p.send(@method, p2).should be_true
+
+ body = lambda { :foo }
+ p = lambda &body
+ p2 = lambda &body
+ p.send(@method, p2).should be_true
+ end
+
+ it "returns true if self and other are different kinds of procs but have the same body" do
+ body = proc { :foo }
+ p = lambda &body
+ p2 = proc &body
+ p.send(@method, p2).should be_true
+
+ body = lambda { :foo }
+ p = proc &body
+ p2 = lambda &body
+ p.send(@method, p2).should be_true
+ end
+
+ ruby_version_is "1.9" do
+ it "returns true if the bodies of self and other are identical but represented by different objects" do
+ foo = proc { :foo }
+ foo2 = lambda { :foo }
+ p = lambda &foo
+ p2 = proc &foo2
+ p.send(@method, p2).should be_true
+ end
+
+ it "returns false if other is not a Proc" do
+ p = proc { :foo }
+ p.send(@method, []).should be_false
+
+ p = Proc.new { :foo }
+ p.send(@method, Object.new).should be_false
+
+ p = lambda { :foo }
+ p.send(@method, :foo).should be_false
+ end
+ end
+
+ it "returns false if self and other are both procs but have different bodies" do
+ p = proc { :bar }
+ p2 = proc { :foo }
+ p.send(@method, p2).should be_false
+ end
+
+ it "returns false if self and other are both lambdas but have different bodies" do
+ p = lambda { :foo }
+ p2 = lambda { :bar }
+ p.send(@method, p2).should be_false
+ end
+
+ it "returns false if self and other are different kinds of procs and have different bodies" do
+ p = lambda { :foo }
+ p2 = proc { :bar }
+ p.send(@method, p2).should be_false
+
+ p = proc { :foo }
+ p2 = lambda { :bar }
+ p.send(@method, p2).should be_false
+ end
+end
Added: MacRuby/branches/experimental/spec/frozen/core/proc/source_location_spec.rb
===================================================================
--- MacRuby/branches/experimental/spec/frozen/core/proc/source_location_spec.rb (rev 0)
+++ MacRuby/branches/experimental/spec/frozen/core/proc/source_location_spec.rb 2009-08-02 13:12:21 UTC (rev 2147)
@@ -0,0 +1,64 @@
+require File.dirname(__FILE__) + '/../../spec_helper'
+require File.dirname(__FILE__) + '/fixtures/procs'
+
+ruby_version_is "1.9" do
+ describe "Proc#source_location" do
+ before(:each) do
+ @proc = ProcSpecs::SourceLocation.my_proc
+ @lambda = ProcSpecs::SourceLocation.my_lambda
+ @proc_new = ProcSpecs::SourceLocation.my_proc_new
+ end
+
+ it "returns an Array" do
+ @proc.source_location.should be_an_instance_of(Array)
+ @proc_new.source_location.should be_an_instance_of(Array)
+ @lambda.source_location.should be_an_instance_of(Array)
+ end
+
+ it "sets the first value to the path of the file in which the proc was defined" do
+ file = @proc.source_location.first
+ file.should be_an_instance_of(String)
+ file.should == File.dirname(__FILE__) + '/fixtures/procs.rb'
+
+ file = @proc_new.source_location.first
+ file.should be_an_instance_of(String)
+ file.should == File.dirname(__FILE__) + '/fixtures/procs.rb'
+
+ file = @lambda.source_location.first
+ file.should be_an_instance_of(String)
+ file.should == File.dirname(__FILE__) + '/fixtures/procs.rb'
+ end
+
+ it "sets the last value to a Fixnum representing the line on which the proc was defined" do
+ line = @proc.source_location.last
+ line.should be_an_instance_of(Fixnum)
+ line.should == 7
+
+ line = @proc_new.source_location.last
+ line.should be_an_instance_of(Fixnum)
+ line.should == 15
+
+ line = @lambda.source_location.last
+ line.should be_an_instance_of(Fixnum)
+ line.should == 11
+ end
+
+ it "works even if the proc was created on the same line" do
+ proc { true }.source_location.should == [__FILE__, __LINE__]
+ Proc.new { true }.source_location.should == [__FILE__, __LINE__]
+ lambda { true }.source_location.should == [__FILE__, __LINE__]
+ end
+
+ it "returns the first line of a multi-line proc (i.e. the line containing 'proc do')" do
+ ProcSpecs::SourceLocation.my_multiline_proc.source_location.last.should == 19
+ ProcSpecs::SourceLocation.my_multiline_proc_new.source_location.last.should == 33
+ ProcSpecs::SourceLocation.my_multiline_lambda.source_location.last.should == 26
+ end
+
+ it "returns the location of the proc's body; not necessarily the proc itself" do
+ ProcSpecs::SourceLocation.my_detached_proc.source_location.last.should == 40
+ ProcSpecs::SourceLocation.my_detached_proc_new.source_location.last.should == 50
+ ProcSpecs::SourceLocation.my_detached_lambda.source_location.last.should ==45
+ end
+ end
+end
Added: MacRuby/branches/experimental/spec/frozen/core/proc/versions/parameters_1.9.rb
===================================================================
--- MacRuby/branches/experimental/spec/frozen/core/proc/versions/parameters_1.9.rb (rev 0)
+++ MacRuby/branches/experimental/spec/frozen/core/proc/versions/parameters_1.9.rb 2009-08-02 13:12:21 UTC (rev 2147)
@@ -0,0 +1,65 @@
+require File.dirname(__FILE__) + '/../../../spec_helper'
+
+ruby_version_is "1.9" do
+ describe "Proc#parameters" do
+ it "returns an empty Array for a proc expecting no parameters" do
+ proc {}.parameters.should == []
+ end
+
+ it "returns an Array of Arrays for a proc expecting parameters" do
+ p = proc {|x| }
+ p.parameters.should be_an_instance_of(Array)
+ p.parameters.first.should be_an_instance_of(Array)
+ end
+
+ it "sets the first element of each sub-Array to :opt for optional arguments" do
+ proc {|x| }.parameters.first.first.should == :opt
+ proc {|y,*x| }.parameters.first.first.should == :opt
+ end
+
+ it "regards named parameters in procs as optional" do
+ proc {|x| }.parameters.first.first.should == :opt
+ end
+
+ it "regards parameters with default values as optional" do
+ lambda {|x=1| }.parameters.first.first.should == :opt
+ proc {|x=1| }.parameters.first.first.should == :opt
+ end
+
+ it "sets the first element of each sub-Array to :req for required arguments" do
+ lambda {|x,y=[]| }.parameters.first.first.should == :req
+ lambda {|y,*x| }.parameters.first.first.should == :req
+ end
+
+ it "regards named parameters in lambdas as required" do
+ lambda {|x| }.parameters.first.first.should == :req
+ end
+
+ it "sets the first element of each sub-Array to :rest for parameters prefixed with asterisks" do
+ lambda {|*x| }.parameters.first.first.should == :rest
+ lambda {|x,*y| }.parameters.last.first.should == :rest
+ proc {|*x| }.parameters.first.first.should == :rest
+ proc {|x,*y| }.parameters.last.first.should == :rest
+ end
+
+ it "sets the first element of each sub-Array to :block for parameters prefixed with ampersands" do
+ lambda {|&x| }.parameters.first.first.should == :block
+ lambda {|x,&y| }.parameters.last.first.should == :block
+ proc {|&x| }.parameters.first.first.should == :block
+ proc {|x,&y| }.parameters.last.first.should == :block
+ end
+
+ it "sets the second element of each sub-Array to the name of the argument" do
+ lambda {|x| }.parameters.first.last.should == :x
+ lambda {|x=Math::PI| }.parameters.first.last.should == :x
+ lambda {|an_argument, glark, &foo| }.parameters[1].last.should == :glark
+ lambda {|*rest| }.parameters.first.last.should == :rest
+ lambda {|&block| }.parameters.first.last.should == :block
+ proc {|x| }.parameters.first.last.should == :x
+ proc {|x=Math::PI| }.parameters.first.last.should == :x
+ proc {|an_argument, glark, &foo| }.parameters[1].last.should == :glark
+ proc {|*rest| }.parameters.first.last.should == :rest
+ proc {|&block| }.parameters.first.last.should == :block
+ end
+ end
+end
Added: MacRuby/branches/experimental/spec/frozen/core/proc/yield_spec.rb
===================================================================
--- MacRuby/branches/experimental/spec/frozen/core/proc/yield_spec.rb (rev 0)
+++ MacRuby/branches/experimental/spec/frozen/core/proc/yield_spec.rb 2009-08-02 13:12:21 UTC (rev 2147)
@@ -0,0 +1,16 @@
+require File.dirname(__FILE__) + '/../../spec_helper'
+require File.dirname(__FILE__) + '/shared/call'
+
+ruby_version_is "1.9" do
+ describe "Proc#yield" do
+ it_behaves_like :proc_call, :yield
+ end
+
+ describe "Proc#yield on a Proc created with Proc.new" do
+ it_behaves_like :proc_call_on_proc_new, :yield
+ end
+
+ describe "Proc#yield on a Proc created with Kernel#lambda or Kernel#proc" do
+ it_behaves_like :proc_call_on_proc_or_lambda, :yield
+ end
+end
Added: MacRuby/branches/experimental/spec/frozen/core/random/bytes_spec.rb
===================================================================
--- MacRuby/branches/experimental/spec/frozen/core/random/bytes_spec.rb (rev 0)
+++ MacRuby/branches/experimental/spec/frozen/core/random/bytes_spec.rb 2009-08-02 13:12:21 UTC (rev 2147)
@@ -0,0 +1,25 @@
+require File.dirname(__FILE__) + '/../../spec_helper'
+
+ruby_version_is "1.9" do
+ describe "Random#bytes" do
+ it "returns a String" do
+ Random.new.bytes(1).should be_an_instance_of(String)
+ end
+
+ it "returns a String of the length given as argument" do
+ Random.new.bytes(15).length.should == 15
+ end
+
+ it "returns an ASCII-8BIT String" do
+ Random.new.bytes(15).encoding.should == Encoding::ASCII_8BIT
+ end
+
+ it "returns the same output for a given seed" do
+ Random.new(33).bytes(2).should == "\x14\\"
+ end
+
+ it "returns a random binary String" do
+ Random.new.bytes(12).should_not == Random.new.bytes(12)
+ end
+ end
+end
Added: MacRuby/branches/experimental/spec/frozen/core/random/equal_value_spec.rb
===================================================================
--- MacRuby/branches/experimental/spec/frozen/core/random/equal_value_spec.rb (rev 0)
+++ MacRuby/branches/experimental/spec/frozen/core/random/equal_value_spec.rb 2009-08-02 13:12:21 UTC (rev 2147)
@@ -0,0 +1,39 @@
+require File.dirname(__FILE__) + '/../../spec_helper'
+
+ruby_version_is "1.9" do
+ describe "Random#==" do
+ it "returns true if the two objects have the same state" do
+ a = Random.new(42)
+ b = Random.new(42)
+ a.send(:state).should == b.send(:state)
+ a.should == b
+ end
+
+ it "returns false if the two objects have different state" do
+ a = Random.new
+ b = Random.new
+ a.send(:state).should_not == b.send(:state)
+ a.should_not == b
+ end
+
+ it "returns true if the two objects have the same seed" do
+ a = Random.new(42)
+ b = Random.new(42.5)
+ a.seed.should == b.seed
+ a.should == b
+ end
+
+ it "returns false if the two objects have a different seed" do
+ a = Random.new(42)
+ b = Random.new(41)
+ a.seed.should_not == b.seed
+ a.should_not == b
+ end
+
+ it "returns false if the other object is not a Random" do
+ a = Random.new(42)
+ a.should_not == 42
+ a.should_not == [a]
+ end
+ end
+end
Added: MacRuby/branches/experimental/spec/frozen/core/random/float_spec.rb
===================================================================
--- MacRuby/branches/experimental/spec/frozen/core/random/float_spec.rb (rev 0)
+++ MacRuby/branches/experimental/spec/frozen/core/random/float_spec.rb 2009-08-02 13:12:21 UTC (rev 2147)
@@ -0,0 +1,84 @@
+require File.dirname(__FILE__) + '/../../spec_helper'
+
+ruby_version_is "1.9" do
+ describe "Random#float" do
+
+ it "returns a Float object" do
+ Random.new.float.should be_an_instance_of(Float)
+ end
+
+ it "returns a number greater than or equal to 0.0" do
+ Random.new.float.should >= 0.0
+ end
+
+ it "returns a number less than 1.0 by default" do
+ Random.new.float.should < 1.0
+ end
+
+ it "returns a different number on each call" do
+ prng = Random.new
+ floats = 20.times.map{ prng.float }
+ floats.uniq.size.should == 20
+ end
+
+ it "returns the same sequence of values for a given seed" do
+ prng = Random.new(176)
+ 2.times.map{ prng.float }.should == [0.3574378113049097, 0.21260493792986923]
+ end
+
+ it "only returns numbers less than the given argument" do
+ prng = Random.new
+ floats = 20.times.map{ prng.float(0.5) }
+ floats.max.should < 0.5
+ end
+
+ it "accepts an optional Integer argument" do
+ lambda do
+ Random.new.float(20)
+ end.should_not raise_error(ArgumentError)
+ end
+
+ it "accepts an optional Float argument" do
+ lambda do
+ Random.new.float(20.3)
+ end.should_not raise_error(ArgumentError)
+ end
+
+ it "accepts an optional Rational argument" do
+ lambda do
+ Random.new.float(Rational(267,20))
+ end.should_not raise_error(ArgumentError)
+ end
+
+ it "accepts an optional Complex (w/ imaginary part) argument" do
+ lambda do
+ Random.new.float(Complex(20))
+ end.should_not raise_error(ArgumentError)
+ end
+
+ it "raises Errno::EDOM for an argument of Infinity" do
+ lambda do
+ Random.new.float(infinity_value)
+ end.should raise_error(Errno::EDOM)
+ end
+
+ it "raises Errno::EDOM for an argument of NaN" do
+ lambda do
+ Random.new.float(nan_value)
+ end.should raise_error(Errno::EDOM)
+ end
+
+ it "raises a RangeError for a Complex (with imaginary part) argument" do
+ lambda do
+ Random.new.float(Complex(20,3))
+ end.should raise_error(RangeError)
+ end
+
+ it "raises a TypeError for a non-Floatish argument" do
+ lambda do
+ Random.new.float("swim")
+ end.should raise_error(TypeError)
+ end
+
+ end
+end
Added: MacRuby/branches/experimental/spec/frozen/core/random/int_spec.rb
===================================================================
--- MacRuby/branches/experimental/spec/frozen/core/random/int_spec.rb (rev 0)
+++ MacRuby/branches/experimental/spec/frozen/core/random/int_spec.rb 2009-08-02 13:12:21 UTC (rev 2147)
@@ -0,0 +1,114 @@
+require File.dirname(__FILE__) + '/../../spec_helper'
+
+ruby_version_is "1.9" do
+ describe "Random#int" do
+
+ it "accepts an Integer argument" do
+ lambda do
+ Random.new.int(20)
+ end.should_not raise_error(ArgumentError)
+ end
+
+ it "accepts a Bignum argument" do
+ lambda do
+ Random.new.int(bignum_value)
+ end.should_not raise_error(ArgumentError)
+ end
+
+ it "accepts a Range argument" do
+ lambda do
+ Random.new.int(1..3)
+ end.should_not raise_error(ArgumentError)
+ end
+
+ it "coerces the argument with #to_int" do
+ obj = mock_numeric('int')
+ obj.should_receive(:to_int).exactly(20).times.and_return(4)
+ prng = Random.new
+ ints = 20.times.map { prng.int(obj) }
+ ints.max.should < 4
+ end
+
+ it "returns an Integer" do
+ Random.new.int(12).should be_kind_of(Integer)
+ end
+
+ it "returns an number >= 0" do
+ prng = Random.new
+ ints = 20.times.map { prng.int(10) }
+ ints.min.should >= 0
+ end
+
+ it "returns a number < the argument" do
+ prng = Random.new
+ ints = 20.times.map { prng.int(10) }
+ ints.max.should < 10
+ end
+
+ it "returns a random number on each call that satisfies the given inequalities" do
+ prng_a = Random.new
+ ints_a = 20.times.map { prng_a.int(5) }
+
+ prng_b = Random.new
+ ints_b = 20.times.map { prng_b.int(5) }
+
+ ints_a.should_not == ints_b
+ end
+
+ it "returns the same sequence of numbers for a given seed" do
+ prng_a = Random.new(34)
+ ints_a = 20.times.map { prng_a.int(5) }
+
+ prng_b = Random.new(34)
+ ints_b = 20.times.map { prng_b.int(5) }
+
+ ints_a.should == ints_b
+ end
+
+ it "returns an integer from the inclusive Integer range if one is given" do
+ prng = Random.new
+ ints = 20.times.map { prng.int(10..12) }
+ ints.uniq.sort.should == [10,11,12]
+ end
+
+ it "returns an integer from the exclusive Integer range if one is given" do
+ prng = Random.new
+ ints = 20.times.map { prng.int(10...12) }
+ ints.uniq.sort.should == [10,11]
+ end
+
+ it "raises a TypeError if a String range is given" do
+ lambda do
+ Random.new.int('10'...'12')
+ end.should raise_error(TypeError)
+ end
+
+ # http://redmine.ruby-lang.org/issues/show/1859
+ quarantine! do
+ it "raises a TypeError if a Float..Integer range is given" do
+ lambda do
+ Random.new.int(20.2..40)
+ end.should raise_error(TypeError)
+ end
+ end
+
+ # The following examples fail. This has been reported as bug #1858
+ it "returns an ArgumentError when the argument is 1" do
+ lambda do
+ Random.new.int(1)
+ end.should raise_error(ArgumentError)
+ end
+
+ it "returns an ArgumentError when the argument is 0" do
+ lambda do
+ Random.new.int(0)
+ end.should raise_error(ArgumentError)
+ end
+
+ it "returns an ArgumentError when the argument is negative" do
+ lambda do
+ Random.new.int(-17)
+ end.should raise_error(ArgumentError)
+ end
+ end
+end
Added: MacRuby/branches/experimental/spec/frozen/core/random/new_seed_spec.rb
===================================================================
--- MacRuby/branches/experimental/spec/frozen/core/random/new_seed_spec.rb (rev 0)
+++ MacRuby/branches/experimental/spec/frozen/core/random/new_seed_spec.rb 2009-08-02 13:12:21 UTC (rev 2147)
@@ -0,0 +1,35 @@
+require File.dirname(__FILE__) + '/../../spec_helper'
+
+ruby_version_is "1.9" do
+ describe "Random.new_seed" do
+
+ it "returns a Bignum" do
+ Random.new_seed.should be_an_instance_of(Bignum)
+ end
+
+ it "returns an arbitrary seed value each time" do
+ bigs = 200.times.map { Random.new_seed }
+ bigs.uniq.size.should == 200
+ end
+
+ # This is probably implementation-specific, but given the complexity and
+ # importance of random number generation, it seems prudent to be explcit
+ # about the current behaviour.
+ it "returns a number less than 40 digits long" do
+ bigs = 2000.times.map { Random.new_seed.to_s.length }.uniq
+ bigs.max.should < 40
+ end
+
+ it "is not affected by Kernel#srand" do
+ begin
+ srand 25
+ a = Random.new_seed
+ srand 25
+ b = Random.new_seed
+ a.should_not == b
+ ensure
+ srand Random.new_seed
+ end
+ end
+ end
+end
Added: MacRuby/branches/experimental/spec/frozen/core/random/new_spec.rb
===================================================================
--- MacRuby/branches/experimental/spec/frozen/core/random/new_spec.rb (rev 0)
+++ MacRuby/branches/experimental/spec/frozen/core/random/new_spec.rb 2009-08-02 13:12:21 UTC (rev 2147)
@@ -0,0 +1,33 @@
+ruby_version_is "1.9" do
+ describe "Random.new" do
+ it "returns a new instance of Random" do
+ Random.new.should be_an_instance_of(Random)
+ end
+
+ it "uses a random seed value if none is supplied" do
+ Random.new.seed.should be_an_instance_of(Bignum)
+ end
+
+ it "accepts an Integer seed value as an argument" do
+ Random.new(2).seed.should == 2
+ end
+
+ it "accepts (and truncates) a Float seed value as an argument" do
+ Random.new(3.4).seed.should == 3
+ end
+
+ it "accepts (and converts to Integer) a Rational seed value as an argument" do
+ Random.new(Rational(20,2)).seed.should == 10
+ end
+
+ it "accepts (and converts to Integer) a Complex (w/ imaginary part) seed value as an argument" do
+ Random.new(Complex(20)).seed.should == 20
+ end
+
+ it "raises a RangeError if passed a Complex (with imaginary part) seed value as an argument" do
+ lambda do
+ Random.new(Complex(20,2))
+ end.should raise_error(RangeError)
+ end
+ end
+end
Added: MacRuby/branches/experimental/spec/frozen/core/random/rand_spec.rb
===================================================================
--- MacRuby/branches/experimental/spec/frozen/core/random/rand_spec.rb (rev 0)
+++ MacRuby/branches/experimental/spec/frozen/core/random/rand_spec.rb 2009-08-02 13:12:21 UTC (rev 2147)
@@ -0,0 +1,55 @@
+require File.dirname(__FILE__) + '/../../spec_helper'
+
+ruby_version_is "1.9" do
+ describe "Random.rand" do
+ it "returns a Float if no max argument is passed" do
+ Random.rand.should be_kind_of(Float)
+ end
+
+ it "returns a Float >= 0 if no max argument is passed" do
+ floats = 200.times.map { Random.rand }
+ floats.min.should >= 0
+ end
+
+ it "returns a Float < 1 if no max argument is passed" do
+ floats = 200.times.map { Random.rand }
+ floats.max.should < 1
+ end
+
+ it "returns the same sequence for a given seed if no max argument is passed" do
+ Random.srand 33
+ floats_a = 20.times.map { Random.rand }
+ Random.srand 33
+ floats_b = 20.times.map { Random.rand }
+ floats_a.should == floats_b
+ end
+
+ it "returns a Integer if an Integer argument is passed" do
+ Random.rand(20).should be_kind_of(Integer)
+ end
+
+ it "returns an Integer >= 0 if an Integer argument is passed" do
+ ints = 200.times.map { Random.rand(34) }
+ ints.min.should >= 0
+ end
+
+ it "returns an Integer < the max argument if an Integer argument is passed" do
+ ints = 200.times.map { Random.rand(55) }
+ ints.max.should < 55
+ end
+
+ it "returns the same sequence for a given seed if an Integer argument is passed" do
+ Random.srand 33
+ floats_a = 20.times.map { Random.rand(90) }
+ Random.srand 33
+ floats_b = 20.times.map { Random.rand(90) }
+ floats_a.should == floats_b
+ end
+
+ it "coerces arguments to Integers with #to_int" do
+ obj = mock_numeric('int')
+ obj.should_receive(:to_int).and_return(99)
+ Random.rand(obj).should be_kind_of(Integer)
+ end
+ end
+end
Added: MacRuby/branches/experimental/spec/frozen/core/random/seed_spec.rb
===================================================================
--- MacRuby/branches/experimental/spec/frozen/core/random/seed_spec.rb (rev 0)
+++ MacRuby/branches/experimental/spec/frozen/core/random/seed_spec.rb 2009-08-02 13:12:21 UTC (rev 2147)
@@ -0,0 +1,32 @@
+require File.dirname(__FILE__) + '/../../spec_helper'
+
+ruby_version_is "1.9" do
+ describe "Random#seed" do
+
+ it "returns an Integer" do
+ Random.new.seed.should be_kind_of(Integer)
+ end
+
+ it "returns an arbitrary seed if the constructor was called without arguments" do
+ Random.new.seed.should_not == Random.new.seed
+ end
+
+ it "returns the same generated seed when repeatedly called on the same object" do
+ prng = Random.new
+ prng.seed.should == prng.seed
+ end
+
+ it "returns the seed given in the constructor" do
+ prng = Random.new(36788)
+ prng.seed.should == prng.seed
+ prng.seed.should == 36788
+ end
+
+ it "returns the given seed coerced with #to_int" do
+ obj = mock_numeric('int')
+ obj.should_receive(:to_int).and_return(34)
+ prng = Random.new(obj)
+ prng.seed.should == 34
+ end
+ end
+end
Added: MacRuby/branches/experimental/spec/frozen/core/random/srand_spec.rb
===================================================================
--- MacRuby/branches/experimental/spec/frozen/core/random/srand_spec.rb (rev 0)
+++ MacRuby/branches/experimental/spec/frozen/core/random/srand_spec.rb 2009-08-02 13:12:21 UTC (rev 2147)
@@ -0,0 +1,43 @@
+require File.dirname(__FILE__) + '/../../spec_helper'
+
+ruby_version_is "1.9" do
+ describe "Random.srand" do
+
+ it "returns an arbitrary seed if .srand wasn't called previously with an argument and no argument is supplied this time" do
+ Random.srand # Reset to random seed in case .srand was called previously
+ Random.srand.should_not == Random.srand
+ end
+
+ it "returns the previous argument to .srand if one was given and no argument is supplied" do
+ Random.srand 34
+ Random.srand.should == 34
+ end
+
+ it "returns an arbitrary seed if .srand wasn't called previously with an argument and 0 is supplied this time" do
+ Random.srand # Reset to random seed in case .srand was called previously
+ Random.srand(0).should_not == Random.srand(0)
+ end
+
+ it "returns the previous argument to .srand if one was given and 0 is supplied" do
+ Random.srand 34
+ Random.srand(0).should == 34
+ end
+
+ it "seeds Random.rand such that its return value is deterministic" do
+ Random.srand 176542
+ a = 20.times.map { Random.rand }
+ Random.srand 176542
+ b = 20.times.map { Random.rand }
+ a.should == b
+ end
+
+ it "seeds Kernel.rand such that its return value is deterministic" do
+ Random.srand 176542
+ a = 20.times.map { Kernel.rand }
+ Random.srand 176542
+ b = 20.times.map { Kernel.rand }
+ a.should == b
+ end
+
+ end
+end
Modified: MacRuby/branches/experimental/spec/frozen/core/string/element_set_spec.rb
===================================================================
--- MacRuby/branches/experimental/spec/frozen/core/string/element_set_spec.rb 2009-08-02 08:57:05 UTC (rev 2146)
+++ MacRuby/branches/experimental/spec/frozen/core/string/element_set_spec.rb 2009-08-02 13:12:21 UTC (rev 2147)
@@ -113,10 +113,25 @@
lambda { str[-20] = "bam" }.should raise_error(IndexError)
str.should == "hello"
- lambda { ""[0] = "bam" }.should raise_error(IndexError)
lambda { ""[-1] = "bam" }.should raise_error(IndexError)
end
+ ruby_version_is ""..."1.9" do
+ it "raises an IndexError when setting the zero'th element of an empty String" do
+ lambda { ""[0] = "bam" }.should raise_error(IndexError)
+ end
+ end
+
+ # Behaviour verfieid correct by matz in
+ # http://redmine.ruby-lang.org/issues/show/1750
+ ruby_version_is "1.9" do
+ it "allows assignment to the zero'th element of an empty String" do
+ str = ""
+ str[0] = "bam"
+ str.should == "bam"
+ end
+ end
+
it "raises IndexError if the string index doesn't match a position in the string" do
str = "hello"
lambda { str['y'] = "bam" }.should raise_error(IndexError)
Added: MacRuby/branches/experimental/spec/frozen/core/string/encode_spec.rb
===================================================================
--- MacRuby/branches/experimental/spec/frozen/core/string/encode_spec.rb (rev 0)
+++ MacRuby/branches/experimental/spec/frozen/core/string/encode_spec.rb 2009-08-02 13:12:21 UTC (rev 2147)
@@ -0,0 +1,261 @@
+# coding: utf-8
+ruby_version_is "1.9" do
+ describe "String#encode!" do
+
+ it "transcodes to the default internal encoding with no argument" do
+ begin
+ old_default_internal = Encoding.default_internal
+ Encoding.default_internal = Encoding::EUC_JP
+ str = "問か".force_encoding('utf-8')
+ str.encoding.should_not == Encoding.default_internal
+ str.encode.encoding.should == Encoding.default_internal
+ ensure
+ Encoding.default_internal = old_default_internal
+ end
+ end
+
+ it "accepts a target encoding name as a String for an argument" do
+ str = "Füll"
+ lambda do
+ str.encode!('binary')
+ end.should_not raise_error(ArgumentError)
+ end
+
+ it "accepts a target encoding as an Encoding for an argument" do
+ str = "Füll"
+ lambda do
+ str.encode!(Encoding::BINARY)
+ end.should_not raise_error(ArgumentError)
+ end
+
+ it "accepts a target and source encoding given as Encoding objects" do
+ str = "Füll"
+ lambda do
+ str.encode!(Encoding::ASCII, Encoding::BINARY)
+ end.should_not raise_error(ArgumentError)
+ end
+
+ it "accepts a target and source encoding given as Strings" do
+ str = "Füll"
+ lambda do
+ str.encode!('ascii', 'binary')
+ end.should_not raise_error(ArgumentError)
+ end
+
+ it "accepts a target encoding given as an Encoding, and a source encoding given as a String" do
+ str = "Füll"
+ lambda do
+ str.encode!(Encoding::ASCII, 'binary')
+ end.should_not raise_error(ArgumentError)
+ end
+
+ it "accepts a target encoding given as a String, and a source encoding given as an Encoding" do
+ str = "Füll"
+ lambda do
+ str.encode!('ascii', Encoding::BINARY)
+ end.should_not raise_error(ArgumentError)
+ end
+
+ it "accepts an options hash as the final argument" do
+ lambda do
+ "yes".encode!('ascii', Encoding::BINARY, {:xml => :text})
+ end.should_not raise_error(ArgumentError)
+
+ lambda do
+ "yes".encode!(Encoding::BINARY, {:xml => :text})
+ end.should_not raise_error(ArgumentError)
+ end
+
+ it "returns self when called with only a target encoding" do
+ str = "strung"
+ str.encode!(Encoding::BINARY).should == str.force_encoding(Encoding::BINARY)
+ end
+
+ it "returns self when called with only a target encoding" do
+ str = "strung"
+ str.encode!(Encoding::BINARY,Encoding::ASCII).should == str.force_encoding(Encoding::BINARY)
+ end
+
+ it "returns self even when no changes are made" do
+ str = "strung"
+ str.encode!(Encoding::UTF_8).should == str
+ end
+
+ it "tags the String with the given encoding" do
+ str = "ürst"
+ str.encoding.should == Encoding::UTF_8
+ str.encode!(Encoding::UTF_16LE)
+ str.encoding.should == Encoding::UTF_16LE
+ end
+
+ it "transcodes self to the given encoding" do
+ str = "\u3042".force_encoding('UTF-8')
+ str.encode!(Encoding::EUC_JP)
+ str.should == "\xA4\xA2".force_encoding('EUC-JP')
+ end
+
+ it "can convert between encodings where a multi-stage conversion path is needed" do
+ str = "big?".force_encoding(Encoding::US_ASCII)
+ str.encode!(Encoding::Big5, Encoding::US_ASCII)
+ str.encoding.should == Encoding::Big5
+ end
+
+ it "raises an Encoding::InvalidByteSequenceError for invalid byte sequences" do
+ lambda do
+ "\xa4".force_encoding(Encoding::EUC_JP).encode!('iso-8859-1')
+ end.should raise_error(Encoding::InvalidByteSequenceError)
+ end
+
+ it "raises UndefinedConversionError if the String contains characters invalid for the target encoding" do
+ str = "\u{6543}"
+ lambda do
+ str.encode!(Encoding.find('macCyrillic'))
+ end.should raise_error(Encoding::UndefinedConversionError)
+ end
+
+ it "raises Encoding::ConverterNotFoundError for invalid target encodings" do
+ lambda do
+ "\u{9878}".encode!('xyz')
+ end.should raise_error(Encoding::ConverterNotFoundError)
+ end
+
+ it "raises a RuntimeError when called on a frozen String" do
+ lambda do
+ "foo".freeze.encode!(Encoding::ANSI_X3_4_1968)
+ end.should raise_error(RuntimeError)
+ end
+
+ # http://redmine.ruby-lang.org/issues/show/1836
+ it "raises a RuntimeError when called on a frozen String when it's a no-op" do
+ lambda do
+ "foo".freeze.encode!("foo".encoding)
+ end.should raise_error(RuntimeError)
+ end
+ end
+
+ describe "String#encode" do
+
+ it "transcodes to the default internal encoding with no argument" do
+ begin
+ old_default_internal = Encoding.default_internal
+ Encoding.default_internal = Encoding::EUC_JP
+ str = "問か".force_encoding('utf-8')
+ str.encoding.should_not == Encoding.default_internal
+ str.encode!
+ str.encoding.should == Encoding.default_internal
+ ensure
+ Encoding.default_internal = old_default_internal
+ end
+ end
+
+ it "accepts a target encoding name as a String for an argument" do
+ str = "Füll"
+ lambda do
+ str.encode('binary')
+ end.should_not raise_error(ArgumentError)
+ end
+
+ it "accepts a target encoding as an Encoding for an argument" do
+ str = "Füll"
+ lambda do
+ str.encode(Encoding::BINARY)
+ end.should_not raise_error(ArgumentError)
+ end
+
+ it "accepts a target and source encoding given as Encoding objects" do
+ str = "Füll"
+ lambda do
+ str.encode(Encoding::ASCII, Encoding::BINARY)
+ end.should_not raise_error(ArgumentError)
+ end
+
+ it "accepts a target and source encoding given as Strings" do
+ str = "Füll"
+ lambda do
+ str.encode('ascii', 'binary')
+ end.should_not raise_error(ArgumentError)
+ end
+
+ it "accepts a target encoding given as an Encoding, and a source encoding given as a String" do
+ str = "Füll"
+ lambda do
+ str.encode(Encoding::ASCII, 'binary')
+ end.should_not raise_error(ArgumentError)
+ end
+
+ it "accepts a target encoding given as a String, and a source encoding given as an Encoding" do
+ str = "Füll"
+ lambda do
+ str.encode('ascii', Encoding::BINARY)
+ end.should_not raise_error(ArgumentError)
+ end
+
+ it "accepts an options hash as the final argument" do
+ lambda do
+ "yes".encode('ascii', Encoding::BINARY, {:xml => :text})
+ end.should_not raise_error(ArgumentError)
+
+ lambda do
+ "yes".encode(Encoding::BINARY, {:xml => :text})
+ end.should_not raise_error(ArgumentError)
+ end
+
+ it "returns a copy of self when called with only a target encoding" do
+ str = "strung".force_encoding(Encoding::UTF_8)
+ copy = str.encode('ascii')
+ str.encoding.should == Encoding::UTF_8
+ copy.encoding.should == Encoding::US_ASCII
+ end
+
+ it "returns self when called with only a target encoding" do
+ str = "strung"
+ copy = str.encode(Encoding::BINARY,Encoding::ASCII)
+ copy.object_id.should_not == str.object_id
+ str.encoding.should == Encoding::UTF_8
+ end
+
+ it "returns a copy of self even when no changes are made" do
+ str = "strung".force_encoding('ASCII')
+ str.encode(Encoding::UTF_8).object_id.should_not == str.object_id
+ str.encoding.should == Encoding::US_ASCII
+ end
+
+ it "returns a String with the given encoding" do
+ str = "ürst"
+ str.encoding.should == Encoding::UTF_8
+ copy = str.encode(Encoding::UTF_16LE)
+ copy.encoding.should == Encoding::UTF_16LE
+ str.encoding.should == Encoding::UTF_8
+ end
+
+ it "transcodes self to the given encoding" do
+ str = "\u3042".force_encoding('UTF-8')
+ str.encode(Encoding::EUC_JP).should == "\xA4\xA2".force_encoding('EUC-JP')
+ end
+
+ it "can convert between encodings where a multi-stage conversion path is needed" do
+ str = "big?".force_encoding(Encoding::US_ASCII)
+ str.encode(Encoding::Big5, Encoding::US_ASCII).encoding.should == Encoding::Big5
+ end
+
+ it "raises an Encoding::InvalidByteSequenceError for invalid byte sequences" do
+ lambda do
+ "\xa4".force_encoding(Encoding::EUC_JP).encode('iso-8859-1')
+ end.should raise_error(Encoding::InvalidByteSequenceError)
+ end
+
+ it "raises UndefinedConversionError if the String contains characters invalid for the target encoding" do
+ str = "\u{6543}"
+ lambda do
+ str.encode(Encoding.find('macCyrillic'))
+ end.should raise_error(Encoding::UndefinedConversionError)
+ end
+
+ it "raises Encoding::ConverterNotFoundError for invalid target encodings" do
+ lambda do
+ "\u{9878}".encode('xyz')
+ end.should raise_error(Encoding::ConverterNotFoundError)
+ end
+
+ end
+end
Modified: MacRuby/branches/experimental/spec/frozen/core/string/tr_spec.rb
===================================================================
--- MacRuby/branches/experimental/spec/frozen/core/string/tr_spec.rb 2009-08-02 08:57:05 UTC (rev 2146)
+++ MacRuby/branches/experimental/spec/frozen/core/string/tr_spec.rb 2009-08-02 13:12:21 UTC (rev 2147)
@@ -1,3 +1,4 @@
+# coding: utf-8
require File.dirname(__FILE__) + '/../../spec_helper'
require File.dirname(__FILE__) + '/fixtures/classes.rb'
@@ -58,6 +59,17 @@
str.tr("e", "a".taint).tainted?.should == false
end
end
+
+ ruby_version_is "1.9" do
+ # http://redmine.ruby-lang.org/issues/show/1839
+ it "can replace a 7-bit ASCII character with a multibyte one" do
+ a = "uber"
+ a.encoding.should == Encoding::UTF_8
+ b = a.tr("u","ü")
+ b.should == "über"
+ b.encoding.should == Encoding::UTF_8
+ end
+ end
end
describe "String#tr!" do
Modified: MacRuby/branches/experimental/spec/frozen/core/struct/inspect_spec.rb
===================================================================
--- MacRuby/branches/experimental/spec/frozen/core/struct/inspect_spec.rb 2009-08-02 08:57:05 UTC (rev 2146)
+++ MacRuby/branches/experimental/spec/frozen/core/struct/inspect_spec.rb 2009-08-02 13:12:21 UTC (rev 2147)
@@ -5,7 +5,11 @@
it "returns a string representation of some kind" do
car = Struct::Car.new('Ford', 'Ranger')
car.inspect.should == '#<struct Struct::Car make="Ford", model="Ranger", year=nil>'
- Whiskey = Struct.new(:name, :ounces)
- Whiskey.new('Jack', 100).inspect.should == '#<struct Whiskey name="Jack", ounces=100>'
+ # ujihisa reported in http://rubyspec.org/issues/show/130 that the
+ # following example failed under mspec. Prefixing 'Whiskey' with a double
+ # colon causes it to work. Given that this is an mspec bug, as opposed to
+ # a problem with a spec, I've used the workaround below.
+ ::Whiskey = Struct.new(:name, :ounces)
+ ::Whiskey.new('Jack', 100).inspect.should == '#<struct Whiskey name="Jack", ounces=100>'
end
end
Added: MacRuby/branches/experimental/spec/frozen/core/symbol/intern_spec.rb
===================================================================
--- MacRuby/branches/experimental/spec/frozen/core/symbol/intern_spec.rb (rev 0)
+++ MacRuby/branches/experimental/spec/frozen/core/symbol/intern_spec.rb 2009-08-02 13:12:21 UTC (rev 2147)
@@ -0,0 +1,11 @@
+ruby_version_is "1.8.7" do
+ describe "Symbol#intern" do
+ it "returns self" do
+ :foo.intern.should == :foo
+ end
+
+ it "returns a Symbol" do
+ :foo.intern.should be_kind_of(Symbol)
+ end
+ end
+end
Modified: MacRuby/branches/experimental/spec/frozen/core/thread/inspect_spec.rb
===================================================================
--- MacRuby/branches/experimental/spec/frozen/core/thread/inspect_spec.rb 2009-08-02 08:57:05 UTC (rev 2146)
+++ MacRuby/branches/experimental/spec/frozen/core/thread/inspect_spec.rb 2009-08-02 13:12:21 UTC (rev 2147)
@@ -30,8 +30,10 @@
ThreadSpecs.status_of_thread_with_uncaught_exception.inspect.should include('dead')
end
- it "describes a dying running thread" do
- ThreadSpecs.status_of_dying_running_thread.inspect.should include('aborting')
+ ruby_version_is ""..."1.9" do
+ it "describes a dying running thread" do
+ ThreadSpecs.status_of_dying_running_thread.inspect.should include('aborting')
+ end
end
it "describes a dying sleeping thread" do
Modified: MacRuby/branches/experimental/spec/frozen/core/thread/status_spec.rb
===================================================================
--- MacRuby/branches/experimental/spec/frozen/core/thread/status_spec.rb 2009-08-02 08:57:05 UTC (rev 2146)
+++ MacRuby/branches/experimental/spec/frozen/core/thread/status_spec.rb 2009-08-02 13:12:21 UTC (rev 2147)
@@ -30,8 +30,10 @@
ThreadSpecs.status_of_thread_with_uncaught_exception.status.should == nil
end
- it "describes a dying running thread" do
- ThreadSpecs.status_of_dying_running_thread.status.should == 'aborting'
+ ruby_version_is ""..."1.9" do
+ it "describes a dying running thread" do
+ ThreadSpecs.status_of_dying_running_thread.status.should == 'aborting'
+ end
end
it "describes a dying sleeping thread" do
Modified: MacRuby/branches/experimental/spec/frozen/language/block_spec.rb
===================================================================
--- MacRuby/branches/experimental/spec/frozen/language/block_spec.rb 2009-08-02 08:57:05 UTC (rev 2146)
+++ MacRuby/branches/experimental/spec/frozen/language/block_spec.rb 2009-08-02 13:12:21 UTC (rev 2147)
@@ -1,6 +1,14 @@
require File.dirname(__FILE__) + '/../spec_helper'
require File.dirname(__FILE__) + '/fixtures/block'
+describe "A block with mismatched arguments" do
+ it "Should fill in unsupplied arguments with nil" do
+ ret = nil
+ BlockSpecs::Yield.new.two_args {|one, two, three| ret = [one, two, three]}
+ ret.should == [1, 2, nil]
+ end
+end
+
describe "A block with a 'rest' arg" do
it "collects all of the arguments passed to yield" do
ret = nil
@@ -36,4 +44,4 @@
end
end
-language_version __FILE__, "block"
\ No newline at end of file
+language_version __FILE__, "block"
Modified: MacRuby/branches/experimental/spec/frozen/language/class_spec.rb
===================================================================
--- MacRuby/branches/experimental/spec/frozen/language/class_spec.rb 2009-08-02 08:57:05 UTC (rev 2146)
+++ MacRuby/branches/experimental/spec/frozen/language/class_spec.rb 2009-08-02 13:12:21 UTC (rev 2147)
@@ -18,6 +18,8 @@
end
it "raises TypeError if constant given as class name exists and is not a Module" do
+ # 1.9 needs the constant defined here because of it's scoping rules
+ ClassSpecsNumber = 12
lambda {
class ClassSpecsNumber
end
Modified: MacRuby/branches/experimental/spec/frozen/language/defined_spec.rb
===================================================================
--- MacRuby/branches/experimental/spec/frozen/language/defined_spec.rb 2009-08-02 08:57:05 UTC (rev 2146)
+++ MacRuby/branches/experimental/spec/frozen/language/defined_spec.rb 2009-08-02 13:12:21 UTC (rev 2147)
@@ -158,6 +158,14 @@
ret.should == "expression"
end
+ it "returns 'yield' when there is a block to yield to and defined?(yield) is sent" do
+ def y
+ ret = defined?(yield)
+ ret.should == 'yield'
+ end
+ y {|a| true}
+ end
+
deviates_on :rubinius do
# Rubinius does not care about dynamic vars
it "returns 'local-variable' when defined? is called on a block var" do
Modified: MacRuby/branches/experimental/spec/frozen/language/file_spec.rb
===================================================================
--- MacRuby/branches/experimental/spec/frozen/language/file_spec.rb 2009-08-02 08:57:05 UTC (rev 2146)
+++ MacRuby/branches/experimental/spec/frozen/language/file_spec.rb 2009-08-02 13:12:21 UTC (rev 2147)
@@ -11,15 +11,28 @@
eval("__FILE__").should == "(eval)"
end
- it "equals a relative path when required using a relative path" do
- base_path = File.dirname(File.dirname(fixture(__FILE__, "file.rb")))
- path = "fixtures/file.rb"
- Dir.chdir(base_path) do
- require path
- ScratchPad.recorded.should == File.join(".",path)
+ ruby_version_is ""..."1.8.7" do
+ it "equals a relative path when required using a relative path" do
+ base_path = File.dirname(File.dirname(fixture(__FILE__, "file.rb")))
+ path = "fixtures/file.rb"
+ Dir.chdir(base_path) do
+ require path
+ ScratchPad.recorded.should == File.join(".",path)
+ end
end
end
-
+
+ ruby_version_is "1.8.7" do
+ it "equals an absolute path when required using a relative path" do
+ base_path = File.dirname(File.dirname(fixture(__FILE__, "file.rb")))
+ path = "./fixtures/file.rb"
+ Dir.chdir(base_path) do
+ require path
+ ScratchPad.recorded.should == File.expand_path(path)
+ end
+ end
+ end
+
it "equals the full path when required using a full path" do
path = fixture(__FILE__, "file.rb")
require path
Added: MacRuby/branches/experimental/spec/frozen/language/literal_lambda_spec.rb
===================================================================
--- MacRuby/branches/experimental/spec/frozen/language/literal_lambda_spec.rb (rev 0)
+++ MacRuby/branches/experimental/spec/frozen/language/literal_lambda_spec.rb 2009-08-02 13:12:21 UTC (rev 2147)
@@ -0,0 +1 @@
+language_version __FILE__, "literal_lambda"
Modified: MacRuby/branches/experimental/spec/frozen/language/super_spec.rb
===================================================================
--- MacRuby/branches/experimental/spec/frozen/language/super_spec.rb 2009-08-02 08:57:05 UTC (rev 2146)
+++ MacRuby/branches/experimental/spec/frozen/language/super_spec.rb 2009-08-02 13:12:21 UTC (rev 2147)
@@ -86,7 +86,7 @@
# sub = Class.new(sup) do
# [:a, :b].each do |name|
# define_method name do
- # super
+ # super()
# end
# end
# end
@@ -95,4 +95,30 @@
# sub.new.b.should == "b"
# sub.new.a.should == "a"
# end
+
+ ruby_version_is ""..."1.9" do
+ it "can be used with implicit arguments from a method defined with define_method" do
+ sup = Class.new do
+ def a; "a"; end
+ end
+
+ sub = Class.new(sup) do
+ define_method :a do
+ super
+ end
+ end
+
+ sub.new.a.should == "a"
+ end
+ end
+
+ ruby_version_is "1.9" do
+ it "can't be used with implicit arguments from a method defined with define_method" do
+ Class.new do
+ define_method :a do
+ super
+ end.should raise_error(RuntimeError)
+ end
+ end
+ end
end
Modified: MacRuby/branches/experimental/spec/frozen/language/versions/block_1.9.rb
===================================================================
--- MacRuby/branches/experimental/spec/frozen/language/versions/block_1.9.rb 2009-08-02 08:57:05 UTC (rev 2146)
+++ MacRuby/branches/experimental/spec/frozen/language/versions/block_1.9.rb 2009-08-02 13:12:21 UTC (rev 2147)
@@ -14,4 +14,85 @@
sum.should == 6
var.should == nil
end
-end
\ No newline at end of file
+end
+
+describe "Block-local variables" do
+ # Examples phrased so the concatenation of the describe and it blocks make
+ # grammatical sense.
+ it "are introduced with a semi-colon in the parameter list" do
+ lambda { [1].each {|one; bl| } }.should_not raise_error(SyntaxError)
+ end
+
+ it "can be specified in a comma-separated list after the semi-colon" do
+ lambda { [1].each {|one; bl, bl2| } }.should_not raise_error(SyntaxError)
+ end
+
+ it "can not have the same name as one of the standard parameters" do
+ lambda { eval "[1].each {|foo; foo| }" }.should raise_error(SyntaxError)
+ lambda { eval "[1].each {|foo, bar; glark, bar| }" }.should raise_error(SyntaxError)
+ end
+
+ it "can not be prefixed with an asterisk" do
+ lambda { eval "[1].each {|foo; *bar| }" }.should raise_error(SyntaxError)
+ lambda do
+ eval "[1].each {|foo, bar; glark, *fnord| }"
+ end.should raise_error(SyntaxError)
+ end
+
+ it "can not be prefixed with an ampersand" do
+ lambda { eval "[1].each {|foo; &bar| }" }.should raise_error(SyntaxError)
+ lambda do
+ eval "[1].each {|foo, bar; glark, &fnord| }"
+ end.should raise_error(SyntaxError)
+ end
+
+ it "can not be assigned default values" do
+ lambda { eval "[1].each {|foo; bar=1| }" }.should raise_error(SyntaxError)
+ lambda do
+ eval "[1].each {|foo, bar; glark, fnord=:fnord| }"
+ end.should raise_error(SyntaxError)
+ end
+
+ it "need not be preceeded by standard parameters" do
+ lambda { [1].each {|; foo| } }.should_not raise_error(SyntaxError)
+ lambda { [1].each {|; glark, bar| } }.should_not raise_error(SyntaxError)
+ end
+
+ it "only allow a single semi-colon in the parameter list" do
+ lambda { eval "[1].each {|foo; bar; glark| }" }.should raise_error(SyntaxError)
+ lambda { eval "[1].each {|; bar; glark| }" }.should raise_error(SyntaxError)
+ end
+
+ it "override shadowed variables from the outer scope" do
+ out = :out
+ [1].each {|; out| out = :in }
+ out.should == :out
+
+ a = :a
+ b = :b
+ c = :c
+ d = :d
+ {:ant => :bee}.each_pair do |a, b; c, d|
+ a = :A
+ b = :B
+ c = :C
+ d = :D
+ end
+ a.should == :a
+ b.should == :b
+ c.should == :c
+ d.should == :d
+ end
+
+ it "are not automatically instantiated in the outer scope" do
+ defined?(glark).should be_nil
+ [1].each {|;glark| 1}
+ defined?(glark).should be_nil
+ end
+
+ it "are automatically instantiated in the block" do
+ [1].each do |;glark|
+ glark.should be_nil
+ end
+ end
+end
Added: MacRuby/branches/experimental/spec/frozen/language/versions/literal_lambda_1.9.rb
===================================================================
--- MacRuby/branches/experimental/spec/frozen/language/versions/literal_lambda_1.9.rb (rev 0)
+++ MacRuby/branches/experimental/spec/frozen/language/versions/literal_lambda_1.9.rb 2009-08-02 13:12:21 UTC (rev 2147)
@@ -0,0 +1,136 @@
+describe "->(){}" do
+ it "can be specified as a literal" do
+ lambda { ->(){} }.should_not raise_error
+ end
+
+ it "returns a Proc object" do
+ ->(){}.should be_an_instance_of(Proc)
+ end
+
+ it "returns a lambda" do
+ ->(){}.lambda?.should be_true
+ end
+
+ it "can be assigned to a variable" do
+ var = ->(){}
+ var.lambda?.should be_true
+ end
+
+ it "understands a do/end block in place of {}" do
+ lambda do
+ ->() do
+ end
+ end.should_not raise_error(SyntaxError)
+ end
+
+ it "requires an associated block" do
+ lambda { eval "->()" }.should raise_error(SyntaxError)
+ lambda { eval "->" }.should raise_error(SyntaxError)
+ end
+
+ it "can be interpolated into a String" do
+ "1+2=#{->{ 1 + 2}.call}".should == "1+2=3"
+ end
+
+ it "can be be used as a Hash key" do
+ h = new_hash
+ h[->(one=1){ one + 2}.call] = :value
+ h.key?(3).should be_true
+ end
+
+ it "can be used in method parameter lists" do
+ def glark7654(a=-> { :foo })
+ a.call
+ end
+ glark7654.should == :foo
+ end
+
+ it "accepts an parameter list between the parenthesis" do
+ lambda { ->(a) {} }.should_not raise_error(SyntaxError)
+ lambda { ->(a,b) {} }.should_not raise_error(SyntaxError)
+ end
+
+ it "accepts an empty parameter list" do
+ lambda { ->() {} }.should_not raise_error(SyntaxError)
+ end
+
+ it "allows the parenthesis to be omitted entirely" do
+ lambda { -> {} }.should_not raise_error(SyntaxError)
+ lambda { ->{} }.should_not raise_error(SyntaxError)
+ lambda do
+ -> do
+ end
+ end.should_not raise_error(SyntaxError)
+ ->{}.should be_an_instance_of(Proc)
+ end
+
+ it "aliases each argument to the corresponding parameter" do
+ ->(a) {a}.call(:sym).should == :sym
+ ->(a,b) {[a, b]}.call(:sym, :bol).should == [:sym, :bol]
+ end
+
+ it "accepts parameters with default parameters between the parenthesis" do
+ lambda { ->(a=1) {} }.should_not raise_error(SyntaxError)
+ lambda { ->(x=1, b=[]) {} }.should_not raise_error(SyntaxError)
+ end
+
+ it "aliases each argument with a default value to the corresponding parameter" do
+ ->(a=:cymbal) {a}.call(:sym).should == :sym
+ ->(a,b=:cymbal) {[a, b]}.call(:sym, :bol).should == [:sym, :bol]
+ end
+
+ it "sets arguments to their default value if one wasn't supplied" do
+ ->(a=:cymbal) {a}.call.should == :cymbal
+ ->(a,b=:cymbal) {[a, b]}.call(:sym).should == [:sym, :cymbal]
+ end
+
+ it "accepts a parameter prefixed with an asterisk between the parenthesis" do
+ lambda { ->(*a) {} }.should_not raise_error(SyntaxError)
+ lambda { ->(x, *a) {} }.should_not raise_error(SyntaxError)
+ end
+
+ it "assigns all remaining arguments to the variable in the parameter list prefixed with an asterisk, if one exists" do
+ ->(*a) {a}.call(:per, :cus, :si, :on).should == [:per, :cus, :si, :on]
+ ->(a,*b) {b}.call(:per, :cus, :si, :on).should == [:cus, :si, :on]
+ end
+
+ it "accepts a parameter prefixed with an ampersand between the parenthesis" do
+ lambda { ->(&a) {} }.should_not raise_error(SyntaxError)
+ lambda { ->(x, &a) {} }.should_not raise_error(SyntaxError)
+ end
+
+ it "assigns the given block to the parameter prefixed with an ampersand if such a parameter exists" do
+ l = ->(&a) { a }.call { :foo }
+ l.call.should == :foo
+ end
+
+ it "assigns nil to the parameter prefixed with an ampersand unless a block was supplied" do
+ ->(&a) { a }.call.should be_nil
+ end
+
+ it "accepts a combination of argument types between the parenthesis" do
+ lambda { ->(x, y={}, z = Object.new, *a, &b) {} }.
+ should_not raise_error(SyntaxError)
+ end
+
+ it "sets parameters appropriately when a combination of parameter types is given between the parenthesis" do
+ l = ->(x, y={}, z = Object.new, *a, &b) { [x,y,z,a,b]}
+ l.call(1, [], [], 30, 40).should == [1, [], [], [30, 40], nil]
+ block = lambda { :lamb }
+ l.call(1, [], [], 30, 40, &block).last.should be_an_instance_of(Proc)
+ l2 = ->(x, y={}, *a) { [x, y, a]}
+ l2.call(:x).should == [:x, {}, []]
+ end
+
+ it "uses lambda's 'rigid' argument handling" do
+ ->(a, b){}.parameters.first.first.should == :req
+ ->(a, b){}.parameters.last.first.should == :req
+ lambda { ->(a, b){}.call 1 }.should raise_error(ArgumentError)
+ end
+
+ it "does not call the associated block" do
+ @called = false
+ ->() { @called = true }
+ @called.should be_false
+ end
+end
Modified: MacRuby/branches/experimental/spec/frozen/library/complex/Complex_spec.rb
===================================================================
--- MacRuby/branches/experimental/spec/frozen/library/complex/Complex_spec.rb 2009-08-02 08:57:05 UTC (rev 2146)
+++ MacRuby/branches/experimental/spec/frozen/library/complex/Complex_spec.rb 2009-08-02 13:12:21 UTC (rev 2147)
@@ -1,57 +1,23 @@
require File.dirname(__FILE__) + '/../../spec_helper'
+require File.dirname(__FILE__) + '/../../shared/complex/Complex'
ruby_version_is ""..."1.9" do
require 'complex'
describe "Complex when passed [Complex, Complex]" do
- it "returns a new Complex number based on the two given numbers" do
- Complex(Complex(3, 4), Complex(5, 6)).should == Complex.new(3 - 6, 4 + 5)
- Complex(Complex(1.5, 2), Complex(-5, 6.3)).should == Complex.new(1.5 - 6.3, 2 - 5)
- end
+ it_behaves_like(:complex_Complex_complex_complex, :Complex)
end
describe "Complex when passed [Complex]" do
- it "returns the passed Complex number" do
- Complex(Complex(1, 2)).should == Complex(1, 2)
- Complex(Complex(-3.4, bignum_value)).should == Complex(-3.4, bignum_value)
- end
+ it_behaves_like(:complex_Complex_complex, :Complex)
end
describe "Complex when passed [Integer, Integer]" do
- it "returns a new Complex number" do
- Complex(1, 2).should == Complex.new(1, 2)
- Complex(-3, -5).should == Complex.new(-3, -5)
- Complex(3.5, -4.5).should == Complex.new(3.5, -4.5)
- Complex(bignum_value, 30).should == Complex.new(bignum_value, 30)
- end
+ it_behaves_like(:complex_Complex_integer_integer, :Complex)
end
describe "Complex when passed [Integer]" do
- it "returns a new Complex number with 0 as the imaginary component" do
- # Guard against the Mathn library
- conflicts_with :Prime do
- Complex(1).should eql(Complex.new(1, 0))
- Complex(-3).should eql(Complex.new(-3, 0))
- Complex(-4.5).should eql(Complex.new(-4.5, 0))
- Complex(bignum_value).should eql(Complex.new(bignum_value, 0))
- end
- end
-
- it "returns the passed Integer when Complex::Unify is defined" do
- # Guard against the Mathn library
- conflicts_with :Prime do
- begin
- Complex::Unify = true
-
- Complex(1).should eql(1)
- Complex(-3).should eql(-3)
- Complex(-4.5).should eql(-4.5)
- Complex(bignum_value).should eql(bignum_value)
- ensure
- Complex.send :remove_const, :Unify
- end
- end
- end
+ it_behaves_like(:complex_Complex_integer, :Complex)
end
end
Modified: MacRuby/branches/experimental/spec/frozen/library/complex/hash_spec.rb
===================================================================
--- MacRuby/branches/experimental/spec/frozen/library/complex/hash_spec.rb 2009-08-02 08:57:05 UTC (rev 2146)
+++ MacRuby/branches/experimental/spec/frozen/library/complex/hash_spec.rb 2009-08-02 13:12:21 UTC (rev 2147)
@@ -1,21 +1,11 @@
require File.dirname(__FILE__) + '/../../spec_helper'
+require File.dirname(__FILE__) + '/../../shared/complex/hash'
ruby_version_is ""..."1.9" do
require 'complex'
describe "Complex#hash" do
- # NOTE:
- # Complex(2, 1).hash == Complex(1, 2).hash
- # This can result in Bugs when using hash and
- # other stuff that relies on #hash
- it "should be static" do
- Complex(1).hash.should == Complex(1).hash
- Complex(1, 0).hash.should == Complex(1).hash
- Complex(1, 1).hash.should == Complex(1, 1).hash
-
- Complex(1, 2).hash.should_not == Complex(1, 1).hash
- Complex(2, 1).hash.should_not == Complex(1, 1).hash
- end
+ it_behaves_like(:complex_hash, :hash)
end
end
Modified: MacRuby/branches/experimental/spec/frozen/library/complex/imag_spec.rb
===================================================================
--- MacRuby/branches/experimental/spec/frozen/library/complex/imag_spec.rb 2009-08-02 08:57:05 UTC (rev 2146)
+++ MacRuby/branches/experimental/spec/frozen/library/complex/imag_spec.rb 2009-08-02 13:12:21 UTC (rev 2147)
@@ -1,7 +1,7 @@
-require File.dirname(__FILE__) + '/../../spec_helper'
-require File.dirname(__FILE__) + '/shared/image'
+require File.dirname(__FILE__) + '/../../shared/complex/image'
ruby_version_is ""..."1.9" do
+
require 'complex'
describe "Complex#imag" do
Modified: MacRuby/branches/experimental/spec/frozen/library/complex/image_spec.rb
===================================================================
--- MacRuby/branches/experimental/spec/frozen/library/complex/image_spec.rb 2009-08-02 08:57:05 UTC (rev 2146)
+++ MacRuby/branches/experimental/spec/frozen/library/complex/image_spec.rb 2009-08-02 13:12:21 UTC (rev 2147)
@@ -1,9 +1,9 @@
require File.dirname(__FILE__) + '/../../spec_helper'
+require File.dirname(__FILE__) + '/../../shared/complex/image'
ruby_version_is ""..."1.9" do
require 'complex'
- require File.dirname(__FILE__) + '/shared/image'
describe "Complex#image" do
it_behaves_like(:complex_image, :image)
Modified: MacRuby/branches/experimental/spec/frozen/library/complex/inspect_spec.rb
===================================================================
--- MacRuby/branches/experimental/spec/frozen/library/complex/inspect_spec.rb 2009-08-02 08:57:05 UTC (rev 2146)
+++ MacRuby/branches/experimental/spec/frozen/library/complex/inspect_spec.rb 2009-08-02 13:12:21 UTC (rev 2147)
@@ -1,19 +1,10 @@
-require File.dirname(__FILE__) + '/../../spec_helper'
+require File.dirname(__FILE__) + '/../../shared/complex/inspect'
ruby_version_is ""..."1.9" do
require 'complex'
describe "Complex#inspect" do
- it %{returns "Complex(real, image)"} do
- # Guard against the Mathn library
- conflicts_with :Prime do
- Complex(1).inspect.should == "Complex(1, 0)"
- Complex(7).inspect.should == "Complex(7, 0)"
- end
-
- Complex(-1, 4).inspect.should == "Complex(-1, 4)"
- Complex(-7, 6.7).inspect.should == "Complex(-7, 6.7)"
- end
+ it_behaves_like(:complex_inspect, :inspect)
end
end
Modified: MacRuby/branches/experimental/spec/frozen/library/complex/math/acos_spec.rb
===================================================================
--- MacRuby/branches/experimental/spec/frozen/library/complex/math/acos_spec.rb 2009-08-02 08:57:05 UTC (rev 2146)
+++ MacRuby/branches/experimental/spec/frozen/library/complex/math/acos_spec.rb 2009-08-02 13:12:21 UTC (rev 2147)
@@ -1,16 +1,16 @@
require File.dirname(__FILE__) + '/../../../spec_helper'
+require 'complex'
require File.dirname(__FILE__) + '/shared/acos'
-ruby_version_is ""..."1.9" do
+describe "Math#acos" do
+ it_behaves_like :complex_math_acos, :_, IncludesMath.new
- describe "Math#acos" do
- it_behaves_like :complex_math_acos, :_, IncludesMath.new
-
- it "should be private" do
- IncludesMath.should have_private_instance_method(:acos)
- end
+ it "should be private" do
+ IncludesMath.should have_private_instance_method(:acos)
end
+end
+ruby_version_is ""..."1.9" do
describe "Math#acos!" do
it_behaves_like :complex_math_acos_bang, :_, IncludesMath.new
@@ -18,11 +18,13 @@
IncludesMath.should have_private_instance_method(:acos!)
end
end
+end
- describe "Math.acos" do
- it_behaves_like :complex_math_acos, :_, Math
- end
+describe "Math.acos" do
+ it_behaves_like :complex_math_acos, :_, Math
+end
+ruby_version_is ""..."1.9" do
describe "Math.acos!" do
it_behaves_like :complex_math_acos_bang, :_, Math
end
Modified: MacRuby/branches/experimental/spec/frozen/library/complex/math/acosh_spec.rb
===================================================================
--- MacRuby/branches/experimental/spec/frozen/library/complex/math/acosh_spec.rb 2009-08-02 08:57:05 UTC (rev 2146)
+++ MacRuby/branches/experimental/spec/frozen/library/complex/math/acosh_spec.rb 2009-08-02 13:12:21 UTC (rev 2147)
@@ -1,15 +1,16 @@
require File.dirname(__FILE__) + '/../../../spec_helper'
+require 'complex'
require File.dirname(__FILE__) + '/shared/acosh'
-ruby_version_is ""..."1.9" do
- describe "Math#acosh" do
- it_behaves_like :complex_math_acosh, :_, IncludesMath.new
+describe "Math#acosh" do
+ it_behaves_like :complex_math_acosh, :_, IncludesMath.new
- it "should be private" do
- IncludesMath.should have_private_instance_method(:acosh)
- end
+ it "should be private" do
+ IncludesMath.should have_private_instance_method(:acosh)
end
+end
+ruby_version_is ""..."1.9" do
describe "Math#acosh!" do
it_behaves_like :complex_math_acosh_bang, :_, IncludesMath.new
@@ -17,11 +18,13 @@
IncludesMath.should have_private_instance_method(:acosh!)
end
end
+end
- describe "Math.acosh" do
- it_behaves_like :complex_math_acosh, :_, Math
- end
+describe "Math.acosh" do
+ it_behaves_like :complex_math_acosh, :_, Math
+end
+ruby_version_is ""..."1.9" do
describe "Math.acosh!" do
it_behaves_like :complex_math_acosh_bang, :_, Math
end
Modified: MacRuby/branches/experimental/spec/frozen/library/complex/math/asin_spec.rb
===================================================================
--- MacRuby/branches/experimental/spec/frozen/library/complex/math/asin_spec.rb 2009-08-02 08:57:05 UTC (rev 2146)
+++ MacRuby/branches/experimental/spec/frozen/library/complex/math/asin_spec.rb 2009-08-02 13:12:21 UTC (rev 2147)
@@ -1,15 +1,16 @@
require File.dirname(__FILE__) + '/../../../spec_helper'
+require 'complex'
require File.dirname(__FILE__) + '/shared/asin'
-ruby_version_is ""..."1.9" do
- describe "Math#asin" do
- it_behaves_like :complex_math_asin, :_, IncludesMath.new
+describe "Math#asin" do
+ it_behaves_like :complex_math_asin, :_, IncludesMath.new
- it "should be private" do
- IncludesMath.should have_private_instance_method(:asin)
- end
+ it "should be private" do
+ IncludesMath.should have_private_instance_method(:asin)
end
+end
+ruby_version_is ""..."1.9" do
describe "Math#asin!" do
it_behaves_like :complex_math_asin_bang, :_, IncludesMath.new
@@ -17,11 +18,13 @@
IncludesMath.should have_private_instance_method(:asin!)
end
end
+end
- describe "Math.asin" do
- it_behaves_like :complex_math_asin, :_, Math
- end
+describe "Math.asin" do
+ it_behaves_like :complex_math_asin, :_, Math
+end
+ruby_version_is ""..."1.9" do
describe "Math.asin!" do
it_behaves_like :complex_math_asin_bang, :_, Math
end
Modified: MacRuby/branches/experimental/spec/frozen/library/complex/math/asinh_spec.rb
===================================================================
--- MacRuby/branches/experimental/spec/frozen/library/complex/math/asinh_spec.rb 2009-08-02 08:57:05 UTC (rev 2146)
+++ MacRuby/branches/experimental/spec/frozen/library/complex/math/asinh_spec.rb 2009-08-02 13:12:21 UTC (rev 2147)
@@ -1,15 +1,16 @@
require File.dirname(__FILE__) + '/../../../spec_helper'
+require 'complex'
require File.dirname(__FILE__) + '/shared/asinh'
-ruby_version_is ""..."1.9" do
- describe "Math#asinh" do
- it_behaves_like :complex_math_asinh, :_, IncludesMath.new
+describe "Math#asinh" do
+ it_behaves_like :complex_math_asinh, :_, IncludesMath.new
- it "should be private" do
- IncludesMath.should have_private_instance_method(:asinh)
- end
+ it "should be private" do
+ IncludesMath.should have_private_instance_method(:asinh)
end
+end
+ruby_version_is ""..."1.9" do
describe "Math#asinh!" do
it_behaves_like :complex_math_asinh_bang, :_, IncludesMath.new
@@ -17,11 +18,13 @@
IncludesMath.should have_private_instance_method(:asinh!)
end
end
+end
- describe "Math.asinh" do
- it_behaves_like :complex_math_asinh, :_, Math
- end
+describe "Math.asinh" do
+ it_behaves_like :complex_math_asinh, :_, Math
+end
+ruby_version_is ""..."1.9" do
describe "Math.asinh!" do
it_behaves_like :complex_math_asinh_bang, :_, Math
end
Modified: MacRuby/branches/experimental/spec/frozen/library/complex/math/atan2_spec.rb
===================================================================
--- MacRuby/branches/experimental/spec/frozen/library/complex/math/atan2_spec.rb 2009-08-02 08:57:05 UTC (rev 2146)
+++ MacRuby/branches/experimental/spec/frozen/library/complex/math/atan2_spec.rb 2009-08-02 13:12:21 UTC (rev 2147)
@@ -1,15 +1,16 @@
require File.dirname(__FILE__) + '/../../../spec_helper'
+require 'complex'
require File.dirname(__FILE__) + '/shared/atan2'
-ruby_version_is ""..."1.9" do
- describe "Math#atan2" do
- it_behaves_like :complex_math_atan2, :_, IncludesMath.new
+describe "Math#atan2" do
+ it_behaves_like :complex_math_atan2, :_, IncludesMath.new
- it "should be private" do
- IncludesMath.should have_private_instance_method(:atan2)
- end
+ it "should be private" do
+ IncludesMath.should have_private_instance_method(:atan2)
end
+end
+ruby_version_is ""..."1.9" do
describe "Math#atan2!" do
it_behaves_like :complex_math_atan2_bang, :_, IncludesMath.new
@@ -17,11 +18,13 @@
IncludesMath.should have_private_instance_method(:atan2!)
end
end
+end
- describe "Math.atan2" do
- it_behaves_like :complex_math_atan2, :_, Math
- end
+describe "Math.atan2" do
+ it_behaves_like :complex_math_atan2, :_, Math
+end
+ruby_version_is ""..."1.9" do
describe "Math.atan2!" do
it_behaves_like :complex_math_atan2_bang, :_, Math
end
Modified: MacRuby/branches/experimental/spec/frozen/library/complex/math/atan_spec.rb
===================================================================
--- MacRuby/branches/experimental/spec/frozen/library/complex/math/atan_spec.rb 2009-08-02 08:57:05 UTC (rev 2146)
+++ MacRuby/branches/experimental/spec/frozen/library/complex/math/atan_spec.rb 2009-08-02 13:12:21 UTC (rev 2147)
@@ -1,15 +1,16 @@
require File.dirname(__FILE__) + '/../../../spec_helper'
+require 'complex'
require File.dirname(__FILE__) + '/shared/atan'
-ruby_version_is ""..."1.9" do
- describe "Math#atan" do
- it_behaves_like :complex_math_atan, :_, IncludesMath.new
+describe "Math#atan" do
+ it_behaves_like :complex_math_atan, :_, IncludesMath.new
- it "should be private" do
- IncludesMath.should have_private_instance_method(:atan)
- end
+ it "should be private" do
+ IncludesMath.should have_private_instance_method(:atan)
end
+end
+ruby_version_is ""..."1.9" do
describe "Math#atan!" do
it_behaves_like :complex_math_atan_bang, :_, IncludesMath.new
@@ -17,11 +18,13 @@
IncludesMath.should have_private_instance_method(:atan!)
end
end
+end
- describe "Math.atan" do
- it_behaves_like :complex_math_atan, :_, Math
- end
+describe "Math.atan" do
+ it_behaves_like :complex_math_atan, :_, Math
+end
+ruby_version_is ""..."1.9" do
describe "Math.atan!" do
it_behaves_like :complex_math_atan_bang, :_, Math
end
Modified: MacRuby/branches/experimental/spec/frozen/library/complex/math/atanh_spec.rb
===================================================================
--- MacRuby/branches/experimental/spec/frozen/library/complex/math/atanh_spec.rb 2009-08-02 08:57:05 UTC (rev 2146)
+++ MacRuby/branches/experimental/spec/frozen/library/complex/math/atanh_spec.rb 2009-08-02 13:12:21 UTC (rev 2147)
@@ -1,15 +1,16 @@
require File.dirname(__FILE__) + '/../../../spec_helper'
+require 'complex'
require File.dirname(__FILE__) + '/shared/atanh'
-ruby_version_is ""..."1.9" do
- describe "Math#atanh" do
- it_behaves_like :complex_math_atanh, :_, IncludesMath.new
+describe "Math#atanh" do
+ it_behaves_like :complex_math_atanh, :_, IncludesMath.new
- it "should be private" do
- IncludesMath.should have_private_instance_method(:atanh)
- end
+ it "should be private" do
+ IncludesMath.should have_private_instance_method(:atanh)
end
+end
+ruby_version_is ""..."1.9" do
describe "Math#atanh!" do
it_behaves_like :complex_math_atanh_bang, :_, IncludesMath.new
@@ -17,11 +18,13 @@
IncludesMath.should have_private_instance_method(:atanh!)
end
end
+end
- describe "Math.atanh" do
- it_behaves_like :complex_math_atanh, :_, Math
- end
+describe "Math.atanh" do
+ it_behaves_like :complex_math_atanh, :_, Math
+end
+ruby_version_is ""..."1.9" do
describe "Math.atanh!" do
it_behaves_like :complex_math_atanh_bang, :_, Math
end
Modified: MacRuby/branches/experimental/spec/frozen/library/complex/math/cos_spec.rb
===================================================================
--- MacRuby/branches/experimental/spec/frozen/library/complex/math/cos_spec.rb 2009-08-02 08:57:05 UTC (rev 2146)
+++ MacRuby/branches/experimental/spec/frozen/library/complex/math/cos_spec.rb 2009-08-02 13:12:21 UTC (rev 2147)
@@ -1,15 +1,16 @@
require File.dirname(__FILE__) + '/../../../spec_helper'
+require 'complex'
require File.dirname(__FILE__) + '/shared/cos'
-ruby_version_is ""..."1.9" do
- describe "Math#cos" do
- it_behaves_like :complex_math_cos, :_, IncludesMath.new
+describe "Math#cos" do
+ it_behaves_like :complex_math_cos, :_, IncludesMath.new
- it "should be private" do
- IncludesMath.should have_private_instance_method(:cos)
- end
+ it "should be private" do
+ IncludesMath.should have_private_instance_method(:cos)
end
+end
+ruby_version_is ""..."1.9" do
describe "Math#cos!" do
it_behaves_like :complex_math_cos_bang, :_, IncludesMath.new
@@ -17,11 +18,13 @@
IncludesMath.should have_private_instance_method(:cos!)
end
end
+end
- describe "Math.cos" do
- it_behaves_like :complex_math_cos, :_, Math
- end
+describe "Math.cos" do
+ it_behaves_like :complex_math_cos, :_, Math
+end
+ruby_version_is ""..."1.9" do
describe "Math.cos!" do
it_behaves_like :complex_math_cos_bang, :_, Math
end
Modified: MacRuby/branches/experimental/spec/frozen/library/complex/math/cosh_spec.rb
===================================================================
--- MacRuby/branches/experimental/spec/frozen/library/complex/math/cosh_spec.rb 2009-08-02 08:57:05 UTC (rev 2146)
+++ MacRuby/branches/experimental/spec/frozen/library/complex/math/cosh_spec.rb 2009-08-02 13:12:21 UTC (rev 2147)
@@ -1,15 +1,16 @@
require File.dirname(__FILE__) + '/../../../spec_helper'
+require 'complex'
require File.dirname(__FILE__) + '/shared/cosh'
-ruby_version_is ""..."1.9" do
- describe "Math#cosh" do
- it_behaves_like :complex_math_cosh, :_, IncludesMath.new
+describe "Math#cosh" do
+ it_behaves_like :complex_math_cosh, :_, IncludesMath.new
- it "should be private" do
- IncludesMath.should have_private_instance_method(:cosh)
- end
+ it "should be private" do
+ IncludesMath.should have_private_instance_method(:cosh)
end
+end
+ruby_version_is ""..."1.9" do
describe "Math#cosh!" do
it_behaves_like :complex_math_cosh_bang, :_, IncludesMath.new
@@ -17,11 +18,13 @@
IncludesMath.should have_private_instance_method(:cosh!)
end
end
+end
- describe "Math.cosh" do
- it_behaves_like :complex_math_cosh, :_, Math
- end
+describe "Math.cosh" do
+ it_behaves_like :complex_math_cosh, :_, Math
+end
+ruby_version_is ""..."1.9" do
describe "Math.cosh!" do
it_behaves_like :complex_math_cosh_bang, :_, Math
end
Modified: MacRuby/branches/experimental/spec/frozen/library/complex/math/exp_spec.rb
===================================================================
--- MacRuby/branches/experimental/spec/frozen/library/complex/math/exp_spec.rb 2009-08-02 08:57:05 UTC (rev 2146)
+++ MacRuby/branches/experimental/spec/frozen/library/complex/math/exp_spec.rb 2009-08-02 13:12:21 UTC (rev 2147)
@@ -1,15 +1,16 @@
require File.dirname(__FILE__) + '/../../../spec_helper'
+require 'complex'
require File.dirname(__FILE__) + '/shared/exp'
-ruby_version_is ""..."1.9" do
- describe "Math#exp" do
- it_behaves_like :complex_math_exp, :_, IncludesMath.new
+describe "Math#exp" do
+ it_behaves_like :complex_math_exp, :_, IncludesMath.new
- it "should be private" do
- IncludesMath.should have_private_instance_method(:exp)
- end
+ it "should be private" do
+ IncludesMath.should have_private_instance_method(:exp)
end
+end
+ruby_version_is ""..."1.9" do
describe "Math#exp!" do
it_behaves_like :complex_math_exp_bang, :_, IncludesMath.new
@@ -17,11 +18,13 @@
IncludesMath.should have_private_instance_method(:exp!)
end
end
+end
- describe "Math.exp" do
- it_behaves_like :complex_math_exp, :_, Math
- end
+describe "Math.exp" do
+ it_behaves_like :complex_math_exp, :_, Math
+end
+ruby_version_is ""..."1.9" do
describe "Math.exp!" do
it_behaves_like :complex_math_exp_bang, :_, Math
end
Modified: MacRuby/branches/experimental/spec/frozen/library/complex/math/log10_spec.rb
===================================================================
--- MacRuby/branches/experimental/spec/frozen/library/complex/math/log10_spec.rb 2009-08-02 08:57:05 UTC (rev 2146)
+++ MacRuby/branches/experimental/spec/frozen/library/complex/math/log10_spec.rb 2009-08-02 13:12:21 UTC (rev 2147)
@@ -1,15 +1,16 @@
require File.dirname(__FILE__) + '/../../../spec_helper'
+require 'complex'
require File.dirname(__FILE__) + '/shared/log10'
-ruby_version_is ""..."1.9" do
- describe "Math#log10" do
- it_behaves_like :complex_math_log10, :_, IncludesMath.new
+describe "Math#log10" do
+ it_behaves_like :complex_math_log10, :_, IncludesMath.new
- it "should be private" do
- IncludesMath.should have_private_instance_method(:log10)
- end
+ it "should be private" do
+ IncludesMath.should have_private_instance_method(:log10)
end
+end
+ruby_version_is ""..."1.9" do
describe "Math#log10!" do
it_behaves_like :complex_math_log10_bang, :_, IncludesMath.new
@@ -17,11 +18,13 @@
IncludesMath.should have_private_instance_method(:log10!)
end
end
+end
- describe "Math.log10" do
- it_behaves_like :complex_math_log10, :_, Math
- end
+describe "Math.log10" do
+ it_behaves_like :complex_math_log10, :_, Math
+end
+ruby_version_is ""..."1.9" do
describe "Math.log10!" do
it_behaves_like :complex_math_log10_bang, :_, Math
end
Modified: MacRuby/branches/experimental/spec/frozen/library/complex/math/log_spec.rb
===================================================================
--- MacRuby/branches/experimental/spec/frozen/library/complex/math/log_spec.rb 2009-08-02 08:57:05 UTC (rev 2146)
+++ MacRuby/branches/experimental/spec/frozen/library/complex/math/log_spec.rb 2009-08-02 13:12:21 UTC (rev 2147)
@@ -1,15 +1,16 @@
require File.dirname(__FILE__) + '/../../../spec_helper'
+require 'complex'
require File.dirname(__FILE__) + '/shared/log'
-ruby_version_is ""..."1.9" do
- describe "Math#log" do
- it_behaves_like :complex_math_log, :_, IncludesMath.new
+describe "Math#log" do
+ it_behaves_like :complex_math_log, :_, IncludesMath.new
- it "should be private" do
- IncludesMath.should have_private_instance_method(:log)
- end
+ it "should be private" do
+ IncludesMath.should have_private_instance_method(:log)
end
+end
+ruby_version_is ""..."1.9" do
describe "Math#log!" do
it_behaves_like :complex_math_log_bang, :_, IncludesMath.new
@@ -17,11 +18,13 @@
IncludesMath.should have_private_instance_method(:log!)
end
end
+end
- describe "Math.log" do
- it_behaves_like :complex_math_log, :_, Math
- end
+describe "Math.log" do
+ it_behaves_like :complex_math_log, :_, Math
+end
+ruby_version_is ""..."1.9" do
describe "Math.log!" do
it_behaves_like :complex_math_log_bang, :_, Math
end
Modified: MacRuby/branches/experimental/spec/frozen/library/complex/math/shared/acosh.rb
===================================================================
--- MacRuby/branches/experimental/spec/frozen/library/complex/math/shared/acosh.rb 2009-08-02 08:57:05 UTC (rev 2146)
+++ MacRuby/branches/experimental/spec/frozen/library/complex/math/shared/acosh.rb 2009-08-02 13:12:21 UTC (rev 2147)
@@ -13,7 +13,9 @@
end
it "returns the principle value of the inverse hyperbolic cosine for Complex numbers" do
- @object.send(:acosh, Complex(3, 4)).should be_close(Complex(2.30550903124348, 0.93681246115572), TOLERANCE)
+ @object.send(:acosh, Complex(3, 4))
+ @object.send(:acosh, Complex(3, 4)).image.should be_close(0.93681246115572, TOLERANCE)
+ @object.send(:acosh, Complex(3, 4)).real.should be_close(2.305509031243477, TOLERANCE)
end
end
Modified: MacRuby/branches/experimental/spec/frozen/library/complex/math/sin_spec.rb
===================================================================
--- MacRuby/branches/experimental/spec/frozen/library/complex/math/sin_spec.rb 2009-08-02 08:57:05 UTC (rev 2146)
+++ MacRuby/branches/experimental/spec/frozen/library/complex/math/sin_spec.rb 2009-08-02 13:12:21 UTC (rev 2147)
@@ -1,15 +1,16 @@
require File.dirname(__FILE__) + '/../../../spec_helper'
+require 'complex'
require File.dirname(__FILE__) + '/shared/sin'
-ruby_version_is ""..."1.9" do
- describe "Math#sin" do
- it_behaves_like :complex_math_sin, :_, IncludesMath.new
+describe "Math#sin" do
+ it_behaves_like :complex_math_sin, :_, IncludesMath.new
- it "should be private" do
- IncludesMath.should have_private_instance_method(:sin)
- end
+ it "should be private" do
+ IncludesMath.should have_private_instance_method(:sin)
end
+end
+ruby_version_is ""..."1.9" do
describe "Math#sin!" do
it_behaves_like :complex_math_sin_bang, :_, IncludesMath.new
@@ -17,11 +18,13 @@
IncludesMath.should have_private_instance_method(:sin!)
end
end
+end
- describe "Math.sin" do
- it_behaves_like :complex_math_sin, :_, Math
- end
+describe "Math.sin" do
+ it_behaves_like :complex_math_sin, :_, Math
+end
+ruby_version_is ""..."1.9" do
describe "Math.sin!" do
it_behaves_like :complex_math_sin_bang, :_, Math
end
Modified: MacRuby/branches/experimental/spec/frozen/library/complex/math/sinh_spec.rb
===================================================================
--- MacRuby/branches/experimental/spec/frozen/library/complex/math/sinh_spec.rb 2009-08-02 08:57:05 UTC (rev 2146)
+++ MacRuby/branches/experimental/spec/frozen/library/complex/math/sinh_spec.rb 2009-08-02 13:12:21 UTC (rev 2147)
@@ -1,15 +1,16 @@
require File.dirname(__FILE__) + '/../../../spec_helper'
+require 'complex'
require File.dirname(__FILE__) + '/shared/sinh'
-ruby_version_is ""..."1.9" do
- describe "Math#sinh" do
- it_behaves_like :complex_math_sinh, :_, IncludesMath.new
+describe "Math#sinh" do
+ it_behaves_like :complex_math_sinh, :_, IncludesMath.new
- it "should be private" do
- IncludesMath.should have_private_instance_method(:sinh)
- end
+ it "should be private" do
+ IncludesMath.should have_private_instance_method(:sinh)
end
+end
+ruby_version_is ""..."1.9" do
describe "Math#sinh!" do
it_behaves_like :complex_math_sinh_bang, :_, IncludesMath.new
@@ -17,11 +18,13 @@
IncludesMath.should have_private_instance_method(:sinh!)
end
end
+end
- describe "Math.sinh" do
- it_behaves_like :complex_math_sinh, :_, Math
- end
+describe "Math.sinh" do
+ it_behaves_like :complex_math_sinh, :_, Math
+end
+ruby_version_is ""..."1.9" do
describe "Math.sinh!" do
it_behaves_like :complex_math_sinh_bang, :_, Math
end
Modified: MacRuby/branches/experimental/spec/frozen/library/complex/math/sqrt_spec.rb
===================================================================
--- MacRuby/branches/experimental/spec/frozen/library/complex/math/sqrt_spec.rb 2009-08-02 08:57:05 UTC (rev 2146)
+++ MacRuby/branches/experimental/spec/frozen/library/complex/math/sqrt_spec.rb 2009-08-02 13:12:21 UTC (rev 2147)
@@ -1,15 +1,16 @@
require File.dirname(__FILE__) + '/../../../spec_helper'
+require 'complex'
require File.dirname(__FILE__) + '/shared/sqrt'
-ruby_version_is ""..."1.9" do
- describe "Math#sqrt" do
- it_behaves_like :complex_math_sqrt, :_, IncludesMath.new
+describe "Math#sqrt" do
+ it_behaves_like :complex_math_sqrt, :_, IncludesMath.new
- it "should be private" do
- IncludesMath.should have_private_instance_method(:sqrt)
- end
+ it "should be private" do
+ IncludesMath.should have_private_instance_method(:sqrt)
end
+end
+ruby_version_is ""..."1.9" do
describe "Math#sqrt!" do
it_behaves_like :complex_math_sqrt_bang, :_, IncludesMath.new
@@ -17,11 +18,13 @@
IncludesMath.should have_private_instance_method(:sqrt!)
end
end
+end
- describe "Math.sqrt" do
- it_behaves_like :complex_math_sqrt, :_, Math
- end
+describe "Math.sqrt" do
+ it_behaves_like :complex_math_sqrt, :_, Math
+end
+ruby_version_is ""..."1.9" do
describe "Math.sqrt!" do
it_behaves_like :complex_math_sqrt_bang, :_, Math
end
Modified: MacRuby/branches/experimental/spec/frozen/library/complex/math/tan_spec.rb
===================================================================
--- MacRuby/branches/experimental/spec/frozen/library/complex/math/tan_spec.rb 2009-08-02 08:57:05 UTC (rev 2146)
+++ MacRuby/branches/experimental/spec/frozen/library/complex/math/tan_spec.rb 2009-08-02 13:12:21 UTC (rev 2147)
@@ -1,15 +1,16 @@
require File.dirname(__FILE__) + '/../../../spec_helper'
+require 'complex'
require File.dirname(__FILE__) + '/shared/tan'
-ruby_version_is ""..."1.9" do
- describe "Math#tan" do
- it_behaves_like :complex_math_tan, :_, IncludesMath.new
+describe "Math#tan" do
+ it_behaves_like :complex_math_tan, :_, IncludesMath.new
- it "should be private" do
- IncludesMath.should have_private_instance_method(:tan)
- end
+ it "should be private" do
+ IncludesMath.should have_private_instance_method(:tan)
end
+end
+ruby_version_is ""..."1.9" do
describe "Math#tan!" do
it_behaves_like :complex_math_tan_bang, :_, IncludesMath.new
@@ -17,11 +18,13 @@
IncludesMath.should have_private_instance_method(:tan!)
end
end
+end
- describe "Math.tan" do
- it_behaves_like :complex_math_tan, :_, Math
- end
+describe "Math.tan" do
+ it_behaves_like :complex_math_tan, :_, Math
+end
+ruby_version_is ""..."1.9" do
describe "Math.tan!" do
it_behaves_like :complex_math_tan_bang, :_, Math
end
Modified: MacRuby/branches/experimental/spec/frozen/library/complex/math/tanh_spec.rb
===================================================================
--- MacRuby/branches/experimental/spec/frozen/library/complex/math/tanh_spec.rb 2009-08-02 08:57:05 UTC (rev 2146)
+++ MacRuby/branches/experimental/spec/frozen/library/complex/math/tanh_spec.rb 2009-08-02 13:12:21 UTC (rev 2147)
@@ -1,15 +1,16 @@
require File.dirname(__FILE__) + '/../../../spec_helper'
+require 'complex'
require File.dirname(__FILE__) + '/shared/tanh'
-ruby_version_is ""..."1.9" do
- describe "Math#tanh" do
- it_behaves_like :complex_math_tanh, :_, IncludesMath.new
+describe "Math#tanh" do
+ it_behaves_like :complex_math_tanh, :_, IncludesMath.new
- it "should be private" do
- IncludesMath.should have_private_instance_method(:tanh)
- end
+ it "should be private" do
+ IncludesMath.should have_private_instance_method(:tanh)
end
+end
+ruby_version_is ""..."1.9" do
describe "Math#tanh!" do
it_behaves_like :complex_math_tanh_bang, :_, IncludesMath.new
@@ -17,11 +18,13 @@
IncludesMath.should have_private_instance_method(:tanh!)
end
end
+end
- describe "Math.tanh" do
- it_behaves_like :complex_math_tanh, :_, Math
- end
+describe "Math.tanh" do
+ it_behaves_like :complex_math_tanh, :_, Math
+end
+ruby_version_is ""..."1.9" do
describe "Math.tanh!" do
it_behaves_like :complex_math_tanh_bang, :_, Math
end
Modified: MacRuby/branches/experimental/spec/frozen/library/complex/minus_spec.rb
===================================================================
--- MacRuby/branches/experimental/spec/frozen/library/complex/minus_spec.rb 2009-08-02 08:57:05 UTC (rev 2146)
+++ MacRuby/branches/experimental/spec/frozen/library/complex/minus_spec.rb 2009-08-02 13:12:21 UTC (rev 2147)
@@ -1,30 +1,18 @@
-require File.dirname(__FILE__) + '/../../spec_helper'
+require File.dirname(__FILE__) + '/../../shared/complex/minus'
ruby_version_is ""..."1.9" do
require 'complex'
describe "Complex#- with Complex" do
- it "subtracts both the real and imaginary components" do
- (Complex(1, 2) - Complex(10, 20)).should == Complex(1 - 10, 2 - 20)
- (Complex(1.5, 2.1) - Complex(100.2, -30.3)).should == Complex(1.5 - 100.2, 2.1 - (-30.3))
- end
+ it_behaves_like(:complex_minus_complex, :-)
end
describe "Complex#- with Integer" do
- it "subtracts the real number from the real component of self" do
- (Complex(1, 2) - 50).should == Complex(-49, 2)
- (Complex(1, 2) - 50.5).should == Complex(-49.5, 2)
- end
+ it_behaves_like(:complex_minus_integer, :-)
end
describe "Complex#- with Object" do
- it "tries to coerce self into other" do
- value = Complex(3, 9)
-
- obj = mock("Object")
- obj.should_receive(:coerce).with(value).and_return([2, 5])
- (value - obj).should == 2 - 5
- end
+ it_behaves_like(:complex_minus_object, :-)
end
end
Modified: MacRuby/branches/experimental/spec/frozen/library/complex/numeric/angle_spec.rb
===================================================================
--- MacRuby/branches/experimental/spec/frozen/library/complex/numeric/angle_spec.rb 2009-08-02 08:57:05 UTC (rev 2146)
+++ MacRuby/branches/experimental/spec/frozen/library/complex/numeric/angle_spec.rb 2009-08-02 13:12:21 UTC (rev 2147)
@@ -1,9 +1,10 @@
require File.dirname(__FILE__) + '/../../../spec_helper'
-require File.dirname(__FILE__) + '/shared/arg'
+require File.dirname(__FILE__) + '/../../../shared/complex/numeric/arg'
ruby_version_is ""..."1.9" do
require 'complex'
+ require 'rational'
describe "Numeric#angle" do
it_behaves_like :numeric_arg, :angle
Modified: MacRuby/branches/experimental/spec/frozen/library/complex/numeric/arg_spec.rb
===================================================================
--- MacRuby/branches/experimental/spec/frozen/library/complex/numeric/arg_spec.rb 2009-08-02 08:57:05 UTC (rev 2146)
+++ MacRuby/branches/experimental/spec/frozen/library/complex/numeric/arg_spec.rb 2009-08-02 13:12:21 UTC (rev 2147)
@@ -1,9 +1,10 @@
require File.dirname(__FILE__) + '/../../../spec_helper'
-require File.dirname(__FILE__) + '/shared/arg'
+require File.dirname(__FILE__) + '/../../../shared/complex/numeric/arg'
ruby_version_is ""..."1.9" do
require 'complex'
+ require 'rational'
describe "Numeric#arg" do
it_behaves_like :numeric_arg, :arg
Modified: MacRuby/branches/experimental/spec/frozen/library/complex/numeric/conj_spec.rb
===================================================================
--- MacRuby/branches/experimental/spec/frozen/library/complex/numeric/conj_spec.rb 2009-08-02 08:57:05 UTC (rev 2146)
+++ MacRuby/branches/experimental/spec/frozen/library/complex/numeric/conj_spec.rb 2009-08-02 13:12:21 UTC (rev 2147)
@@ -1,11 +1,12 @@
require File.dirname(__FILE__) + '/../../../spec_helper'
-require File.dirname(__FILE__) + '/shared/conjugate'
+require File.dirname(__FILE__) + '/../../../shared/complex/numeric/conj'
ruby_version_is ""..."1.9" do
require 'complex'
+ require 'rational'
describe "Numeric#conj" do
- it_behaves_like :numeric_conjugate, :conj
+ it_behaves_like :numeric_conj, :conj
end
end
Modified: MacRuby/branches/experimental/spec/frozen/library/complex/numeric/conjugate_spec.rb
===================================================================
--- MacRuby/branches/experimental/spec/frozen/library/complex/numeric/conjugate_spec.rb 2009-08-02 08:57:05 UTC (rev 2146)
+++ MacRuby/branches/experimental/spec/frozen/library/complex/numeric/conjugate_spec.rb 2009-08-02 13:12:21 UTC (rev 2147)
@@ -1,11 +1,12 @@
require File.dirname(__FILE__) + '/../../../spec_helper'
-require File.dirname(__FILE__) + '/shared/conjugate'
+require File.dirname(__FILE__) + '/../../../shared/complex/numeric/conj'
ruby_version_is ""..."1.9" do
require 'complex'
+ require 'rational'
describe "Numeric#conjugate" do
- it_behaves_like :numeric_conjugate, :conjugate
+ it_behaves_like :numeric_conj, :conjugate
end
end
Modified: MacRuby/branches/experimental/spec/frozen/library/complex/numeric/imag_spec.rb
===================================================================
--- MacRuby/branches/experimental/spec/frozen/library/complex/numeric/imag_spec.rb 2009-08-02 08:57:05 UTC (rev 2146)
+++ MacRuby/branches/experimental/spec/frozen/library/complex/numeric/imag_spec.rb 2009-08-02 13:12:21 UTC (rev 2147)
@@ -1,11 +1,12 @@
require File.dirname(__FILE__) + '/../../../spec_helper'
-require File.dirname(__FILE__) + '/shared/image'
+require File.dirname(__FILE__) + '/../../../shared/complex/numeric/imag'
ruby_version_is ""..."1.9" do
require 'complex'
+ require 'rational'
describe "Numeric#imag" do
- it_behaves_like :numeric_image, :imag
+ it_behaves_like :numeric_imag, :imag
end
end
Modified: MacRuby/branches/experimental/spec/frozen/library/complex/numeric/image_spec.rb
===================================================================
--- MacRuby/branches/experimental/spec/frozen/library/complex/numeric/image_spec.rb 2009-08-02 08:57:05 UTC (rev 2146)
+++ MacRuby/branches/experimental/spec/frozen/library/complex/numeric/image_spec.rb 2009-08-02 13:12:21 UTC (rev 2147)
@@ -1,11 +1,12 @@
require File.dirname(__FILE__) + '/../../../spec_helper'
-require File.dirname(__FILE__) + '/shared/image'
+require File.dirname(__FILE__) + '/../../../shared/complex/numeric/imag'
ruby_version_is ""..."1.9" do
require 'complex'
+ require 'rational'
describe "Numeric#image" do
- it_behaves_like :numeric_image, :image
+ it_behaves_like :numeric_imag, :image
end
end
Modified: MacRuby/branches/experimental/spec/frozen/library/complex/numeric/polar_spec.rb
===================================================================
--- MacRuby/branches/experimental/spec/frozen/library/complex/numeric/polar_spec.rb 2009-08-02 08:57:05 UTC (rev 2146)
+++ MacRuby/branches/experimental/spec/frozen/library/complex/numeric/polar_spec.rb 2009-08-02 13:12:21 UTC (rev 2147)
@@ -1,19 +1,12 @@
require File.dirname(__FILE__) + '/../../../spec_helper'
+require File.dirname(__FILE__) + '/../../../shared/complex/numeric/polar'
ruby_version_is ""..."1.9" do
require 'complex'
+ require 'rational'
describe "Numeric#polar" do
- it "returns self's absolute value and self's argument" do
- 5.polar.should == [5, 0]
- (-5).polar.should == [5, Math::PI]
-
- 4.5.polar.should == [4.5, 0]
- (-4.5).polar.should == [4.5, Math::PI]
-
- bignum_value.polar.should == [bignum_value, 0]
- (-bignum_value).polar.should == [bignum_value, Math::PI]
- end
+ it_behaves_like(:numeric_polar, :polar)
end
end
Modified: MacRuby/branches/experimental/spec/frozen/library/complex/numeric/real_spec.rb
===================================================================
--- MacRuby/branches/experimental/spec/frozen/library/complex/numeric/real_spec.rb 2009-08-02 08:57:05 UTC (rev 2146)
+++ MacRuby/branches/experimental/spec/frozen/library/complex/numeric/real_spec.rb 2009-08-02 13:12:21 UTC (rev 2147)
@@ -1,14 +1,12 @@
require File.dirname(__FILE__) + '/../../../spec_helper'
+require File.dirname(__FILE__) + '/../../../shared/complex/numeric/real'
ruby_version_is ""..."1.9" do
require 'complex'
+ require 'rational'
describe "Numeric#real" do
- it "returns self" do
- 20.real.should == 20
- (-4.5).real.should == -4.5
- bignum_value.real.should == bignum_value
- end
+ it_behaves_like(:numeric_real, :real)
end
end
Deleted: MacRuby/branches/experimental/spec/frozen/library/complex/numeric/shared/arg.rb
===================================================================
--- MacRuby/branches/experimental/spec/frozen/library/complex/numeric/shared/arg.rb 2009-08-02 08:57:05 UTC (rev 2146)
+++ MacRuby/branches/experimental/spec/frozen/library/complex/numeric/shared/arg.rb 2009-08-02 13:12:21 UTC (rev 2147)
@@ -1,17 +0,0 @@
-describe :numeric_arg, :shared => true do
- it "returns 0 if self is greater than or equal to 0" do
- 0.send(@method).should == 0
- 0.0.send(@method).should == 0
- (-0).send(@method).should == 0
-
- 20.send(@method).should == 0
- 4.5.send(@method).should == 0
- bignum_value.send(@method).should == 0
- end
-
- it "returns Math::PI if self is greater than or equal to 0" do
- (-20).send(@method).should == Math::PI
- (-4.5).send(@method).should == Math::PI
- (-bignum_value).send(@method).should == Math::PI
- end
-end
Deleted: MacRuby/branches/experimental/spec/frozen/library/complex/numeric/shared/conjugate.rb
===================================================================
--- MacRuby/branches/experimental/spec/frozen/library/complex/numeric/shared/conjugate.rb 2009-08-02 08:57:05 UTC (rev 2146)
+++ MacRuby/branches/experimental/spec/frozen/library/complex/numeric/shared/conjugate.rb 2009-08-02 13:12:21 UTC (rev 2147)
@@ -1,7 +0,0 @@
-describe :numeric_conjugate, :shared => true do
- it "returns self" do
- 20.send(@method).should == 20
- (-4.5).send(@method).should == -4.5
- bignum_value.send(@method).should == bignum_value
- end
-end
Deleted: MacRuby/branches/experimental/spec/frozen/library/complex/numeric/shared/image.rb
===================================================================
--- MacRuby/branches/experimental/spec/frozen/library/complex/numeric/shared/image.rb 2009-08-02 08:57:05 UTC (rev 2146)
+++ MacRuby/branches/experimental/spec/frozen/library/complex/numeric/shared/image.rb 2009-08-02 13:12:21 UTC (rev 2147)
@@ -1,7 +0,0 @@
-describe :numeric_image, :shared => true do
- it "returns 0" do
- 20.send(@method).should == 0
- (-4.5).send(@method).should == 0
- bignum_value.send(@method).should == 0
- end
-end
Deleted: MacRuby/branches/experimental/spec/frozen/library/complex/shared/image.rb
===================================================================
--- MacRuby/branches/experimental/spec/frozen/library/complex/shared/image.rb 2009-08-02 08:57:05 UTC (rev 2146)
+++ MacRuby/branches/experimental/spec/frozen/library/complex/shared/image.rb 2009-08-02 13:12:21 UTC (rev 2147)
@@ -1,8 +0,0 @@
-describe :complex_image, :shared => true do
- it "returns the imaginary part of self" do
- Complex(1, 0).send(@method).should == 0
- Complex(2, 1).send(@method).should == 1
- Complex(6.7, 8.9).send(@method).should == 8.9
- Complex(1, bignum_value).send(@method).should == bignum_value
- end
-end
Modified: MacRuby/branches/experimental/spec/frozen/library/prime/prime_division_spec.rb
===================================================================
--- MacRuby/branches/experimental/spec/frozen/library/prime/prime_division_spec.rb 2009-08-02 08:57:05 UTC (rev 2146)
+++ MacRuby/branches/experimental/spec/frozen/library/prime/prime_division_spec.rb 2009-08-02 13:12:21 UTC (rev 2147)
@@ -10,9 +10,15 @@
it "returns an empty array for 1" do
Prime.prime_division(1).should == []
end
- it "returns an empty array for -1" do
- Prime.prime_division(-1).should == []
+
+ it "returns [[-1, 1]] for -1" do
+ Prime.prime_division(-1).should == [[-1, 1]]
end
+
+ it "includes [[-1, 1]] in the divisors of a negative number" do
+ Prime.prime_division(-10).should include([-1, 1])
+ end
+
it "raises ZeroDivisionError for 0" do
lambda { Prime.prime_division(0) }.should raise_error(ZeroDivisionError)
end
Added: MacRuby/branches/experimental/spec/frozen/shared/array/join.rb
===================================================================
--- MacRuby/branches/experimental/spec/frozen/shared/array/join.rb (rev 0)
+++ MacRuby/branches/experimental/spec/frozen/shared/array/join.rb 2009-08-02 13:12:21 UTC (rev 2147)
@@ -0,0 +1,145 @@
+describe :array_join, :shared => true do
+ it "returns an empty string if the Array is empty" do
+ a = @object.new
+ a.send(@method, ':').should == ''
+ end
+
+ it "returns a string formed by concatenating each element.to_s separated by separator without trailing separator" do
+ obj = mock('foo')
+ def obj.to_s() 'foo' end
+ @object.new(1, 2, 3, 4, obj).send(@method, ' | ').should == '1 | 2 | 3 | 4 | foo'
+
+ obj = mock('o')
+ class << obj; undef :to_s; end
+ obj.should_receive(:method_missing).with(:to_s).and_return("o")
+ @object.new(1, obj).send(@method, ":").should == "1:o"
+ end
+
+ it "raises a NoMethodError if an element does not respond to #to_s" do
+ obj = mock('o')
+ class << obj; undef :to_s; end
+ lambda{ @object.new(1,obj).send(@method, ':') }.should raise_error(NoMethodError)
+ end
+
+ it "uses the same separator with nested arrays" do
+ @object.new(1, @object.new(2, @object.new(3, 4), 5), 6).send(@method, ":").should == "1:2:3:4:5:6"
+ @object.new(1, @object.new(2, ArraySpecs::MyArray[3, 4], 5), 6).send(@method, ":").should == "1:2:3:4:5:6"
+ end
+
+ it "tries to convert the passed separator to a String using #to_str" do
+ obj = mock('::')
+ obj.should_receive(:to_str).and_return("::")
+ @object.new(1, 2, 3, 4).send(@method, obj).should == '1::2::3::4'
+ end
+
+ ruby_version_is ""..."1.9" do
+ # Detail of joining recursive arrays is implementation dependent: [ruby-dev:37021]
+ it "handles recursive arrays" do
+ x = @object.new
+ x << x
+ x.send(@method, ':').should be_kind_of(String)
+
+ x = @object.new("one", "two")
+ x << x
+ str = x.send(@method, '/')
+ str.should include("one/two")
+
+ x << "three"
+ x << "four"
+ str = x.send(@method, '/')
+ str.should include("one/two")
+ str.should include("three/four")
+
+ # nested and recursive
+ x = @object.new(@object.new("one", "two"), @object.new("three", "four"))
+ x << x
+ str = x.send(@method, '/')
+ str.should include("one/two")
+ str.should include("three/four")
+
+ x = @object.new
+ y = @object.new
+ y << 9 << x << 8 << y << 7
+ x << 1 << x << 2 << y << 3
+ # representations when recursing from x
+ # these are here to make it easier to understand what is happening
+ str = x.send(@method, ':')
+ str.should include('1')
+ str.should include('2')
+ str.should include('3')
+ end
+ end
+
+ ruby_version_is "1.9" do
+ it "raises an ArgumentError when the Array is recursive" do
+ x = @object.new
+ x << x
+ lambda { x.send(@method, ':') }.should raise_error(ArgumentError)
+
+ x = @object.new("one", "two")
+ x << x
+ lambda { x.send(@method, '/') }.should raise_error(ArgumentError)
+
+ # nested and recursive
+ x = @object.new(@object.new("one", "two"), @object.new("three", "four"))
+ x << x
+ lambda { x.send(@method, '/') }.should raise_error(ArgumentError)
+ end
+ end
+
+ it "does not consider taint of either the array or the separator when the array is empty" do
+ @object.new.send(@method, ":").tainted?.should == false
+ @object.new.taint.send(@method, ":").tainted?.should == false
+ @object.new.send(@method, ":".taint).tainted?.should == false
+ @object.new.taint.send(@method, ":".taint).tainted?.should == false
+ end
+
+ # This doesn't work for Enumerable#join on 1.9. See bug #1732
+ it "returns a string which would be infected with taint of the array, its elements or the separator when the array is not empty" do
+ @object.new("a", "b").send(@method, ":").tainted?.should == false
+ @object.new("a", "b").send(@method, ":".taint).tainted?.should == true
+ @object.new("a", "b").taint.send(@method, ":").tainted?.should == true
+ @object.new("a", "b").taint.send(@method, ":".taint).tainted?.should == true
+ @object.new("a", "b".taint).send(@method, ":").tainted?.should == true
+ @object.new("a", "b".taint).send(@method, ":".taint).tainted?.should == true
+ @object.new("a", "b".taint).taint.send(@method, ":").tainted?.should == true
+ @object.new("a", "b".taint).taint.send(@method, ":".taint).tainted?.should == true
+ @object.new("a".taint, "b").send(@method, ":").tainted?.should == true
+ @object.new("a".taint, "b").send(@method, ":".taint).tainted?.should == true
+ @object.new("a".taint, "b").taint.send(@method, ":").tainted?.should == true
+ @object.new("a".taint, "b").taint.send(@method, ":".taint).tainted?.should == true
+ @object.new("a".taint, "b".taint).send(@method, ":").tainted?.should == true
+ @object.new("a".taint, "b".taint).send(@method, ":".taint).tainted?.should == true
+ @object.new("a".taint, "b".taint).taint.send(@method, ":").tainted?.should == true
+ @object.new("a".taint, "b".taint).taint.send(@method, ":".taint).tainted?.should == true
+ end
+
+ ruby_version_is '1.9' do
+ it "does not consider untrustworthiness of either the array or the separator when the array is empty" do
+ @object.new.send(@method, ":").untrusted?.should == false
+ @object.new.untrust.send(@method, ":").untrusted?.should == false
+ @object.new.send(@method, ":".untrust).untrusted?.should == false
+ @object.new.untrust.send(@method, ":".untrust).untrusted?.should == false
+ end
+
+ # This doesn't work for Enumerable#join on 1.9. See bug #1732
+ it "returns a string which would be infected with untrustworthiness of the array, its elements or the separator when the array is not empty" do
+ @object.new("a", "b").send(@method, ":").untrusted?.should == false
+ @object.new("a", "b").send(@method, ":".untrust).untrusted?.should == true
+ @object.new("a", "b").untrust.send(@method, ":").untrusted?.should == true
+ @object.new("a", "b").untrust.send(@method, ":".untrust).untrusted?.should == true
+ @object.new("a", "b".untrust).send(@method, ":").untrusted?.should == true
+ @object.new("a", "b".untrust).send(@method, ":".untrust).untrusted?.should == true
+ @object.new("a", "b".untrust).untrust.send(@method, ":").untrusted?.should == true
+ @object.new("a", "b".untrust).untrust.send(@method, ":".untrust).untrusted?.should == true
+ @object.new("a".untrust, "b").send(@method, ":").untrusted?.should == true
+ @object.new("a".untrust, "b").send(@method, ":".untrust).untrusted?.should == true
+ @object.new("a".untrust, "b").untrust.send(@method, ":").untrusted?.should == true
+ @object.new("a".untrust, "b").untrust.send(@method, ":".untrust).untrusted?.should == true
+ @object.new("a".untrust, "b".untrust).send(@method, ":").untrusted?.should == true
+ @object.new("a".untrust, "b".untrust).send(@method, ":".untrust).untrusted?.should == true
+ @object.new("a".untrust, "b".untrust).untrust.send(@method, ":").untrusted?.should == true
+ @object.new("a".untrust, "b".untrust).untrust.send(@method, ":".untrust).untrusted?.should == true
+ end
+ end
+end
Added: MacRuby/branches/experimental/spec/frozen/shared/complex/Complex.rb
===================================================================
--- MacRuby/branches/experimental/spec/frozen/shared/complex/Complex.rb (rev 0)
+++ MacRuby/branches/experimental/spec/frozen/shared/complex/Complex.rb 2009-08-02 13:12:21 UTC (rev 2147)
@@ -0,0 +1,76 @@
+require File.dirname(__FILE__) + '/../../spec_helper'
+
+describe :complex_Complex_complex_complex, :shared => true do
+ it "returns a new Complex number based on the two given numbers" do
+ Complex(Complex(3, 4), Complex(5, 6)).should == Complex(3 - 6, 4 + 5)
+ Complex(Complex(1.5, 2), Complex(-5, 6.3)).should == Complex(1.5 - 6.3, 2 - 5)
+ end
+end
+
+describe :complex_Complex_complex, :shared => true do
+ it "returns the passed Complex number" do
+ Complex(Complex(1, 2)).should == Complex(1, 2)
+ Complex(Complex(-3.4, bignum_value)).should == Complex(-3.4, bignum_value)
+ end
+end
+
+describe :complex_Complex_integer_integer, :shared => true do
+ it "returns a new Complex number" do
+ Complex(1, 2).should be_an_instance_of(Complex)
+ Complex(1, 2).real.should == 1
+ Complex(1, 2).imag.should == 2
+
+ Complex(-3, -5).should be_an_instance_of(Complex)
+ Complex(-3, -5).real.should == -3
+ Complex(-3, -5).imag.should == -5
+
+ Complex(3.5, -4.5).should be_an_instance_of(Complex)
+ Complex(3.5, -4.5).real.should == 3.5
+ Complex(3.5, -4.5).imag.should == -4.5
+
+ Complex(bignum_value, 30).should be_an_instance_of(Complex)
+ Complex(bignum_value, 30).real.should == bignum_value
+ Complex(bignum_value, 30).imag.should == 30
+ end
+end
+
+describe :complex_Complex_integer, :shared => true do
+ it "returns a new Complex number with 0 as the imaginary component" do
+ # Guard against the Mathn library
+ conflicts_with :Prime do
+ Complex(1).should be_an_instance_of(Complex)
+ Complex(1).imag.should == 0
+ Complex(1).real.should == 1
+
+ Complex(-3).should be_an_instance_of(Complex)
+ Complex(-3).imag.should == 0
+ Complex(-3).real.should == -3
+
+ Complex(-4.5).should be_an_instance_of(Complex)
+ Complex(-4.5).imag.should == 0
+ Complex(-4.5).real.should == -4.5
+
+ Complex(bignum_value).should be_an_instance_of(Complex)
+ Complex(bignum_value).imag.should == 0
+ Complex(bignum_value).real.should == bignum_value
+ end
+ end
+
+ ruby_version_is ""..."1.9" do
+ it "returns the passed Integer when Complex::Unify is defined" do
+ # Guard against the Mathn library
+ conflicts_with :Prime do
+ begin
+ Complex::Unify = true
+
+ Complex(1).should eql(1)
+ Complex(-3).should eql(-3)
+ Complex(-4.5).should eql(-4.5)
+ Complex(bignum_value).should eql(bignum_value)
+ ensure
+ Complex.send :remove_const, :Unify
+ end
+ end
+ end
+ end
+end
Modified: MacRuby/branches/experimental/spec/frozen/shared/complex/equal_value.rb
===================================================================
--- MacRuby/branches/experimental/spec/frozen/shared/complex/equal_value.rb 2009-08-02 08:57:05 UTC (rev 2146)
+++ MacRuby/branches/experimental/spec/frozen/shared/complex/equal_value.rb 2009-08-02 13:12:21 UTC (rev 2147)
@@ -21,11 +21,13 @@
Complex(bignum_value, 2.5).should == Complex(bignum_value, 2.5)
Complex(3.75, bignum_value).should_not == Complex(1.5, bignum_value)
+
+ Complex(nan_value).should_not == Complex(nan_value)
end
end
describe :complex_equal_value_numeric, :shared => true do
- it "returns true when self's imaginery part is 0 and the real part and other have numerical equality" do
+ it "returns true when self's imaginary part is 0 and the real part and other have numerical equality" do
Complex(3, 0).should == 3
Complex(-3, 0).should == -3
Modified: MacRuby/branches/experimental/spec/frozen/shared/complex/exponent.rb
===================================================================
--- MacRuby/branches/experimental/spec/frozen/shared/complex/exponent.rb 2009-08-02 08:57:05 UTC (rev 2146)
+++ MacRuby/branches/experimental/spec/frozen/shared/complex/exponent.rb 2009-08-02 13:12:21 UTC (rev 2147)
@@ -28,6 +28,8 @@
(Complex(3, 4) ** 2.5).should be_close(Complex(-38.0, 41.0), TOLERANCE)
(Complex(3, 4) ** -2.5).should be_close(Complex(-0.01216, -0.01312), TOLERANCE)
+ (Complex(1) ** 1).should == Complex(1)
+
# NOTE: Takes way too long...
#(Complex(2, 1) ** bignum_value)
end
Added: MacRuby/branches/experimental/spec/frozen/shared/complex/hash.rb
===================================================================
--- MacRuby/branches/experimental/spec/frozen/shared/complex/hash.rb (rev 0)
+++ MacRuby/branches/experimental/spec/frozen/shared/complex/hash.rb 2009-08-02 13:12:21 UTC (rev 2147)
@@ -0,0 +1,16 @@
+require File.dirname(__FILE__) + '/../../spec_helper'
+
+describe :complex_hash, :shared => true do
+ # NOTE:
+ # On 1.8 Complex(2, 1).hash == Complex(1, 2).hash
+ # This can result in Bugs when using hash and
+ # other stuff that relies on #hash
+ it "should be static" do
+ Complex(1).hash.should == Complex(1).hash
+ Complex(1, 0).hash.should == Complex(1).hash
+ Complex(1, 1).hash.should == Complex(1, 1).hash
+
+ Complex(1, 2).hash.should_not == Complex(1, 1).hash
+ Complex(2, 1).hash.should_not == Complex(1, 1).hash
+ end
+end
Copied: MacRuby/branches/experimental/spec/frozen/shared/complex/image.rb (from rev 2146, MacRuby/branches/experimental/spec/frozen/library/complex/shared/image.rb)
===================================================================
--- MacRuby/branches/experimental/spec/frozen/shared/complex/image.rb (rev 0)
+++ MacRuby/branches/experimental/spec/frozen/shared/complex/image.rb 2009-08-02 13:12:21 UTC (rev 2147)
@@ -0,0 +1,10 @@
+require File.dirname(__FILE__) + '/../../spec_helper'
+
+describe :complex_image, :shared => true do
+ it "returns the imaginary part of self" do
+ Complex(1, 0).send(@method).should == 0
+ Complex(2, 1).send(@method).should == 1
+ Complex(6.7, 8.9).send(@method).should == 8.9
+ Complex(1, bignum_value).send(@method).should == bignum_value
+ end
+end
Added: MacRuby/branches/experimental/spec/frozen/shared/complex/inspect.rb
===================================================================
--- MacRuby/branches/experimental/spec/frozen/shared/complex/inspect.rb (rev 0)
+++ MacRuby/branches/experimental/spec/frozen/shared/complex/inspect.rb 2009-08-02 13:12:21 UTC (rev 2147)
@@ -0,0 +1,29 @@
+describe :complex_inspect, :shared => true do
+ ruby_version_is ""..."1.9" do
+ it "returns Complex(real, image)" do
+ # Guard against the Mathn library
+ conflicts_with :Prime do
+ Complex(1).inspect.should == "Complex(1, 0)"
+ Complex(7).inspect.should == "Complex(7, 0)"
+ end
+
+ Complex(-1, 4).inspect.should == "Complex(-1, 4)"
+ Complex(-7, 6.7).inspect.should == "Complex(-7, 6.7)"
+ end
+ end
+
+ ruby_version_is "1.9" do
+ it "returns (${real}+${image}i) for positive imaginary parts" do
+ Complex(1).inspect.should == "(1+0i)"
+ Complex(7).inspect.should == "(7+0i)"
+ Complex(-1, 4).inspect.should == "(-1+4i)"
+ Complex(-7, 6.7).inspect.should == "(-7+6.7i)"
+ end
+
+ it "returns (${real}-${image}i) for negative imaginary parts" do
+ Complex(0, -1).inspect.should == "(0-1i)"
+ Complex(-1, -4).inspect.should == "(-1-4i)"
+ Complex(-7, -6.7).inspect.should == "(-7-6.7i)"
+ end
+ end
+end
Added: MacRuby/branches/experimental/spec/frozen/shared/complex/minus.rb
===================================================================
--- MacRuby/branches/experimental/spec/frozen/shared/complex/minus.rb (rev 0)
+++ MacRuby/branches/experimental/spec/frozen/shared/complex/minus.rb 2009-08-02 13:12:21 UTC (rev 2147)
@@ -0,0 +1,25 @@
+require File.dirname(__FILE__) + '/../../spec_helper'
+
+describe :complex_minus_complex, :shared => true do
+ it "subtracts both the real and imaginary components" do
+ (Complex(1, 2) - Complex(10, 20)).should == Complex(1 - 10, 2 - 20)
+ (Complex(1.5, 2.1) - Complex(100.2, -30.3)).should == Complex(1.5 - 100.2, 2.1 - (-30.3))
+ end
+end
+
+describe :complex_minus_integer, :shared => true do
+ it "subtracts the real number from the real component of self" do
+ (Complex(1, 2) - 50).should == Complex(-49, 2)
+ (Complex(1, 2) - 50.5).should == Complex(-49.5, 2)
+ end
+end
+
+describe :complex_minus_object, :shared => true do
+ it "tries to coerce self into other" do
+ value = Complex(3, 9)
+
+ obj = mock("Object")
+ obj.should_receive(:coerce).with(value).and_return([2, 5])
+ (value - obj).should == 2 - 5
+ end
+end
Copied: MacRuby/branches/experimental/spec/frozen/shared/complex/numeric/arg.rb (from rev 2146, MacRuby/branches/experimental/spec/frozen/core/numeric/shared/phase.rb)
===================================================================
--- MacRuby/branches/experimental/spec/frozen/shared/complex/numeric/arg.rb (rev 0)
+++ MacRuby/branches/experimental/spec/frozen/shared/complex/numeric/arg.rb 2009-08-02 13:12:21 UTC (rev 2147)
@@ -0,0 +1,43 @@
+require File.dirname(__FILE__) + '/../../../spec_helper'
+
+describe :numeric_arg, :shared => true do
+ before(:each) do
+ @numbers = [
+ 20, # Integer
+ 398.72, # Float
+ Rational(3, 4), # Rational
+ 99999999**99, # Bignum
+ Float::MAX * 2, # Infinity
+ ]
+ end
+
+ it "returns 0 if positive" do
+ @numbers.each do |number|
+ number.send(@method).should == 0
+ end
+ end
+
+ ruby_bug "#1715", "1.8.6.369" do
+ it "returns NaN if self is NaN" do
+ (-nan_value).send(@method).nan?.should be_true
+ nan_value.send(@method).nan?.should be_true
+ end
+ end
+
+ it "returns Pi if negative" do
+ @numbers.each do |number|
+ (0-number).send(@method).should == Math::PI
+ end
+ end
+
+ # This was established in r23960
+ it "returns Pi if -0.0" do
+ (-0.0).send(@method).should == Math::PI
+ end
+
+ it "raises an ArgumentError if given any arguments" do
+ @numbers.each do |number|
+ lambda { number.send(@method, number) }.should raise_error(ArgumentError)
+ end
+ end
+end
Copied: MacRuby/branches/experimental/spec/frozen/shared/complex/numeric/conj.rb (from rev 2146, MacRuby/branches/experimental/spec/frozen/core/numeric/shared/conj.rb)
===================================================================
--- MacRuby/branches/experimental/spec/frozen/shared/complex/numeric/conj.rb (rev 0)
+++ MacRuby/branches/experimental/spec/frozen/shared/complex/numeric/conj.rb 2009-08-02 13:12:21 UTC (rev 2147)
@@ -0,0 +1,26 @@
+require File.dirname(__FILE__) + '/../../../spec_helper'
+
+describe :numeric_conj, :shared => true do
+ before(:each) do
+ @numbers = [
+ 20, # Integer
+ 398.72, # Float
+ Rational(3, 4), # Rational
+ 99999999**99, # Bignum
+ Float::MAX * 2, # Infinity
+ 0/0.0 # NaN
+ ]
+ end
+
+ it "returns self" do
+ @numbers.each do |number|
+ number.send(@method).to_s.should == number.to_s
+ end
+ end
+
+ it "raises an ArgumentError if given any arguments" do
+ @numbers.each do |number|
+ lambda { number.send(@method, number) }.should raise_error(ArgumentError)
+ end
+ end
+end
Copied: MacRuby/branches/experimental/spec/frozen/shared/complex/numeric/imag.rb (from rev 2146, MacRuby/branches/experimental/spec/frozen/core/numeric/shared/imag.rb)
===================================================================
--- MacRuby/branches/experimental/spec/frozen/shared/complex/numeric/imag.rb (rev 0)
+++ MacRuby/branches/experimental/spec/frozen/shared/complex/numeric/imag.rb 2009-08-02 13:12:21 UTC (rev 2147)
@@ -0,0 +1,26 @@
+require File.dirname(__FILE__) + '/../../../spec_helper'
+
+describe :numeric_imag, :shared => true do
+ before(:each) do
+ @numbers = [
+ 20, # Integer
+ 398.72, # Float
+ Rational(3, 4), # Rational
+ bignum_value, # Bignum
+ Float::MAX * 2, # Infinity
+ 0/0.0 # NaN
+ ].map{|n| [n,-n]}.flatten
+ end
+
+ it "returns 0" do
+ @numbers.each do |number|
+ number.send(@method).should == 0
+ end
+ end
+
+ it "raises an ArgumentError if given any arguments" do
+ @numbers.each do |number|
+ lambda { number.send(@method, number) }.should raise_error(ArgumentError)
+ end
+ end
+end
Added: MacRuby/branches/experimental/spec/frozen/shared/complex/numeric/polar.rb
===================================================================
--- MacRuby/branches/experimental/spec/frozen/shared/complex/numeric/polar.rb (rev 0)
+++ MacRuby/branches/experimental/spec/frozen/shared/complex/numeric/polar.rb 2009-08-02 13:12:21 UTC (rev 2147)
@@ -0,0 +1,52 @@
+require File.dirname(__FILE__) + '/../../../spec_helper'
+
+describe :numeric_polar, :shared => true do
+ before(:each) do
+ @pos_numbers = [
+ 1,
+ 3898172610**9,
+ 987.18273,
+ Float::MAX,
+ Rational(13,7),
+ 1/0.0,
+ ]
+ @neg_numbers = @pos_numbers.map {|n| -n}
+ @numbers = @pos_numbers + @neg_numbers
+ @numbers.push(0, 0.0)
+ end
+
+ it "returns a two-element Array" do
+ @numbers.each do |number|
+ number.polar.should be_an_instance_of(Array)
+ number.polar.size.should == 2
+ end
+ end
+
+ it "sets the first value to the absolute value of self" do
+ @numbers.each do |number|
+ number.polar.first.should == number.abs
+ end
+ end
+
+ it "sets the last value to 0 if self is positive" do
+ (@numbers - @neg_numbers).each do |number|
+ number.should >= 0
+ number.polar.last.should == 0
+ end
+ end
+
+ it "sets the last value to Pi if self is negative" do
+ @neg_numbers.each do |number|
+ number.should < 0
+ number.polar.last.should == Math::PI
+ end
+ end
+
+ ruby_bug "#1715", "1.8.6.369" do
+ it "returns [NaN, NaN] if self is NaN" do
+ nan_value.polar.size.should == 2
+ nan_value.polar.first.nan?.should be_true
+ nan_value.polar.last.nan?.should be_true
+ end
+ end
+end
Copied: MacRuby/branches/experimental/spec/frozen/shared/complex/numeric/real.rb (from rev 2146, MacRuby/branches/experimental/spec/frozen/core/numeric/shared/conj.rb)
===================================================================
--- MacRuby/branches/experimental/spec/frozen/shared/complex/numeric/real.rb (rev 0)
+++ MacRuby/branches/experimental/spec/frozen/shared/complex/numeric/real.rb 2009-08-02 13:12:21 UTC (rev 2147)
@@ -0,0 +1,30 @@
+require File.dirname(__FILE__) + '/../../../spec_helper'
+
+describe :numeric_real, :shared => true do
+ before(:each) do
+ @numbers = [
+ 20, # Integer
+ 398.72, # Float
+ Rational(3, 4), # Rational
+ bignum_value, # Bignum
+ Float::MAX * 2, # Infinity
+ 0/0.0 # NaN
+ ].map{|n| [n,-n]}.flatten
+ end
+
+ it "returns self" do
+ @numbers.each do |number|
+ if number.to_f.nan?
+ number.real.nan?.should be_true
+ else
+ number.real.should == number
+ end
+ end
+ end
+
+ it "raises an ArgumentError if given any arguments" do
+ @numbers.each do |number|
+ lambda { number.real(number) }.should raise_error(ArgumentError)
+ end
+ end
+end
Added: MacRuby/branches/experimental/spec/frozen/tags/1.9/core/enumerable/join_tags.txt
===================================================================
--- MacRuby/branches/experimental/spec/frozen/tags/1.9/core/enumerable/join_tags.txt (rev 0)
+++ MacRuby/branches/experimental/spec/frozen/tags/1.9/core/enumerable/join_tags.txt 2009-08-02 13:12:21 UTC (rev 2147)
@@ -0,0 +1,5 @@
+fails:Enumerable#join handles recursive arrays
+fails:Enumerable#join returns a string which would be infected with taint of the array, its elements or the separator when the array is not empty
+fails:Enumerable#join returns a string which would be infected with untrustworthiness of the array, its elements or the separator when the array is not empty
+fails:Enumerable#join uses the same separator with nested arrays
+fails:Enumerable#join tries to convert the passed separator to a String using #to_str
Deleted: MacRuby/branches/experimental/spec/frozen/tags/1.9/core/hash/element_reference_tags.txt
===================================================================
--- MacRuby/branches/experimental/spec/frozen/tags/1.9/core/hash/element_reference_tags.txt 2009-08-02 08:57:05 UTC (rev 2146)
+++ MacRuby/branches/experimental/spec/frozen/tags/1.9/core/hash/element_reference_tags.txt 2009-08-02 13:12:21 UTC (rev 2147)
@@ -1 +0,0 @@
-fails:Hash#[] compares key via hash
Modified: MacRuby/branches/experimental/spec/frozen/tags/1.9/core/io/reopen_tags.txt
===================================================================
--- MacRuby/branches/experimental/spec/frozen/tags/1.9/core/io/reopen_tags.txt 2009-08-02 08:57:05 UTC (rev 2146)
+++ MacRuby/branches/experimental/spec/frozen/tags/1.9/core/io/reopen_tags.txt 2009-08-02 13:12:21 UTC (rev 2147)
@@ -1,2 +1,2 @@
-fails:IO#reopen reassociates self with the I/O stream specified as an argument, after some reads
-fails:IO#reopen reassociates self with new a new stream after some reads
+bug(1755):IO#reopen reassociates self with the I/O stream specified as an argument, after some reads
+bug(1755):IO#reopen reassociates self with a new stream after some reads
Deleted: MacRuby/branches/experimental/spec/frozen/tags/1.9/core/kernel/caller_tags.txt
===================================================================
--- MacRuby/branches/experimental/spec/frozen/tags/1.9/core/kernel/caller_tags.txt 2009-08-02 08:57:05 UTC (rev 2146)
+++ MacRuby/branches/experimental/spec/frozen/tags/1.9/core/kernel/caller_tags.txt 2009-08-02 13:12:21 UTC (rev 2147)
@@ -1,7 +0,0 @@
-fails:Kernel#caller in a Proc or eval returns the definition trace of a block when evaluated in a Proc binding
-fails:Kernel#caller in a Proc or eval returns the definition trace of a Proc
-fails:Kernel#caller in a Proc or eval returns the correct caller line from a called Proc
-fails:Kernel#caller in a Proc or eval returns the correct definition line for a complex Proc trace
-fails:Kernel#caller in a Proc or eval begins with (eval) for caller(0) in eval
-fails:Kernel#caller in a Proc or eval begins with the eval's sender's sender for caller(1) in eval
-fails:Kernel#caller in a Proc or eval shows the current line in the calling block twice when evaled
Modified: MacRuby/branches/experimental/spec/frozen/tags/1.9/core/kernel/freeze_tags.txt
===================================================================
--- MacRuby/branches/experimental/spec/frozen/tags/1.9/core/kernel/freeze_tags.txt 2009-08-02 08:57:05 UTC (rev 2146)
+++ MacRuby/branches/experimental/spec/frozen/tags/1.9/core/kernel/freeze_tags.txt 2009-08-02 13:12:21 UTC (rev 2147)
@@ -1 +1 @@
-fails:Kernel#freeze has no effect on immediate values
+bug:Kernel#freeze has no effect on immediate values
Modified: MacRuby/branches/experimental/spec/frozen/tags/1.9/core/kernel/puts_tags.txt
===================================================================
--- MacRuby/branches/experimental/spec/frozen/tags/1.9/core/kernel/puts_tags.txt 2009-08-02 08:57:05 UTC (rev 2146)
+++ MacRuby/branches/experimental/spec/frozen/tags/1.9/core/kernel/puts_tags.txt 2009-08-02 13:12:21 UTC (rev 2147)
@@ -1 +1 @@
-fails:Kernel#puts writes nil with a newline when given nil as an arg
+bug:Kernel#puts writes nil with a newline when given nil as an arg
Deleted: MacRuby/branches/experimental/spec/frozen/tags/1.9/core/module/attr_writer_tags.txt
===================================================================
--- MacRuby/branches/experimental/spec/frozen/tags/1.9/core/module/attr_writer_tags.txt 2009-08-02 08:57:05 UTC (rev 2146)
+++ MacRuby/branches/experimental/spec/frozen/tags/1.9/core/module/attr_writer_tags.txt 2009-08-02 13:12:21 UTC (rev 2147)
@@ -1 +0,0 @@
-fails:Module#attr_writer creates a setter for an attribute name given as a Fixnum
Deleted: MacRuby/branches/experimental/spec/frozen/tags/1.9/core/module/autoload_tags.txt
===================================================================
--- MacRuby/branches/experimental/spec/frozen/tags/1.9/core/module/autoload_tags.txt 2009-08-02 08:57:05 UTC (rev 2146)
+++ MacRuby/branches/experimental/spec/frozen/tags/1.9/core/module/autoload_tags.txt 2009-08-02 13:12:21 UTC (rev 2147)
@@ -1,6 +0,0 @@
-fails:Module#autoload with constant enumeration or removal doesn't trigger file load
-fails:Module#autoload autoloaded constants are removed on the first access
-fails:Module#autoload raises a NameError when the autoload file did not define the constant and a module is opened with the same name
-critical:Module#autoload does not remove the constant from the constant table if the loaded files does not define it
-critical:Module#autoload does not load the file when refering to the constant in defined?
-critical:Module#autoload shares the autoload request across dup'ed copies of modules
Deleted: MacRuby/branches/experimental/spec/frozen/tags/1.9/core/module/class_eval_tags.txt
===================================================================
--- MacRuby/branches/experimental/spec/frozen/tags/1.9/core/module/class_eval_tags.txt 2009-08-02 08:57:05 UTC (rev 2146)
+++ MacRuby/branches/experimental/spec/frozen/tags/1.9/core/module/class_eval_tags.txt 2009-08-02 13:12:21 UTC (rev 2147)
@@ -1 +0,0 @@
-fails:Module#class_eval shares a scope across sibling evals
Deleted: MacRuby/branches/experimental/spec/frozen/tags/1.9/core/module/class_variable_defined_tags.txt
===================================================================
--- MacRuby/branches/experimental/spec/frozen/tags/1.9/core/module/class_variable_defined_tags.txt 2009-08-02 08:57:05 UTC (rev 2146)
+++ MacRuby/branches/experimental/spec/frozen/tags/1.9/core/module/class_variable_defined_tags.txt 2009-08-02 13:12:21 UTC (rev 2147)
@@ -1 +0,0 @@
-fails:Module#class_variable_defined? accepts Fixnums for class variables
Deleted: MacRuby/branches/experimental/spec/frozen/tags/1.9/core/module/class_variable_get_tags.txt
===================================================================
--- MacRuby/branches/experimental/spec/frozen/tags/1.9/core/module/class_variable_get_tags.txt 2009-08-02 08:57:05 UTC (rev 2146)
+++ MacRuby/branches/experimental/spec/frozen/tags/1.9/core/module/class_variable_get_tags.txt 2009-08-02 13:12:21 UTC (rev 2147)
@@ -1 +0,0 @@
-fails:Module#class_variable_get accepts Fixnums for class variables
Deleted: MacRuby/branches/experimental/spec/frozen/tags/1.9/core/module/class_variable_set_tags.txt
===================================================================
--- MacRuby/branches/experimental/spec/frozen/tags/1.9/core/module/class_variable_set_tags.txt 2009-08-02 08:57:05 UTC (rev 2146)
+++ MacRuby/branches/experimental/spec/frozen/tags/1.9/core/module/class_variable_set_tags.txt 2009-08-02 13:12:21 UTC (rev 2147)
@@ -1,2 +0,0 @@
-fails:Module#class_variable_set accepts Fixnums for class variables
-fails:Module#class_variable_set raises a TypeError when self is frozen
Deleted: MacRuby/branches/experimental/spec/frozen/tags/1.9/core/module/class_variables_tags.txt
===================================================================
--- MacRuby/branches/experimental/spec/frozen/tags/1.9/core/module/class_variables_tags.txt 2009-08-02 08:57:05 UTC (rev 2146)
+++ MacRuby/branches/experimental/spec/frozen/tags/1.9/core/module/class_variables_tags.txt 2009-08-02 13:12:21 UTC (rev 2147)
@@ -1,3 +0,0 @@
-fails:Module#class_variables returns an Array with the names of class variables of self and self's ancestors
-fails:Module#class_variables returns an Array with names of class variables defined in metaclasses
-fails:Module#class_variables returns an Array with names of class variables defined in included modules
Deleted: MacRuby/branches/experimental/spec/frozen/tags/1.9/core/module/const_defined_tags.txt
===================================================================
--- MacRuby/branches/experimental/spec/frozen/tags/1.9/core/module/const_defined_tags.txt 2009-08-02 08:57:05 UTC (rev 2146)
+++ MacRuby/branches/experimental/spec/frozen/tags/1.9/core/module/const_defined_tags.txt 2009-08-02 13:12:21 UTC (rev 2147)
@@ -1 +0,0 @@
-fails:Module#const_defined? returns false if the constant is not defined in the receiver
Deleted: MacRuby/branches/experimental/spec/frozen/tags/1.9/core/module/const_missing_tags.txt
===================================================================
--- MacRuby/branches/experimental/spec/frozen/tags/1.9/core/module/const_missing_tags.txt 2009-08-02 08:57:05 UTC (rev 2146)
+++ MacRuby/branches/experimental/spec/frozen/tags/1.9/core/module/const_missing_tags.txt 2009-08-02 13:12:21 UTC (rev 2147)
@@ -1,2 +0,0 @@
-fails:Module#const_missing is called when an undefined constant is referenced via literal form
-fails:Module#const_missing is called when an undefined constant is referenced via #const_get
Deleted: MacRuby/branches/experimental/spec/frozen/tags/1.9/core/module/define_method_tags.txt
===================================================================
--- MacRuby/branches/experimental/spec/frozen/tags/1.9/core/module/define_method_tags.txt 2009-08-02 08:57:05 UTC (rev 2146)
+++ MacRuby/branches/experimental/spec/frozen/tags/1.9/core/module/define_method_tags.txt 2009-08-02 13:12:21 UTC (rev 2147)
@@ -1 +0,0 @@
-fails:Module#define_method when given an UnboundMethod adds the new method to the methods list
Deleted: MacRuby/branches/experimental/spec/frozen/tags/1.9/core/module/freeze_tags.txt
===================================================================
--- MacRuby/branches/experimental/spec/frozen/tags/1.9/core/module/freeze_tags.txt 2009-08-02 08:57:05 UTC (rev 2146)
+++ MacRuby/branches/experimental/spec/frozen/tags/1.9/core/module/freeze_tags.txt 2009-08-02 13:12:21 UTC (rev 2147)
@@ -1 +0,0 @@
-fails:Module#freeze prevents further modifications to self
Deleted: MacRuby/branches/experimental/spec/frozen/tags/1.9/core/module/include_tags.txt
===================================================================
--- MacRuby/branches/experimental/spec/frozen/tags/1.9/core/module/include_tags.txt 2009-08-02 08:57:05 UTC (rev 2146)
+++ MacRuby/branches/experimental/spec/frozen/tags/1.9/core/module/include_tags.txt 2009-08-02 13:12:21 UTC (rev 2147)
@@ -1,3 +0,0 @@
-fails:Module#include imports constants to modules and classes
-fails:Module#include imports instance methods to modules and classes
-fails:Module#include does not import methods to modules and classes
Deleted: MacRuby/branches/experimental/spec/frozen/tags/1.9/core/module/instance_methods_tags.txt
===================================================================
--- MacRuby/branches/experimental/spec/frozen/tags/1.9/core/module/instance_methods_tags.txt 2009-08-02 08:57:05 UTC (rev 2146)
+++ MacRuby/branches/experimental/spec/frozen/tags/1.9/core/module/instance_methods_tags.txt 2009-08-02 13:12:21 UTC (rev 2147)
@@ -1,2 +0,0 @@
-fails:Module#instance_methods returns an array containing the public and protected methods of self if include_super is false
-fails:Module#instance_methods returns an array containing the public and protected methods of self and it's ancestors
Deleted: MacRuby/branches/experimental/spec/frozen/tags/1.9/core/module/module_eval_tags.txt
===================================================================
--- MacRuby/branches/experimental/spec/frozen/tags/1.9/core/module/module_eval_tags.txt 2009-08-02 08:57:05 UTC (rev 2146)
+++ MacRuby/branches/experimental/spec/frozen/tags/1.9/core/module/module_eval_tags.txt 2009-08-02 13:12:21 UTC (rev 2147)
@@ -1 +0,0 @@
-fails:Module#module_eval shares a scope across sibling evals
Deleted: MacRuby/branches/experimental/spec/frozen/tags/1.9/core/module/name_tags.txt
===================================================================
--- MacRuby/branches/experimental/spec/frozen/tags/1.9/core/module/name_tags.txt 2009-08-02 08:57:05 UTC (rev 2146)
+++ MacRuby/branches/experimental/spec/frozen/tags/1.9/core/module/name_tags.txt 2009-08-02 13:12:21 UTC (rev 2147)
@@ -1 +0,0 @@
-fails:Module#name returns the name of self
Deleted: MacRuby/branches/experimental/spec/frozen/tags/1.9/core/module/private_method_defined_tags.txt
===================================================================
--- MacRuby/branches/experimental/spec/frozen/tags/1.9/core/module/private_method_defined_tags.txt 2009-08-02 08:57:05 UTC (rev 2146)
+++ MacRuby/branches/experimental/spec/frozen/tags/1.9/core/module/private_method_defined_tags.txt 2009-08-02 13:12:21 UTC (rev 2147)
@@ -1 +0,0 @@
-fails:Module#private_method_defined? raises an ArgumentError if passed a Fixnum
Deleted: MacRuby/branches/experimental/spec/frozen/tags/1.9/core/module/protected_instance_methods_tags.txt
===================================================================
--- MacRuby/branches/experimental/spec/frozen/tags/1.9/core/module/protected_instance_methods_tags.txt 2009-08-02 08:57:05 UTC (rev 2146)
+++ MacRuby/branches/experimental/spec/frozen/tags/1.9/core/module/protected_instance_methods_tags.txt 2009-08-02 13:12:21 UTC (rev 2147)
@@ -1,2 +0,0 @@
-fails:Module#protected_instance_methods returns a list of protected methods in module and its ancestors
-fails:Module#protected_instance_methods when passed false as a parameter, should return only methods defined in that module
Deleted: MacRuby/branches/experimental/spec/frozen/tags/1.9/core/module/protected_method_defined_tags.txt
===================================================================
--- MacRuby/branches/experimental/spec/frozen/tags/1.9/core/module/protected_method_defined_tags.txt 2009-08-02 08:57:05 UTC (rev 2146)
+++ MacRuby/branches/experimental/spec/frozen/tags/1.9/core/module/protected_method_defined_tags.txt 2009-08-02 13:12:21 UTC (rev 2147)
@@ -1 +0,0 @@
-fails:Module#protected_method_defined? raises an ArgumentError if passed a Fixnum
Deleted: MacRuby/branches/experimental/spec/frozen/tags/1.9/core/module/public_instance_methods_tags.txt
===================================================================
--- MacRuby/branches/experimental/spec/frozen/tags/1.9/core/module/public_instance_methods_tags.txt 2009-08-02 08:57:05 UTC (rev 2146)
+++ MacRuby/branches/experimental/spec/frozen/tags/1.9/core/module/public_instance_methods_tags.txt 2009-08-02 13:12:21 UTC (rev 2147)
@@ -1,2 +0,0 @@
-fails:Module#public_instance_methods returns a list of public methods in module and its ancestors
-fails:Module#public_instance_methods when passed false as a parameter, should return only methods defined in that module
Deleted: MacRuby/branches/experimental/spec/frozen/tags/1.9/core/module/public_method_defined_tags.txt
===================================================================
--- MacRuby/branches/experimental/spec/frozen/tags/1.9/core/module/public_method_defined_tags.txt 2009-08-02 08:57:05 UTC (rev 2146)
+++ MacRuby/branches/experimental/spec/frozen/tags/1.9/core/module/public_method_defined_tags.txt 2009-08-02 13:12:21 UTC (rev 2147)
@@ -1 +0,0 @@
-fails:Module#public_method_defined? raises an ArgumentError if called with a Fixnum
Deleted: MacRuby/branches/experimental/spec/frozen/tags/1.9/core/range/inspect_tags.txt
===================================================================
--- MacRuby/branches/experimental/spec/frozen/tags/1.9/core/range/inspect_tags.txt 2009-08-02 08:57:05 UTC (rev 2146)
+++ MacRuby/branches/experimental/spec/frozen/tags/1.9/core/range/inspect_tags.txt 2009-08-02 13:12:21 UTC (rev 2147)
@@ -1 +0,0 @@
-fails:Range#inspect provides a printable form, using #inspect to convert the start and end objects
Deleted: MacRuby/branches/experimental/spec/frozen/tags/1.9/core/range/to_s_tags.txt
===================================================================
--- MacRuby/branches/experimental/spec/frozen/tags/1.9/core/range/to_s_tags.txt 2009-08-02 08:57:05 UTC (rev 2146)
+++ MacRuby/branches/experimental/spec/frozen/tags/1.9/core/range/to_s_tags.txt 2009-08-02 13:12:21 UTC (rev 2147)
@@ -1 +0,0 @@
-fails:Range#to_s provides a printable form of self
Modified: MacRuby/branches/experimental/spec/frozen/upstream
===================================================================
--- MacRuby/branches/experimental/spec/frozen/upstream 2009-08-02 08:57:05 UTC (rev 2146)
+++ MacRuby/branches/experimental/spec/frozen/upstream 2009-08-02 13:12:21 UTC (rev 2147)
@@ -1 +1 @@
-8a452e68e5b045a20ce1964fa997f9d691316b1c
\ No newline at end of file
+f4a506d2e78447c34f1e1ac28b948a20532c8e67
\ No newline at end of file
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macosforge.org/pipermail/macruby-changes/attachments/20090802/06004fa3/attachment-0001.html>
More information about the macruby-changes
mailing list