[macruby-changes] [1957] MacRuby/branches/experimental/spec/frozen
source_changes at macosforge.org
source_changes at macosforge.org
Wed Jul 1 16:43:50 PDT 2009
Revision: 1957
http://trac.macosforge.org/projects/ruby/changeset/1957
Author: eloy.de.enige at gmail.com
Date: 2009-07-01 16:43:49 -0700 (Wed, 01 Jul 2009)
Log Message:
-----------
Updated RubySpec to 7e9a0d56fb3b981bf7985f313b0bd9c3e79e7e74
Modified Paths:
--------------
MacRuby/branches/experimental/spec/frozen/TODO
MacRuby/branches/experimental/spec/frozen/core/argf/binmode_spec.rb
MacRuby/branches/experimental/spec/frozen/core/argf/close_spec.rb
MacRuby/branches/experimental/spec/frozen/core/argf/rewind_spec.rb
MacRuby/branches/experimental/spec/frozen/core/array/fixtures/classes.rb
MacRuby/branches/experimental/spec/frozen/core/array/plus_spec.rb
MacRuby/branches/experimental/spec/frozen/core/array/product_spec.rb
MacRuby/branches/experimental/spec/frozen/core/array/sort_spec.rb
MacRuby/branches/experimental/spec/frozen/core/bignum/comparison_spec.rb
MacRuby/branches/experimental/spec/frozen/core/bignum/divmod_spec.rb
MacRuby/branches/experimental/spec/frozen/core/bignum/quo_spec.rb
MacRuby/branches/experimental/spec/frozen/core/bignum/remainder_spec.rb
MacRuby/branches/experimental/spec/frozen/core/bignum/shared/modulo.rb
MacRuby/branches/experimental/spec/frozen/core/bignum/size_spec.rb
MacRuby/branches/experimental/spec/frozen/core/builtin_constants/builtin_constants_spec.rb
MacRuby/branches/experimental/spec/frozen/core/class/new_spec.rb
MacRuby/branches/experimental/spec/frozen/core/class/superclass_spec.rb
MacRuby/branches/experimental/spec/frozen/core/complex/rect_spec.rb
MacRuby/branches/experimental/spec/frozen/core/complex/rectangular_spec.rb
MacRuby/branches/experimental/spec/frozen/core/dir/chroot_spec.rb
MacRuby/branches/experimental/spec/frozen/core/encoding/aliases_spec.rb
MacRuby/branches/experimental/spec/frozen/core/encoding/compatible_spec.rb
MacRuby/branches/experimental/spec/frozen/core/encoding/converter/asciicompat_encoding_spec.rb
MacRuby/branches/experimental/spec/frozen/core/encoding/converter/convert_spec.rb
MacRuby/branches/experimental/spec/frozen/core/encoding/converter/convpath_spec.rb
MacRuby/branches/experimental/spec/frozen/core/encoding/converter/destination_encoding_spec.rb
MacRuby/branches/experimental/spec/frozen/core/encoding/converter/finish_spec.rb
MacRuby/branches/experimental/spec/frozen/core/encoding/converter/last_error_spec.rb
MacRuby/branches/experimental/spec/frozen/core/encoding/converter/primitive_convert_spec.rb
MacRuby/branches/experimental/spec/frozen/core/encoding/converter/primitive_errinfo_spec.rb
MacRuby/branches/experimental/spec/frozen/core/encoding/converter/putback_spec.rb
MacRuby/branches/experimental/spec/frozen/core/encoding/converter/replacement_spec.rb
MacRuby/branches/experimental/spec/frozen/core/encoding/converter/search_convpath_spec.rb
MacRuby/branches/experimental/spec/frozen/core/encoding/converter/source_encoding_spec.rb
MacRuby/branches/experimental/spec/frozen/core/encoding/dummy_spec.rb
MacRuby/branches/experimental/spec/frozen/core/encoding/find_spec.rb
MacRuby/branches/experimental/spec/frozen/core/encoding/inspect_spec.rb
MacRuby/branches/experimental/spec/frozen/core/encoding/list_spec.rb
MacRuby/branches/experimental/spec/frozen/core/encoding/locale_charmap_spec.rb
MacRuby/branches/experimental/spec/frozen/core/encoding/name_list_spec.rb
MacRuby/branches/experimental/spec/frozen/core/encoding/name_spec.rb
MacRuby/branches/experimental/spec/frozen/core/encoding/names_spec.rb
MacRuby/branches/experimental/spec/frozen/core/encoding/to_s_spec.rb
MacRuby/branches/experimental/spec/frozen/core/enumerable/fixtures/classes.rb
MacRuby/branches/experimental/spec/frozen/core/enumerable/shared/take.rb
MacRuby/branches/experimental/spec/frozen/core/enumerable/sort_spec.rb
MacRuby/branches/experimental/spec/frozen/core/exception/backtrace_spec.rb
MacRuby/branches/experimental/spec/frozen/core/exception/exception_spec.rb
MacRuby/branches/experimental/spec/frozen/core/exception/fixtures/common.rb
MacRuby/branches/experimental/spec/frozen/core/float/comparison_spec.rb
MacRuby/branches/experimental/spec/frozen/core/float/numerator_spec.rb
MacRuby/branches/experimental/spec/frozen/core/hash/default_proc_spec.rb
MacRuby/branches/experimental/spec/frozen/core/integer/chr_spec.rb
MacRuby/branches/experimental/spec/frozen/core/io/eof_spec.rb
MacRuby/branches/experimental/spec/frozen/core/kernel/instance_variable_set_spec.rb
MacRuby/branches/experimental/spec/frozen/core/method/fixtures/classes.rb
MacRuby/branches/experimental/spec/frozen/core/numeric/denominator_spec.rb
MacRuby/branches/experimental/spec/frozen/core/numeric/numerator_spec.rb
MacRuby/branches/experimental/spec/frozen/core/numeric/real_spec.rb
MacRuby/branches/experimental/spec/frozen/core/numeric/shared/rect.rb
MacRuby/branches/experimental/spec/frozen/core/objectspace/define_finalizer_spec.rb
MacRuby/branches/experimental/spec/frozen/core/proc/arity_spec.rb
MacRuby/branches/experimental/spec/frozen/core/proc/new_spec.rb
MacRuby/branches/experimental/spec/frozen/core/proc/shared/call.rb
MacRuby/branches/experimental/spec/frozen/core/regexp/inspect_spec.rb
MacRuby/branches/experimental/spec/frozen/core/string/ascii_only_spec_disabled.rb
MacRuby/branches/experimental/spec/frozen/core/string/bytesize_spec_disabled.rb
MacRuby/branches/experimental/spec/frozen/core/string/dump_spec.rb
MacRuby/branches/experimental/spec/frozen/core/string/each_char_spec.rb
MacRuby/branches/experimental/spec/frozen/core/string/gsub_spec.rb
MacRuby/branches/experimental/spec/frozen/core/string/shared/each_line.rb
MacRuby/branches/experimental/spec/frozen/core/string/upto_spec.rb
MacRuby/branches/experimental/spec/frozen/core/struct/new_spec.rb
MacRuby/branches/experimental/spec/frozen/language/versions/method_1.9.rb
MacRuby/branches/experimental/spec/frozen/library/complex/abs2_spec.rb
MacRuby/branches/experimental/spec/frozen/library/complex/abs_spec.rb
MacRuby/branches/experimental/spec/frozen/library/complex/angle_spec.rb
MacRuby/branches/experimental/spec/frozen/library/complex/arg_spec.rb
MacRuby/branches/experimental/spec/frozen/library/complex/coerce_spec.rb
MacRuby/branches/experimental/spec/frozen/library/complex/comparison_spec.rb
MacRuby/branches/experimental/spec/frozen/library/complex/conj_spec.rb
MacRuby/branches/experimental/spec/frozen/library/complex/conjugate_spec.rb
MacRuby/branches/experimental/spec/frozen/library/complex/denominator_spec.rb
MacRuby/branches/experimental/spec/frozen/library/complex/divide_spec.rb
MacRuby/branches/experimental/spec/frozen/library/complex/equal_value_spec.rb
MacRuby/branches/experimental/spec/frozen/library/complex/exponent_spec.rb
MacRuby/branches/experimental/spec/frozen/shared/rational/div.rb
MacRuby/branches/experimental/spec/frozen/shared/rational/divmod.rb
MacRuby/branches/experimental/spec/frozen/shared/rational/exponent.rb
MacRuby/branches/experimental/spec/frozen/shared/rational/modulo.rb
MacRuby/branches/experimental/spec/frozen/upstream
Added Paths:
-----------
MacRuby/branches/experimental/spec/frozen/command_line/dash_upper_u_spec.rb
MacRuby/branches/experimental/spec/frozen/core/complex/abs2_spec.rb
MacRuby/branches/experimental/spec/frozen/core/complex/abs_spec.rb
MacRuby/branches/experimental/spec/frozen/core/complex/angle_spec.rb
MacRuby/branches/experimental/spec/frozen/core/complex/arg_spec.rb
MacRuby/branches/experimental/spec/frozen/core/complex/coerce_spec.rb
MacRuby/branches/experimental/spec/frozen/core/complex/conj_spec.rb
MacRuby/branches/experimental/spec/frozen/core/complex/conjugate_spec.rb
MacRuby/branches/experimental/spec/frozen/core/complex/denominator_spec.rb
MacRuby/branches/experimental/spec/frozen/core/complex/divide_spec.rb
MacRuby/branches/experimental/spec/frozen/core/complex/equal_value_spec.rb
MacRuby/branches/experimental/spec/frozen/core/complex/exponent_spec.rb
MacRuby/branches/experimental/spec/frozen/core/dir/exist_spec.rb
MacRuby/branches/experimental/spec/frozen/core/dir/exists_spec.rb
MacRuby/branches/experimental/spec/frozen/core/dir/shared/exists.rb
MacRuby/branches/experimental/spec/frozen/core/encoding/converter/constants_spec.rb
MacRuby/branches/experimental/spec/frozen/core/encoding/default_external_spec.rb
MacRuby/branches/experimental/spec/frozen/core/encoding/default_internal_spec.rb
MacRuby/branches/experimental/spec/frozen/core/encoding/fixtures/
MacRuby/branches/experimental/spec/frozen/core/encoding/fixtures/classes.rb
MacRuby/branches/experimental/spec/frozen/core/encoding/invalid_byte_sequence_error/
MacRuby/branches/experimental/spec/frozen/core/encoding/invalid_byte_sequence_error/destination_encoding_name_spec.rb
MacRuby/branches/experimental/spec/frozen/core/encoding/invalid_byte_sequence_error/destination_encoding_spec.rb
MacRuby/branches/experimental/spec/frozen/core/encoding/invalid_byte_sequence_error/error_bytes_spec.rb
MacRuby/branches/experimental/spec/frozen/core/encoding/invalid_byte_sequence_error/incomplete_input_spec.rb
MacRuby/branches/experimental/spec/frozen/core/encoding/invalid_byte_sequence_error/readagain_bytes_spec.rb
MacRuby/branches/experimental/spec/frozen/core/encoding/invalid_byte_sequence_error/source_encoding_name_spec.rb
MacRuby/branches/experimental/spec/frozen/core/encoding/invalid_byte_sequence_error/source_encoding_spec.rb
MacRuby/branches/experimental/spec/frozen/core/encoding/shared/
MacRuby/branches/experimental/spec/frozen/core/encoding/shared/name.rb
MacRuby/branches/experimental/spec/frozen/core/encoding/undefined_conversion_error/
MacRuby/branches/experimental/spec/frozen/core/encoding/undefined_conversion_error/destination_encoding_name_spec.rb
MacRuby/branches/experimental/spec/frozen/core/encoding/undefined_conversion_error/destination_encoding_spec.rb
MacRuby/branches/experimental/spec/frozen/core/encoding/undefined_conversion_error/error_char_spec.rb
MacRuby/branches/experimental/spec/frozen/core/encoding/undefined_conversion_error/source_encoding_name_spec.rb
MacRuby/branches/experimental/spec/frozen/core/encoding/undefined_conversion_error/source_encoding_spec.rb
MacRuby/branches/experimental/spec/frozen/core/exception/equal_value_spec.rb
MacRuby/branches/experimental/spec/frozen/core/io/codepoints.rb
MacRuby/branches/experimental/spec/frozen/core/io/each_codepoint.rb
MacRuby/branches/experimental/spec/frozen/core/io/shared/codepoints.rb
MacRuby/branches/experimental/spec/frozen/core/method/source_location_spec.rb
MacRuby/branches/experimental/spec/frozen/core/numeric/abs2_spec.rb
MacRuby/branches/experimental/spec/frozen/core/numeric/fdiv_spec.rb
MacRuby/branches/experimental/spec/frozen/core/string/chars_spec.rb
MacRuby/branches/experimental/spec/frozen/core/string/chr_spec.rb
MacRuby/branches/experimental/spec/frozen/core/string/clear_spec.rb
MacRuby/branches/experimental/spec/frozen/core/string/codepoints_spec.rb
MacRuby/branches/experimental/spec/frozen/core/string/each_codepoint_spec.rb
MacRuby/branches/experimental/spec/frozen/core/string/encoding_spec.rb
MacRuby/branches/experimental/spec/frozen/core/string/fixtures/iso-8859-9-encoding.rb
MacRuby/branches/experimental/spec/frozen/core/string/force_encoding_spec.rb
MacRuby/branches/experimental/spec/frozen/core/string/getbyte_spec.rb
MacRuby/branches/experimental/spec/frozen/core/string/lines_spec.rb
MacRuby/branches/experimental/spec/frozen/core/string/ord_spec.rb
MacRuby/branches/experimental/spec/frozen/core/string/setbyte_spec.rb
MacRuby/branches/experimental/spec/frozen/core/string/shared/chars.rb
MacRuby/branches/experimental/spec/frozen/core/string/shared/codepoints.rb
MacRuby/branches/experimental/spec/frozen/core/string/to_c_spec.rb
MacRuby/branches/experimental/spec/frozen/core/string/to_r_spec.rb
MacRuby/branches/experimental/spec/frozen/core/string/valid_encoding_spec.rb
MacRuby/branches/experimental/spec/frozen/library/stringio/codepoints.rb
MacRuby/branches/experimental/spec/frozen/library/stringio/each_codepoint.rb
MacRuby/branches/experimental/spec/frozen/library/stringio/shared/codepoints.rb
MacRuby/branches/experimental/spec/frozen/shared/complex/
MacRuby/branches/experimental/spec/frozen/shared/complex/abs.rb
MacRuby/branches/experimental/spec/frozen/shared/complex/abs2.rb
MacRuby/branches/experimental/spec/frozen/shared/complex/arg.rb
MacRuby/branches/experimental/spec/frozen/shared/complex/coerce.rb
MacRuby/branches/experimental/spec/frozen/shared/complex/conjugate.rb
MacRuby/branches/experimental/spec/frozen/shared/complex/denominator.rb
MacRuby/branches/experimental/spec/frozen/shared/complex/divide.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/shared/complex/rect.rb
Removed Paths:
-------------
MacRuby/branches/experimental/spec/frozen/core/complex/shared/rect.rb
MacRuby/branches/experimental/spec/frozen/core/encoding/converter/insert_output_spec.rb
MacRuby/branches/experimental/spec/frozen/core/encoding/converter/inspect_spec.rb
MacRuby/branches/experimental/spec/frozen/core/encoding/default_external_spec_disabled.rb
MacRuby/branches/experimental/spec/frozen/core/encoding/default_internal_spec_disabled.rb
MacRuby/branches/experimental/spec/frozen/library/complex/shared/arg.rb
MacRuby/branches/experimental/spec/frozen/library/complex/shared/conjugate.rb
Modified: MacRuby/branches/experimental/spec/frozen/TODO
===================================================================
--- MacRuby/branches/experimental/spec/frozen/TODO 2009-07-01 23:05:28 UTC (rev 1956)
+++ MacRuby/branches/experimental/spec/frozen/TODO 2009-07-01 23:43:49 UTC (rev 1957)
@@ -21,6 +21,8 @@
* Ascertain backport policy for 1.9.2 -> 1.9.1 -> 1.8.7. Are bug fixes merged
backwards by default, or is it all case by case? The answer will inform how
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.
# Windows
==========
@@ -47,3 +49,5 @@
* Unify treatment of bugs after conversation with brixen. Bugs that occur only
in 1.9 shouldn't be guarded; we just tag them with the bug number, e.g. " mspec
tag --add 'fails(#555)' -e 'the failing stuff' path/to/spec".
+* Ask Ruby core about what Array#pack should do to encoding; citing failing
+ tests as example questions.
Added: MacRuby/branches/experimental/spec/frozen/command_line/dash_upper_u_spec.rb
===================================================================
--- MacRuby/branches/experimental/spec/frozen/command_line/dash_upper_u_spec.rb (rev 0)
+++ MacRuby/branches/experimental/spec/frozen/command_line/dash_upper_u_spec.rb 2009-07-01 23:43:49 UTC (rev 1957)
@@ -0,0 +1,43 @@
+ruby_version_is "1.9" do
+ describe "ruby -U" do
+ it "sets Encoding.default_internal to UTF-8" do
+ ruby_exe('print Encoding.default_internal.name',
+ :options => '-U').should == 'UTF-8'
+ end
+
+ it "does nothing different if specified multiple times" do
+ ruby_exe('print Encoding.default_internal.name',
+ :options => '-U -U').should == 'UTF-8'
+ end
+
+ it "is overruled by Encoding.default_internal=" do
+ ruby_exe('Encoding.default_internal="ascii"; print Encoding.default_internal.name',
+ :options => '-U').should == 'US-ASCII'
+ end
+
+ it "does not affect the default external encoding" do
+ ruby_exe('Encoding.default_external="ascii"; print Encoding.default_external.name',
+ :options => '-U').should == 'US-ASCII'
+ end
+
+ it "does not affect the source encoding" do
+ ruby_exe("print __ENCODING__.name",
+ :options => '-U -KE').should == 'EUC-JP'
+ ruby_exe("print __ENCODING__.name",
+ :options => '-KE -U').should == 'EUC-JP'
+ end
+
+ # I assume IO redirection will break on Windows...
+ it "raises a RuntimeError if used with -Eext:int" do
+ ruby_exe("p 1",
+ :options => '-U -Eascii:ascii',
+ :args => '2>&1').should =~ /RuntimeError/
+ end
+
+ it "raises a RuntimeError if used with -E:int" do
+ ruby_exe("p 1",
+ :options => '-U -E:ascii',
+ :args => '2>&1').should =~ /RuntimeError/
+ end
+ end
+end
Modified: MacRuby/branches/experimental/spec/frozen/core/argf/binmode_spec.rb
===================================================================
--- MacRuby/branches/experimental/spec/frozen/core/argf/binmode_spec.rb 2009-07-01 23:05:28 UTC (rev 1956)
+++ MacRuby/branches/experimental/spec/frozen/core/argf/binmode_spec.rb 2009-07-01 23:43:49 UTC (rev 1957)
@@ -45,4 +45,16 @@
end
end
end
+
+ ruby_version_is "1.9" do
+ it "sets the file's encoding to ASCII-8BIT" do
+ argv [@bin_file, @file1] do
+ ARGF.binmode
+ ARGF.binmode?.should be_true
+ ARGF.gets.encoding.should == Encoding::ASCII_8BIT
+ ARGF.skip
+ ARGF.read.encoding.should == Encoding::ASCII_8BIT
+ end
+ end
+ end
end
Modified: MacRuby/branches/experimental/spec/frozen/core/argf/close_spec.rb
===================================================================
--- MacRuby/branches/experimental/spec/frozen/core/argf/close_spec.rb 2009-07-01 23:05:28 UTC (rev 1956)
+++ MacRuby/branches/experimental/spec/frozen/core/argf/close_spec.rb 2009-07-01 23:43:49 UTC (rev 1957)
@@ -24,10 +24,8 @@
end
end
- # This passes on 1.9, but fails on 1.8. matz claims to have fixed it in the
- # attached ticket. The actual exception raised may differ; this will need
- # checking.
- ruby_bug "#1633", "1.8" do
+ # This passes on 1.9 and 1.8 HEAD, but fails on 1.8.7 and 1.8.6
+ ruby_bug "#1633", "1.8.7.174" do
it "raises an IOError if called on a closed stream" do
argv [@file1_name] do
lambda { ARGF.close }.should_not raise_error
@@ -38,13 +36,11 @@
# This passes on 1.8.6 and 1.8.7 but fails on 1.9. matz confirmed that it
# should pass in the referenced bug report
- ruby_bug "#1633", "1.9.2" do
- it "can close STDIN" do
- argv [] do
- ARGV.size.should == 0
- ARGF.close.should == ARGF
- ARGF.closed?.should be_true
- end
- end
- end
+ it "can close STDIN" do
+ argv ['-'] do
+ ARGV.size.should == 1
+ ARGF.close.should == ARGF
+ ARGF.closed?.should be_true
+ end
+ end
end
Modified: MacRuby/branches/experimental/spec/frozen/core/argf/rewind_spec.rb
===================================================================
--- MacRuby/branches/experimental/spec/frozen/core/argf/rewind_spec.rb 2009-07-01 23:05:28 UTC (rev 1956)
+++ MacRuby/branches/experimental/spec/frozen/core/argf/rewind_spec.rb 2009-07-01 23:43:49 UTC (rev 1957)
@@ -28,6 +28,20 @@
end
end
+ # This fails on all versions as reported in bug #1693. If it's deemed not to
+ # be a bug, this guard can be removed
+ ruby_bug "#1693", "1.8.7.174" do
+ it "resets ARGF.lineno to 0" do
+ argv [@file2_name] do
+ ARGF.lineno = 0
+ ARGF.gets;
+ ARGF.lineno.should > 0
+ ARGF.rewind;
+ ARGF.lineno.should == 0
+ end
+ end
+ end
+
it "raises an ArgumentError when end of stream reached" do
argv [@file1_name, @file2_name] do
ARGF.read
Modified: MacRuby/branches/experimental/spec/frozen/core/array/fixtures/classes.rb
===================================================================
--- MacRuby/branches/experimental/spec/frozen/core/array/fixtures/classes.rb 2009-07-01 23:05:28 UTC (rev 1956)
+++ MacRuby/branches/experimental/spec/frozen/core/array/fixtures/classes.rb 2009-07-01 23:43:49 UTC (rev 1957)
@@ -82,12 +82,12 @@
def initialize(*values, &block)
@values = values;
end
-
+
def to_a
self.called = :to_a
@values
end
-
+
def to_ary
self.called = :to_ary
@values
@@ -127,7 +127,7 @@
protected
attr_accessor :order
end
-
+
class ComparableWithFixnum
include Comparable
def initialize(num)
@@ -138,4 +138,10 @@
@num <=> fixnum
end
end
+
+ class Uncomparable
+ def <=>(obj)
+ nil
+ end
+ end
end
Modified: MacRuby/branches/experimental/spec/frozen/core/array/plus_spec.rb
===================================================================
--- MacRuby/branches/experimental/spec/frozen/core/array/plus_spec.rb 2009-07-01 23:05:28 UTC (rev 1956)
+++ MacRuby/branches/experimental/spec/frozen/core/array/plus_spec.rb 2009-07-01 23:43:49 UTC (rev 1957)
@@ -41,7 +41,7 @@
([5, 6] + ArraySpecs::ToAryArray[1, 2]).should == [5, 6, 1, 2]
end
- it "does not infected even if an original array is tainted" do
+ it "does not get infected even if an original array is tainted" do
([1, 2] + [3, 4]).tainted?.should be_false
([1, 2].taint + [3, 4]).tainted?.should be_false
([1, 2] + [3, 4].taint).tainted?.should be_false
Modified: MacRuby/branches/experimental/spec/frozen/core/array/product_spec.rb
===================================================================
--- MacRuby/branches/experimental/spec/frozen/core/array/product_spec.rb 2009-07-01 23:05:28 UTC (rev 1956)
+++ MacRuby/branches/experimental/spec/frozen/core/array/product_spec.rb 2009-07-01 23:43:49 UTC (rev 1957)
@@ -3,7 +3,7 @@
describe "Array#product" do
ruby_version_is "1.9" do
- it "returns convert arguments using :to_ary" do
+ it "returns converted arguments using :to_ary" do
lambda{ [1].product(2..3) }.should raise_error(TypeError)
ar = ArraySpecs::ArrayConvertable.new(2,3)
[1].product(ar).should == [[1,2],[1,3]]
@@ -19,4 +19,4 @@
[1,2].product.should == [[1],[2]]
end
end
-end
\ No newline at end of file
+end
Modified: MacRuby/branches/experimental/spec/frozen/core/array/sort_spec.rb
===================================================================
--- MacRuby/branches/experimental/spec/frozen/core/array/sort_spec.rb 2009-07-01 23:05:28 UTC (rev 1956)
+++ MacRuby/branches/experimental/spec/frozen/core/array/sort_spec.rb 2009-07-01 23:43:49 UTC (rev 1957)
@@ -105,7 +105,7 @@
it "returns the specified value when it would break in the given block" do
[1, 2, 3].sort{ break :a }.should == :a
end
-
+
it "compares values returned by block with 0" do
a = [1, 2, 5, 10, 7, -4, 12]
a.sort { |n, m| n - m }.should == [-4, 1, 2, 5, 7, 10, 12]
@@ -116,7 +116,11 @@
a.sort { |n, m| (n - m).to_s }
}.should raise_error(ArgumentError)
end
-
+
+ it "raises an error if objects can't be compared" do
+ a=[ArraySpecs::Uncomparable.new, ArraySpecs::Uncomparable.new]
+ lambda {a.sort}.should raise_error(ArgumentError)
+ end
end
describe "Array#sort!" do
Modified: MacRuby/branches/experimental/spec/frozen/core/bignum/comparison_spec.rb
===================================================================
--- MacRuby/branches/experimental/spec/frozen/core/bignum/comparison_spec.rb 2009-07-01 23:05:28 UTC (rev 1956)
+++ MacRuby/branches/experimental/spec/frozen/core/bignum/comparison_spec.rb 2009-07-01 23:43:49 UTC (rev 1957)
@@ -5,18 +5,18 @@
@bignum = bignum_value(96)
@inf = 1/0.0
end
-
+
it "returns -1 when self is less than the given argument" do
(- at bignum <=> @bignum).should == -1
(- at bignum <=> -1).should == -1
(- at bignum <=> -4.5).should == -1
end
-
+
it "returns 0 when self is equal to the given argument" do
(@bignum <=> @bignum).should == 0
(- at bignum <=> - at bignum).should == 0
end
-
+
it "returns 1 when self is greater than the given argument" do
(@bignum <=> - at bignum).should == 1
(@bignum <=> 1).should == 1
@@ -34,18 +34,18 @@
#
it "returns 1 when self is Infinity and other is a Bignum" do
(@inf <=> Float::MAX.to_i*2).should == 1
- end
+ end
- it "returns 1 when self is negative and other is Infinty" do
+ it "returns 1 when self is negative and other is -Infinity" do
(-Float::MAX.to_i*2 <=> @inf).should == 1
- end
+ end
it "returns -1 when self is -Infinity and other is negative" do
(- at inf <=> -Float::MAX.to_i*2).should == -1
end
- it "returns 1 when self is negative and other is -Infinity" do
- (-Float::MAX.to_i*2 <=> - at inf).should == 1
+ it "returns -1 when self is negative and other is Infinty" do
+ (-Float::MAX.to_i*2 <=> @inf).should == -1
end
end
@@ -54,18 +54,18 @@
#
it "returns 1 when self is Infinity and other is a Bignum" do
(@inf <=> Float::MAX.to_i*2).should == 1
- end
+ end
- it "returns 1 when self is negative and other is Infinty" do
- (-Float::MAX.to_i*2 <=> @inf).should == 1
- end
+ it "returns 1 when self is negative and other is -Infinity" do
+ (-Float::MAX.to_i*2 <=> - at inf).should == 1
+ end
it "returns -1 when self is -Infinity and other is negative" do
(- at inf <=> -Float::MAX.to_i*2).should == -1
end
- it "returns 1 when self is negative and other is -Infinity" do
- (-Float::MAX.to_i*2 <=> - at inf).should == 1
+ it "returns -1 when self is negative and other is Infinty" do
+ (-Float::MAX.to_i*2 <=> @inf).should == -1
end
end
end
Modified: MacRuby/branches/experimental/spec/frozen/core/bignum/divmod_spec.rb
===================================================================
--- MacRuby/branches/experimental/spec/frozen/core/bignum/divmod_spec.rb 2009-07-01 23:05:28 UTC (rev 1956)
+++ MacRuby/branches/experimental/spec/frozen/core/bignum/divmod_spec.rb 2009-07-01 23:43:49 UTC (rev 1957)
@@ -32,11 +32,20 @@
lambda { (- at bignum).divmod(0) }.should raise_error(ZeroDivisionError)
end
- it "raises a FloatDomainError when the given argument is 0 and a Float" do
- lambda { @bignum.divmod(0.0) }.should raise_error(FloatDomainError)
- lambda { (- at bignum).divmod(0.0) }.should raise_error(FloatDomainError)
+ 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)
+ lambda { (- at bignum).divmod(0.0) }.should raise_error(FloatDomainError)
+ end
end
+ ruby_version_is "1.9" do
+ it "raises a ZeroDivisionError when the given argument is 0 and a Float" do
+ lambda { @bignum.divmod(0.0) }.should raise_error(ZeroDivisionError)
+ lambda { (- at bignum).divmod(0.0) }.should raise_error(ZeroDivisionError)
+ end
+ end
+
it "raises a TypeError when the given argument is not an Integer" do
lambda { @bignum.divmod(mock('10')) }.should raise_error(TypeError)
lambda { @bignum.divmod("10") }.should raise_error(TypeError)
Modified: MacRuby/branches/experimental/spec/frozen/core/bignum/quo_spec.rb
===================================================================
--- MacRuby/branches/experimental/spec/frozen/core/bignum/quo_spec.rb 2009-07-01 23:05:28 UTC (rev 1956)
+++ MacRuby/branches/experimental/spec/frozen/core/bignum/quo_spec.rb 2009-07-01 23:43:49 UTC (rev 1957)
@@ -12,13 +12,22 @@
end
conflicts_with :Rational do
- it "does not raise a ZeroDivisionError when the given Integer is 0" do
- @bignum.quo(0).to_s.should == "Infinity"
- (- at bignum).quo(0).to_s.should == "-Infinity"
+ ruby_version_is ""..."1.9" do
+ it "does not raise a ZeroDivisionError when the given Integer is 0" do
+ @bignum.quo(0).to_s.should == "Infinity"
+ (- at bignum).quo(0).to_s.should == "-Infinity"
+ end
end
end
- it "does not raise a FloatDomainError when the given Integer is 0 and a Float" do
+ ruby_version_is "1.9" do
+ it "raises a ZeroDivisionError when the given Integer is 0" do
+ lambda { @bignum.quo(0) }.should raise_error(ZeroDivisionError)
+ lambda { - at bignum.quo(0) }.should raise_error(ZeroDivisionError)
+ end
+ end
+
+ it "does not raise a FloatDomainError when the given argument is 0 and a Float" do
@bignum.quo(0.0).to_s.should == "Infinity"
(- at bignum).quo(0.0).to_s.should == "-Infinity"
end
@@ -33,4 +42,4 @@
lambda { @bignum.quo(:symbol) }.should raise_error(TypeError)
end
end
-end
\ No newline at end of file
+end
Modified: MacRuby/branches/experimental/spec/frozen/core/bignum/remainder_spec.rb
===================================================================
--- MacRuby/branches/experimental/spec/frozen/core/bignum/remainder_spec.rb 2009-07-01 23:05:28 UTC (rev 1956)
+++ MacRuby/branches/experimental/spec/frozen/core/bignum/remainder_spec.rb 2009-07-01 23:43:49 UTC (rev 1957)
@@ -12,10 +12,21 @@
lambda { bignum_value(66).remainder(0) }.should raise_error(ZeroDivisionError)
end
- it "does NOT raise ZeroDivisionError if other is zero and is a Float" do
- a = bignum_value(7)
- b = bignum_value(32)
- a.remainder(0.0).to_s.should == 'NaN'
- b.remainder(-0.0).to_s.should == 'NaN'
+ ruby_version_is ""..."1.9" do
+ it "does NOT raise ZeroDivisionError if other is zero and is a Float" do
+ a = bignum_value(7)
+ b = bignum_value(32)
+ a.remainder(0.0).to_s.should == 'NaN'
+ b.remainder(-0.0).to_s.should == 'NaN'
+ end
end
+
+ ruby_version_is "1.9" do
+ it "does raises ZeroDivisionError if other is zero and a Float" do
+ a = bignum_value(7)
+ b = bignum_value(32)
+ lambda { a.remainder(0.0) }.should raise_error(ZeroDivisionError)
+ lambda { b.remainder(-0.0) }.should raise_error(ZeroDivisionError)
+ end
+ end
end
Modified: MacRuby/branches/experimental/spec/frozen/core/bignum/shared/modulo.rb
===================================================================
--- MacRuby/branches/experimental/spec/frozen/core/bignum/shared/modulo.rb 2009-07-01 23:05:28 UTC (rev 1956)
+++ MacRuby/branches/experimental/spec/frozen/core/bignum/shared/modulo.rb 2009-07-01 23:43:49 UTC (rev 1957)
@@ -16,11 +16,22 @@
lambda { (- at bignum).send(@method, 0) }.should raise_error(ZeroDivisionError)
end
- it "does not raise a FloatDomainError when the given argument is 0 and a Float" do
- @bignum.send(@method, 0.0).to_s.should == "NaN"
- (- at bignum).send(@method, 0.0).to_s.should == "NaN"
+ ruby_version_is ""..."1.9" do
+ it "does not raise a FloatDomainError when the given argument is 0 and a Float" do
+ @bignum.send(@method, 0.0).to_s.should == "NaN"
+ (- at bignum).send(@method, 0.0).to_s.should == "NaN"
+ end
end
+ ruby_version_is "1.9" do
+ it "raises a ZeroDivisionError when the given argument is 0 and a Float" do
+ lambda { @bignum.send(@method, 0.0) }.should
+ raise_error(ZeroDivisionError)
+ lambda { - at bignum.send(@method, 0.0) }.should
+ raise_error(ZeroDivisionError)
+ end
+ end
+
it "raises a TypeError when given a non-Integer" do
lambda { @bignum.send(@method, mock('10')) }.should raise_error(TypeError)
lambda { @bignum.send(@method, "10") }.should raise_error(TypeError)
Modified: MacRuby/branches/experimental/spec/frozen/core/bignum/size_spec.rb
===================================================================
--- MacRuby/branches/experimental/spec/frozen/core/bignum/size_spec.rb 2009-07-01 23:05:28 UTC (rev 1956)
+++ MacRuby/branches/experimental/spec/frozen/core/bignum/size_spec.rb 2009-07-01 23:43:49 UTC (rev 1957)
@@ -29,4 +29,18 @@
(256**40-1).size .should == 40
end
end
+
+ deviates_on :maglev do
+ it "returns the number of bytes in the machine representation in multiples of four" do
+ (256**7).size .should == 8
+ (256**8).size .should == 16
+ (256**9).size .should == 16
+ (256**10).size .should == 16
+ (256**10-1).size.should == 16
+ (256**11).size .should == 16
+ (256**12).size .should == 20
+ (256**20-1).size.should == 24
+ (256**40-1).size.should == 44
+ end
+ end
end
Modified: MacRuby/branches/experimental/spec/frozen/core/builtin_constants/builtin_constants_spec.rb
===================================================================
--- MacRuby/branches/experimental/spec/frozen/core/builtin_constants/builtin_constants_spec.rb 2009-07-01 23:05:28 UTC (rev 1956)
+++ MacRuby/branches/experimental/spec/frozen/core/builtin_constants/builtin_constants_spec.rb 2009-07-01 23:43:49 UTC (rev 1957)
@@ -1,15 +1,15 @@
require File.dirname(__FILE__) + '/../../spec_helper'
describe "RUBY_VERSION" do
- it "is a String" do
- RUBY_VERSION.should be_kind_of(String)
- end
+ it "is a String" do
+ RUBY_VERSION.should be_kind_of(String)
+ end
end
describe "RUBY_PATCHLEVEL" do
- it "is a Fixnum" do
- RUBY_PATCHLEVEL.should be_kind_of(Fixnum)
- end
+ it "is a Fixnum" do
+ RUBY_PATCHLEVEL.should be_kind_of(Fixnum)
+ end
end
ruby_version_is "1.8.7" do
@@ -54,4 +54,4 @@
RUBY_REVISION.should be_kind_of(Fixnum)
end
end
-end
\ No newline at end of file
+end
Modified: MacRuby/branches/experimental/spec/frozen/core/class/new_spec.rb
===================================================================
--- MacRuby/branches/experimental/spec/frozen/core/class/new_spec.rb 2009-07-01 23:05:28 UTC (rev 1956)
+++ MacRuby/branches/experimental/spec/frozen/core/class/new_spec.rb 2009-07-01 23:43:49 UTC (rev 1957)
@@ -50,10 +50,18 @@
klass_instance.is_a?(klass).should == true
end
- it "creates a class without a name" do
- Class.new.name.should == ""
+ ruby_version_is ""..."1.9" do
+ it "creates a class without a name" do
+ Class.new.name.should == ""
+ end
end
+ ruby_version_is "1.9" do
+ it "creates a class without a name" do
+ Class.new.name.should be_nil
+ end
+ 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"
Modified: MacRuby/branches/experimental/spec/frozen/core/class/superclass_spec.rb
===================================================================
--- MacRuby/branches/experimental/spec/frozen/core/class/superclass_spec.rb 2009-07-01 23:05:28 UTC (rev 1956)
+++ MacRuby/branches/experimental/spec/frozen/core/class/superclass_spec.rb 2009-07-01 23:43:49 UTC (rev 1957)
@@ -1,11 +1,24 @@
require File.dirname(__FILE__) + '/../../spec_helper'
describe "Class#superclass" do
- it "returns the superclass of self" do
- Object.superclass.should == nil
- Class.superclass.should == Module
- Class.new.superclass.should == Object
- Class.new(String).superclass.should == String
- Class.new(Fixnum).superclass.should == Fixnum
+ ruby_version_is ""..."1.9" do
+ it "returns the superclass of self" do
+ Object.superclass.should == nil
+ Class.superclass.should == Module
+ Class.new.superclass.should == Object
+ Class.new(String).superclass.should == String
+ Class.new(Fixnum).superclass.should == Fixnum
+ end
end
-end
\ No newline at end of file
+
+ ruby_version_is "1.9" do
+ it "returns the superclass of self" do
+ BasicObject.superclass.should be_nil
+ Object.superclass.should == BasicObject
+ Class.superclass.should == Module
+ Class.new.superclass.should == Object
+ Class.new(String).superclass.should == String
+ Class.new(Fixnum).superclass.should == Fixnum
+ end
+ end
+end
Added: MacRuby/branches/experimental/spec/frozen/core/complex/abs2_spec.rb
===================================================================
--- MacRuby/branches/experimental/spec/frozen/core/complex/abs2_spec.rb (rev 0)
+++ MacRuby/branches/experimental/spec/frozen/core/complex/abs2_spec.rb 2009-07-01 23:43:49 UTC (rev 1957)
@@ -0,0 +1,7 @@
+require File.dirname(__FILE__) + '/../../shared/complex/abs2'
+
+ruby_version_is "1.9" do
+ describe "Complex#abs2" do
+ it_behaves_like(:complex_abs2, :abs2)
+ end
+end
Added: MacRuby/branches/experimental/spec/frozen/core/complex/abs_spec.rb
===================================================================
--- MacRuby/branches/experimental/spec/frozen/core/complex/abs_spec.rb (rev 0)
+++ MacRuby/branches/experimental/spec/frozen/core/complex/abs_spec.rb 2009-07-01 23:43:49 UTC (rev 1957)
@@ -0,0 +1,7 @@
+require File.dirname(__FILE__) + '/../../shared/complex/abs'
+
+ruby_version_is "1.9" do
+ describe "Complex#abs" do
+ it_behaves_like(:complex_abs, :abs)
+ end
+end
Added: MacRuby/branches/experimental/spec/frozen/core/complex/angle_spec.rb
===================================================================
--- MacRuby/branches/experimental/spec/frozen/core/complex/angle_spec.rb (rev 0)
+++ MacRuby/branches/experimental/spec/frozen/core/complex/angle_spec.rb 2009-07-01 23:43:49 UTC (rev 1957)
@@ -0,0 +1,8 @@
+require File.dirname(__FILE__) + '/../../spec_helper'
+require File.dirname(__FILE__) + '/../../shared/complex/arg'
+
+ruby_version_is "1.9" do
+ describe "Complex#angle" do
+ it_behaves_like(:complex_arg, :angle)
+ end
+end
Added: MacRuby/branches/experimental/spec/frozen/core/complex/arg_spec.rb
===================================================================
--- MacRuby/branches/experimental/spec/frozen/core/complex/arg_spec.rb (rev 0)
+++ MacRuby/branches/experimental/spec/frozen/core/complex/arg_spec.rb 2009-07-01 23:43:49 UTC (rev 1957)
@@ -0,0 +1,8 @@
+require File.dirname(__FILE__) + '/../../spec_helper'
+require File.dirname(__FILE__) + '/../../shared/complex/arg'
+
+ruby_version_is "1.9" do
+ describe "Complex#arg" do
+ it_behaves_like(:complex_arg, :arg)
+ end
+end
Added: MacRuby/branches/experimental/spec/frozen/core/complex/coerce_spec.rb
===================================================================
--- MacRuby/branches/experimental/spec/frozen/core/complex/coerce_spec.rb (rev 0)
+++ MacRuby/branches/experimental/spec/frozen/core/complex/coerce_spec.rb 2009-07-01 23:43:49 UTC (rev 1957)
@@ -0,0 +1,7 @@
+require File.dirname(__FILE__) + '/../../shared/complex/coerce'
+
+ruby_version_is "1.9" do
+ describe "Complex#coerce" do
+ it_behaves_like(:complex_coerce, :coerce)
+ end
+end
Added: MacRuby/branches/experimental/spec/frozen/core/complex/conj_spec.rb
===================================================================
--- MacRuby/branches/experimental/spec/frozen/core/complex/conj_spec.rb (rev 0)
+++ MacRuby/branches/experimental/spec/frozen/core/complex/conj_spec.rb 2009-07-01 23:43:49 UTC (rev 1957)
@@ -0,0 +1,8 @@
+require File.dirname(__FILE__) + '/../../spec_helper'
+require File.dirname(__FILE__) + '/../../shared/complex/conjugate'
+
+ruby_version_is "1.9" do
+ describe "Complex#conj" do
+ it_behaves_like(:complex_conjugate, :conj)
+ end
+end
Added: MacRuby/branches/experimental/spec/frozen/core/complex/conjugate_spec.rb
===================================================================
--- MacRuby/branches/experimental/spec/frozen/core/complex/conjugate_spec.rb (rev 0)
+++ MacRuby/branches/experimental/spec/frozen/core/complex/conjugate_spec.rb 2009-07-01 23:43:49 UTC (rev 1957)
@@ -0,0 +1,8 @@
+require File.dirname(__FILE__) + '/../../spec_helper'
+require File.dirname(__FILE__) + '/../../shared/complex/conjugate'
+
+ruby_version_is "1.9" do
+ describe "Complex#conjugate" do
+ it_behaves_like(:complex_conjugate, :conjugate)
+ end
+end
Added: MacRuby/branches/experimental/spec/frozen/core/complex/denominator_spec.rb
===================================================================
--- MacRuby/branches/experimental/spec/frozen/core/complex/denominator_spec.rb (rev 0)
+++ MacRuby/branches/experimental/spec/frozen/core/complex/denominator_spec.rb 2009-07-01 23:43:49 UTC (rev 1957)
@@ -0,0 +1,7 @@
+require File.dirname(__FILE__) + '/../../shared/complex/denominator'
+
+ruby_version_is "1.9" do
+ describe "Complex#denominator" do
+ it_behaves_like(:complex_denominator, :denominator)
+ end
+end
Added: MacRuby/branches/experimental/spec/frozen/core/complex/divide_spec.rb
===================================================================
--- MacRuby/branches/experimental/spec/frozen/core/complex/divide_spec.rb (rev 0)
+++ MacRuby/branches/experimental/spec/frozen/core/complex/divide_spec.rb 2009-07-01 23:43:49 UTC (rev 1957)
@@ -0,0 +1,23 @@
+require File.dirname(__FILE__) + '/../../shared/complex/divide'
+
+ruby_version_is "1.9" do
+ describe "Complex#/ with Complex" do
+ it_behaves_like(:complex_divide_complex, :/)
+ end
+
+ describe "Complex#/ with Fixnum" do
+ it_behaves_like(:complex_divide_fixnum, :/)
+ end
+
+ describe "Complex#/ with Bignum" do
+ it_behaves_like(:complex_divide_bignum, :/)
+ end
+
+ describe "Complex#/ with Float" do
+ it_behaves_like(:complex_divide_float, :/)
+ end
+
+ describe "Complex#/ with Object" do
+ it_behaves_like(:complex_divide_object, :/)
+ end
+end
Added: MacRuby/branches/experimental/spec/frozen/core/complex/equal_value_spec.rb
===================================================================
--- MacRuby/branches/experimental/spec/frozen/core/complex/equal_value_spec.rb (rev 0)
+++ MacRuby/branches/experimental/spec/frozen/core/complex/equal_value_spec.rb 2009-07-01 23:43:49 UTC (rev 1957)
@@ -0,0 +1,15 @@
+require File.dirname(__FILE__) + '/../../shared/complex/equal_value'
+
+ruby_version_is "1.9" do
+ describe "Complex#== with Complex" do
+ it_behaves_like(:complex_equal_value_complex, :shared => true)
+ end
+
+ describe "Complex#== with Numeric" do
+ it_behaves_like(:complex_equal_value_numeric, :shared => true)
+ end
+
+ describe "Complex#== with Object" do
+ it_behaves_like(:complex_equal_value_object, :shared => true)
+ end
+end
Added: MacRuby/branches/experimental/spec/frozen/core/complex/exponent_spec.rb
===================================================================
--- MacRuby/branches/experimental/spec/frozen/core/complex/exponent_spec.rb (rev 0)
+++ MacRuby/branches/experimental/spec/frozen/core/complex/exponent_spec.rb 2009-07-01 23:43:49 UTC (rev 1957)
@@ -0,0 +1,23 @@
+require File.dirname(__FILE__) + '/../../shared/complex/exponent'
+
+ruby_version_is "1.9" do
+ describe "Complex#** when given 0" do
+ it_behaves_like(:complex_exponent_zero, :**)
+ end
+
+ describe "Complex#** with Complex" do
+ it_behaves_like(:complex_exponent_complex, :**)
+ end
+
+ describe "Complex#** with Integer" do
+ it_behaves_like(:complex_exponent_integer, :**)
+ end
+
+ describe "Complex#** with Rational" do
+ it_behaves_like(:complex_exponent_rational, :**)
+ end
+
+ describe "Complex#** with Object" do
+ it_behaves_like(:complex_exponent_object, :**)
+ end
+end
Modified: MacRuby/branches/experimental/spec/frozen/core/complex/rect_spec.rb
===================================================================
--- MacRuby/branches/experimental/spec/frozen/core/complex/rect_spec.rb 2009-07-01 23:05:28 UTC (rev 1956)
+++ MacRuby/branches/experimental/spec/frozen/core/complex/rect_spec.rb 2009-07-01 23:43:49 UTC (rev 1957)
@@ -1,5 +1,4 @@
-require File.dirname(__FILE__) + '/../../spec_helper'
-require File.dirname(__FILE__) + '/shared/rect'
+require File.dirname(__FILE__) + '/../../shared/complex/rect'
ruby_version_is "1.9" do
describe "Complex#rect" do
Modified: MacRuby/branches/experimental/spec/frozen/core/complex/rectangular_spec.rb
===================================================================
--- MacRuby/branches/experimental/spec/frozen/core/complex/rectangular_spec.rb 2009-07-01 23:05:28 UTC (rev 1956)
+++ MacRuby/branches/experimental/spec/frozen/core/complex/rectangular_spec.rb 2009-07-01 23:43:49 UTC (rev 1957)
@@ -1,5 +1,5 @@
require File.dirname(__FILE__) + '/../../spec_helper'
-require File.dirname(__FILE__) + '/shared/rect'
+require File.dirname(__FILE__) + '/../../shared/complex/rect'
ruby_version_is "1.9" do
describe "Complex#rectangular" do
Deleted: MacRuby/branches/experimental/spec/frozen/core/complex/shared/rect.rb
===================================================================
--- MacRuby/branches/experimental/spec/frozen/core/complex/shared/rect.rb 2009-07-01 23:05:28 UTC (rev 1956)
+++ MacRuby/branches/experimental/spec/frozen/core/complex/shared/rect.rb 2009-07-01 23:43:49 UTC (rev 1957)
@@ -1,45 +0,0 @@
-require File.dirname(__FILE__) + '/../../../spec_helper'
-
-describe :complex_rect, :shared => true do
- before(:each) do
- @numbers = [
- Complex(1),
- Complex(0, 20),
- Complex(0, 0),
- Complex(0.0),
- Complex(9999999**99),
- Complex(-20),
- Complex.polar(76, 10)
- ]
- end
-
- it "returns an Array" do
- @numbers.each do |number|
- number.send(@method).should be_an_instance_of(Array)
- end
- end
-
- it "returns a two-element Array" do
- @numbers.each do |number|
- number.send(@method).size.should == 2
- end
- end
-
- it "returns the real part of self as the first element" do
- @numbers.each do |number|
- number.send(@method).first.should == number.real
- end
- end
-
- it "returns the imaginary part of self as the last element" do
- @numbers.each do |number|
- number.send(@method).last.should == number.imaginary
- 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/dir/chroot_spec.rb
===================================================================
--- MacRuby/branches/experimental/spec/frozen/core/dir/chroot_spec.rb 2009-07-01 23:05:28 UTC (rev 1956)
+++ MacRuby/branches/experimental/spec/frozen/core/dir/chroot_spec.rb 2009-07-01 23:43:49 UTC (rev 1957)
@@ -1,27 +1,52 @@
require File.dirname(__FILE__) + '/../../spec_helper'
require File.dirname(__FILE__) + '/fixtures/common'
-# Need special perms to run chroot
-# describe "Dir.chroot" do
-# it 'Dir.chroot can be used to change the process\' root directory, see chroot(2)' do
-# example do
-# Kernel.fork {
-# begin
-# ret = Dir.chroot mock_dir
-# File.open('/root_contents.txt', 'wb') {|f| f.puts ret; f.puts Dir.entries('/').sort}
-# FileUtils.chmod 0777, '/root_contents.txt'
-# rescue SystemCallError
-# warn '**WARN: Insufficient permissions to test Dir.chroot! (Not a huge problem.)'
-# end
-# }
-#
-# Process.waitall
-#
-# contents = File.read "#{mock_dir}/root_contents.txt"
-# FileUtils.rm "#{mock_dir}/root_contents.txt"
-#
-# # Should have the return value + the filenames
-# contents.split("\n").sort
-# end.should == %w|0 . .. .dotfile .dotsubdir subdir_one subdir_two deeply nondotfile file_one.ext file_two.ext root_contents.txt|.sort
-# end
-# end
+platform_is_not :windows do
+ not_supported_on :jruby do
+ as_superuser do
+ describe "Dir.chroot as root" do
+ before(:all) do
+ @real_root = "../" * (File.dirname(__FILE__).count('/') - 1)
+ @ref_dir = File.join("/", Dir.new('/').entries.first)
+ end
+
+ after(:all) do
+ until File.exists?(@ref_dir)
+ Dir.chroot("../") or break
+ end
+ end
+
+ it "can be used to change the process' root directory" do
+ lambda { Dir.chroot(File.dirname(__FILE__)) }.should_not raise_error
+ File.exists?("/#{File.basename(__FILE__)}").should be_true
+ end
+
+ it "returns 0 if successful" do
+ Dir.chroot('/').should == 0
+ end
+
+ it "raises an Errno::ENOENT exception if the directory doesn't exist" do
+ lambda { Dir.chroot('xgwhwhsjai2222jg') }.should raise_error(Errno::ENOENT)
+ end
+
+ it "can be escaped from with ../" do
+ Dir.chroot(@real_root)
+ File.exists?(@ref_dir).should be_true
+ File.exists?("/#{File.basename(__FILE__)}").should be_false
+ end
+ end
+ end
+
+ as_user do
+ describe "Dir.chroot as regular user" do
+ it "raises an Errno::EPERM exception if the directory exists" do
+ lambda { Dir.chroot('.') }.should raise_error(Errno::EPERM)
+ end
+
+ it "raises an Errno::ENOENT exception if the directory doesn't exist" do
+ lambda { Dir.chroot('xgwhwhsjai2222jg') }.should raise_error(Errno::ENOENT)
+ end
+ end
+ end
+ end
+end
Added: MacRuby/branches/experimental/spec/frozen/core/dir/exist_spec.rb
===================================================================
--- MacRuby/branches/experimental/spec/frozen/core/dir/exist_spec.rb (rev 0)
+++ MacRuby/branches/experimental/spec/frozen/core/dir/exist_spec.rb 2009-07-01 23:43:49 UTC (rev 1957)
@@ -0,0 +1,8 @@
+require File.dirname(__FILE__) + '/../../spec_helper'
+require File.dirname(__FILE__) + '/shared/exists'
+
+ruby_version_is "1.9" do
+ describe "Dir.exist?" do
+ it_behaves_like(:dir_exists, :exist?)
+ end
+end
Added: MacRuby/branches/experimental/spec/frozen/core/dir/exists_spec.rb
===================================================================
--- MacRuby/branches/experimental/spec/frozen/core/dir/exists_spec.rb (rev 0)
+++ MacRuby/branches/experimental/spec/frozen/core/dir/exists_spec.rb 2009-07-01 23:43:49 UTC (rev 1957)
@@ -0,0 +1,8 @@
+require File.dirname(__FILE__) + '/../../spec_helper'
+require File.dirname(__FILE__) + '/shared/exists'
+
+ruby_version_is "1.9" do
+ describe "Dir.exists?" do
+ it_behaves_like(:dir_exists, :exists?)
+ end
+end
Added: MacRuby/branches/experimental/spec/frozen/core/dir/shared/exists.rb
===================================================================
--- MacRuby/branches/experimental/spec/frozen/core/dir/shared/exists.rb (rev 0)
+++ MacRuby/branches/experimental/spec/frozen/core/dir/shared/exists.rb 2009-07-01 23:43:49 UTC (rev 1957)
@@ -0,0 +1,46 @@
+describe :dir_exists, :shared => true do
+ it "returns true if the given directory exists" do
+ Dir.send(@method, File.dirname(__FILE__)).should be_true
+ end
+
+ it "returns true for '.'" do
+ Dir.send(@method, '.').should be_true
+ end
+
+ it "returns true for '..'" do
+ Dir.send(@method, '..').should be_true
+ end
+
+ it "understands non-ASCII paths" do
+ subdir = File.join(tmp("\u{9876}\u{665}"))
+ Dir.send(@method, subdir).should be_false
+ Dir.mkdir(subdir)
+ Dir.send(@method, subdir).should be_true
+ Dir.rmdir(subdir)
+ end
+
+ it "understands relative paths" do
+ Dir.send(@method, File.dirname(__FILE__) + '/../').should be_true
+ end
+
+ it "returns false if the given directory doesn't exist" do
+ Dir.send(@method, 'y26dg27n2nwjs8a/').should be_false
+ end
+
+ it "doesn't require the name to have a trailing slash" do
+ dir = File.dirname(__FILE__)
+ dir.sub!(/\/$/,'')
+ Dir.send(@method, dir).should be_true
+ end
+
+ it "doesn't expand paths" do
+ Dir.send(@method, File.expand_path('~')).should be_true
+ Dir.send(@method, '~').should be_false
+ end
+
+ it "returns false if the argument exists but is a file" do
+ File.exists?(__FILE__).should be_true
+ Dir.send(@method, __FILE__).should be_false
+ end
+
+end
Modified: MacRuby/branches/experimental/spec/frozen/core/encoding/aliases_spec.rb
===================================================================
--- MacRuby/branches/experimental/spec/frozen/core/encoding/aliases_spec.rb 2009-07-01 23:05:28 UTC (rev 1956)
+++ MacRuby/branches/experimental/spec/frozen/core/encoding/aliases_spec.rb 2009-07-01 23:43:49 UTC (rev 1957)
@@ -1,11 +1,45 @@
require File.dirname(__FILE__) + '/../../spec_helper'
-describe "Encoding.aliases" do
- it "returns a hash" do
- Encoding.aliases.should be_kind_of(Hash)
- end
+ruby_version_is "1.9" do
+ describe "Encoding.aliases" do
+ it "returns a Hash" do
+ Encoding.aliases.should be_an_instance_of(Hash)
+ end
- it "returns an encoding name for a given alias" do
- Encoding.aliases["BINARY"].should == "ASCII-8BIT"
+ it "has Strings as keys" do
+ Encoding.aliases.keys.each do |key|
+ key.should be_an_instance_of(String)
+ end
+ end
+
+ it "has Strings as values" do
+ Encoding.aliases.values.each do |value|
+ value.should be_an_instance_of(String)
+ end
+ end
+
+ it "has alias names as its keys" do
+ Encoding.aliases.key?('BINARY').should be_true
+ Encoding.aliases.key?('ASCII').should be_true
+ end
+
+ it "has the names of the aliased encoding as its values" do
+ Encoding.aliases['BINARY'].should == 'ASCII-8BIT'
+ Encoding.aliases['ASCII'].should == 'US-ASCII'
+ end
+
+ it "has an 'external' key with the external default encoding as its value" do
+ Encoding.aliases['external'].should == Encoding.default_external.name
+ end
+
+ it "has a 'locale' key with the locale charmap encoding as its value" do
+ Encoding.aliases['locale'].should == Encoding.locale_charmap
+ end
+
+ it "only contains valid aliased encodings" do
+ Encoding.aliases.each do |enc_alias|
+ lambda { Encoding.find(enc_alias) }.should_not raise_error(ArgumentError)
+ end
+ end
end
-end
+end
\ No newline at end of file
Modified: MacRuby/branches/experimental/spec/frozen/core/encoding/compatible_spec.rb
===================================================================
--- MacRuby/branches/experimental/spec/frozen/core/encoding/compatible_spec.rb 2009-07-01 23:05:28 UTC (rev 1956)
+++ MacRuby/branches/experimental/spec/frozen/core/encoding/compatible_spec.rb 2009-07-01 23:43:49 UTC (rev 1957)
@@ -1,31 +1,26 @@
-# encoding: utf-8
-
require File.dirname(__FILE__) + '/../../spec_helper'
-describe "Encoding.compatible?" do
- before :all do
- @ascii1 = "ant"
- @ascii2 = "bee"
- @iso = "\xee"
- @iso.force_encoding(Encoding::ISO_8859_1)
- @utf = "δog"
- end
+ruby_version_is "1.9" do
+ describe "Encoding.compatible?" do
+ it "returns an Encoding object if the given encodings are compatible" do
+ Encoding.compatible?('a','a').should be_an_instance_of(Encoding)
+ end
- it "returns an Encoding instance which will be compatible with both given strings" do
- encoding = Encoding.compatible?(@ascii1, @ascii2)
- encoding.should be_kind_of(Encoding)
- encoding.name.should == "UTF-8"
+ it "returns the encoding of the string that would result from concatenating the arguments" do
+ [["\u{9876}".force_encoding('UTF-8'), "\u{1254}".force_encoding('UTF-8')],
+ ["a".encode!('SJIS'), "b".encode!('ASCII')]].each do |pair|
+ Encoding.compatible?(pair.first, pair.last).
+ should == pair.first.concat(pair.last).encoding
+ end
+ end
- encoding = Encoding.compatible?(@ascii1, @iso)
- encoding.should be_kind_of(Encoding)
- encoding.name.should == "ISO-8859-1"
+ it "returns nil if there is not a compatible encoding for the arguments" do
+ Encoding.compatible?("\xa1".force_encoding("iso-8859-1"),
+ "\xa1\xa1".force_encoding("euc-jp")).should be_nil
+ end
- encoding = Encoding.compatible?(@ascii1, @utf)
- encoding.should be_kind_of(Encoding)
- encoding.name.should == "UTF-8"
+ it "returns nil unless both arguments are Strings" do
+ Encoding.compatible?([], :foo).should be_nil
+ end
end
-
- it "returns `nil' if no compatible Encoding for the two given strings exists" do
- Encoding.compatible?(@iso, @utf).should be_nil
- end
-end
+end
\ No newline at end of file
Modified: MacRuby/branches/experimental/spec/frozen/core/encoding/converter/asciicompat_encoding_spec.rb
===================================================================
--- MacRuby/branches/experimental/spec/frozen/core/encoding/converter/asciicompat_encoding_spec.rb 2009-07-01 23:05:28 UTC (rev 1956)
+++ MacRuby/branches/experimental/spec/frozen/core/encoding/converter/asciicompat_encoding_spec.rb 2009-07-01 23:43:49 UTC (rev 1957)
@@ -1,5 +1,55 @@
require File.dirname(__FILE__) + '/../../../spec_helper'
-describe "Encoding::Converter.asciicompat_encoding" do
- it "needs to be reviewed for spec completeness"
+ruby_version_is "1.9" do
+ describe "Encoding::Converter.asciicompat_encoding" do
+ it "accepts an encoding name as a String argument" do
+ lambda { Encoding::Converter.asciicompat_encoding('UTF-8') }.
+ should_not raise_error
+ end
+
+ it "coerces non-String/Encoding objects with #to_str" do
+ str = mock('string')
+ str.should_receive(:to_str).twice.and_return('string')
+ Encoding::Converter.asciicompat_encoding(str)
+ end
+
+ it "accepts an Encoding object as an argument" do
+ Encoding::Converter.
+ asciicompat_encoding(Encoding.find("ISO-2022-JP")).
+ should == Encoding::Converter.asciicompat_encoding("ISO-2022-JP")
+ end
+
+ it "returns a corresponding ASCII compatible encoding for ASCII-incompatible encodings" do
+ Encoding::Converter.asciicompat_encoding('UTF-16BE').should == Encoding::UTF_8
+ Encoding::Converter.asciicompat_encoding("ISO-2022-JP").should == Encoding.find("stateless-ISO-2022-JP")
+ end
+
+ it "returns nil when the given encoding is ASCII compatible" do
+ Encoding::Converter.asciicompat_encoding('ASCII').should be_nil
+ Encoding::Converter.asciicompat_encoding('UTF-8').should be_nil
+ end
+
+ quarantine! do
+ # Reported as bug #1659
+ it "handles encoding names who resolve to nil encodings" do
+ internal = Encoding.default_internal
+ Encoding.default_internal = nil
+ Encoding::Converter.asciicompat_encoding('internal')
+ Encoding.default_internal = internal
+ end
+ end
+
+ it "returns nil if called with an encoding it returned previously" do
+ internal = Encoding.default_internal
+ # We set the default_internal encoding explicitly because otherwise we
+ # trigger bug #1659
+ Encoding.default_internal = 'UTF-8'
+ Encoding.name_list.each do |name|
+ asciicompat = Encoding::Converter.asciicompat_encoding(name)
+ next if asciicompat.nil?
+ Encoding::Converter.asciicompat_encoding(asciicompat).should be_nil
+ end
+ Encoding.default_internal = internal
+ end
+ end
end
Added: MacRuby/branches/experimental/spec/frozen/core/encoding/converter/constants_spec.rb
===================================================================
--- MacRuby/branches/experimental/spec/frozen/core/encoding/converter/constants_spec.rb (rev 0)
+++ MacRuby/branches/experimental/spec/frozen/core/encoding/converter/constants_spec.rb 2009-07-01 23:43:49 UTC (rev 1957)
@@ -0,0 +1,133 @@
+require File.dirname(__FILE__) + '/../../../spec_helper'
+
+ruby_version_is "1.9" do
+ describe "Encoding::Converter::INVALID_MASK" do
+ it "exists" do
+ Encoding::Converter.should have_constant(:INVALID_MASK)
+ end
+
+ it "has a Fixnum value" do
+ Encoding::Converter::INVALID_MASK.should be_an_instance_of(Fixnum)
+ end
+ end
+
+ describe "Encoding::Converter::INVALID_REPLACE" do
+ it "exists" do
+ Encoding::Converter.should have_constant(:INVALID_REPLACE)
+ end
+
+ it "has a Fixnum value" do
+ Encoding::Converter::INVALID_REPLACE.should be_an_instance_of(Fixnum)
+ end
+ end
+
+ describe "Encoding::Converter::UNDEF_MASK" do
+ it "exists" do
+ Encoding::Converter.should have_constant(:UNDEF_MASK)
+ end
+
+ it "has a Fixnum value" do
+ Encoding::Converter::UNDEF_MASK.should be_an_instance_of(Fixnum)
+ end
+ end
+
+ describe "Encoding::Converter::UNDEF_REPLACE" do
+ it "exists" do
+ Encoding::Converter.should have_constant(:UNDEF_REPLACE)
+ end
+
+ it "has a Fixnum value" do
+ Encoding::Converter::UNDEF_REPLACE.should be_an_instance_of(Fixnum)
+ end
+ end
+
+ describe "Encoding::Converter::UNDEF_HEX_CHARREF" do
+ it "exists" do
+ Encoding::Converter.should have_constant(:UNDEF_HEX_CHARREF)
+ end
+
+ it "has a Fixnum value" do
+ Encoding::Converter::UNDEF_HEX_CHARREF.should be_an_instance_of(Fixnum)
+ end
+ end
+
+ describe "Encoding::Converter::PARTIAL_INPUT" do
+ it "exists" do
+ Encoding::Converter.should have_constant(:PARTIAL_INPUT)
+ end
+
+ it "has a Fixnum value" do
+ Encoding::Converter::PARTIAL_INPUT.should be_an_instance_of(Fixnum)
+ end
+ end
+
+ describe "Encoding::Converter::AFTER_OUTPUT" do
+ it "exists" do
+ Encoding::Converter.should have_constant(:AFTER_OUTPUT)
+ end
+
+ it "has a Fixnum value" do
+ Encoding::Converter::AFTER_OUTPUT.should be_an_instance_of(Fixnum)
+ end
+ end
+
+ describe "Encoding::Converter::UNIVERSAL_NEWLINE_DECORATOR" do
+ it "exists" do
+ Encoding::Converter.should have_constant(:UNIVERSAL_NEWLINE_DECORATOR)
+ end
+
+ it "has a Fixnum value" do
+ Encoding::Converter::UNIVERSAL_NEWLINE_DECORATOR.should be_an_instance_of(Fixnum)
+ end
+ end
+
+ describe "Encoding::Converter::CRLF_NEWLINE_DECORATOR" do
+ it "exists" do
+ Encoding::Converter.should have_constant(:CRLF_NEWLINE_DECORATOR)
+ end
+
+ it "has a Fixnum value" do
+ Encoding::Converter::CRLF_NEWLINE_DECORATOR.should be_an_instance_of(Fixnum)
+ end
+ end
+
+ describe "Encoding::Converter::CR_NEWLINE_DECORATOR" do
+ it "exists" do
+ Encoding::Converter.should have_constant(:CR_NEWLINE_DECORATOR)
+ end
+
+ it "has a Fixnum value" do
+ Encoding::Converter::CR_NEWLINE_DECORATOR.should be_an_instance_of(Fixnum)
+ end
+ end
+
+ describe "Encoding::Converter::XML_TEXT_DECORATOR" do
+ it "exists" do
+ Encoding::Converter.should have_constant(:XML_TEXT_DECORATOR)
+ end
+
+ it "has a Fixnum value" do
+ Encoding::Converter::XML_TEXT_DECORATOR.should be_an_instance_of(Fixnum)
+ end
+ end
+
+ describe "Encoding::Converter::XML_ATTR_CONTENT_DECORATOR" do
+ it "exists" do
+ Encoding::Converter.should have_constant(:XML_ATTR_CONTENT_DECORATOR)
+ end
+
+ it "has a Fixnum value" do
+ Encoding::Converter::XML_ATTR_CONTENT_DECORATOR.should be_an_instance_of(Fixnum)
+ end
+ end
+
+ describe "Encoding::Converter::XML_ATTR_QUOTE_DECORATOR" do
+ it "exists" do
+ Encoding::Converter.should have_constant(:XML_ATTR_QUOTE_DECORATOR)
+ end
+
+ it "has a Fixnum value" do
+ Encoding::Converter::XML_ATTR_QUOTE_DECORATOR.should be_an_instance_of(Fixnum)
+ end
+ end
+end
Modified: MacRuby/branches/experimental/spec/frozen/core/encoding/converter/convert_spec.rb
===================================================================
--- MacRuby/branches/experimental/spec/frozen/core/encoding/converter/convert_spec.rb 2009-07-01 23:05:28 UTC (rev 1956)
+++ MacRuby/branches/experimental/spec/frozen/core/encoding/converter/convert_spec.rb 2009-07-01 23:43:49 UTC (rev 1957)
@@ -1,5 +1,46 @@
require File.dirname(__FILE__) + '/../../../spec_helper'
-describe "Encoding::Converter#convert" do
- it "needs to be reviewed for spec completeness"
+ruby_version_is "1.9" do
+ describe "Encoding::Converter#convert" do
+ it "returns a String" do
+ ec = Encoding::Converter.new('ascii', 'utf-8')
+ ec.convert('glark').should be_an_instance_of(String)
+ end
+
+ it "sets the encoding of the result to the target encoding" do
+ ec = Encoding::Converter.new('ascii', 'utf-8')
+ str = 'glark'.force_encoding('ascii')
+ ec.convert(str).encoding.should == Encoding::UTF_8
+ end
+
+ it "transcodes the given String to the target encoding" do
+ ec = Encoding::Converter.new("utf-8", "euc-jp")
+ ec.convert("\u3042".force_encoding('UTF-8')).should == \
+ "\xA4\xA2".force_encoding('EUC-JP')
+ end
+
+ it "allows Strings of different encodings to the source encoding" do
+ ec = Encoding::Converter.new('ascii', 'utf-8')
+ str = 'glark'.force_encoding('SJIS')
+ ec.convert(str).encoding.should == Encoding::UTF_8
+ end
+
+ it "reuses the given encoding pair if called multiple times" do
+ ec = Encoding::Converter.new('ascii', 'SJIS')
+ ec.convert('a'.force_encoding('ASCII')).should == 'a'.force_encoding('SJIS')
+ ec.convert('b'.force_encoding('ASCII')).should == 'b'.force_encoding('SJIS')
+ end
+
+ it "raises UndefinedConversionError if the String contains characters invalid for the target encoding" do
+ ec = Encoding::Converter.new('UTF-8', Encoding.find('macCyrillic'))
+ lambda { ec.convert("\u{6543}".force_encoding('UTF-8')) }.should \
+ raise_error(Encoding::UndefinedConversionError)
+ end
+
+ it "raises an ArgumentError if called on a finished stream" do
+ ec = Encoding::Converter.new('UTF-8', Encoding.find('macCyrillic'))
+ ec.finish
+ lambda { ec.convert("\u{65}") }.should raise_error(ArgumentError)
+ end
+ end
end
Modified: MacRuby/branches/experimental/spec/frozen/core/encoding/converter/convpath_spec.rb
===================================================================
--- MacRuby/branches/experimental/spec/frozen/core/encoding/converter/convpath_spec.rb 2009-07-01 23:05:28 UTC (rev 1956)
+++ MacRuby/branches/experimental/spec/frozen/core/encoding/converter/convpath_spec.rb 2009-07-01 23:43:49 UTC (rev 1957)
@@ -1,5 +1,64 @@
require File.dirname(__FILE__) + '/../../../spec_helper'
-describe "Encoding::Converter#convpath" do
- it "needs to be reviewed for spec completeness"
+ruby_version_is "1.9" do
+ describe "Encoding::Converter#convpath" do
+ before(:all) do
+ @perms = Encoding.name_list.permutation(2).map do |pair|
+ Encoding::Converter.new(pair.first, pair.last) rescue nil
+ end.compact.map{|ec| ec.convpath}
+ end
+
+ it "returns an Array" do
+ ec = Encoding::Converter.new('ASCII', 'EUC-JP')
+ ec.convpath.should be_an_instance_of(Array)
+ end
+
+ it "returns each encoding pair as a sub-Array" do
+ ec = Encoding::Converter.new('ASCII', 'EUC-JP')
+ ec.convpath.first.should be_an_instance_of(Array)
+ ec.convpath.first.size.should == 2
+ end
+
+ it "returns each encoding as an Encoding object" do
+ ec = Encoding::Converter.new('ASCII', 'EUC-JP')
+ ec.convpath.first.first.should be_an_instance_of(Encoding)
+ ec.convpath.first.last.should be_an_instance_of(Encoding)
+ end
+
+ it "returns multiple encoding pairs when direct conversion is impossible" do
+ ec = Encoding::Converter.new('ascii','Big5')
+ ec.convpath.size.should == 2
+ ec.convpath.first.should == [Encoding::US_ASCII, Encoding::UTF_8]
+ ec.convpath.last.should == [Encoding::UTF_8, Encoding::Big5]
+ end
+
+ it "sets the last element of each pair to the first element of the next" do
+ @perms.each do |convpath|
+ next if convpath.size == 1
+ convpath.each_with_index do |pair, idx|
+ break if idx == convpath.size - 1
+ pair.last.should == convpath[idx+1].first
+ end
+ end
+ end
+
+ it "only lists a source encoding once" do
+ @perms.each do |convpath|
+ next if convpath.size < 2
+ seen = Hash.new(false)
+ convpath.each_with_index do |pair, idx|
+ seen.key?(pair.first).should be_false if idx > 0
+ seen[pair.first] = true
+ end
+ end
+ end
+
+ it "indicates if crlf_newline conversion would occur" do
+ ec = Encoding::Converter.new("ISo-8859-1", "EUC-JP", {:crlf_newline => true})
+ ec.convpath.last.should == "crlf_newline"
+
+ ec = Encoding::Converter.new("ASCII", "UTF-8", {:crlf_newline => false})
+ ec.convpath.last.should_not == "crlf_newline"
+ end
+ end
end
Modified: MacRuby/branches/experimental/spec/frozen/core/encoding/converter/destination_encoding_spec.rb
===================================================================
--- MacRuby/branches/experimental/spec/frozen/core/encoding/converter/destination_encoding_spec.rb 2009-07-01 23:05:28 UTC (rev 1956)
+++ MacRuby/branches/experimental/spec/frozen/core/encoding/converter/destination_encoding_spec.rb 2009-07-01 23:43:49 UTC (rev 1957)
@@ -1,5 +1,13 @@
require File.dirname(__FILE__) + '/../../../spec_helper'
-describe "Encoding::Converter#destination_encoding" do
- it "needs to be reviewed for spec completeness"
+ruby_version_is "1.9" do
+ describe "Encoding::Converter#destination_encoding" do
+ it "returns the destination encoding as an Encoding object" do
+ ec = Encoding::Converter.new('ASCII','Big5')
+ ec.destination_encoding.should == Encoding::BIG5
+
+ ec = Encoding::Converter.new('SJIS','EUC-JP')
+ ec.destination_encoding.should == Encoding::EUC_JP
+ end
+ end
end
Modified: MacRuby/branches/experimental/spec/frozen/core/encoding/converter/finish_spec.rb
===================================================================
--- MacRuby/branches/experimental/spec/frozen/core/encoding/converter/finish_spec.rb 2009-07-01 23:05:28 UTC (rev 1956)
+++ MacRuby/branches/experimental/spec/frozen/core/encoding/converter/finish_spec.rb 2009-07-01 23:43:49 UTC (rev 1957)
@@ -1,5 +1,38 @@
require File.dirname(__FILE__) + '/../../../spec_helper'
-describe "Encoding::Converter#finish" do
- it "needs to be reviewed for spec completeness"
+ruby_version_is "1.9" do
+ describe "Encoding::Converter#finish" do
+ before(:each) do
+ @ec = Encoding::Converter.new("utf-8", "iso-2022-jp")
+ end
+
+ it "returns a String" do
+ @ec.convert('foo')
+ @ec.finish.should be_an_instance_of(String)
+ end
+
+ it "returns an empty String if there is nothing more to convert" do
+ @ec.convert("glark")
+ @ec.finish.should == ""
+ end
+
+ it "returns the last part of the converted String if it hasn't already" do
+ @ec.convert("\u{9999}").should == "\e$B9a".force_encoding('iso-2022-jp')
+ @ec.finish.should == "\e(B".force_encoding('iso-2022-jp')
+ end
+
+ it "returns a String in the destination encoding" do
+ @ec.convert("glark")
+ @ec.finish.encoding.should == Encoding::ISO2022_JP
+ end
+
+ it "returns an empty String if self was not given anything to convert" do
+ @ec.finish.should == ""
+ end
+
+ it "returns an empty String on subsequent invocations" do
+ @ec.finish.should == ""
+ @ec.finish.should == ""
+ end
+ end
end
Deleted: MacRuby/branches/experimental/spec/frozen/core/encoding/converter/insert_output_spec.rb
===================================================================
--- MacRuby/branches/experimental/spec/frozen/core/encoding/converter/insert_output_spec.rb 2009-07-01 23:05:28 UTC (rev 1956)
+++ MacRuby/branches/experimental/spec/frozen/core/encoding/converter/insert_output_spec.rb 2009-07-01 23:43:49 UTC (rev 1957)
@@ -1,5 +0,0 @@
-require File.dirname(__FILE__) + '/../../../spec_helper'
-
-describe "Encoding::Converter#insert_output" do
- it "needs to be reviewed for spec completeness"
-end
Deleted: MacRuby/branches/experimental/spec/frozen/core/encoding/converter/inspect_spec.rb
===================================================================
--- MacRuby/branches/experimental/spec/frozen/core/encoding/converter/inspect_spec.rb 2009-07-01 23:05:28 UTC (rev 1956)
+++ MacRuby/branches/experimental/spec/frozen/core/encoding/converter/inspect_spec.rb 2009-07-01 23:43:49 UTC (rev 1957)
@@ -1,5 +0,0 @@
-require File.dirname(__FILE__) + '/../../../spec_helper'
-
-describe "Encoding::Converter#inspect" do
- it "needs to be reviewed for spec completeness"
-end
Modified: MacRuby/branches/experimental/spec/frozen/core/encoding/converter/last_error_spec.rb
===================================================================
--- MacRuby/branches/experimental/spec/frozen/core/encoding/converter/last_error_spec.rb 2009-07-01 23:05:28 UTC (rev 1956)
+++ MacRuby/branches/experimental/spec/frozen/core/encoding/converter/last_error_spec.rb 2009-07-01 23:43:49 UTC (rev 1957)
@@ -1,5 +1,84 @@
require File.dirname(__FILE__) + '/../../../spec_helper'
-describe "Encoding::Converter#last_error" do
- it "needs to be reviewed for spec completeness"
+ruby_version_is "1.9" do
+ describe "Encoding::Converter#last_error" do
+ it "returns nil when the no conversion has been attempted" do
+ ec = Encoding::Converter.new('ascii','utf-8')
+ ec.last_error.should be_nil
+ end
+
+ it "returns nil when the last conversion did not produce an error" do
+ ec = Encoding::Converter.new('ascii','utf-8')
+ ec.convert('a'.force_encoding('ascii'))
+ ec.last_error.should be_nil
+ end
+
+ it "returns nil when #primitive_convert last returned :destination_buffer_full" do
+ ec = Encoding::Converter.new("utf-8", "iso-2022-jp")
+ ec.primitive_convert("\u{9999}", "", 0, 0, :partial_input => false) \
+ .should == :destination_buffer_full
+ ec.last_error.should be_nil
+ end
+
+ it "returns nil when #primitive_convert last returned :finished" do
+ ec = Encoding::Converter.new("utf-8", "iso-8859-1")
+ ec.primitive_convert("glark".force_encoding('utf-8'),"").should == :finished
+ ec.last_error.should be_nil
+ end
+
+ it "returns nil if the last conversion succeeded but the penultimate failed" do
+ ec = Encoding::Converter.new("utf-8", "iso-8859-1")
+ ec.primitive_convert("\xf1abcd","").should == :invalid_byte_sequence
+ ec.primitive_convert("glark".force_encoding('utf-8'),"").should == :finished
+ ec.last_error.should be_nil
+ end
+
+ it "returns an Encoding::InvalidByteSequenceError when #primitive_convert last returned :invalid_byte_sequence" do
+ ec = Encoding::Converter.new("utf-8", "iso-8859-1")
+ ec.primitive_convert("\xf1abcd","").should == :invalid_byte_sequence
+ ec.last_error.should be_an_instance_of(Encoding::InvalidByteSequenceError)
+ end
+
+ it "returns an Encoding::UndefinedConversionError when #primitive_convert last returned :undefined_conversion" do
+ ec = Encoding::Converter.new("utf-8", "iso-8859-1")
+ ec.primitive_convert("\u{9876}","").should == :undefined_conversion
+ ec.last_error.should be_an_instance_of(Encoding::UndefinedConversionError)
+ end
+
+ it "returns an Encoding::InvalidByteSequenceError when #primitive_convert last returned :incomplete_input" do
+ ec = Encoding::Converter.new("EUC-JP", "ISO-8859-1")
+ ec.primitive_convert("\xa4", "", nil, 10).should == :incomplete_input
+ ec.last_error.should be_an_instance_of(Encoding::InvalidByteSequenceError)
+ end
+
+ it "returns an Encoding::InvalidByteSequenceError when the last call to #convert produced one" do
+ ec = Encoding::Converter.new("utf-8", "iso-8859-1")
+ exception = nil
+ lambda do
+ begin
+ ec.convert("\xf1abcd")
+ rescue Encoding::InvalidByteSequenceError => e
+ exception = e
+ raise e
+ end
+ end.should raise_error(Encoding::InvalidByteSequenceError)
+ ec.last_error.should be_an_instance_of(Encoding::InvalidByteSequenceError)
+ ec.last_error.message.should == exception.message
+ end
+
+ it "returns an Encoding::UndefinedConversionError when the last call to #convert produced one" do
+ ec = Encoding::Converter.new("utf-8", "iso-8859-1")
+ exception = nil
+ lambda do
+ begin
+ ec.convert("\u{9899}")
+ rescue Encoding::UndefinedConversionError => e
+ exception = e
+ raise e
+ end
+ end.should raise_error(Encoding::UndefinedConversionError)
+ ec.last_error.should be_an_instance_of(Encoding::UndefinedConversionError)
+ ec.last_error.message.should == exception.message
+ end
+ end
end
Modified: MacRuby/branches/experimental/spec/frozen/core/encoding/converter/primitive_convert_spec.rb
===================================================================
--- MacRuby/branches/experimental/spec/frozen/core/encoding/converter/primitive_convert_spec.rb 2009-07-01 23:05:28 UTC (rev 1956)
+++ MacRuby/branches/experimental/spec/frozen/core/encoding/converter/primitive_convert_spec.rb 2009-07-01 23:43:49 UTC (rev 1957)
@@ -1,5 +1,137 @@
require File.dirname(__FILE__) + '/../../../spec_helper'
-describe "Encoding::Converter#primitive_convert" do
- it "needs to be reviewed for spec completeness"
-end
+ruby_version_is "1.9" do
+ describe "Encoding::Converter#primitive_convert" do
+ it "accepts a nil source buffer" do
+ ec = Encoding::Converter.new("utf-8", "iso-8859-1")
+ lambda { ec.primitive_convert(nil,"") }.should_not raise_error
+ end
+
+ it "accepts a String as the source buffer" do
+ ec = Encoding::Converter.new("utf-8", "iso-8859-1")
+ lambda { ec.primitive_convert("","") }.should_not raise_error
+ end
+
+ it "accepts nil for the destination byte offset" do
+ ec = Encoding::Converter.new("utf-8", "iso-8859-1")
+ lambda { ec.primitive_convert("","", nil) }.should_not raise_error
+ end
+
+ it "accepts an integer for the destination byte offset" do
+ ec = Encoding::Converter.new("utf-8", "iso-8859-1")
+ lambda { ec.primitive_convert("","a", 1) }.should_not raise_error
+ end
+
+ it "raises an ArgumentError if the destination byte offset is greater than the bytesize of the destination buffer" do
+ ec = Encoding::Converter.new("utf-8", "iso-8859-1")
+ lambda { ec.primitive_convert("","am", 0) }.should_not raise_error
+ lambda { ec.primitive_convert("","am", 1) }.should_not raise_error
+ lambda { ec.primitive_convert("","am", 2) }.should_not raise_error
+ lambda { ec.primitive_convert("","am", 3) }.should raise_error(ArgumentError)
+ end
+
+ it "uses the destination byte offset to determine where to write the result in the destination buffer" do
+ dest = "aa"
+ ec = Encoding::Converter.new("utf-8", "iso-8859-1")
+ ec.primitive_convert("b",dest, nil, 0)
+ dest.should == "aa"
+
+ ec.primitive_convert("b",dest, nil, 1)
+ dest.should == "aab"
+
+ ec.primitive_convert("b",dest, nil, 2)
+ dest.should == "aabbb"
+ end
+
+ it "accepts nil for the destination bytesize" do
+ ec = Encoding::Converter.new("utf-8", "iso-8859-1")
+ lambda { ec.primitive_convert("","", nil, nil) }.should_not raise_error
+ end
+
+ it "accepts an integer for the destination bytesize" do
+ ec = Encoding::Converter.new("utf-8", "iso-8859-1")
+ lambda { ec.primitive_convert("","", nil, 0) }.should_not raise_error
+ end
+
+ it "allows a destination bytesize value greater than the bytesize of the source buffer" do
+ ec = Encoding::Converter.new("utf-8", "iso-8859-1")
+ lambda { ec.primitive_convert("am","", nil, 3) }.should_not raise_error
+ end
+
+ it "allows a destination bytesize value less than the bytesize of the source buffer" do
+ ec = Encoding::Converter.new("utf-8", "iso-8859-1")
+ lambda { ec.primitive_convert("am","", nil, 1) }.should_not raise_error
+ end
+
+ it "uses destination bytesize as the maximumn bytesize of the destination buffer" do
+ ec = Encoding::Converter.new("utf-8", "iso-8859-1")
+ source = "glark"
+ dest = ""
+ ec.primitive_convert("glark",dest, nil, 1)
+ dest.bytesize.should == 1
+ end
+
+ it "allows a destination buffer of unlimited size if destination bytesize is nil" do
+ ec = Encoding::Converter.new("utf-8", "iso-8859-1")
+ source = "glark".force_encoding('utf-8')
+ dest = ""
+ ec.primitive_convert("glark",dest, nil, nil)
+ dest.bytesize.should == source.bytesize
+ end
+
+ it "accepts an options hash" do
+ ec = Encoding::Converter.new("utf-8", "iso-8859-1")
+ ec.primitive_convert("","",nil,nil, {:after_output => true})\
+ .should_not raise_error(ArgumentError)
+ end
+
+ it "sets the destination buffer's encoding to the destination encoding if the conversion suceeded" do
+ ec = Encoding::Converter.new("utf-8", "iso-8859-1")
+ dest = "".force_encoding('utf-8')
+ dest.encoding.should == Encoding::UTF_8
+ ec.primitive_convert("\u{98}",dest).should == :finished
+ dest.encoding.should == Encoding::ISO_8859_1
+ end
+
+ it "sets the destination buffer's encoding to the destination encoding if the conversion failed" do
+ ec = Encoding::Converter.new("utf-8", "iso-8859-1")
+ dest = "".force_encoding('utf-8')
+ dest.encoding.should == Encoding::UTF_8
+ ec.primitive_convert("\u{9878}",dest).should == :undefined_conversion
+ dest.encoding.should == Encoding::ISO_8859_1
+ end
+
+ it "returns :incomplete_input when source buffer ends unexpectedly and :partial_input isn't specified" do
+ ec = Encoding::Converter.new("EUC-JP", "ISO-8859-1")
+ ec.primitive_convert("\xa4", "", nil, nil, :partial_input => false).should == :incomplete_input
+ end
+
+ it "returns :source_buffer_empty when source buffer ends unexpectedly and :partial_input is true" do
+ ec = Encoding::Converter.new("EUC-JP", "ISO-8859-1")
+ ec.primitive_convert("\xa4", "", nil, nil, :partial_input => true).should == :source_buffer_empty
+ end
+
+ it "returns :undefined_conversion when a character in the source buffer is not representable in the output encoding" do
+ ec = Encoding::Converter.new("utf-8", "iso-8859-1")
+ ec.primitive_convert("\u{9876}","").should == :undefined_conversion
+ end
+
+ it "returns :invalid_byte_sequence when an invalid byte sequence was found in the source buffer" do
+ ec = Encoding::Converter.new("utf-8", "iso-8859-1")
+ ec.primitive_convert("\xf1abcd","").should == :invalid_byte_sequence
+ end
+
+ it "returns :finished when the conversion succeeded" do
+ ec = Encoding::Converter.new("utf-8", "iso-8859-1")
+ ec.primitive_convert("glark".force_encoding('utf-8'),"").should == :finished
+ end
+
+ it "returns :destination_buffer_full when the destination buffer is too small" do
+ ec = Encoding::Converter.new("utf-8", "iso-2022-jp")
+ source = "\u{9999}"
+ destination_bytesize = source.bytesize - 1
+ ec.primitive_convert(source, "", 0, destination_bytesize) \
+ .should == :destination_buffer_full
+ end
+ end
+end
\ No newline at end of file
Modified: MacRuby/branches/experimental/spec/frozen/core/encoding/converter/primitive_errinfo_spec.rb
===================================================================
--- MacRuby/branches/experimental/spec/frozen/core/encoding/converter/primitive_errinfo_spec.rb 2009-07-01 23:05:28 UTC (rev 1956)
+++ MacRuby/branches/experimental/spec/frozen/core/encoding/converter/primitive_errinfo_spec.rb 2009-07-01 23:43:49 UTC (rev 1957)
@@ -1,5 +1,71 @@
require File.dirname(__FILE__) + '/../../../spec_helper'
-describe "Encoding::Converter#primitive_errinfo" do
- it "needs to be reviewed for spec completeness"
+ruby_version_is "1.9" do
+ describe "Encoding::Converter#primitive_errinfo" do
+ it "returns [:source_buffer_empty,nil,nil,nil,nil] when no conversion has been attempted" do
+ ec = Encoding::Converter.new('ascii','utf-8')
+ ec.primitive_errinfo.should == [:source_buffer_empty, nil, nil, nil, nil]
+ end
+
+ it "returns [:finished,nil,nil,nil,nil] when #primitive_convert last returned :finished" do
+ ec = Encoding::Converter.new('ascii','utf-8')
+ ec.primitive_convert("a","").should == :finished
+ ec.primitive_errinfo.should == [:finished, nil, nil, nil, nil]
+ end
+
+ it "returns [:source_buffer_empty,nil,nil,nil, nil] when #convert last succeeded" do
+ ec = Encoding::Converter.new('ascii','utf-8')
+ ec.convert("a".force_encoding('ascii')).should == "a".\
+ force_encoding('utf-8')
+ ec.primitive_errinfo.should == [:source_buffer_empty, nil, nil, nil, nil]
+ end
+
+ it "returns [:destination_buffer_full,nil,nil,nil,nil] when #primitive_convert last returned :destination_buffer_full" do
+ ec = Encoding::Converter.new("utf-8", "iso-2022-jp")
+ ec.primitive_convert("\u{9999}", "", 0, 0, :partial_input => false) \
+ .should == :destination_buffer_full
+ ec.primitive_errinfo.should == [:destination_buffer_full, nil, nil, nil, nil]
+ end
+
+ it "returns the status of the last primitive conversion, even if it was successful and the previous one wasn't" do
+ ec = Encoding::Converter.new("utf-8", "iso-8859-1")
+ ec.primitive_convert("\xf1abcd","").should == :invalid_byte_sequence
+ ec.primitive_convert("glark".force_encoding('utf-8'),"").should == :finished
+ ec.primitive_errinfo.should == [:finished, nil, nil, nil, nil]
+ end
+
+ it "returns the state, source encoding, target encoding, and the erroneous bytes when #primitive_convert last returned :undefined_conversion" do
+ ec = Encoding::Converter.new("utf-8", "iso-8859-1")
+ ec.primitive_convert("\u{9876}","").should == :undefined_conversion
+ ec.primitive_errinfo.should ==
+ [:undefined_conversion, "UTF-8", "ISO-8859-1", "\xE9\xA1\xB6", ""]
+ end
+
+ it "returns the state, source encoding, target encoding, and erroneous bytes when #primitive_convert last returned :incomplete_input" do
+ ec = Encoding::Converter.new("EUC-JP", "ISO-8859-1")
+ ec.primitive_convert("\xa4", "", nil, 10).should == :incomplete_input
+ ec.primitive_errinfo.should == [:incomplete_input, "EUC-JP", "UTF-8", "\xA4", ""]
+ end
+
+ it "returns the state, source encoding, target encoding, erroneous bytes, and the read-again bytes when #primitive_convert last returned :invalid_byte_sequence" do
+ ec = Encoding::Converter.new("utf-8", "iso-8859-1")
+ ec.primitive_convert("\xf1abcd","").should == :invalid_byte_sequence
+ ec.primitive_errinfo.should ==
+ [:invalid_byte_sequence, "UTF-8", "ISO-8859-1", "\xF1", "a"]
+ end
+
+ it "returns the state, source encoding, target encoding, erroneous bytes, and the read-again bytes when #convert last raised InvalidByteSequenceError" do
+ ec = Encoding::Converter.new("utf-8", "iso-8859-1")
+ lambda { ec.convert("\xf1abcd") }.should raise_error(Encoding::InvalidByteSequenceError)
+ ec.primitive_errinfo.should ==
+ [:invalid_byte_sequence, "UTF-8", "ISO-8859-1", "\xF1", "a"]
+ end
+
+ it "returns the state, source encoding, target encoding, erroneous bytes, and the read-again bytes when #finish last raised InvalidByteSequenceError" do
+ ec = Encoding::Converter.new("EUC-JP", "ISO-8859-1")
+ ec.convert("\xa4")
+ lambda { ec.finish }.should raise_error(Encoding::InvalidByteSequenceError)
+ ec.primitive_errinfo.should == [:incomplete_input, "EUC-JP", "UTF-8", "\xA4", ""]
+ end
+ end
end
Modified: MacRuby/branches/experimental/spec/frozen/core/encoding/converter/putback_spec.rb
===================================================================
--- MacRuby/branches/experimental/spec/frozen/core/encoding/converter/putback_spec.rb 2009-07-01 23:05:28 UTC (rev 1956)
+++ MacRuby/branches/experimental/spec/frozen/core/encoding/converter/putback_spec.rb 2009-07-01 23:43:49 UTC (rev 1957)
@@ -1,5 +1,49 @@
require File.dirname(__FILE__) + '/../../../spec_helper'
-describe "Encoding::Converter#putback" do
- it "needs to be reviewed for spec completeness"
+ruby_version_is "1.9" do
+ describe "Encoding::Converter#putback" do
+ before(:each) do
+ @ec = Encoding::Converter.new("EUC-JP", "ISO-8859-1")
+ @ret = @ec.primitive_convert(@src="abc\xa1def", @dst="", nil, 10)
+ end
+
+ it "returns a String" do
+ @ec.putback.should be_an_instance_of(String)
+ end
+
+ it "returns a String in the source encoding" do
+ @ec.putback.encoding.should == Encoding::EUC_JP
+ end
+
+ it "returns the bytes buffered due to an :invalid_byte_sequence error" do
+ @ret.should == :invalid_byte_sequence
+ @ec.putback.should == 'd'
+ @ec.primitive_errinfo.last.should == 'd'
+ end
+
+ it "allows conversion to be resumed after an :invalid_byte_sequence" do
+ @src = @ec.putback + @src
+ @ret = @ec.primitive_convert(@src, @dst, nil, 10)
+ @ret.should == :finished
+ @dst.should == "abcdef"
+ @src.should == ""
+ end
+
+ it "returns an empty String when there are no more bytes to put back" do
+ @ec.putback
+ @ec.putback.should == ""
+ end
+
+ it "accepts an integer argument corresponding to the number of bytes to be put back" do
+ ec = Encoding::Converter.new("utf-16le", "iso-8859-1")
+ src = "\x00\xd8\x61\x00"
+ dst = ""
+ ec.primitive_convert(src, dst).should == :invalid_byte_sequence
+ ec.primitive_errinfo.should ==
+ [:invalid_byte_sequence, "UTF-16LE", "UTF-8", "\x00\xD8", "a\x00"]
+ ec.putback(1).should == "\x00".force_encoding("utf-16le")
+ ec.putback.should == "a".force_encoding("utf-16le")
+ ec.putback.should == ""
+ end
+ end
end
Modified: MacRuby/branches/experimental/spec/frozen/core/encoding/converter/replacement_spec.rb
===================================================================
--- MacRuby/branches/experimental/spec/frozen/core/encoding/converter/replacement_spec.rb 2009-07-01 23:05:28 UTC (rev 1956)
+++ MacRuby/branches/experimental/spec/frozen/core/encoding/converter/replacement_spec.rb 2009-07-01 23:43:49 UTC (rev 1957)
@@ -1,9 +1,63 @@
require File.dirname(__FILE__) + '/../../../spec_helper'
-describe "Encoding::Converter#replacement" do
- it "needs to be reviewed for spec completeness"
-end
+ruby_version_is "1.9" do
+ describe "Encoding::Converter#replacement" do
+ it "returns '?' in US-ASCII when the destination encoding is not UTF-8" do
+ ec = Encoding::Converter.new("utf-8", "us-ascii")
+ ec.replacement.should == "?"
+ ec.replacement.encoding.should == Encoding::US_ASCII
-describe "Encoding::Converter#replacement=" do
- it "needs to be reviewed for spec completeness"
+ ec = Encoding::Converter.new("utf-8", "sjis")
+ ec.replacement.should == "?"
+ ec.replacement.encoding.should == Encoding::US_ASCII
+ end
+
+ it "returns \u{fffd} when the destination encoding is UTF-8" do
+ ec = Encoding::Converter.new("us-ascii", "utf-8")
+ ec.replacement.should == "\u{fffd}".force_encoding('utf-8')
+ ec.replacement.encoding.should == Encoding::UTF_8
+ end
+ end
+
+ describe "Encoding::Converter#replacement=" do
+ it "accepts a String argument" do
+ ec = Encoding::Converter.new("utf-8", "us-ascii")
+ lambda { ec.replacement = "!" }.should_not raise_error(ArgumentError)
+ end
+
+ it "accepts a String argument of arbitrary length" do
+ ec = Encoding::Converter.new("utf-8", "us-ascii")
+ lambda { ec.replacement = "?!?" * 9999 }.should_not raise_error(ArgumentError)
+ ec.replacement.should == "?!?" * 9999
+ end
+
+ it "raises an TypeError if assigned a non-String argument" do
+ ec = Encoding::Converter.new("utf-8", "us-ascii")
+ lambda { ec.replacement = nil }.should raise_error(TypeError)
+ end
+
+ it "sets #replacement" do
+ ec = Encoding::Converter.new("us-ascii", "utf-8")
+ ec.replacement.should == "\u{fffd}".force_encoding('utf-8')
+ ec.replacement = '?'.encode('utf-8')
+ ec.replacement.should == '?'.force_encoding('utf-8')
+ end
+
+ it "raises an UndefinedConversionError is the argument cannot be converted into the destination encoding" do
+ ec = Encoding::Converter.new("sjis", "ascii")
+ utf8_q = "\u{986}".force_encoding('utf-8')
+ ec.primitive_convert(utf8_q,"").should == :undefined_conversion
+ lambda { ec.replacement = utf8_q }.should \
+ raise_error(Encoding::UndefinedConversionError)
+ end
+
+ it "does not change the replacement character if the argument cannot be converted into the destination encoding" do
+ ec = Encoding::Converter.new("sjis", "ascii")
+ utf8_q = "\u{986}".force_encoding('utf-8')
+ ec.primitive_convert(utf8_q,"").should == :undefined_conversion
+ lambda { ec.replacement = utf8_q }.should \
+ raise_error(Encoding::UndefinedConversionError)
+ ec.replacement.should == "?".force_encoding('us-ascii')
+ end
+ end
end
Modified: MacRuby/branches/experimental/spec/frozen/core/encoding/converter/search_convpath_spec.rb
===================================================================
--- MacRuby/branches/experimental/spec/frozen/core/encoding/converter/search_convpath_spec.rb 2009-07-01 23:05:28 UTC (rev 1956)
+++ MacRuby/branches/experimental/spec/frozen/core/encoding/converter/search_convpath_spec.rb 2009-07-01 23:43:49 UTC (rev 1957)
@@ -1,5 +1,73 @@
require File.dirname(__FILE__) + '/../../../spec_helper'
-describe "Encoding::Converter.search_convpath" do
- it "needs to be reviewed for spec completeness"
+ruby_version_is "1.9" do
+ describe "Encoding::Converter.search_convpath" do
+ before(:all) do
+ @perms = Encoding.name_list.permutation(2).map do |pair|
+ Encoding::Converter.search_convpath(pair.first, pair.last) rescue []
+ end
+ end
+
+ it "returns an Array" do
+ Encoding::Converter.search_convpath('ASCII', 'EUC-JP').\
+ should be_an_instance_of(Array)
+ end
+
+ it "returns each encoding pair as a sub-Array" do
+ cp = Encoding::Converter.search_convpath('ASCII', 'EUC-JP')
+ cp.first.should be_an_instance_of(Array)
+ cp.first.size.should == 2
+ end
+
+ it "returns each encoding as an Encoding object" do
+ cp = Encoding::Converter.search_convpath('ASCII', 'EUC-JP')
+ cp.first.first.should be_an_instance_of(Encoding)
+ cp.first.last.should be_an_instance_of(Encoding)
+ end
+
+ it "returns multiple encoding pairs when direct conversion is impossible" do
+ cp = Encoding::Converter.search_convpath('ascii','Big5')
+ cp.size.should == 2
+ cp.first.should == [Encoding::US_ASCII, Encoding::UTF_8]
+ cp.last.should == [Encoding::UTF_8, Encoding::Big5]
+ end
+
+ it "sets the last element of each pair to the first element of the next" do
+ @perms.each do |convpath|
+ next if convpath.size == 1
+ convpath.each_with_index do |pair, idx|
+ break if idx == convpath.size - 1
+ pair.last.should == convpath[idx+1].first
+ end
+ end
+ end
+
+ it "only lists a source encoding once" do
+ @perms.each do |convpath|
+ next if convpath.size < 2
+ seen = Hash.new(false)
+ convpath.each_with_index do |pair, idx|
+ seen.key?(pair.first).should be_false if idx > 0
+ seen[pair.first] = true
+ end
+ end
+ end
+
+ it "indicates if crlf_newline conversion would occur" do
+ cp = Encoding::Converter.search_convpath(
+ "ISo-8859-1", "EUC-JP", {:crlf_newline => true})
+ cp.last.should == "crlf_newline"
+
+ cp = Encoding::Converter.search_convpath(
+ "ASCII", "UTF-8", {:crlf_newline => false})
+ cp.last.should_not == "crlf_newline"
+ end
+
+ it "raises an Encoding::ConverterNotFoundError if no conversion path exists" do
+ lambda do
+ Encoding::Converter.search_convpath(
+ Encoding::ASCII_8BIT, Encoding::Emacs_Mule)
+ end.should raise_error(Encoding::ConverterNotFoundError)
+ end
+ end
end
Modified: MacRuby/branches/experimental/spec/frozen/core/encoding/converter/source_encoding_spec.rb
===================================================================
--- MacRuby/branches/experimental/spec/frozen/core/encoding/converter/source_encoding_spec.rb 2009-07-01 23:05:28 UTC (rev 1956)
+++ MacRuby/branches/experimental/spec/frozen/core/encoding/converter/source_encoding_spec.rb 2009-07-01 23:43:49 UTC (rev 1957)
@@ -1,5 +1,13 @@
require File.dirname(__FILE__) + '/../../../spec_helper'
-describe "Encoding::Converter#source_encoding" do
- it "needs to be reviewed for spec completeness"
+ruby_version_is "1.9" do
+ describe "Encoding::Converter#source_encoding" do
+ it "returns the source encoding as an Encoding object" do
+ ec = Encoding::Converter.new('ASCII','Big5')
+ ec.source_encoding.should == Encoding::US_ASCII
+
+ ec = Encoding::Converter.new('SJIS','EUC-JP')
+ ec.source_encoding.should == Encoding::SHIFT_JIS
+ end
+ end
end
Added: MacRuby/branches/experimental/spec/frozen/core/encoding/default_external_spec.rb
===================================================================
--- MacRuby/branches/experimental/spec/frozen/core/encoding/default_external_spec.rb (rev 0)
+++ MacRuby/branches/experimental/spec/frozen/core/encoding/default_external_spec.rb 2009-07-01 23:43:49 UTC (rev 1957)
@@ -0,0 +1,57 @@
+require File.dirname(__FILE__) + '/../../spec_helper'
+
+ruby_version_is "1.9" do
+ describe "Encoding.default_external" do
+ before(:all) do
+ @original_encoding = Encoding.default_external
+ end
+
+ after(:all) do
+ Encoding.default_external = @original_encoding
+ end
+
+ it "returns an Encoding object" do
+ Encoding.default_external.should be_an_instance_of(Encoding)
+ end
+
+ it "returns the default external encoding" do
+ Encoding.default_external = Encoding::UTF_8
+ Encoding.default_external.should == Encoding::UTF_8
+ end
+ end
+
+ describe "Encoding.default_external=" do
+ before(:all) do
+ @original_encoding = Encoding.default_external
+ end
+
+ after(:all) do
+ Encoding.default_external = @original_encoding
+ end
+
+ it "sets the default external encoding" do
+ Encoding.default_external = Encoding::UTF_8
+ Encoding.default_external.should == Encoding::UTF_8
+ end
+
+ it "can accept a name of an encoding as a String" do
+ Encoding.default_external = 'sjis'
+ Encoding.default_external.should == Encoding::SHIFT_JIS
+ end
+
+ it "calls #to_s on arguments that are neither Strings nor Encodings" do
+ string = mock('string')
+ string.should_receive(:to_str).twice.and_return('ascii')
+ Encoding.default_external = string
+ Encoding.default_external.should == Encoding::ASCII
+ end
+
+ it "raises a TypeError unless the argument is an Encoding or convertible to a String" do
+ lambda { Encoding.default_external = [] }.should raise_error(TypeError)
+ end
+
+ it "raises an ArgumentError if the argument is nil" do
+ lambda { Encoding.default_external = nil }.should raise_error(ArgumentError)
+ end
+ end
+end
Deleted: MacRuby/branches/experimental/spec/frozen/core/encoding/default_external_spec_disabled.rb
===================================================================
--- MacRuby/branches/experimental/spec/frozen/core/encoding/default_external_spec_disabled.rb 2009-07-01 23:05:28 UTC (rev 1956)
+++ MacRuby/branches/experimental/spec/frozen/core/encoding/default_external_spec_disabled.rb 2009-07-01 23:43:49 UTC (rev 1957)
@@ -1,45 +0,0 @@
-require File.dirname(__FILE__) + '/../../spec_helper'
-
-describe "Encoding.default_external" do
- it "returns the default external Encoding instance" do
- Encoding.default_external.should be_kind_of(Encoding)
- end
-end
-
-describe "Encoding.default_external=" do
- before :all do
- @before = Encoding.default_external
- end
-
- after :each do
- Encoding.default_external = @before
- end
-
- it "takes an Encoding instance" do
- Encoding.default_external = Encoding.find('UTF-8')
- Encoding.default_external.name.should == 'UTF-8'
-
- Encoding.default_external = Encoding.find('US-ASCII')
- Encoding.default_external.name.should == 'US-ASCII'
- end
-
- it "takes a string name of an encoding" do
- Encoding.default_external = 'UTF-8'
- Encoding.default_external.name.should == 'UTF-8'
-
- Encoding.default_external = 'US-ASCII'
- Encoding.default_external.name.should == 'US-ASCII'
- end
-
- it "assigns the default external encoding to be used for IO" do
- Encoding.default_external = 'UTF-8'
- open(__FILE__) do |file|
- file.external_encoding.name.should == 'UTF-8'
- end
-
- Encoding.default_external = 'US-ASCII'
- open(__FILE__) do |file|
- file.external_encoding.name.should == 'US-ASCII'
- end
- end
-end
Added: MacRuby/branches/experimental/spec/frozen/core/encoding/default_internal_spec.rb
===================================================================
--- MacRuby/branches/experimental/spec/frozen/core/encoding/default_internal_spec.rb (rev 0)
+++ MacRuby/branches/experimental/spec/frozen/core/encoding/default_internal_spec.rb 2009-07-01 23:43:49 UTC (rev 1957)
@@ -0,0 +1,82 @@
+require File.dirname(__FILE__) + '/../../spec_helper'
+
+ruby_version_is "1.9" do
+ describe "Encoding.default_internal" do
+ before(:each) do
+ @original_encoding = Encoding.default_internal
+ end
+
+ after(:each) do
+ Encoding.default_internal = @original_encoding
+ end
+
+ it "is nil by default" do
+ Encoding.default_internal.should be_nil
+ end
+
+ it "returns an Encoding object if a default internal encoding is set" do
+ Encoding.default_internal = Encoding::ASCII
+ Encoding.default_internal.should be_an_instance_of(Encoding)
+ end
+
+ it "returns nil if no default internal encoding is set" do
+ Encoding.default_internal = nil
+ Encoding.default_internal.should be_nil
+ end
+
+ it "returns the default internal encoding" do
+ Encoding.default_internal = Encoding::ASCII_8BIT
+ Encoding.default_internal.should == Encoding::ASCII_8BIT
+ end
+
+ it "returns Encoding::UTF_8 if ruby was invoked with -U" do
+ ruby_exe("print Encoding.default_internal", :options => '-U').
+ should == 'UTF-8'
+ end
+
+ it "uses the encoding specified when ruby is invoked with an '-E :internal' argument" do
+ ruby_exe("print Encoding.default_internal", :options => '-E :SHIFT_JIS').
+ should == 'Shift_JIS'
+ end
+
+ it "uses the encoding specified when ruby is invoked with an '-E external:internal' argument" do
+ ruby_exe("print Encoding.default_internal", :options => '-E UTF-8:SHIFT_JIS').
+ should == 'Shift_JIS'
+ end
+ end
+
+ describe "Encoding.default_internal=" do
+ before(:all) do
+ @original_encoding = Encoding.default_internal
+ end
+
+ after(:all) do
+ Encoding.default_internal = @original_encoding
+ end
+
+ it "sets the default internal encoding" do
+ Encoding.default_internal = Encoding::SHIFT_JIS
+ Encoding.default_internal.should == Encoding::SHIFT_JIS
+ end
+
+ it "can accept a name of an encoding as a String" do
+ Encoding.default_internal = 'sjis'
+ Encoding.default_internal.should == Encoding::SHIFT_JIS
+ end
+
+ it "calls #to_s on arguments that are neither Strings nor Encodings" do
+ string = mock('string')
+ string.should_receive(:to_str).twice.and_return('ascii')
+ Encoding.default_internal = string
+ Encoding.default_internal.should == Encoding::ASCII
+ end
+
+ it "raises a TypeError unless the argument is an Encoding or convertible to a String" do
+ lambda { Encoding.default_internal = [] }.should raise_error(TypeError)
+ end
+
+ it "accepts an argument of nil to unset the default internal encoding" do
+ lambda { Encoding.default_internal = nil }.should_not raise_error
+ end
+ end
+end
Deleted: MacRuby/branches/experimental/spec/frozen/core/encoding/default_internal_spec_disabled.rb
===================================================================
--- MacRuby/branches/experimental/spec/frozen/core/encoding/default_internal_spec_disabled.rb 2009-07-01 23:05:28 UTC (rev 1956)
+++ MacRuby/branches/experimental/spec/frozen/core/encoding/default_internal_spec_disabled.rb 2009-07-01 23:43:49 UTC (rev 1957)
@@ -1,50 +0,0 @@
-require File.dirname(__FILE__) + '/../../spec_helper'
-
-describe "Encoding.default_internal" do
- it "returns `nil' by default" do
- Encoding.default_internal.should be_nil
- end
-end
-
-describe "Encoding.default_internal=" do
- before :all do
- @before = Encoding.default_external
- Encoding.default_external = 'ISO-8859-1'
- end
-
- after :all do
- Encoding.default_external = @before
- end
-
- after :each do
- Encoding.default_internal = nil
- end
-
- it "takes an Encoding instance" do
- Encoding.default_internal = Encoding.find('UTF-8')
- Encoding.default_internal.name.should == 'UTF-8'
-
- Encoding.default_internal = Encoding.find('US-ASCII')
- Encoding.default_internal.name.should == 'US-ASCII'
- end
-
- it "takes a string name of an encoding" do
- Encoding.default_internal = 'UTF-8'
- Encoding.default_internal.name.should == 'UTF-8'
-
- Encoding.default_internal = 'US-ASCII'
- Encoding.default_internal.name.should == 'US-ASCII'
- end
-
- it "assigns the default external encoding to be used for IO" do
- Encoding.default_internal = 'UTF-8'
- open(__FILE__) do |file|
- file.internal_encoding.name.should == 'UTF-8'
- end
-
- Encoding.default_internal = 'US-ASCII'
- open(__FILE__) do |file|
- file.internal_encoding.name.should == 'US-ASCII'
- end
- end
-end
Modified: MacRuby/branches/experimental/spec/frozen/core/encoding/dummy_spec.rb
===================================================================
--- MacRuby/branches/experimental/spec/frozen/core/encoding/dummy_spec.rb 2009-07-01 23:05:28 UTC (rev 1956)
+++ MacRuby/branches/experimental/spec/frozen/core/encoding/dummy_spec.rb 2009-07-01 23:43:49 UTC (rev 1957)
@@ -1,40 +1,16 @@
require File.dirname(__FILE__) + '/../../spec_helper'
-# This will fail on MacRuby. How to properly spec this.
-
-describe "Encoding#dummy?" do
- before :all do
- @encodings = %w{
- ASCII-8BIT
- Big5
- CP51932 CP850 CP852 CP855 CP949
- EUC-JP EUC-KR EUC-TW Emacs-Mule eucJP-ms
- GB12345 GB18030 GB1988 GB2312 GBK
- IBM437 IBM737 IBM775 IBM852 IBM855 IBM857 IBM860 IBM861 IBM862 IBM863 IBM864 IBM865 IBM866 IBM869
- ISO-2022-JP ISO-2022-JP-2 ISO-8859-1 ISO-8859-10 ISO-8859-11 ISO-8859-13 ISO-8859-14 ISO-8859-15
- ISO-8859-16 ISO-8859-2 ISO-8859-3 ISO-8859-4 ISO-8859-5 ISO-8859-6 ISO-8859-7 ISO-8859-8 ISO-8859-9
- KOI8-R KOI8-U
- MacJapanese macCentEuro macCroatian macCyrillic macGreek macIceland macRoman macRomania macThai
- macTurkish macUkraine
- Shift_JIS stateless-ISO-2022-JP
- TIS-620
- US-ASCII UTF-16BE UTF-16LE UTF-32BE UTF-32LE UTF-7 UTF-8 UTF8-MAC
- Windows-1250 Windows-1251 Windows-1252 Windows-1253 Windows-1254 Windows-1255 Windows-1256
- Windows-1257 Windows-1258 Windows-31J Windows-874
- }
-
- @dummy_encodings = %w{ ISO-2022-JP ISO-2022-JP-2 UTF-7 }
- end
-
- it "returns `false' if an encoding can be handled correctly" do
- (@encodings - @dummy_encodings).each do |name|
- Encoding.find(name).dummy?.should be_false
+ruby_version_is "1.9" do
+ describe "Encoding#dummy?" do
+ it "returns false for proper encodings" do
+ Encoding::UTF_8.dummy?.should be_false
+ Encoding::ASCII.dummy?.should be_false
end
- end
- it "returns `true' if an encoding is a placeholder which can't be handled correctly" do
- @dummy_encodings.each do |name|
- Encoding.find(name).dummy?.should be_true
+ it "returns true for dummy encodings" do
+ Encoding::ISO_2022_JP.dummy?.should be_true
+ Encoding::CP50221.dummy?.should be_true
+ Encoding::UTF_7.dummy?.should be_true
end
end
-end
+end
\ No newline at end of file
Modified: MacRuby/branches/experimental/spec/frozen/core/encoding/find_spec.rb
===================================================================
--- MacRuby/branches/experimental/spec/frozen/core/encoding/find_spec.rb 2009-07-01 23:05:28 UTC (rev 1956)
+++ MacRuby/branches/experimental/spec/frozen/core/encoding/find_spec.rb 2009-07-01 23:43:49 UTC (rev 1957)
@@ -20,3 +20,58 @@
Encoding.find(o).name.should == "UTF-8"
end
end
+
+require File.dirname(__FILE__) + '/../../spec_helper'
+
+ruby_version_is "1.9" do
+ describe "Encoding.find" do
+ before(:all) do
+ @encodings = Encoding.aliases.to_a.flatten.uniq
+ end
+
+ it "returns the corresponding Encoding object if given a valid encoding name" do
+ @encodings.each do |enc|
+ Encoding.find(enc).should be_an_instance_of(Encoding)
+ end
+ end
+
+ it "returns the corresponding Encoding object if given a valid alias name" do
+ Encoding.aliases.keys.each do |enc_alias|
+ Encoding.find(enc_alias).should be_an_instance_of(Encoding)
+ end
+ end
+
+ it "accepts encoding names as Symbols" do
+ @encodings.each do |enc|
+ Encoding.find(enc.to_sym).should == Encoding.find(enc)
+ end
+ end
+
+ it "accepts encoding names as Strings" do
+ Encoding.list.each do |enc|
+ Encoding.find(enc.name).should == enc
+ end
+ end
+
+ it "accepts any object as encoding name, if it responds to #to_str" do
+ obj = Object.new
+ def obj.encoding_name=(name); @name; end
+ def obj.to_str; @name; end
+
+ Encoding.list.each do |enc|
+ obj.encoding_name = enc.name
+ Encoding.find(obj).should == enc
+ end
+ end
+
+ it "is case insensitive" do
+ @encodings.each do |enc|
+ Encoding.find(enc.upcase).should == Encoding.find(enc)
+ end
+ end
+
+ it "raises an ArgumentError if the given encoding does not exist" do
+ lambda { Encoding.find('dh2dh278d') }.should raise_error(ArgumentError)
+ end
+ end
+end
\ No newline at end of file
Added: MacRuby/branches/experimental/spec/frozen/core/encoding/fixtures/classes.rb
===================================================================
--- MacRuby/branches/experimental/spec/frozen/core/encoding/fixtures/classes.rb (rev 0)
+++ MacRuby/branches/experimental/spec/frozen/core/encoding/fixtures/classes.rb 2009-07-01 23:43:49 UTC (rev 1957)
@@ -0,0 +1,48 @@
+module EncodingSpecs
+ class UndefinedConversionError
+ def self.exception
+ ec = Encoding::Converter.new('utf-8','ascii')
+ begin
+ ec.convert("\u{8765}")
+ rescue Encoding::UndefinedConversionError => e
+ e
+ end
+ end
+ end
+
+ class UndefinedConversionErrorIndirect
+ def self.exception
+ ec = Encoding::Converter.new("ISO-8859-1", "EUC-JP")
+ begin
+ ec.convert("\xA0")
+ rescue Encoding::UndefinedConversionError => e
+ e
+ end
+ end
+ end
+
+ class InvalidByteSequenceError
+ def self.exception
+ ec = Encoding::Converter.new("utf-8", "iso-8859-1")
+ begin
+ ec.convert("\xf1abcd")
+ rescue Encoding::InvalidByteSequenceError => e
+ # Return the exception object and the primitive_errinfo Array
+ [e, ec.primitive_errinfo]
+ end
+ end
+ end
+
+ class InvalidByteSequenceErrorIndirect
+ def self.exception
+ ec = Encoding::Converter.new("EUC-JP", "ISO-8859-1")
+ begin
+ ec.convert("abc\xA1\xFFdef")
+ rescue Encoding::InvalidByteSequenceError => e
+ # Return the exception object and the discarded bytes reported by
+ # #primitive_errinfo
+ [e, ec.primitive_errinfo]
+ end
+ end
+ end
+end
Modified: MacRuby/branches/experimental/spec/frozen/core/encoding/inspect_spec.rb
===================================================================
--- MacRuby/branches/experimental/spec/frozen/core/encoding/inspect_spec.rb 2009-07-01 23:05:28 UTC (rev 1956)
+++ MacRuby/branches/experimental/spec/frozen/core/encoding/inspect_spec.rb 2009-07-01 23:43:49 UTC (rev 1957)
@@ -1,5 +1,21 @@
require File.dirname(__FILE__) + '/../../spec_helper'
-describe "Encoding#inspect" do
- it "needs to be reviewed for spec completeness"
-end
+ruby_version_is "1.9" do
+ describe "Encoding#inspect" do
+ it "returns a String" do
+ Encoding::UTF_8.inspect.should be_an_instance_of(String)
+ end
+
+ it "returns #<Encoding:name> for a non-dummy encoding named 'name'" do
+ Encoding.list.to_a.reject {|e| e.dummy? }.each do |enc|
+ enc.inspect.should =~ /#<Encoding:#{enc.name}>/
+ end
+ end
+
+ it "returns #<Encoding:name (dummy)> for a dummy encoding named 'name'" do
+ Encoding.list.to_a.select {|e| e.dummy? }.each do |enc|
+ enc.inspect.should =~ /#<Encoding:#{enc.name} \(dummy\)>/
+ end
+ end
+ end
+end
\ No newline at end of file
Added: MacRuby/branches/experimental/spec/frozen/core/encoding/invalid_byte_sequence_error/destination_encoding_name_spec.rb
===================================================================
--- MacRuby/branches/experimental/spec/frozen/core/encoding/invalid_byte_sequence_error/destination_encoding_name_spec.rb (rev 0)
+++ MacRuby/branches/experimental/spec/frozen/core/encoding/invalid_byte_sequence_error/destination_encoding_name_spec.rb 2009-07-01 23:43:49 UTC (rev 1957)
@@ -0,0 +1,20 @@
+require File.dirname(__FILE__) + '/../fixtures/classes'
+
+ruby_version_is "1.9" do
+ describe "Encoding::InvalidByteSequenceError#destination_encoding_name" do
+ before(:each) do
+ @exception, = EncodingSpecs::InvalidByteSequenceError.exception
+ @exception2, = EncodingSpecs::InvalidByteSequenceErrorIndirect.exception
+ end
+
+ it "returns a String" do
+ @exception.destination_encoding_name.should be_an_instance_of(String)
+ @exception2.destination_encoding_name.should be_an_instance_of(String)
+ end
+
+ it "is equal to the destination encoding name of the object that raised it" do
+ @exception.destination_encoding_name.should == "ISO-8859-1"
+ @exception2.destination_encoding_name.should == "UTF-8"
+ end
+ end
+end
Added: MacRuby/branches/experimental/spec/frozen/core/encoding/invalid_byte_sequence_error/destination_encoding_spec.rb
===================================================================
--- MacRuby/branches/experimental/spec/frozen/core/encoding/invalid_byte_sequence_error/destination_encoding_spec.rb (rev 0)
+++ MacRuby/branches/experimental/spec/frozen/core/encoding/invalid_byte_sequence_error/destination_encoding_spec.rb 2009-07-01 23:43:49 UTC (rev 1957)
@@ -0,0 +1,20 @@
+require File.dirname(__FILE__) + '/../fixtures/classes'
+
+ruby_version_is "1.9" do
+ describe "Encoding::InvalidByteSequenceError#destination_encoding" do
+ before(:each) do
+ @exception, = EncodingSpecs::InvalidByteSequenceError.exception
+ @exception2, = EncodingSpecs::InvalidByteSequenceErrorIndirect.exception
+ end
+
+ it "returns an Encoding object" do
+ @exception.destination_encoding.should be_an_instance_of(Encoding)
+ @exception2.destination_encoding.should be_an_instance_of(Encoding)
+ end
+
+ it "is equal to the destination encoding of the object that raised it" do
+ @exception.destination_encoding.should == Encoding::ISO_8859_1
+ @exception2.destination_encoding.should == Encoding::UTF_8
+ end
+ end
+end
Added: MacRuby/branches/experimental/spec/frozen/core/encoding/invalid_byte_sequence_error/error_bytes_spec.rb
===================================================================
--- MacRuby/branches/experimental/spec/frozen/core/encoding/invalid_byte_sequence_error/error_bytes_spec.rb (rev 0)
+++ MacRuby/branches/experimental/spec/frozen/core/encoding/invalid_byte_sequence_error/error_bytes_spec.rb 2009-07-01 23:43:49 UTC (rev 1957)
@@ -0,0 +1,31 @@
+require File.dirname(__FILE__) + '/../fixtures/classes'
+
+ruby_version_is "1.9" do
+ describe "Encoding::InvalidByteSequenceError#error_bytes" do
+ before(:each) do
+ @exception, @errinfo = EncodingSpecs::InvalidByteSequenceError.exception
+ @exception2, @errinfo2 = EncodingSpecs::InvalidByteSequenceErrorIndirect.exception
+ end
+
+ it "returns a String" do
+ @exception.error_bytes.should be_an_instance_of(String)
+ @exception2.error_bytes.should be_an_instance_of(String)
+ end
+
+ it "returns the bytes that caused the exception" do
+ @exception.error_bytes.size.should == 1
+ @exception.error_bytes.should == "\xF1"
+ @exception.error_bytes.should == @errinfo[-2]
+
+ @exception2.error_bytes.size.should == 1
+ @exception2.error_bytes.should == "\xA1"
+ @exception2.error_bytes.should == @errinfo2[-2]
+ end
+
+ it "uses ASCII-8BIT as the encoding" do
+ @exception.error_bytes.encoding.should == Encoding::ASCII_8BIT
+
+ @exception2.error_bytes.encoding.should == Encoding::ASCII_8BIT
+ end
+ end
+end
Added: MacRuby/branches/experimental/spec/frozen/core/encoding/invalid_byte_sequence_error/incomplete_input_spec.rb
===================================================================
--- MacRuby/branches/experimental/spec/frozen/core/encoding/invalid_byte_sequence_error/incomplete_input_spec.rb (rev 0)
+++ MacRuby/branches/experimental/spec/frozen/core/encoding/invalid_byte_sequence_error/incomplete_input_spec.rb 2009-07-01 23:43:49 UTC (rev 1957)
@@ -0,0 +1,30 @@
+require File.dirname(__FILE__) + '/../../../spec_helper'
+
+ruby_version_is "1.9" do
+ describe "Encoding::InvalidByteSequenceError#incomplete_input?" do
+
+ it "returns nil by default" do
+ Encoding::InvalidByteSequenceError.new.incomplete_input?.should be_nil
+ end
+
+ it "returns true if #primitive_convert returned :incomplete_input for the same data" do
+ ec = Encoding::Converter.new("EUC-JP", "ISO-8859-1")
+ ec.primitive_convert("\xA1",'').should == :incomplete_input
+ begin
+ ec.convert("\xA1")
+ rescue Encoding::InvalidByteSequenceError => e
+ e.incomplete_input?.should be_true
+ end
+ end
+
+ it "returns false if #primitive_convert returned :invalid_byte_sequence for the same data" do
+ ec = Encoding::Converter.new("ascii", "utf-8")
+ ec.primitive_convert("\xfffffffff",'').should == :invalid_byte_sequence
+ begin
+ ec.convert("\xfffffffff")
+ rescue Encoding::InvalidByteSequenceError => e
+ e.incomplete_input?.should be_false
+ end
+ end
+ end
+end
Added: MacRuby/branches/experimental/spec/frozen/core/encoding/invalid_byte_sequence_error/readagain_bytes_spec.rb
===================================================================
--- MacRuby/branches/experimental/spec/frozen/core/encoding/invalid_byte_sequence_error/readagain_bytes_spec.rb (rev 0)
+++ MacRuby/branches/experimental/spec/frozen/core/encoding/invalid_byte_sequence_error/readagain_bytes_spec.rb 2009-07-01 23:43:49 UTC (rev 1957)
@@ -0,0 +1,31 @@
+require File.dirname(__FILE__) + '/../fixtures/classes'
+
+ruby_version_is "1.9" do
+ describe "Encoding::InvalidByteSequenceError#readagain_bytes" do
+ before(:each) do
+ @exception, @errinfo = EncodingSpecs::InvalidByteSequenceError.exception
+ @exception2, @errinfo2 = EncodingSpecs::InvalidByteSequenceErrorIndirect.exception
+ end
+
+ it "returns a String" do
+ @exception.readagain_bytes.should be_an_instance_of(String)
+ @exception2.readagain_bytes.should be_an_instance_of(String)
+ end
+
+ it "returns the bytes to be read again" do
+ @exception.readagain_bytes.size.should == 1
+ @exception.readagain_bytes.should == "a".force_encoding('binary')
+ @exception.readagain_bytes.should == @errinfo[-1]
+
+ @exception2.readagain_bytes.size.should == 1
+ @exception2.readagain_bytes.should == "\xFF".force_encoding('binary')
+ @exception2.readagain_bytes.should == @errinfo2[-1]
+ end
+
+ it "uses ASCII-8BIT as the encoding" do
+ @exception.readagain_bytes.encoding.should == Encoding::ASCII_8BIT
+
+ @exception2.readagain_bytes.encoding.should == Encoding::ASCII_8BIT
+ end
+ end
+end
Added: MacRuby/branches/experimental/spec/frozen/core/encoding/invalid_byte_sequence_error/source_encoding_name_spec.rb
===================================================================
--- MacRuby/branches/experimental/spec/frozen/core/encoding/invalid_byte_sequence_error/source_encoding_name_spec.rb (rev 0)
+++ MacRuby/branches/experimental/spec/frozen/core/encoding/invalid_byte_sequence_error/source_encoding_name_spec.rb 2009-07-01 23:43:49 UTC (rev 1957)
@@ -0,0 +1,30 @@
+require File.dirname(__FILE__) + '/../fixtures/classes'
+
+ruby_version_is "1.9" do
+ describe "Encoding::UndefinedConversionError#source_encoding_name" do
+ before(:each) do
+ @exception, = EncodingSpecs::UndefinedConversionError.exception
+ @exception2, = EncodingSpecs::UndefinedConversionErrorIndirect.exception
+ end
+
+ it "returns a String" do
+ @exception.source_encoding_name.should be_an_instance_of(String)
+ end
+
+ it "is equal to the source encoding name of the object that raised it" do
+ @exception.source_encoding_name.should == "UTF-8"
+ end
+
+ # The source encoding specified in the Encoding::Converter constructor may
+ # differ from the source encoding returned here. What seems to happen is
+ # that when transcoding along a path with multiple pairs of encodings, the
+ # last one encountered when the error occurred is returned. So in this
+ # case, the conversion path is ISO-8859-1 -> UTF-8 -> EUC-JP. The
+ # conversion from ISO-8859-1 -> UTF-8 succeeded, but the conversion from
+ # UTF-8 to EUC-JP failed. IOW, it failed when the source encoding was
+ # UTF-8, so UTF-8 is regarded as the source encoding.
+ it "is equal to the source encoding at the stage of the conversion path where the error occured" do
+ @exception2.source_encoding_name.should == 'UTF-8'
+ end
+ end
+end
Added: MacRuby/branches/experimental/spec/frozen/core/encoding/invalid_byte_sequence_error/source_encoding_spec.rb
===================================================================
--- MacRuby/branches/experimental/spec/frozen/core/encoding/invalid_byte_sequence_error/source_encoding_spec.rb (rev 0)
+++ MacRuby/branches/experimental/spec/frozen/core/encoding/invalid_byte_sequence_error/source_encoding_spec.rb 2009-07-01 23:43:49 UTC (rev 1957)
@@ -0,0 +1,35 @@
+require File.dirname(__FILE__) + '/../fixtures/classes'
+
+ruby_version_is "1.9" do
+ describe "Encoding::InvalidByteSequenceError#source_encoding" do
+ before(:each) do
+ @exception, = EncodingSpecs::InvalidByteSequenceError.exception
+ @exception2, = EncodingSpecs::InvalidByteSequenceErrorIndirect.exception
+ end
+
+ it "returns an Encoding object" do
+ @exception.source_encoding.should be_an_instance_of(Encoding)
+ @exception2.source_encoding.should be_an_instance_of(Encoding)
+ end
+
+ it "is equal to the source encoding of the object that raised it" do
+ @exception.source_encoding.should == Encoding::UTF_8
+ end
+
+ # The source encoding specified in the Encoding::Converter constructor may
+ # differ from the source encoding returned here. What seems to happen is
+ # that when transcoding along a path with multiple pairs of encodings, the
+ # last one encountered when the error occurred is returned. So in this
+ # case, the conversion path is EUC-JP -> UTF-8 -> ISO-8859-1. The
+ # conversions failed with the first pair of encodings (i.e. transcoding
+ # from EUC-JP to UTF-8, so UTF-8 is regarded as the source encoding; if
+ # the error had occurred when converting from UTF-8 to ISO-8859-1, UTF-8
+ # would have been the source encoding.
+
+ # FIXME: Derive example where the failure occurs at the UTF-8 ->
+ # ISO-8859-1 case so as to better illustrate the issue
+ it "is equal to the source encoding at the stage of the conversion path where the error occured" do
+ @exception2.source_encoding.should == Encoding::EUC_JP
+ end
+ end
+end
Modified: MacRuby/branches/experimental/spec/frozen/core/encoding/list_spec.rb
===================================================================
--- MacRuby/branches/experimental/spec/frozen/core/encoding/list_spec.rb 2009-07-01 23:05:28 UTC (rev 1956)
+++ MacRuby/branches/experimental/spec/frozen/core/encoding/list_spec.rb 2009-07-01 23:43:49 UTC (rev 1957)
@@ -1,5 +1,43 @@
require File.dirname(__FILE__) + '/../../spec_helper'
-describe "Encoding.list" do
- it "needs to be reviewed for spec completeness"
-end
+ruby_version_is "1.9" do
+ describe "Encoding.list" do
+ it "returns an Array" do
+ Encoding.list.should be_an_instance_of(Array)
+ end
+
+ it "returns an Array of Encoding objects" do
+ Encoding.list.each do |enc|
+ enc.should be_an_instance_of(Encoding)
+ end
+ end
+
+ it "returns each encoding only once" do
+ orig = Encoding.list.map {|e| e.name}
+ orig.should == orig.uniq
+ end
+
+ it "includes the default external encoding" do
+ Encoding.list.include?(Encoding.default_external).should be_true
+ end
+
+ it "does not include any alias names" do
+ Encoding.aliases.keys.each do |enc_alias|
+ Encoding.list.include?(enc_alias).should be_false
+ end
+ end
+
+ it "includes all aliased encodings" do
+ Encoding.aliases.values.each do |enc_alias|
+ Encoding.list.include?(Encoding.find(enc_alias)).should be_true
+ end
+ end
+
+ it "includes dummy encodings" do
+ Encoding.list.select {|e| e.dummy?}.should_not == []
+ end
+
+ # TODO: Find example that illustrates this
+ it "updates the list when #find is used to load a new encoding"
+ end
+end
\ No newline at end of file
Modified: MacRuby/branches/experimental/spec/frozen/core/encoding/locale_charmap_spec.rb
===================================================================
--- MacRuby/branches/experimental/spec/frozen/core/encoding/locale_charmap_spec.rb 2009-07-01 23:05:28 UTC (rev 1956)
+++ MacRuby/branches/experimental/spec/frozen/core/encoding/locale_charmap_spec.rb 2009-07-01 23:43:49 UTC (rev 1957)
@@ -1,7 +1,27 @@
require File.dirname(__FILE__) + '/../../spec_helper'
-describe "Encoding.locale_charmap" do
- it "returns the name of the charmap of the current environment's locale" do
- Encoding.locale_charmap.should == ENV["LANG"].split('.').last
+ruby_version_is "1.9" do
+ describe "Encoding.locale_charmap" do
+ it "returns a String" do
+ Encoding.locale_charmap.should be_an_instance_of(String)
+ end
+
+ # FIXME: Get this working on Windows
+ platform_is :os => [:darwin, :linux] do
+ it "returns a value based on the LANG environment variable" do
+ old_lang = ENV['LANG']
+ ENV['LANG'] = 'C'
+ ruby_exe("print Encoding.locale_charmap").should == 'ANSI_X3.4-1968'
+ ENV['LANG'] = old_lang
+ end
+
+ it "is unaffected by assigning to ENV['LANG'] in the same process" do
+ old_charmap = Encoding.locale_charmap
+ old_lang = ENV['LANG']
+ ENV['LANG'] = 'C'
+ Encoding.locale_charmap.should == old_charmap
+ ENV['LANG'] = old_lang
+ end
+ end
end
-end
+end
\ No newline at end of file
Modified: MacRuby/branches/experimental/spec/frozen/core/encoding/name_list_spec.rb
===================================================================
--- MacRuby/branches/experimental/spec/frozen/core/encoding/name_list_spec.rb 2009-07-01 23:05:28 UTC (rev 1956)
+++ MacRuby/branches/experimental/spec/frozen/core/encoding/name_list_spec.rb 2009-07-01 23:43:49 UTC (rev 1957)
@@ -1,5 +1,25 @@
require File.dirname(__FILE__) + '/../../spec_helper'
-describe "Encoding.name_list" do
- it "needs to be reviewed for spec completeness"
-end
+ruby_version_is "1.9" do
+ describe "Encoding.name_list" do
+ it "returns an Array" do
+ Encoding.name_list.should be_an_instance_of(Array)
+ end
+
+ it "returns encoding names as Strings" do
+ Encoding.name_list.each {|e| e.should be_an_instance_of(String) }
+ end
+
+ it "includes all aliases" do
+ Encoding.aliases.keys.each do |enc_alias|
+ Encoding.name_list.include?(enc_alias).should be_true
+ end
+ end
+
+ it "includes all non-dummy encodings" do
+ Encoding.list.each do |enc|
+ Encoding.name_list.include?(enc.name).should be_true
+ end
+ end
+ end
+end
\ No newline at end of file
Modified: MacRuby/branches/experimental/spec/frozen/core/encoding/name_spec.rb
===================================================================
--- MacRuby/branches/experimental/spec/frozen/core/encoding/name_spec.rb 2009-07-01 23:05:28 UTC (rev 1956)
+++ MacRuby/branches/experimental/spec/frozen/core/encoding/name_spec.rb 2009-07-01 23:43:49 UTC (rev 1957)
@@ -1,8 +1,7 @@
-require File.dirname(__FILE__) + '/../../spec_helper'
+require File.dirname(__FILE__) + '/shared/name'
-describe "Encoding#name" do
- it "returns the name of the Encoding instance" do
- Encoding.find("UTF-8").name.should == "UTF-8"
- Encoding.find("ASCII").name.should == "US-ASCII"
+ruby_version_is "1.9" do
+ describe "Encoding#name" do
+ it_behaves_like(:encoding_name, :name)
end
-end
+end
\ No newline at end of file
Modified: MacRuby/branches/experimental/spec/frozen/core/encoding/names_spec.rb
===================================================================
--- MacRuby/branches/experimental/spec/frozen/core/encoding/names_spec.rb 2009-07-01 23:05:28 UTC (rev 1956)
+++ MacRuby/branches/experimental/spec/frozen/core/encoding/names_spec.rb 2009-07-01 23:43:49 UTC (rev 1957)
@@ -1,8 +1,37 @@
require File.dirname(__FILE__) + '/../../spec_helper'
-describe "Encoding#names" do
- it "returns an array of names by which an Encoding instance can be referenced" do
- Encoding.find("UTF-8").names.should == %w{ UTF-8 CP65001 locale external }
- Encoding.find("ASCII").names.should == %w{ US-ASCII ASCII ANSI_X3.4-1968 646 }
+ruby_version_is "1.9" do
+ describe "Encoding#names" do
+ it "returns an Array" do
+ Encoding.name_list.each do |name|
+ e = Encoding.find(name) or next
+ e.names.should be_an_instance_of(Array)
+ end
+ end
+
+ it "returns names as Strings" do
+ Encoding.name_list.each do |name|
+ e = Encoding.find(name) or next
+ e.names.each do |this_name|
+ this_name.should be_an_instance_of(String)
+ end
+ end
+ end
+
+ it "returns #name as the first value" do
+ Encoding.name_list.each do |name|
+ e = Encoding.find(name) or next
+ e.names.first.should == e.name
+ end
+ end
+
+ it "includes any aliases the encoding has" do
+ Encoding.name_list.each do |name|
+ e = Encoding.find(name) or next
+ aliases = Encoding.aliases.select{|a,n| n == name}.keys
+ names = e.names
+ aliases.each {|a| names.include?(a).should be_true}
+ end
+ end
end
-end
+end
\ No newline at end of file
Added: MacRuby/branches/experimental/spec/frozen/core/encoding/shared/name.rb
===================================================================
--- MacRuby/branches/experimental/spec/frozen/core/encoding/shared/name.rb (rev 0)
+++ MacRuby/branches/experimental/spec/frozen/core/encoding/shared/name.rb 2009-07-01 23:43:49 UTC (rev 1957)
@@ -0,0 +1,15 @@
+require File.dirname(__FILE__) + '/../../../spec_helper'
+
+describe :encoding_name, :shared => true do
+ it "returns a String" do
+ Encoding.list.each do |e|
+ e.send(@method).should be_an_instance_of(String)
+ end
+ end
+
+ it "uniquely identifies an encoding" do
+ Encoding.list.each do |e|
+ e.should == Encoding.find(e.send(@method))
+ end
+ end
+end
Modified: MacRuby/branches/experimental/spec/frozen/core/encoding/to_s_spec.rb
===================================================================
--- MacRuby/branches/experimental/spec/frozen/core/encoding/to_s_spec.rb 2009-07-01 23:05:28 UTC (rev 1956)
+++ MacRuby/branches/experimental/spec/frozen/core/encoding/to_s_spec.rb 2009-07-01 23:43:49 UTC (rev 1957)
@@ -1,5 +1,7 @@
-require File.dirname(__FILE__) + '/../../spec_helper'
+require File.dirname(__FILE__) + '/shared/name'
-describe "Encoding#to_s" do
- it "needs to be reviewed for spec completeness"
-end
+ruby_version_is "1.9" do
+ describe "Encoding#to_s" do
+ it_behaves_like(:encoding_name, :to_s)
+ end
+end
\ No newline at end of file
Added: MacRuby/branches/experimental/spec/frozen/core/encoding/undefined_conversion_error/destination_encoding_name_spec.rb
===================================================================
--- MacRuby/branches/experimental/spec/frozen/core/encoding/undefined_conversion_error/destination_encoding_name_spec.rb (rev 0)
+++ MacRuby/branches/experimental/spec/frozen/core/encoding/undefined_conversion_error/destination_encoding_name_spec.rb 2009-07-01 23:43:49 UTC (rev 1957)
@@ -0,0 +1,17 @@
+require File.dirname(__FILE__) + '/../fixtures/classes'
+
+ruby_version_is "1.9" do
+ describe "Encoding::UndefinedConversionError#destination_encoding_name" do
+ before(:each) do
+ @exception = EncodingSpecs::UndefinedConversionError.exception
+ end
+
+ it "returns a String" do
+ @exception.destination_encoding_name.should be_an_instance_of(String)
+ end
+
+ it "is equal to the destination encoding name of the object that raised it" do
+ @exception.destination_encoding_name.should == "US-ASCII"
+ end
+ end
+end
Added: MacRuby/branches/experimental/spec/frozen/core/encoding/undefined_conversion_error/destination_encoding_spec.rb
===================================================================
--- MacRuby/branches/experimental/spec/frozen/core/encoding/undefined_conversion_error/destination_encoding_spec.rb (rev 0)
+++ MacRuby/branches/experimental/spec/frozen/core/encoding/undefined_conversion_error/destination_encoding_spec.rb 2009-07-01 23:43:49 UTC (rev 1957)
@@ -0,0 +1,17 @@
+require File.dirname(__FILE__) + '/../fixtures/classes'
+
+ruby_version_is "1.9" do
+ describe "Encoding::UndefinedConversionError#destination_encoding" do
+ before(:each) do
+ @exception = EncodingSpecs::UndefinedConversionError.exception
+ end
+
+ it "returns an Encoding object" do
+ @exception.destination_encoding.should be_an_instance_of(Encoding)
+ end
+
+ it "is equal to the destination encoding of the object that raised it" do
+ @exception.destination_encoding.should == Encoding::US_ASCII
+ end
+ end
+end
Added: MacRuby/branches/experimental/spec/frozen/core/encoding/undefined_conversion_error/error_char_spec.rb
===================================================================
--- MacRuby/branches/experimental/spec/frozen/core/encoding/undefined_conversion_error/error_char_spec.rb (rev 0)
+++ MacRuby/branches/experimental/spec/frozen/core/encoding/undefined_conversion_error/error_char_spec.rb 2009-07-01 23:43:49 UTC (rev 1957)
@@ -0,0 +1,29 @@
+require File.dirname(__FILE__) + '/../fixtures/classes'
+
+ruby_version_is "1.9" do
+ describe "Encoding::UndefinedConversionError#error_char" do
+ before(:each) do
+ @exception = EncodingSpecs::UndefinedConversionError.exception
+ @exception2 = EncodingSpecs::UndefinedConversionErrorIndirect.exception
+ end
+
+ it "returns a String" do
+ @exception.error_char.should be_an_instance_of(String)
+ @exception2.error_char.should be_an_instance_of(String)
+ end
+
+ it "returns the one-character String that caused the exception" do
+ @exception.error_char.size.should == 1
+ @exception.error_char.should == "\u{8765}"
+
+ @exception2.error_char.size.should == 1
+ @exception2.error_char.should == "\u{A0}"
+ end
+
+ it "uses the source encoding" do
+ @exception.error_char.encoding.should == @exception.source_encoding
+
+ @exception2.error_char.encoding.should == @exception2.source_encoding
+ end
+ end
+end
Added: MacRuby/branches/experimental/spec/frozen/core/encoding/undefined_conversion_error/source_encoding_name_spec.rb
===================================================================
--- MacRuby/branches/experimental/spec/frozen/core/encoding/undefined_conversion_error/source_encoding_name_spec.rb (rev 0)
+++ MacRuby/branches/experimental/spec/frozen/core/encoding/undefined_conversion_error/source_encoding_name_spec.rb 2009-07-01 23:43:49 UTC (rev 1957)
@@ -0,0 +1,30 @@
+require File.dirname(__FILE__) + '/../fixtures/classes'
+
+ruby_version_is "1.9" do
+ describe "Encoding::UndefinedConversionError#source_encoding_name" do
+ before(:each) do
+ @exception = EncodingSpecs::UndefinedConversionError.exception
+ @exception2 = EncodingSpecs::UndefinedConversionErrorIndirect.exception
+ end
+
+ it "returns a String" do
+ @exception.source_encoding_name.should be_an_instance_of(String)
+ end
+
+ it "is equal to the source encoding name of the object that raised it" do
+ @exception.source_encoding_name.should == "UTF-8"
+ end
+
+ # The source encoding specified in the Encoding::Converter constructor may
+ # differ from the source encoding returned here. What seems to happen is
+ # that when transcoding along a path with multiple pairs of encodings, the
+ # last one encountered when the error occurred is returned. So in this
+ # case, the conversion path is ISO-8859-1 -> UTF-8 -> EUC-JP. The
+ # conversion from ISO-8859-1 -> UTF-8 succeeded, but the conversion from
+ # UTF-8 to EUC-JP failed. IOW, it failed when the source encoding was
+ # UTF-8, so UTF-8 is regarded as the source encoding.
+ it "is equal to the source encoding at the stage of the conversion path where the error occured" do
+ @exception2.source_encoding_name.should == 'UTF-8'
+ end
+ end
+end
Added: MacRuby/branches/experimental/spec/frozen/core/encoding/undefined_conversion_error/source_encoding_spec.rb
===================================================================
--- MacRuby/branches/experimental/spec/frozen/core/encoding/undefined_conversion_error/source_encoding_spec.rb (rev 0)
+++ MacRuby/branches/experimental/spec/frozen/core/encoding/undefined_conversion_error/source_encoding_spec.rb 2009-07-01 23:43:49 UTC (rev 1957)
@@ -0,0 +1,31 @@
+require File.dirname(__FILE__) + '/../fixtures/classes'
+
+ruby_version_is "1.9" do
+ describe "Encoding::UndefinedConversionError#source_encoding" do
+ before(:each) do
+ @exception = EncodingSpecs::UndefinedConversionError.exception
+ @exception2 = EncodingSpecs::UndefinedConversionErrorIndirect.exception
+ end
+
+ it "returns an Encoding object" do
+ @exception.source_encoding.should be_an_instance_of(Encoding)
+ @exception2.source_encoding.should be_an_instance_of(Encoding)
+ end
+
+ it "is equal to the source encoding of the object that raised it" do
+ @exception.source_encoding.should == Encoding::UTF_8
+ end
+
+ # The source encoding specified in the Encoding::Converter constructor may
+ # differ from the source encoding returned here. What seems to happen is
+ # that when transcoding along a path with multiple pairs of encodings, the
+ # last one encountered when the error occurred is returned. So in this
+ # case, the conversion path is ISO-8859-1 -> UTF-8 -> EUC-JP. The
+ # conversion from ISO-8859-1 -> UTF-8 succeeded, but the conversion from
+ # UTF-8 to EUC-JP failed. IOW, it failed when the source encoding was
+ # UTF-8, so UTF-8 is regarded as the source encoding.
+ it "is equal to the source encoding at the stage of the conversion path where the error occured" do
+ @exception2.source_encoding.should == Encoding::UTF_8
+ end
+ end
+end
Modified: MacRuby/branches/experimental/spec/frozen/core/enumerable/fixtures/classes.rb
===================================================================
--- MacRuby/branches/experimental/spec/frozen/core/enumerable/fixtures/classes.rb 2009-07-01 23:05:28 UTC (rev 1956)
+++ MacRuby/branches/experimental/spec/frozen/core/enumerable/fixtures/classes.rb 2009-07-01 23:43:49 UTC (rev 1957)
@@ -5,10 +5,10 @@
def initialize(*list)
@list = list.empty? ? [2, 5, 3, 6, 1, 4] : list
end
-
+
def each
@list.each { |i| yield i }
- end
+ end
end
class EachCounter < Numerous
@@ -17,16 +17,16 @@
super(*list)
@times_yielded = @times_called = 0
end
-
+
def each(*arg)
@times_called += 1
@times_yielded = 0
@arguments_passed = arg
@list.each do |i|
- @times_yielded +=1
+ @times_yielded +=1
yield i
end
- end
+ end
end
class Empty
@@ -56,7 +56,7 @@
def initialize(*arr)
@arr = arr
end
-
+
def each
i = 0
loop do
@@ -66,7 +66,7 @@
end
end
- end
+ end
class SortByDummy
def initialize(s)
@@ -79,23 +79,23 @@
end
class ComparesByVowelCount
-
+
attr_accessor :value, :vowels
-
+
def self.wrap(*args)
args.map {|element| ComparesByVowelCount.new(element)}
end
-
+
def initialize(string)
self.value = string
all_vowels = ['a', 'e' , 'i' , 'o', 'u']
self.vowels = string.gsub(/[^aeiou]/,'').size
end
-
+
def <=>(other)
self.vowels <=> other.vowels
end
-
+
end
class InvalidComparable
@@ -109,12 +109,12 @@
def initialize(*values)
@values = values;
end
-
+
def to_a
self.called = :to_a
@values
end
-
+
def to_ary
self.called = :to_ary
@values
@@ -152,7 +152,7 @@
other.num <=> @num
end
end
-
+
class ComparableWithFixnum
include Comparable
def initialize(num)
@@ -164,4 +164,9 @@
end
end
+ class Uncomparable
+ def <=>(obj)
+ nil
+ end
+ end
end # EnumerableSpecs utility classes
Modified: MacRuby/branches/experimental/spec/frozen/core/enumerable/shared/take.rb
===================================================================
--- MacRuby/branches/experimental/spec/frozen/core/enumerable/shared/take.rb 2009-07-01 23:05:28 UTC (rev 1956)
+++ MacRuby/branches/experimental/spec/frozen/core/enumerable/shared/take.rb 2009-07-01 23:43:49 UTC (rev 1957)
@@ -1,11 +1,12 @@
describe :enumerable_take, :shared => true do
before :each do
- @values = [4,3,2,1]
+ @values = [4,3,2,1,0,-1]
@enum = EnumerableSpecs::Numerous.new(*@values)
end
it "returns the first count elements if given a count" do
@enum.send(@method, 2).should == [4, 3]
+ @enum.send(@method, 4).should == [4, 3, 2, 1] # See redmine #1686 !
end
it "returns an empty array when passed count on an empty array" do
@@ -28,7 +29,8 @@
end
it "returns the entire array when count > length" do
- @enum.send(@method, 10).should == @values
+ @enum.send(@method, 100).should == @values
+ @enum.send(@method, 8).should == @values # See redmine #1686 !
end
it "tries to convert the passed argument to an Integer using #to_int" do
Modified: MacRuby/branches/experimental/spec/frozen/core/enumerable/sort_spec.rb
===================================================================
--- MacRuby/branches/experimental/spec/frozen/core/enumerable/sort_spec.rb 2009-07-01 23:05:28 UTC (rev 1956)
+++ MacRuby/branches/experimental/spec/frozen/core/enumerable/sort_spec.rb 2009-07-01 23:43:49 UTC (rev 1957)
@@ -27,7 +27,7 @@
x <=> y
}.should == [true, true, nil, nil, nil, nil, nil, false, false]
end
-
+
it "compare values returned by block with 0" do
EnumerableSpecs::Numerous.new.sort { |n, m| -(n+m) * (n <=> m) }.should == [6, 5, 4, 3, 2, 1]
EnumerableSpecs::Numerous.new.sort { |n, m|
@@ -37,6 +37,9 @@
EnumerableSpecs::Numerous.new.sort { |n, m| (n <=> m).to_s }
}.should raise_error(ArgumentError)
end
-
+
+ it "raises an error if objects can't be compared" do
+ a=EnumerableSpecs::Numerous.new(EnumerableSpecs::Uncomparable.new, EnumerableSpecs::Uncomparable.new)
+ lambda {a.sort}.should raise_error(ArgumentError)
+ end
end
-
Modified: MacRuby/branches/experimental/spec/frozen/core/exception/backtrace_spec.rb
===================================================================
--- MacRuby/branches/experimental/spec/frozen/core/exception/backtrace_spec.rb 2009-07-01 23:05:28 UTC (rev 1956)
+++ MacRuby/branches/experimental/spec/frozen/core/exception/backtrace_spec.rb 2009-07-01 23:43:49 UTC (rev 1957)
@@ -1 +1,51 @@
require File.dirname(__FILE__) + '/../../spec_helper'
+require File.dirname(__FILE__) + '/fixtures/common'
+
+describe "Exception#backtrace" do
+ before(:each) do
+ @backtrace = ExceptionSpecs::Backtrace.backtrace
+ end
+
+ it "returns nil if no backtrace was set" do
+ Exception.new.backtrace.should be_nil
+ end
+
+ it "returns an Array" do
+ @backtrace.should be_an_instance_of(Array)
+ end
+
+ it "sets each element to a String" do
+ @backtrace.each {|l| l.should be_an_instance_of(String)}
+ end
+
+ it "includes the filename of the location where self raised in the first element" do
+ @backtrace.first.should =~ /common\.rb/
+ end
+
+ it "includes the line number of the location where self raised in the first element" do
+ @backtrace.first.should =~ /:22:in /
+ end
+
+ it "includes the name of the method from where self raised in the first element" do
+ @backtrace.first.should =~ /in `backtrace'/
+ end
+
+ it "includes the filename of the location immediately prior to where self raised in the second element" do
+ @backtrace[1].should =~ /backtrace_spec\.rb/
+ end
+
+ it "includes the line number of the location immediately prior to where self raised in the second element" do
+ @backtrace[1].should =~ /:6(:in )?/
+ end
+
+ it "contains lines of the same format for each prior position in the stack" do
+ @backtrace[2..-1].each do |line|
+ # This regexp is deliberately imprecise to account for 1.9 using
+ # absolute paths where 1.8 used relative paths, the need to abstract out
+ # the paths of the included mspec files, the differences in output
+ # between 1.8 and 1.9, and the desire to avoid specifying in any
+ # detail what the in `...' portion looks like.
+ line.should =~ /^[^ ]+\:\d+(:in `[^`]+')?$/
+ end
+ end
+end
Added: MacRuby/branches/experimental/spec/frozen/core/exception/equal_value_spec.rb
===================================================================
--- MacRuby/branches/experimental/spec/frozen/core/exception/equal_value_spec.rb (rev 0)
+++ MacRuby/branches/experimental/spec/frozen/core/exception/equal_value_spec.rb 2009-07-01 23:43:49 UTC (rev 1957)
@@ -0,0 +1,70 @@
+require File.dirname(__FILE__) + '/../../spec_helper'
+require File.dirname(__FILE__) + '/fixtures/common'
+
+ruby_version_is "1.9" do
+ describe "Exception#==" do
+ it "returns true if both exceptions are the same object" do
+ e = ArgumentError.new
+ e.should == e
+ end
+
+ it "returns true if one exception is the dup'd copy of the other" do
+ e = ArgumentError.new
+ e.should == e.dup
+ end
+
+ it "returns true if both exceptions have the same class, no message, and no backtrace" do
+ RuntimeError.new.should == RuntimeError.new
+ end
+
+ it "returns true if both exceptions have the same class, the same message, and no backtrace" do
+ TypeError.new(:message).should == TypeError.new(:message)
+ end
+
+ it "returns true if both exceptions have the same class, the same message, and the same backtrace" do
+ one = TypeError.new(:message)
+ one.set_backtrace [File.dirname(__FILE__)]
+ two = TypeError.new(:message)
+ two.set_backtrace [File.dirname(__FILE__)]
+ one.should == two
+ end
+
+ it "returns true if the two exceptions inherit from Exception but have different classes" do
+ one = RuntimeError.new(:message)
+ one.set_backtrace [File.dirname(__FILE__)]
+ one.should be_kind_of(Exception)
+ two = TypeError.new(:message)
+ two.set_backtrace [File.dirname(__FILE__)]
+ two.should be_kind_of(Exception)
+ one.should == two
+ end
+
+ it "returns true if the two objects subclass Exception and have the same message and backtrace" do
+ one = ExceptionSpecs::UnExceptional.new
+ two = ExceptionSpecs::UnExceptional.new
+ one.message.should == two.message
+ two.backtrace.should == two.backtrace
+ one.should == two
+ end
+
+ it "returns false if the argument is not an Exception" do
+ ArgumentError.new.should_not == String.new
+ end
+
+ it "returns false if the two exceptions differ only in their backtrace" do
+ one = RuntimeError.new(:message)
+ one.set_backtrace [File.dirname(__FILE__)]
+ two = RuntimeError.new(:message)
+ two.set_backtrace nil
+ one.should_not == two
+ end
+
+ it "returns false if the two exceptions differ only in their message" do
+ one = RuntimeError.new(:message)
+ one.set_backtrace [File.dirname(__FILE__)]
+ two = RuntimeError.new(:message2)
+ two.set_backtrace [File.dirname(__FILE__)]
+ one.should_not == two
+ end
+ end
+end
Modified: MacRuby/branches/experimental/spec/frozen/core/exception/exception_spec.rb
===================================================================
--- MacRuby/branches/experimental/spec/frozen/core/exception/exception_spec.rb 2009-07-01 23:05:28 UTC (rev 1956)
+++ MacRuby/branches/experimental/spec/frozen/core/exception/exception_spec.rb 2009-07-01 23:43:49 UTC (rev 1957)
@@ -42,5 +42,28 @@
it "is a superclass of SecurityError" do
Exception.should be_ancestor_of(SecurityError)
end
+
+ it "is a superclass of EncodingError" do
+ Exception.should be_ancestor_of(EncodingError)
+ end
end
end
+
+describe "Exception#exception" do
+ it "returns self when passed no argument" do
+ e = RuntimeError.new
+ e.should == e.exception
+ end
+
+ it "returns self when passed self as an argument" do
+ e = RuntimeError.new
+ e.should == e.exception(e)
+ end
+
+ it "returns an exception of the same class as self with the message given as argument" do
+ e = RuntimeError.new
+ e2 = e.exception(:message)
+ e2.should be_an_instance_of(RuntimeError)
+ e2.message.should == :message
+ end
+end
Modified: MacRuby/branches/experimental/spec/frozen/core/exception/fixtures/common.rb
===================================================================
--- MacRuby/branches/experimental/spec/frozen/core/exception/fixtures/common.rb 2009-07-01 23:05:28 UTC (rev 1956)
+++ MacRuby/branches/experimental/spec/frozen/core/exception/fixtures/common.rb 2009-07-01 23:43:49 UTC (rev 1957)
@@ -15,4 +15,23 @@
module ExceptionSpecs
class Exceptional < Exception; end
+
+ class Backtrace
+ def self.backtrace
+ begin
+ raise
+ rescue RuntimeError => e
+ e.backtrace
+ end
+ end
+ end
+
+ class UnExceptional < Exception
+ def backtrace
+ nil
+ end
+ def message
+ nil
+ end
+ end
end
Modified: MacRuby/branches/experimental/spec/frozen/core/float/comparison_spec.rb
===================================================================
--- MacRuby/branches/experimental/spec/frozen/core/float/comparison_spec.rb 2009-07-01 23:05:28 UTC (rev 1956)
+++ MacRuby/branches/experimental/spec/frozen/core/float/comparison_spec.rb 2009-07-01 23:43:49 UTC (rev 1957)
@@ -12,6 +12,11 @@
((bignum_value*1.1) <=> bignum_value).should == 1
end
+ it "returns nil when either argument is NaN" do
+ (@nan <=> 71.2).should be_nil
+ (1771.176 <=> @nan).should be_nil
+ end
+
# TODO: Remove duplicate ruby_bug guards when ruby_bug is fixed.
ruby_bug "[ruby-dev:38672] [Bug #1645]", "1.8.6.369" do
# The 4 tests below are taken from matz's revision 23730 for Ruby trunk
Modified: MacRuby/branches/experimental/spec/frozen/core/float/numerator_spec.rb
===================================================================
--- MacRuby/branches/experimental/spec/frozen/core/float/numerator_spec.rb 2009-07-01 23:05:28 UTC (rev 1956)
+++ MacRuby/branches/experimental/spec/frozen/core/float/numerator_spec.rb 2009-07-01 23:43:49 UTC (rev 1957)
@@ -1,7 +1,7 @@
require File.dirname(__FILE__) + '/../../spec_helper'
ruby_version_is "1.9" do
- describe "Numeric#numerator" do
+ describe "Float#numerator" do
before(:all) do
@numbers = [
29871.2722891,
Modified: MacRuby/branches/experimental/spec/frozen/core/hash/default_proc_spec.rb
===================================================================
--- MacRuby/branches/experimental/spec/frozen/core/hash/default_proc_spec.rb 2009-07-01 23:05:28 UTC (rev 1956)
+++ MacRuby/branches/experimental/spec/frozen/core/hash/default_proc_spec.rb 2009-07-01 23:43:49 UTC (rev 1957)
@@ -37,7 +37,7 @@
h.default_proc.call.should == 6
end
- it "raise an error if passed stuff not convertible to procs" do
+ it "raises an error if passed stuff not convertible to procs" do
lambda{new_hash.default_proc = nil}.should raise_error(TypeError)
lambda{new_hash.default_proc = 42}.should raise_error(TypeError)
end
Modified: MacRuby/branches/experimental/spec/frozen/core/integer/chr_spec.rb
===================================================================
--- MacRuby/branches/experimental/spec/frozen/core/integer/chr_spec.rb 2009-07-01 23:05:28 UTC (rev 1956)
+++ MacRuby/branches/experimental/spec/frozen/core/integer/chr_spec.rb 2009-07-01 23:43:49 UTC (rev 1957)
@@ -1,23 +1,144 @@
require File.dirname(__FILE__) + '/../../spec_helper'
-describe "Integer#chr" do
- it "returns a string containing the ASCII character represented by self" do
- [82.chr, 117.chr, 98.chr, 105.chr, 110.chr, 105.chr, 117.chr, 115.chr,
- 32.chr,
- 114.chr, 111.chr, 99.chr, 107.chr, 115.chr].should ==
- ["R", "u", "b", "i", "n", "i", "u", "s", " ", "r", "o", "c", "k", "s"]
+ruby_version_is ""..."1.9" do
+ describe "Integer#chr" do
+ it "returns a string containing the ASCII character represented by self" do
+ [82.chr, 117.chr, 98.chr, 105.chr, 110.chr, 105.chr, 117.chr, 115.chr,
+ 32.chr,
+ 114.chr, 111.chr, 99.chr, 107.chr, 115.chr].should ==
+ ["R", "u", "b", "i", "n", "i", "u", "s", " ", "r", "o", "c", "k", "s"]
+ end
+
+ it "returns a new String for each call" do
+ 82.chr.should_not equal(82.chr)
+ end
+
+ it "raises a RangeError if self is out of the ASCII character range" do
+ lambda { -1.chr }.should raise_error(RangeError)
+ lambda { -300.chr }.should raise_error(RangeError)
+ lambda { (-bignum_value).chr }.should raise_error(RangeError)
+
+ lambda { 300.chr }.should raise_error(RangeError)
+ lambda { bignum_value.chr }.should raise_error(RangeError)
+ end
end
+end
- it "returns a new String for each call" do
- 82.chr.should_not equal(82.chr)
+ruby_version_is "1.9" do
+ describe "Integer#chr without argument" do
+ it "returns a String" do
+ 17.chr.should be_an_instance_of(String)
+ end
+
+ it "returns a new String for each call" do
+ 82.chr.should_not equal(82.chr)
+ end
+
+ it "returns a US-ASCII String if self is between 0 and 127 (inclusive)" do
+ 0.chr.encoding.should == Encoding::US_ASCII
+ 69.chr.encoding.should == Encoding::US_ASCII
+ 127.chr.encoding.should == Encoding::US_ASCII
+ 128.chr.encoding.should_not == Encoding::US_ASCII
+ end
+
+ it "returns an ASCII-8BIT String if self is between 128 and 255 (inclusive)" do
+ 128.chr.encoding.should == Encoding::ASCII_8BIT
+ 210.chr.encoding.should == Encoding::ASCII_8BIT
+ 255.chr.encoding.should == Encoding::ASCII_8BIT
+ end
+
+ it "interprets self as a codepoint in the corresponding character set" do
+ 80.chr.should == 'P'.force_encoding(Encoding::US_ASCII)
+ 80.chr.codepoints.to_a.should == [80]
+
+ 200.chr.should == "\xC8".force_encoding(Encoding::ASCII_8BIT)
+ 200.chr.codepoints.to_a.should == [200]
+ end
+
+ it "raises a RangeError is self is greater than 255 and the internal encoding is nil" do
+ Encoding.default_internal.should be_nil
+ lambda { 256.chr }.should raise_error(RangeError)
+ lambda { bignum_value.chr }.should raise_error(RangeError)
+ end
+
+ it "infers the encoding from Encoding.default_internal" do
+ old_internal = Encoding.default_internal
+ Encoding.default_internal = Encoding::UTF_8
+ 120818.chr.should == "\u{1d7f2}"
+ Encoding.default_internal = old_internal
+ end
+
+ it "raises a RangeError is self is less than 0" do
+ lambda { -1.chr }.should raise_error(RangeError)
+ lambda { -bignum_value.chr }.should raise_error(RangeError)
+ end
end
-
- it "raises a RangeError if self is out of the ASCII character range" do
- lambda { -1.chr }.should raise_error(RangeError)
- lambda { -300.chr }.should raise_error(RangeError)
- lambda { (-bignum_value).chr }.should raise_error(RangeError)
- lambda { 300.chr }.should raise_error(RangeError)
- lambda { bignum_value.chr }.should raise_error(RangeError)
+ describe "Integer#chr with an encoding argument" do
+ it "returns a String" do
+ 900.chr(Encoding::UTF_8).should be_an_instance_of(String)
+ end
+
+ it "returns a new String for each call" do
+ 8287.chr(Encoding::UTF_8).should_not equal(8287.chr(Encoding::UTF_8))
+ end
+
+ it "accepts an Encoding object as an argument" do
+ lambda { 568.chr(Encoding::SHIFT_JIS) }.should_not raise_error
+ end
+
+ it "accepts a String as an argument" do
+ lambda { 56.chr('euc-jp') }.should_not raise_error
+ end
+
+ it "converts a String to an Encoding as Encoding.find does" do
+ ['utf-8', 'UTF-8', 'Utf-8'].each do |encoding|
+ 7894.chr(encoding).encoding.should == Encoding::UTF_8
+ end
+ end
+
+ it "returns characters in the specified encoding even if they exist in US-ASCII" do
+ 97.chr.encoding.should == Encoding::US_ASCII
+ 97.chr(Encoding::UTF_8).encoding.should == Encoding::UTF_8
+ end
+
+ it "behaves as called with no argument if encoding is specified as US-ASCII and self is less than 128" do
+ 0.chr(Encoding::US_ASCII).should == 0.chr
+ 69.chr(Encoding::US_ASCII).should == 69.chr
+ 127.chr(Encoding::US_ASCII).should == 127.chr
+ end
+
+ it "behaves as called with no argument if encoding is specified as ASCII-8BIT and self is between 128 and 255" do
+ 128.chr(Encoding::ASCII_8BIT).should == 128.chr
+ 200.chr(Encoding::ASCII_8BIT).should == 200.chr
+ 255.chr(Encoding::ASCII_8BIT).should == 255.chr
+ lambda { 256.chr(Encoding::ASCII_8BIT) }.should raise_error(RangeError)
+ end
+
+ it "interprets self as a codepoint in the corresponding character set" do
+ 0x56CE.chr(Encoding::UTF_8).should == "\u{56CE}"
+ 0x56CE.chr(Encoding::UTF_8).codepoints.to_a.should == [0x56CE]
+
+ 41900.chr(Encoding::BIG5).should == "\xA3\xAC".\
+ force_encoding(Encoding::BIG5)
+ 41900.chr(Encoding::BIG5).codepoints.to_a.should == [41900]
+
+ 129.chr(Encoding::KOI8_R).should == "\x81".\
+ force_encoding(Encoding::KOI8_R)
+ 129.chr(Encoding::KOI8_R).codepoints.to_a.should == [129]
+ end
+
+ it "raises a RangeError if self is an invalid codepoint for the given encoding" do
+ lambda { 0x81.chr(Encoding::EUC_JP) }.should raise_error(RangeError)
+ lambda { 256.chr(Encoding::ISO_8859_9) }.should raise_error(RangeError)
+ lambda { 620.chr(Encoding::TIS_620) }.should raise_error(RangeError)
+ end
+
+ it "raises a RangeError is self is less than 0" do
+ lambda { -1.chr(Encoding::UTF_8) }.\
+ should raise_error(RangeError)
+ lambda { -bignum_value.chr(Encoding::EUC_JP) }.\
+ should raise_error(RangeError)
+ end
end
end
Added: MacRuby/branches/experimental/spec/frozen/core/io/codepoints.rb
===================================================================
--- MacRuby/branches/experimental/spec/frozen/core/io/codepoints.rb (rev 0)
+++ MacRuby/branches/experimental/spec/frozen/core/io/codepoints.rb 2009-07-01 23:43:49 UTC (rev 1957)
@@ -0,0 +1,17 @@
+require File.dirname(__FILE__) + '/../../spec_helper'
+require File.dirname(__FILE__) + '/fixtures/classes'
+require File.dirname(__FILE__) + '/shared/codepoints'
+
+# See redmine #1667
+describe "IO#codepoints" do
+ ruby_version_is "1.9.2" do
+ it_behaves_like(:io_codepoints, :codepoints)
+
+ it "ignores a given block" do
+ File.open(IOSpecs.gets_fixtures) do |io|
+ enum = io.codepoints{ raise "Never called!"}
+ enum.first.should == 86
+ end
+ end
+ end
+end
Added: MacRuby/branches/experimental/spec/frozen/core/io/each_codepoint.rb
===================================================================
--- MacRuby/branches/experimental/spec/frozen/core/io/each_codepoint.rb (rev 0)
+++ MacRuby/branches/experimental/spec/frozen/core/io/each_codepoint.rb 2009-07-01 23:43:49 UTC (rev 1957)
@@ -0,0 +1,26 @@
+require File.dirname(__FILE__) + '/../../spec_helper'
+require File.dirname(__FILE__) + '/fixtures/classes'
+require File.dirname(__FILE__) + '/shared/codepoints'
+
+# See redmine #1667
+describe "IO#each_codepoint" do
+ ruby_version_is "1.9.2" do
+ it_behaves_like(:io_codepoints, :codepoints)
+
+ it "calls the given block" do
+ File.open(IOSpecs.gets_fixtures) do |io|
+ r = []
+ io.each_codepoint{|c| r << c }
+ r[24].should == 232
+ r.last.should == 10
+ end
+ end
+
+ it "returns self" do
+ File.open(IOSpecs.gets_fixtures) do |io|
+ io.each_codepoint {|l| l }.should equal(io)
+ end
+ end
+ end
+end
+
Modified: MacRuby/branches/experimental/spec/frozen/core/io/eof_spec.rb
===================================================================
--- MacRuby/branches/experimental/spec/frozen/core/io/eof_spec.rb 2009-07-01 23:05:28 UTC (rev 1956)
+++ MacRuby/branches/experimental/spec/frozen/core/io/eof_spec.rb 2009-07-01 23:43:49 UTC (rev 1957)
@@ -48,11 +48,20 @@
@file.eof?.should == false
end
- it "should not consume the data from the stream" do
- @file.eof?.should == false
- @file.getc.should == 86
+ ruby_version_is ""..."1.9" do
+ it "should not consume the data from the stream" do
+ @file.eof?.should == false
+ @file.getc.should == 86
+ end
end
+ ruby_version_is "1.9" do
+ it "should not consume the data from the stream" do
+ @file.eof?.should == false
+ @file.getc.should == 'V'
+ end
+ end
+
it "raises IOError on closed stream" do
lambda { IOSpecs.closed_file.eof? }.should raise_error(IOError)
end
Added: MacRuby/branches/experimental/spec/frozen/core/io/shared/codepoints.rb
===================================================================
--- MacRuby/branches/experimental/spec/frozen/core/io/shared/codepoints.rb (rev 0)
+++ MacRuby/branches/experimental/spec/frozen/core/io/shared/codepoints.rb 2009-07-01 23:43:49 UTC (rev 1957)
@@ -0,0 +1,42 @@
+# encoding: utf-8
+require File.dirname(__FILE__) + '/../fixtures/classes'
+
+describe :io_codepoints, :shared => true do
+ before(:each) do
+ @io = File.open(IOSpecs.gets_fixtures)
+ @enum = @io.send(@method)
+ end
+
+ after(:each) do
+ @io.close
+ end
+
+ it "returns an Enumerator when passed no block" do
+ @enum.should be_an_instance_of(enumerator_class)
+ end
+
+ it "yields each codepoint" do
+ @enum.first(25).should == [86, 111, 105, 99, 105, 32, 108, 97, 32, 108, 105, 103, 110, 101, 32, 117, 110, 101, 46, 10, 81, 117, 105, 32, 232]
+ end
+
+ it "yields each codepoint starting from the current position" do
+ @io.pos = 130
+ @enum.to_a.should == [101, 32, 115, 105, 120, 46, 10]
+ end
+
+ it "raises an error if reading invalid sequence" do
+ @io.pos = 60 # inside of a multibyte sequence
+ lambda { @enum.first }.should raise_error(ArgumentError)
+ end
+
+ it "does not change $_" do
+ $_ = "test"
+ @enum.to_a
+ $_.should == "test"
+ end
+
+ it "raises an IOError when self is not readable" do
+ lambda { IOSpecs.closed_file.send(@method).to_a }.should raise_error(IOError)
+ end
+
+end
\ No newline at end of file
Modified: MacRuby/branches/experimental/spec/frozen/core/kernel/instance_variable_set_spec.rb
===================================================================
--- MacRuby/branches/experimental/spec/frozen/core/kernel/instance_variable_set_spec.rb 2009-07-01 23:05:28 UTC (rev 1956)
+++ MacRuby/branches/experimental/spec/frozen/core/kernel/instance_variable_set_spec.rb 2009-07-01 23:43:49 UTC (rev 1957)
@@ -21,10 +21,18 @@
lambda { NoDog.new.instance_variable_set(:c, "cat") }.should raise_error(NameError)
end
- it "raises an ArgumentError if the instance variable name is a Fixnum" do
- lambda { "".instance_variable_set(1, 2) }.should raise_error(ArgumentError)
+ ruby_version_is ""..."1.9" do
+ it "raises an ArgumentError if the instance variable name is a Fixnum" do
+ lambda { "".instance_variable_set(1, 2) }.should raise_error(ArgumentError)
+ end
end
+ ruby_version_is "1.9" do
+ it "raises a TypeError if the instance variable name is a Fixnum" do
+ lambda { "".instance_variable_set(1, 2) }.should raise_error(TypeError)
+ end
+ end
+
it "raises a TypeError if the instance variable name is an object that does not respond to to_str" do
class KernelSpecs::A; end
lambda { "".instance_variable_set(KernelSpecs::A.new, 3) }.should raise_error(TypeError)
Modified: MacRuby/branches/experimental/spec/frozen/core/method/fixtures/classes.rb
===================================================================
--- MacRuby/branches/experimental/spec/frozen/core/method/fixtures/classes.rb 2009-07-01 23:05:28 UTC (rev 1956)
+++ MacRuby/branches/experimental/spec/frozen/core/method/fixtures/classes.rb 2009-07-01 23:43:49 UTC (rev 1957)
@@ -1,4 +1,20 @@
module MethodSpecs
+
+
+ class SourceLocation
+ def self.location # This needs to be on this line
+ :location # for the spec to pass
+ end
+
+ def self.redefined
+ :first
+ end
+
+ def self.redefined
+ :last
+ end
+ end
+
class Methods
def foo
true
Added: MacRuby/branches/experimental/spec/frozen/core/method/source_location_spec.rb
===================================================================
--- MacRuby/branches/experimental/spec/frozen/core/method/source_location_spec.rb (rev 0)
+++ MacRuby/branches/experimental/spec/frozen/core/method/source_location_spec.rb 2009-07-01 23:43:49 UTC (rev 1957)
@@ -0,0 +1,34 @@
+require File.dirname(__FILE__) + '/../../spec_helper'
+require File.dirname(__FILE__) + '/fixtures/classes'
+
+ruby_version_is "1.9" do
+ describe "Method#source_location" do
+ before(:each) do
+ @method = MethodSpecs::SourceLocation.method(:location)
+ end
+
+ it "returns nil for built-in methods" do
+ File.method(:size).source_location.should be_nil
+ end
+
+ it "returns an Array" do
+ @method.source_location.should be_an_instance_of(Array)
+ end
+
+ it "sets the first value to the path of the file in which the method was defined" do
+ file = @method.source_location.first
+ file.should be_an_instance_of(String)
+ file.should == File.dirname(__FILE__) + '/fixtures/classes.rb'
+ end
+
+ it "sets the last value to a Fixnum representing the line on which the method was defined" do
+ line = @method.source_location.last
+ line.should be_an_instance_of(Fixnum)
+ line.should == 5
+ end
+
+ it "returns the last place the method was defined" do
+ MethodSpecs::SourceLocation.method(:redefined).source_location.last.should == 13
+ end
+ end
+end
Added: MacRuby/branches/experimental/spec/frozen/core/numeric/abs2_spec.rb
===================================================================
--- MacRuby/branches/experimental/spec/frozen/core/numeric/abs2_spec.rb (rev 0)
+++ MacRuby/branches/experimental/spec/frozen/core/numeric/abs2_spec.rb 2009-07-01 23:43:49 UTC (rev 1957)
@@ -0,0 +1,36 @@
+require File.dirname(__FILE__) + '/../../spec_helper'
+
+ruby_version_is "1.9" do
+ describe "Numeric#abs2" do
+ before(:each) do
+ @numbers = [
+ 0,
+ 0.0,
+ 1,
+ 20,
+ bignum_value,
+ 278202.292871,
+ 72829,
+ 3.333333333333,
+ 0.1,
+ 1/0.0
+ ].map { |n| [-n, n] }.flatten
+ end
+
+ it "returns the square of the absolute value of self" do
+ @numbers.each do |number|
+ number.abs2.should eql(number.abs ** 2)
+ end
+ end
+
+ it "calls #* on self" do
+ number = mock_numeric('numeric')
+ number.should_receive(:*).and_return(:result)
+ number.abs2.should == :result
+ end
+
+ it "returns NaN when self is NaN" do
+ (0/0.0).abs2.nan?.should be_true
+ end
+ end
+end
Modified: MacRuby/branches/experimental/spec/frozen/core/numeric/denominator_spec.rb
===================================================================
--- MacRuby/branches/experimental/spec/frozen/core/numeric/denominator_spec.rb 2009-07-01 23:05:28 UTC (rev 1956)
+++ MacRuby/branches/experimental/spec/frozen/core/numeric/denominator_spec.rb 2009-07-01 23:43:49 UTC (rev 1957)
@@ -14,5 +14,13 @@
it "returns 1" do
@numbers.each {|number| number.denominator.should == 1}
end
+
+ it "works with Numeric subclasses" do
+ rational = mock_numeric('rational')
+ rational.should_receive(:denominator).and_return(:denominator)
+ numeric = mock_numeric('numeric')
+ numeric.should_receive(:to_r).and_return(rational)
+ numeric.denominator.should == :denominator
+ end
end
end
Added: MacRuby/branches/experimental/spec/frozen/core/numeric/fdiv_spec.rb
===================================================================
--- MacRuby/branches/experimental/spec/frozen/core/numeric/fdiv_spec.rb (rev 0)
+++ MacRuby/branches/experimental/spec/frozen/core/numeric/fdiv_spec.rb 2009-07-01 23:43:49 UTC (rev 1957)
@@ -0,0 +1,37 @@
+require File.dirname(__FILE__) + '/../../spec_helper'
+
+describe "Numeric#fdiv" do
+ ruby_version_is "1.9" do
+ it "coerces self with #to_f" do
+ numeric = mock_numeric('numeric')
+ numeric.should_receive(:to_f).and_return(3.0)
+ numeric.fdiv(0.5).should == 6.0
+ end
+
+ it "coerces other with #to_f" do
+ numeric = mock_numeric('numeric')
+ numeric.should_receive(:to_f).and_return(3.0)
+ 6.fdiv(numeric).should == 2.0
+ end
+
+ it "performs floating-point division" do
+ 3.fdiv(2).should == 1.5
+ end
+
+ it "returns a Float" do
+ bignum_value.fdiv(Float::MAX).should be_an_instance_of(Float)
+ end
+
+ it "returns Infinity if other is 0" do
+ 8121.92821.fdiv(0).infinite?.should == 1
+ end
+
+ it "returns NaN if other is NaN" do
+ 3334.fdiv(0/0.0).nan?.should be_true
+ end
+ end
+
+ ruby_version_is ""..."1.9" do
+ it "needs to be reviewed for spec completeness"
+ end
+end
Modified: MacRuby/branches/experimental/spec/frozen/core/numeric/numerator_spec.rb
===================================================================
--- MacRuby/branches/experimental/spec/frozen/core/numeric/numerator_spec.rb 2009-07-01 23:05:28 UTC (rev 1956)
+++ MacRuby/branches/experimental/spec/frozen/core/numeric/numerator_spec.rb 2009-07-01 23:43:49 UTC (rev 1957)
@@ -23,5 +23,13 @@
number.numerator.should == Rational(number).numerator
end
end
+
+ it "works with Numeric subclasses" do
+ rational = mock_numeric('rational')
+ rational.should_receive(:numerator).and_return(:numerator)
+ numeric = mock_numeric('numeric')
+ numeric.should_receive(:to_r).and_return(rational)
+ numeric.numerator.should == :numerator
+ 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-07-01 23:05:28 UTC (rev 1956)
+++ MacRuby/branches/experimental/spec/frozen/core/numeric/real_spec.rb 2009-07-01 23:43:49 UTC (rev 1957)
@@ -15,13 +15,17 @@
it "returns self" do
@numbers.each do |number|
- number.send(@method).should == 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.send(@method, number) }.should raise_error(ArgumentError)
+ lambda { number.real(number) }.should raise_error(ArgumentError)
end
end
end
Modified: MacRuby/branches/experimental/spec/frozen/core/numeric/shared/rect.rb
===================================================================
--- MacRuby/branches/experimental/spec/frozen/core/numeric/shared/rect.rb 2009-07-01 23:05:28 UTC (rev 1956)
+++ MacRuby/branches/experimental/spec/frozen/core/numeric/shared/rect.rb 2009-07-01 23:43:49 UTC (rev 1957)
@@ -26,7 +26,11 @@
it "returns self as the first element" do
@numbers.each do |number|
- number.send(@method).first.should == number
+ if number.to_f.nan?
+ number.send(@method).first.nan?.should be_true
+ else
+ number.send(@method).first.should == number
+ end
end
end
Modified: MacRuby/branches/experimental/spec/frozen/core/objectspace/define_finalizer_spec.rb
===================================================================
--- MacRuby/branches/experimental/spec/frozen/core/objectspace/define_finalizer_spec.rb 2009-07-01 23:05:28 UTC (rev 1956)
+++ MacRuby/branches/experimental/spec/frozen/core/objectspace/define_finalizer_spec.rb 2009-07-01 23:43:49 UTC (rev 1957)
@@ -23,18 +23,35 @@
ObjectSpace.define_finalizer("garbage", handler).should == [0, handler]
end
- it "calls finalizer on process termination" do
- rd, wr = IO.pipe
- if Kernel::fork then
- wr.close
- rd.read.should == "finalized"
- rd.close
- else
- rd.close
- obj = "Test"
- handler = Proc.new { wr.write "finalized"; wr.close }
- ObjectSpace.define_finalizer(obj, handler)
- exit 0
+ ruby_bug "#1706", "1.9.2" do
+ it "calls finalizer on process termination" do
+ rd, wr = IO.pipe
+ if Kernel::fork then
+ wr.close
+ rd.read.should == "finalized"
+ rd.close
+ else
+ rd.close
+ handler = Proc.new { wr.write "finalized"; wr.close }
+ obj = "Test"
+ ObjectSpace.define_finalizer(obj, handler)
+ exit 0
+ end
end
+
+ it "doesn't call self-referencing finalizers" do
+ rd, wr = IO.pipe
+ if Kernel::fork then
+ wr.close
+ rd.read.should_not == "finalized"
+ rd.close
+ else
+ rd.close
+ obj = "Test"
+ handler = Proc.new { wr.write "finalized"; wr.close }
+ ObjectSpace.define_finalizer(obj, handler)
+ exit 0
+ end
+ end
end
end
Modified: MacRuby/branches/experimental/spec/frozen/core/proc/arity_spec.rb
===================================================================
--- MacRuby/branches/experimental/spec/frozen/core/proc/arity_spec.rb 2009-07-01 23:05:28 UTC (rev 1956)
+++ MacRuby/branches/experimental/spec/frozen/core/proc/arity_spec.rb 2009-07-01 23:43:49 UTC (rev 1957)
@@ -43,15 +43,31 @@
proc { |a, b, *c| }.arity.should == -3
end
- it "returns -1 if no argument declaration is made, using Proc.new" do
- Proc.new { }.arity.should == -1
+ ruby_version_is ""..."1.9" do
+ it "returns -1 if no argument declaration is made, using Kernel#lambda" do
+ lambda { }.arity.should == -1
+ end
+
+ it "returns -1 if no argument declaration is made, using Kernel#proc" do
+ proc { }.arity.should == -1
+ end
+
+ it "returns -1 if no argument declaration is made, using Proc.new" do
+ Proc.new { }.arity.should == -1
+ end
end
- it "returns -1 if no argument declaration is made, using Kernel#lambda" do
- lambda { }.arity.should == -1
+ ruby_version_is "1.9" do
+ it "returns 0 if no argument declaration is made, using Kernel#lambda" do
+ lambda { }.arity.should == 0
+ end
+
+ it "returns 0 if no argument declaration is made, using Kernel#proc" do
+ proc { }.arity.should == 0
+ end
+
+ it "returns 0 if no argument declaration is made, using Proc.new" do
+ Proc.new { }.arity.should == 0
+ end
end
-
- it "returns -1 if no argument declaration is made, using Kernel#proc" do
- proc { }.arity.should == -1
- end
end
Modified: MacRuby/branches/experimental/spec/frozen/core/proc/new_spec.rb
===================================================================
--- MacRuby/branches/experimental/spec/frozen/core/proc/new_spec.rb 2009-07-01 23:05:28 UTC (rev 1956)
+++ MacRuby/branches/experimental/spec/frozen/core/proc/new_spec.rb 2009-07-01 23:43:49 UTC (rev 1957)
@@ -7,12 +7,24 @@
Proc.new { "hello" }.call.should == "hello"
end
+ # This raises a ThreadError on 1.8 HEAD. Reported as bug #1707
it "raises a LocalJumpError when context of the block no longer exists" do
def some_method(&b) b end
a_proc = Proc.new { return }
res = some_method(&a_proc)
+
+ # Using raise_error here causes 1.9 to hang, so we roll our own
+ # begin/rescue block to verify that the exception is raised.
- lambda { res.call }.should raise_error(LocalJumpError)
+ exception = nil
+
+ begin
+ res.call
+ rescue LocalJumpError => e
+ exception = e
+ end
+
+ e.should be_an_instance_of(LocalJumpError)
end
it "returns from within enclosing method when 'return' is used in the block" do
Modified: MacRuby/branches/experimental/spec/frozen/core/proc/shared/call.rb
===================================================================
--- MacRuby/branches/experimental/spec/frozen/core/proc/shared/call.rb 2009-07-01 23:05:28 UTC (rev 1956)
+++ MacRuby/branches/experimental/spec/frozen/core/proc/shared/call.rb 2009-07-01 23:43:49 UTC (rev 1957)
@@ -19,25 +19,28 @@
proc { |_, *args| args }.send(@method, 1, 2, 3).should == [2, 3]
end
- it "sets self's single parameter to an Array of all given values" do
- [Proc.new { |x| [x] }, lambda { |x| [x] }, proc { |x| [x] }].each do |p|
- a = p.send(@method)
- a.class.should == Array
- a.should == [nil]
-
- a = p.send(@method, 1)
- a.class.should == Array
- a.should == [1]
-
- a = p.send(@method, 1, 2)
- a.class.should == Array
- a.should == [[1, 2]]
-
- a = p.send(@method, 1, 2, 3)
- a.class.should == Array
- a.should == [[1, 2, 3]]
+ ruby_version_is ""..."1.9" do
+ it "sets self's single parameter to an Array of all given values" do
+ [Proc.new { |x| [x] }, lambda { |x| [x] }, proc { |x| [x] }].each do |p|
+ a = p.send(@method)
+ a.class.should == Array
+ a.should == [nil]
+
+ a = p.send(@method, 1)
+ a.class.should == Array
+ a.should == [1]
+
+ a = p.send(@method, 1, 2)
+ a.class.should == Array
+ a.should == [[1, 2]]
+
+ a = p.send(@method, 1, 2, 3)
+ a.class.should == Array
+ a.should == [[1, 2, 3]]
+ end
end
end
+
end
describe :proc_call_on_proc_new, :shared => true do
@@ -60,22 +63,67 @@
end
describe :proc_call_on_proc_or_lambda, :shared => true do
- it "raises an ArgumentError when called with too few arguments" do
- lambda { lambda { |a, b| [a, b] }.send(@method) }.should raise_error(ArgumentError)
- lambda { lambda { |a, b| [a, b] }.send(@method, 1) }.should raise_error(ArgumentError)
- lambda { proc { |a, b| [a, b] }.send(@method) }.should raise_error(ArgumentError)
- lambda { proc { |a, b| [a, b] }.send(@method, 1) }.should raise_error(ArgumentError)
- end
+ ruby_version_is ""..."1.9" do
+ it "raises an ArgumentError when called with too few arguments" do
+ lambda { lambda { |a, b| [a, b] }.send(@method) }.should raise_error(ArgumentError)
+ lambda { lambda { |a, b| [a, b] }.send(@method, 1) }.should raise_error(ArgumentError)
+ lambda { proc { |a, b| [a, b] }.send(@method) }.should raise_error(ArgumentError)
+ lambda { proc { |a, b| [a, b] }.send(@method, 1) }.should raise_error(ArgumentError)
+ end
- it "raises an ArgumentError when called with too many arguments" do
- lambda { lambda { |a, b| [a, b] }.send(@method, 1, 2, 3) }.should raise_error(ArgumentError)
- lambda { proc { |a, b| [a, b] }.send(@method, 1, 2, 3) }.should raise_error(ArgumentError)
+ it "raises an ArgumentError when called with too many arguments" do
+ lambda { lambda { |a, b| [a, b] }.send(@method, 1, 2, 3) }.should raise_error(ArgumentError)
+ lambda { proc { |a, b| [a, b] }.send(@method, 1, 2, 3) }.should raise_error(ArgumentError)
+ end
+
+ it "treats a single Array argument as a single argument" do
+ lambda { |a| [a] }.send(@method, [1, 2]).should == [[1, 2]]
+ lambda { lambda { |a, b| [a, b] }.send(@method, [1, 2]) }.should raise_error(ArgumentError)
+ proc { |a| [a] }.send(@method, [1, 2]).should == [[1, 2]]
+ lambda { proc { |a, b| [a, b] }.send(@method, [1, 2]) }.should raise_error(ArgumentError)
+ end
end
- it "treats a single Array argument as a single argument" do
- lambda { |a| [a] }.send(@method, [1, 2]).should == [[1, 2]]
- lambda { lambda { |a, b| [a, b] }.send(@method, [1, 2]) }.should raise_error(ArgumentError)
- proc { |a| [a] }.send(@method, [1, 2]).should == [[1, 2]]
- lambda { proc { |a, b| [a, b] }.send(@method, [1, 2]) }.should raise_error(ArgumentError)
+ ruby_version_is "1.9" do
+ it "ignores excess arguments when self is a proc" do
+ a = proc {|x| x}.send(@method, 1, 2)
+ a.should == 1
+
+ a = proc {|x| x}.send(@method, 1, 2, 3)
+ a.should == 1
+ end
+
+ it "substitutes nil for missing arguments when self is a proc" do
+ proc {|x,y| [x,y]}.send(@method).should == [nil,nil]
+
+ a = proc {|x,y| [x, y]}.send(@method, 1)
+ a.should == [1,nil]
+ end
+
+ it "raises an ArgumentError on excess arguments when self is a lambda" do
+ lambda { lambda {|x| x}.send(@method, 1, 2) }.should
+ raise_error(ArgumentError)
+
+ lambda { lambda {|x| x}.send(@method, 1, 2, 3) }.should
+ raise_error(ArgumentError)
+ end
+
+ it "raises an ArgumentError on missing arguments when self is a lambda" do
+ lambda { lambda {|x| x}.send(@method) }.should
+ raise_error(ArgumentError)
+
+ lambda { lambda {|x,y| [x,y]}.send(@method, 1) }.should
+ raise_error(ArgumentError)
+ end
+
+ it "treats a single Array argument as a single argument when self is a lambda" do
+ lambda { |a| a }.send(@method, [1, 2]).should == [1, 2]
+ lambda { |a, b| [a, b] }.send(@method, [1, 2], 3).should == [[1,2], 3]
+ end
+
+ it "treats a single Array argument as a single argument when self is a proc" do
+ proc { |a| a }.send(@method, [1, 2]).should == [1, 2]
+ proc { |a, b| [a, b] }.send(@method, [1, 2], 3).should == [[1,2], 3]
+ end
end
end
Modified: MacRuby/branches/experimental/spec/frozen/core/regexp/inspect_spec.rb
===================================================================
--- MacRuby/branches/experimental/spec/frozen/core/regexp/inspect_spec.rb 2009-07-01 23:05:28 UTC (rev 1956)
+++ MacRuby/branches/experimental/spec/frozen/core/regexp/inspect_spec.rb 2009-07-01 23:43:49 UTC (rev 1957)
@@ -4,7 +4,9 @@
it "returns a formatted string that would eval to the same regexp" do
/ab+c/ix.inspect.should == "/ab+c/ix"
/a(.)+s/n.inspect.should =~ %r|/a(.)+s/n?| # Default 'n' may not appear
- /a(.)+s/u.inspect.should == "/a(.)+s/u" # But a specified one does
+ # 1.9 doesn't round-trip the encoding flags, such as 'u'. This is
+ # seemingly by design.
+ /a(.)+s/m.inspect.should == "/a(.)+s/m" # But a specified one does
end
it "correctly escapes forward slashes /" do
Modified: MacRuby/branches/experimental/spec/frozen/core/string/ascii_only_spec_disabled.rb
===================================================================
--- MacRuby/branches/experimental/spec/frozen/core/string/ascii_only_spec_disabled.rb 2009-07-01 23:05:28 UTC (rev 1956)
+++ MacRuby/branches/experimental/spec/frozen/core/string/ascii_only_spec_disabled.rb 2009-07-01 23:43:49 UTC (rev 1957)
@@ -4,49 +4,59 @@
ruby_version_is '1.9' do
describe "String#ascii_only?" do
- it "needs to be reviewed for spec completeness"
-
- it "returns true if the String contains only ASCII characters" do
+ it "returns true if the String contains only US-ASCII characters" do
"hello".ascii_only?.should be_true
end
- it "returns true if the String contains only ASCII characters
- and is encoded as ASCII" do
- "hello".force_encoding('ASCII').ascii_only?.should be_true
- "hello".encode("ASCII").ascii_only?.should be_true
+ it "returns true if the String contains only US-ASCII characters
+ and is encoded as US-ASCII" do
+ "hello".force_encoding(Encoding::US_ASCII).ascii_only?.should be_true
+ "hello".encode(Encoding::US_ASCII).ascii_only?.should be_true
end
- it "returns true if the String contains only ASCII characters
+ it "returns true if the String contains only US-ASCII characters
and is encoded as UTF-8" do
"hello".force_encoding('UTF-8').ascii_only?.should be_true
"hello".encode('UTF-8').ascii_only?.should be_true
end
- it "returns false if the String contains only non-ASCII characters" do
+ it "returns true for all single-character US-ASCII Strings" do
+ 0.upto(127) do |n|
+ n.chr.ascii_only?.should be_true
+ end
+ end
+
+ it "returns false for the first non-US-ASCII single-character String" do
+ chr = 128.chr
+ chr.encoding.should == Encoding::ASCII_8BIT
+ chr.ascii_only?.should be_false
+ end
+
+ it "returns false if the String contains only non-US-ASCII characters" do
"\u{6666}".ascii_only?.should be_false
end
- it "returns false if the String contains only non-ASCII characters
+ it "returns false if the String contains only non-US-ASCII characters
and is encoded as UTF-8" do
"\u{6666}".force_encoding('UTF-8').ascii_only?.should be_false
"\u{6666}".encode('UTF-8').ascii_only?.should be_false
end
it "returns false if the String contains only non-ASCII characters
- and is encoded as ASCII" do
- "\u{6666}".force_encoding('ASCII').ascii_only?.should be_false
+ and is encoded as US-ASCII" do
+ "\u{6666}".force_encoding(Encoding::US_ASCII).ascii_only?.should be_false
end
- it "returns false if the String contains ASCII and non-ASCII characters" do
+ it "returns false if the String contains US-ASCII and non-US-ASCII characters" do
"hello, \u{6666}".ascii_only?.should be_false
end
- it "returns false if the String contains ASCII and non-ASCII characters
- and is encoded as ASCII" do
- "hello, \u{6666}".force_encoding('ASCII').ascii_only?.should be_false
+ it "returns false if the String contains US-ASCII and non-US-ASCII characters
+ and is encoded as US-ASCII" do
+ "hello, \u{6666}".force_encoding(Encoding::US_ASCII).ascii_only?.should be_false
end
- it "returns false if the String contains ASCII and non-ASCII characters
+ it "returns false if the String contains US-ASCII and non-US-ASCII characters
and is encoded as UTF-8" do
"hello, \u{6666}".encode('UTF-8').ascii_only?.should be_false
"hello, \u{6666}".force_encoding('UTF-8').ascii_only?.should be_false
Modified: MacRuby/branches/experimental/spec/frozen/core/string/bytesize_spec_disabled.rb
===================================================================
--- MacRuby/branches/experimental/spec/frozen/core/string/bytesize_spec_disabled.rb 2009-07-01 23:05:28 UTC (rev 1956)
+++ MacRuby/branches/experimental/spec/frozen/core/string/bytesize_spec_disabled.rb 2009-07-01 23:43:49 UTC (rev 1957)
@@ -15,7 +15,7 @@
"\u{6666}".bytesize.should == 3
end
- it "works with psuedo-ASCII strings containing single UTF-8 characters" do
+ it "works with pseudo-ASCII strings containing single UTF-8 characters" do
"\u{6666}".force_encoding('ASCII').bytesize.should == 3
end
@@ -24,7 +24,7 @@
"c \u{6666}".bytesize.should == 5
end
- it "works with psuedo-ASCII strings containing UTF-8 characters" do
+ it "works with pseudo-ASCII strings containing UTF-8 characters" do
"c \u{6666}".force_encoding('ASCII').bytesize.should == 5
end
Added: MacRuby/branches/experimental/spec/frozen/core/string/chars_spec.rb
===================================================================
--- MacRuby/branches/experimental/spec/frozen/core/string/chars_spec.rb (rev 0)
+++ MacRuby/branches/experimental/spec/frozen/core/string/chars_spec.rb 2009-07-01 23:43:49 UTC (rev 1957)
@@ -0,0 +1,7 @@
+require File.dirname(__FILE__) + '/shared/chars'
+
+ruby_version_is '1.8.7' do
+ describe "String#chars" do
+ it_behaves_like(:string_chars, :chars)
+ end
+end
Added: MacRuby/branches/experimental/spec/frozen/core/string/chr_spec.rb
===================================================================
--- MacRuby/branches/experimental/spec/frozen/core/string/chr_spec.rb (rev 0)
+++ MacRuby/branches/experimental/spec/frozen/core/string/chr_spec.rb 2009-07-01 23:43:49 UTC (rev 1957)
@@ -0,0 +1,44 @@
+require File.dirname(__FILE__) + '/../../spec_helper'
+
+ruby_version_is "1.9" do
+ describe "String#chr" do
+ it "returns a copy of self" do
+ s = 'e'
+ s.object_id.should_not == s.chr.object_id
+ end
+
+ it "returns a String" do
+ 'glark'.chr.should be_an_instance_of(String)
+ end
+
+ it "returns an empty String if self is an empty String" do
+ "".chr.should == ""
+ end
+
+ it "returns a 1-character String" do
+ "glark".chr.size.should == 1
+ end
+
+ it "returns the character at the start of the String" do
+ "Goodbye, world".chr.should == "G"
+ end
+
+ it "returns a String in the same encoding as self" do
+ "\x24".encode(Encoding::US_ASCII).chr.encoding.should == Encoding::US_ASCII
+ end
+
+ it "understands multi-byte characters" do
+ s = "\u{9879}"
+ s.bytesize.should == 3
+ s.chr.should == s
+ end
+
+ it "understands Strings that contain a mixture of character widths" do
+ three = "\u{8082}"
+ three.bytesize.should == 3
+ four = "\u{77082}"
+ four.bytesize.should == 4
+ "#{three}#{four}".chr.should == three
+ end
+ end
+end
Added: MacRuby/branches/experimental/spec/frozen/core/string/clear_spec.rb
===================================================================
--- MacRuby/branches/experimental/spec/frozen/core/string/clear_spec.rb (rev 0)
+++ MacRuby/branches/experimental/spec/frozen/core/string/clear_spec.rb 2009-07-01 23:43:49 UTC (rev 1957)
@@ -0,0 +1,39 @@
+require File.dirname(__FILE__) + '/../../spec_helper'
+
+ruby_version_is "1.9" do
+ describe "String#clear" do
+ before(:each) do
+ @s = "Jolene"
+ end
+
+ it "sets self equal to the empty String" do
+ @s.clear
+ @s.should == ""
+ end
+
+ it "returns self after emptying it" do
+ cleared = @s.clear
+ cleared.should == ""
+ cleared.object_id.should == @s.object_id
+ end
+
+ it "preserves its encoding" do
+ @s.encode!(Encoding::SHIFT_JIS)
+ @s.encoding.should == Encoding::SHIFT_JIS
+ @s.clear.encoding.should == Encoding::SHIFT_JIS
+ @s.encoding.should == Encoding::SHIFT_JIS
+ end
+
+ it "works with multibyte Strings" do
+ s = "\u{9765}\u{876}"
+ s.clear
+ s.should == ""
+ end
+
+ it "raises a RuntimeError if self is frozen" do
+ @s.freeze
+ lambda { @s.clear }.should raise_error(RuntimeError)
+ lambda { "".freeze.clear }.should raise_error(RuntimeError)
+ end
+ end
+end
Added: MacRuby/branches/experimental/spec/frozen/core/string/codepoints_spec.rb
===================================================================
--- MacRuby/branches/experimental/spec/frozen/core/string/codepoints_spec.rb (rev 0)
+++ MacRuby/branches/experimental/spec/frozen/core/string/codepoints_spec.rb 2009-07-01 23:43:49 UTC (rev 1957)
@@ -0,0 +1,8 @@
+require File.dirname(__FILE__) + '/../../spec_helper'
+require File.dirname(__FILE__) + '/shared/codepoints'
+
+ruby_version_is "1.9" do
+ describe "String#codepoints" do
+ it_behaves_like(:string_codepoints, :codepoints)
+ end
+end
Modified: MacRuby/branches/experimental/spec/frozen/core/string/dump_spec.rb
===================================================================
--- MacRuby/branches/experimental/spec/frozen/core/string/dump_spec.rb 2009-07-01 23:05:28 UTC (rev 1956)
+++ MacRuby/branches/experimental/spec/frozen/core/string/dump_spec.rb 2009-07-01 23:43:49 UTC (rev 1957)
@@ -15,6 +15,14 @@
ruby_version_is "1.9" do
it "returns a string with nonprinting charaters replaced by \\x notation" do
("\000".."A").to_a.join('').should == "\x00\x01\x02\x03\x04\x05\x06\a\b\t\n\v\f\r\x0E\x0F\x10\x11\x12\x13\x14\x15\x16\x17\x18\x19\x1A\e\x1C\x1D\x1E\x1F !\"\#$%&'()*+,-./0123456789:;<=>?@A"
+ # This test is based on my observations; the precise workings of this
+ # feature are unknown to me
+ it "includes .force_encoding(name) if the encoding isn't ASCII compatiable" do
+ "\u{876}".encode('utf-16be').dump.should ==
+ "\"\\bv\".force_encoding(\"UTF-16BE\")"
+ "\u{876}".encode('utf-16le').dump.should ==
+ "\"v\\b\".force_encoding(\"UTF-16LE\")"
+ end
end
end
Modified: MacRuby/branches/experimental/spec/frozen/core/string/each_char_spec.rb
===================================================================
--- MacRuby/branches/experimental/spec/frozen/core/string/each_char_spec.rb 2009-07-01 23:05:28 UTC (rev 1956)
+++ MacRuby/branches/experimental/spec/frozen/core/string/each_char_spec.rb 2009-07-01 23:43:49 UTC (rev 1957)
@@ -1,34 +1,8 @@
-# encoding: utf-8
-require File.dirname(__FILE__) + '/../../spec_helper'
-require File.dirname(__FILE__) + '/fixtures/classes'
+require File.dirname(__FILE__) + '/shared/chars'
ruby_version_is '1.8.7' do
describe "String#each_char" do
- it "passes each char in self to the given block" do
- a = []
- "hello".each_char { |c| a << c }
- a.should == ['h', 'e', 'l', 'l', 'o']
- end
-
- ruby_bug 'redmine #1487', '1.9.1' do
- it "returns self" do
- s = StringSpecs::MyString.new "hello"
- s.each_char{}.should equal(s)
- end
- end
-
- it "returns an enumerator when no block given" do
- enum = "hello".each_char
- enum.should be_kind_of(enumerator_class)
- enum.to_a.should == ['h', 'e', 'l', 'l', 'o']
- end
-
- it "is unicode aware" do
- before = $KCODE
- $KCODE = "UTF-8"
- "\303\207\342\210\202\303\251\306\222g".each_char.to_a.should == ["\303\207", "\342\210\202", "\303\251", "\306\222", "g"]
- $KCODE = before
- end
-
+ it_behaves_like(:string_chars, :each_char)
end
end
+
Added: MacRuby/branches/experimental/spec/frozen/core/string/each_codepoint_spec.rb
===================================================================
--- MacRuby/branches/experimental/spec/frozen/core/string/each_codepoint_spec.rb (rev 0)
+++ MacRuby/branches/experimental/spec/frozen/core/string/each_codepoint_spec.rb 2009-07-01 23:43:49 UTC (rev 1957)
@@ -0,0 +1,8 @@
+require File.dirname(__FILE__) + '/../../spec_helper'
+require File.dirname(__FILE__) + '/shared/codepoints'
+
+ruby_version_is "1.9" do
+ describe "String#each_codepoint" do
+ it_behaves_like(:string_codepoints, :each_codepoint)
+ end
+end
Added: MacRuby/branches/experimental/spec/frozen/core/string/encoding_spec.rb
===================================================================
--- MacRuby/branches/experimental/spec/frozen/core/string/encoding_spec.rb (rev 0)
+++ MacRuby/branches/experimental/spec/frozen/core/string/encoding_spec.rb 2009-07-01 23:43:49 UTC (rev 1957)
@@ -0,0 +1,181 @@
+require File.dirname(__FILE__) + '/../../spec_helper'
+require File.dirname(__FILE__) + '/fixtures/iso-8859-9-encoding'
+
+ruby_version_is "1.9" do
+ describe "String#encoding" do
+ it "returns an Encoding object" do
+ String.new.encoding.should be_an_instance_of(Encoding)
+ end
+
+ it "is equal to the source encoding by default" do
+ s = StringSpecs::ISO88599Encoding.new
+ s.cedilla.encoding.should == s.source_encoding
+ end
+
+ it "returns the given encoding if #force_encoding has been called" do
+ "a".force_encoding(Encoding::SHIFT_JIS).encoding.should == Encoding::SHIFT_JIS
+ end
+
+ it "returns the given encoding if #encode!has been called" do
+ "a".encode!(Encoding::SHIFT_JIS).encoding.should == Encoding::SHIFT_JIS
+ end
+ end
+
+ describe "String#encoding for US-ASCII Strings" do
+ it "returns US-ASCII if self is US-ASCII" do
+ "a".encoding.should == Encoding::US_ASCII
+ end
+
+ it "returns US-ASCII if self is US-ASCII only, despite the default internal encoding being different" do
+ default_internal = Encoding.default_internal
+ Encoding.default_internal = Encoding::UTF_8
+ "a".encoding.should == Encoding::US_ASCII
+ Encoding.default_internal = default_internal
+ end
+
+ it "returns US-ASCII if self is US-ASCII only, despite the default external encoding being different" do
+ default_external = Encoding.default_external
+ Encoding.default_external = Encoding::UTF_8
+ "a".encoding.should == Encoding::US_ASCII
+ Encoding.default_external = default_external
+ end
+
+ it "returns US-ASCII if self is US-ASCII only, despite the default internal and external encodings being different" do
+ default_internal = Encoding.default_internal
+ default_external = Encoding.default_external
+ Encoding.default_internal = Encoding::UTF_8
+ Encoding.default_external = Encoding::UTF_8
+ "a".encoding.should == Encoding::US_ASCII
+ Encoding.default_external = default_external
+ Encoding.default_internal = default_internal
+ end
+
+ it "returns US-ASCII if self is US-ASCII only, despite the default encodings being different" do
+ default_internal = Encoding.default_internal
+ default_external = Encoding.default_external
+ Encoding.default_internal = Encoding::UTF_8
+ Encoding.default_external = Encoding::UTF_8
+ "a".encoding.should == Encoding::US_ASCII
+ Encoding.default_external = default_external
+ Encoding.default_internal = default_internal
+ end
+
+ end
+
+ describe "String#encoding for Strings with \\u escapes" do
+ it "returns UTF-8" do
+ "\u{4040}".encoding.should == Encoding::UTF_8
+ end
+
+ it "returns US-ASCII if self is US-ASCII only" do
+ s = "\u{40}"
+ s.ascii_only?.should be_true
+ s.encoding.should == Encoding::US_ASCII
+ end
+
+ it "returns UTF-8 if self isn't US-ASCII only" do
+ s = "\u{4076}\u{619}"
+ s.ascii_only?.should be_false
+ s.encoding.should == Encoding::UTF_8
+ end
+
+ it "is not affected by the default internal encoding" do
+ default_internal = Encoding.default_internal
+ Encoding.default_internal = Encoding::ISO_8859_15
+ "\u{5050}".encoding.should == Encoding::UTF_8
+ "\u{50}".encoding.should == Encoding::US_ASCII
+ Encoding.default_internal = default_internal
+ end
+
+ it "is not affected by the default external encoding" do
+ default_external = Encoding.default_external
+ Encoding.default_external = Encoding::SHIFT_JIS
+ "\u{50}".encoding.should == Encoding::US_ASCII
+ "\u{5050}".encoding.should == Encoding::UTF_8
+ Encoding.default_external = default_external
+ end
+
+ it "is not affected by both the default internal and external encoding being set at the same time" do
+ default_internal = Encoding.default_internal
+ default_external = Encoding.default_external
+ Encoding.default_internal = Encoding::EUC_JP
+ Encoding.default_external = Encoding::SHIFT_JIS
+ "\u{50}".encoding.should == Encoding::US_ASCII
+ "\u{507}".encoding.should == Encoding::UTF_8
+ Encoding.default_external = default_external
+ Encoding.default_internal = default_internal
+ end
+
+ it "returns the given encoding if #force_encoding has been called" do
+ "\u{20}".force_encoding(Encoding::SHIFT_JIS).encoding.should == Encoding::SHIFT_JIS
+ "\u{2020}".force_encoding(Encoding::SHIFT_JIS).encoding.should == Encoding::SHIFT_JIS
+ end
+
+ it "returns the given encoding if #encode!has been called" do
+ "\u{20}".encode!(Encoding::SHIFT_JIS).encoding.should == Encoding::SHIFT_JIS
+ "\u{2020}".encode!(Encoding::SHIFT_JIS).encoding.should == Encoding::SHIFT_JIS
+ end
+ end
+
+ describe "String#encoding for Strings with \\x escapes" do
+
+ it "returns US-ASCII if self is US-ASCII only" do
+ s = "\x61"
+ s.ascii_only?.should be_true
+ s.encoding.should == Encoding::US_ASCII
+ end
+
+ it "returns ASCII-8BIT when an escape creates a byte with the 8th bit set if the source encoding is US-ASCII" do
+ __ENCODING__.should == Encoding::US_ASCII
+ s = "\xDF"
+ s.ascii_only?.should be_false
+ s.encoding.should == Encoding::ASCII_8BIT
+ end
+
+ # TODO: Deal with case when the byte in question isn't valid in the source
+ # encoding?
+ it "returns the source encoding when an escape creates a byte with the 8th bit set if the source encoding isn't US-ASCII" do
+ fixture = StringSpecs::ISO88599Encoding.new
+ fixture.source_encoding.should == Encoding::ISO8859_9
+ fixture.x_escape.ascii_only?.should be_false
+ fixture.x_escape.encoding.should == Encoding::ISO8859_9
+ end
+
+ it "is not affected by the default internal encoding" do
+ default_internal = Encoding.default_internal
+ Encoding.default_internal = Encoding::ISO_8859_15
+ "\x50".encoding.should == Encoding::US_ASCII
+ "\x50".encoding.should == Encoding::US_ASCII
+ Encoding.default_internal = default_internal
+ end
+
+ it "is not affected by the default external encoding" do
+ default_external = Encoding.default_external
+ Encoding.default_external = Encoding::SHIFT_JIS
+ "\x50".encoding.should == Encoding::US_ASCII
+ "\xD4".encoding.should == Encoding::ASCII_8BIT
+ Encoding.default_external = default_external
+ end
+
+ it "is not affected by both the default internal and external encoding being set at the same time" do
+ default_internal = Encoding.default_internal
+ default_external = Encoding.default_external
+ Encoding.default_internal = Encoding::EUC_JP
+ Encoding.default_external = Encoding::SHIFT_JIS
+ "\x50".encoding.should == Encoding::US_ASCII
+ "\xD4".encoding.should == Encoding::ASCII_8BIT
+ Encoding.default_external = default_external
+ Encoding.default_internal = default_internal
+ end
+
+ it "returns the given encoding if #force_encoding has been called" do
+ "\x50".force_encoding(Encoding::SHIFT_JIS).encoding.should == Encoding::SHIFT_JIS
+ "\xD4".force_encoding(Encoding::ISO_8859_9).encoding.should == Encoding::ISO_8859_9
+ end
+
+ it "returns the given encoding if #encode!has been called" do
+ "\x50".encode!(Encoding::SHIFT_JIS).encoding.should == Encoding::SHIFT_JIS
+ "\x00".encode!(Encoding::UTF_8).encoding.should == Encoding::UTF_8
+ end
+ end
+end
Added: MacRuby/branches/experimental/spec/frozen/core/string/fixtures/iso-8859-9-encoding.rb
===================================================================
--- MacRuby/branches/experimental/spec/frozen/core/string/fixtures/iso-8859-9-encoding.rb (rev 0)
+++ MacRuby/branches/experimental/spec/frozen/core/string/fixtures/iso-8859-9-encoding.rb 2009-07-01 23:43:49 UTC (rev 1957)
@@ -0,0 +1,9 @@
+# coding: iso-8859-9
+module StringSpecs
+ class ISO88599Encoding
+ def source_encoding; __ENCODING__; end
+ def x_escape; "\xDF"; end
+ def ascii_only; "glark"; end
+ def cedilla; "Ş"; end
+ end
+end
Added: MacRuby/branches/experimental/spec/frozen/core/string/force_encoding_spec.rb
===================================================================
--- MacRuby/branches/experimental/spec/frozen/core/string/force_encoding_spec.rb (rev 0)
+++ MacRuby/branches/experimental/spec/frozen/core/string/force_encoding_spec.rb 2009-07-01 23:43:49 UTC (rev 1957)
@@ -0,0 +1,54 @@
+
+ruby_version_is "1.9" do
+ describe "String#force_encoding" do
+ it "requires exactly one argument" do
+ lambda { "glark".force_encoding }.should
+ raise_error(ArgumentError)
+ lambda { "glark".force_encoding('h','d') }.should
+ raise_error(ArgumentError)
+ end
+
+ it "accepts the encoding name as a String" do
+ lambda { str.force_encoding('shift_jis') }.should_not
+ raise_error(ArgumentError)
+ end
+
+ it "accepts the encoding name as an Encoding object" do
+ lambda { str.force_encoding(Encoding::SHIFT_JIS) }.should_not
+ raise_error(ArgumentError)
+ end
+
+ it "tags the String with the given encoding" do
+ str = "a"
+ str.encoding.should == Encoding::US_ASCII
+ str.force_encoding(Encoding::SHIFT_JIS)
+ str.encoding.should == Encoding::SHIFT_JIS
+ end
+
+ it "returns self" do
+ str = "glark"
+ id = str.object_id
+ str.force_encoding('utf-8').object_id.should == id
+ end
+
+ it "does not care if self would be invalid in given encoding" do
+ str = "\u{9765}"
+ str.force_encoding('euc-jp')
+ str.encoding.should == Encoding::EUC_JP
+ str.valid_encoding?.should be_false
+ end
+
+ it "does not care if self is already tagged with the given encoding" do
+ str = "\u{9765}"
+ str.encoding.should == Encoding::UTF_8
+ lambda { str.force_encoding('utf-8') }.should_not
+ raise_error(ArgumentError)
+ str.encoding.should == Encoding::UTF_8
+ end
+
+ it "does not transcode self" do
+ "\u{8612}".force_encoding('utf-16le').should_not ==
+ "\u{8612}".encode('utf-16le')
+ end
+ end
+end
Added: MacRuby/branches/experimental/spec/frozen/core/string/getbyte_spec.rb
===================================================================
--- MacRuby/branches/experimental/spec/frozen/core/string/getbyte_spec.rb (rev 0)
+++ MacRuby/branches/experimental/spec/frozen/core/string/getbyte_spec.rb 2009-07-01 23:43:49 UTC (rev 1957)
@@ -0,0 +1,63 @@
+# coding: utf-8
+require File.dirname(__FILE__) + '/../../spec_helper'
+
+ruby_version_is "1.9" do
+ describe "String#getbyte" do
+ it "returns an Integer if given a valid index" do
+ "a".getbyte(0).should be_kind_of(Integer)
+ end
+
+ it "starts indexing at 0" do
+ "b".getbyte(0).should == 98
+ end
+
+ it "counts from the end of the String if given a negative argument" do
+ "glark".getbyte(-1).should == "glark".getbyte(4)
+ end
+
+ it "returns an Integer between 0 and 255" do
+ "\x00".getbyte(0).should == 0
+ "\xFF".getbyte(0).should == 255
+ 256.chr('utf-8').getbyte(0).should == 196
+ 256.chr('utf-8').getbyte(1).should == 128
+ end
+
+ it "regards a multi-byte character as having multiple bytes" do
+ chr = "\u{998}"
+ chr.bytesize.should == 3
+ chr.getbyte(0).should == 224
+ chr.getbyte(1).should == 166
+ chr.getbyte(2).should == 152
+ end
+
+ it "mirrors the output of #bytes" do
+ str = "UTF-8 (\u{9865}} characters and hex escapes (\xDE)"
+ str.bytes.to_a.each_with_index do |byte, index|
+ str.getbyte(index).should == byte
+ end
+ end
+
+ it "interprets bytes relative to the String's encoding" do
+ str = "\u{333}"
+ str.encode('utf-8').getbyte(0).should_not == \
+ str.encode('utf-16le').getbyte(0)
+ end
+
+ it "returns nil for out-of-bound indexes" do
+ "g".getbyte(1).should be_nil
+ end
+
+ it "regards the empty String as containing no bytes" do
+ "".getbyte(0).should be_nil
+ end
+
+ it "raises an ArgumentError unless given one argument" do
+ lambda { "glark".getbyte }.should raise_error(ArgumentError)
+ lambda { "food".getbyte(0,0) }.should raise_error(ArgumentError)
+ end
+
+ it "raises a TypeError unless its argument can be coerced into an Integer" do
+ lambda { "a".getbyte('a') }.should raise_error(TypeError)
+ end
+ end
+end
Modified: MacRuby/branches/experimental/spec/frozen/core/string/gsub_spec.rb
===================================================================
--- MacRuby/branches/experimental/spec/frozen/core/string/gsub_spec.rb 2009-07-01 23:05:28 UTC (rev 1956)
+++ MacRuby/branches/experimental/spec/frozen/core/string/gsub_spec.rb 2009-07-01 23:43:49 UTC (rev 1957)
@@ -283,9 +283,11 @@
$~.should == nil
end
- it "raises a RuntimeError if the string is modified while substituting" do
- str = "hello"
- lambda { str.gsub(//) { str[0] = 'x' } }.should raise_error(RuntimeError)
+ ruby_version_is ""..."1.9" do
+ it "raises a RuntimeError if the string is modified while substituting" do
+ str = "hello"
+ lambda { str.gsub(//) { str[0] = 'x' } }.should raise_error(RuntimeError)
+ end
end
it "doesn't interpolate special sequences like \\1 for the block's return value" do
Added: MacRuby/branches/experimental/spec/frozen/core/string/lines_spec.rb
===================================================================
--- MacRuby/branches/experimental/spec/frozen/core/string/lines_spec.rb (rev 0)
+++ MacRuby/branches/experimental/spec/frozen/core/string/lines_spec.rb 2009-07-01 23:43:49 UTC (rev 1957)
@@ -0,0 +1,9 @@
+require File.dirname(__FILE__) + '/../../spec_helper'
+require File.dirname(__FILE__) + '/fixtures/classes'
+require File.dirname(__FILE__) + '/shared/each_line'
+
+ruby_version_is "1.8.7" do
+ describe "String#lines" do
+ it_behaves_like(:string_each_line, :lines)
+ end
+end
Added: MacRuby/branches/experimental/spec/frozen/core/string/ord_spec.rb
===================================================================
--- MacRuby/branches/experimental/spec/frozen/core/string/ord_spec.rb (rev 0)
+++ MacRuby/branches/experimental/spec/frozen/core/string/ord_spec.rb 2009-07-01 23:43:49 UTC (rev 1957)
@@ -0,0 +1,32 @@
+require File.dirname(__FILE__) + '/../../spec_helper'
+
+ruby_version_is "1.8.8" do
+ describe "String#ord" do
+ it "returns a Fixnum" do
+ 'a'.ord.should be_an_instance_of(Fixnum)
+ end
+
+ it "returns the codepoint of the first character in the String" do
+ 'a'.ord.should == 97
+ end
+
+
+ it "ignores subsequent characters" do
+ "\u{287}a".ord.should == "\u{287}".ord
+ end
+
+ ruby_version_is "1.9" do
+ it "understands multibyte characters" do
+ "\u{9879}".ord.should == 39033
+ end
+
+ it "is equivalent to #codepoints.first" do
+ "\u{981}\u{982}".ord.should == "\u{981}\u{982}".codepoints.first
+ end
+ end
+
+ it "raises an ArgumentError if called on an empty String" do
+ lambda { ''.ord }.should raise_error(ArgumentError)
+ end
+ end
+end
Added: MacRuby/branches/experimental/spec/frozen/core/string/setbyte_spec.rb
===================================================================
--- MacRuby/branches/experimental/spec/frozen/core/string/setbyte_spec.rb (rev 0)
+++ MacRuby/branches/experimental/spec/frozen/core/string/setbyte_spec.rb 2009-07-01 23:43:49 UTC (rev 1957)
@@ -0,0 +1,55 @@
+require File.dirname(__FILE__) + '/../../spec_helper'
+
+ruby_version_is "1.9" do
+ describe "String#setbyte" do
+ it "returns an Integer" do
+ "a".setbyte(0,1).should be_kind_of(Integer)
+ end
+
+ it "modifies the receiver" do
+ str = "glark"
+ old_id = str.object_id
+ str.setbyte(0,88)
+ str.object_id.should == old_id
+ end
+
+ it "changes the byte at the given index to the new byte" do
+ str = "a"
+ str.setbyte(0,98)
+ str.should == 'b'
+ end
+
+ it "allows changing bytes in multi-byte characters" do
+ str = "\u{915}"
+ str.setbyte(1,254)
+ str.getbyte(1).should == 254
+ end
+
+ it "can invalidate a String's encoding" do
+ str = "glark"
+ str.valid_encoding?.should be_true
+ str.setbyte(2,253)
+ str.valid_encoding?.should be_false
+ end
+
+ it "regards a negative index as counting from the end of the String" do
+ str = "hedgehog"
+ str.setbyte(-3, 108)
+ str.should == "hedgelog"
+ end
+
+ it "raises an IndexError unless the index is inside the String" do
+ lambda { "?".setbyte(1,97) }.should raise_error(IndexError)
+ end
+
+ it "raises a RuntimeError if self is frozen" do
+ str = "cold".freeze
+ str.frozen?.should be_true
+ lambda { str.setbyte(3,96) }.should raise_error(RuntimeError)
+ end
+
+ it "raises a TypeError unless the second argument is an Integer" do
+ lambda { "a".setbyte(0,'a') }.should raise_error(TypeError)
+ end
+ end
+end
Added: MacRuby/branches/experimental/spec/frozen/core/string/shared/chars.rb
===================================================================
--- MacRuby/branches/experimental/spec/frozen/core/string/shared/chars.rb (rev 0)
+++ MacRuby/branches/experimental/spec/frozen/core/string/shared/chars.rb 2009-07-01 23:43:49 UTC (rev 1957)
@@ -0,0 +1,70 @@
+# encoding: utf-8
+require File.dirname(__FILE__) + '/../../../spec_helper'
+require File.dirname(__FILE__) + '/../fixtures/classes'
+
+describe :string_chars, :shared => true do
+ it "passes each char in self to the given block" do
+ a = []
+ "hello".send(@method) { |c| a << c }
+ a.should == ['h', 'e', 'l', 'l', 'o']
+ end
+
+ ruby_bug 'redmine #1487', '1.9.1' do
+ it "returns self" do
+ s = StringSpecs::MyString.new "hello"
+ s.send(@method){}.should equal(s)
+ end
+ end
+
+ it "returns an enumerator when no block given" do
+ enum = "hello".send(@method)
+ enum.should be_kind_of(enumerator_class)
+ enum.to_a.should == ['h', 'e', 'l', 'l', 'o']
+ end
+
+
+ it "is unicode aware" do
+ before = $KCODE
+ $KCODE = "UTF-8"
+ "\303\207\342\210\202\303\251\306\222g".send(@method).to_a.should == ["\303\207", "\342\210\202", "\303\251", "\306\222", "g"]
+ $KCODE = before
+ end
+
+ ruby_version_is "1.9" do
+ it "returns characters in the same encoding as self" do
+ "&%".force_encoding('Shift_JIS').chars.to_a.all? {|c| c.encoding.name.should == 'Shift_JIS'}
+ "&%".encode('ASCII-8BIT').chars.to_a.all? {|c| c.encoding.name.should == 'ASCII-8BIT'}
+ end
+
+ it "works with multibyte characters" do
+ s = "\u{8987}".force_encoding("UTF-8")
+ s.bytesize.should == 3
+ s.send(@method).to_a.should == [s]
+ end
+
+ it "works if the String's contents is invalid for its encoding" do
+ s = "\xA4"
+ s.force_encoding('UTF-8')
+ s.valid_encoding?.should be_false
+ s.send(@method).to_a.should == ["\xA4".force_encoding("UTF-8")]
+ end
+
+ it "returns a different character if the String is transcoded" do
+ s = "\u{20AC}".force_encoding('UTF-8')
+ s.encode('UTF-8').send(@method).to_a.should == ["\u{20AC}".force_encoding('UTF-8')]
+ s.encode('iso-8859-15').send(@method).to_a.should == [
+ "\xA4".force_encoding('iso-8859-15')]
+ s.encode('iso-8859-15').encode('UTF-8').send(@method).to_a.should == [
+ "\u{20AC}".force_encoding('UTF-8')]
+ end
+
+ it "uses the String's encoding to determine what characters it contains" do
+ s = "\u{287}"
+ s.force_encoding('UTF-8').send(@method).to_a.should == [s.force_encoding('UTF-8')]
+ s.force_encoding('BINARY').send(@method).to_a.should == [
+ "\xCA".force_encoding('BINARY'), "\x87".force_encoding('BINARY')]
+ s.force_encoding('SJIS').send(@method).to_a.should == [
+ "\xCA".force_encoding('SJIS'), "\x87".force_encoding('SJIS')]
+ end
+ end
+end
Added: MacRuby/branches/experimental/spec/frozen/core/string/shared/codepoints.rb
===================================================================
--- MacRuby/branches/experimental/spec/frozen/core/string/shared/codepoints.rb (rev 0)
+++ MacRuby/branches/experimental/spec/frozen/core/string/shared/codepoints.rb 2009-07-01 23:43:49 UTC (rev 1957)
@@ -0,0 +1,66 @@
+
+describe :string_codepoints, :shared => true do
+ it "returns an Enumerator when no block is given" do
+ "".send(@method).should be_an_instance_of(Enumerator)
+ end
+
+ it "returns an Enumerator when no block is given even when self has an invalid encoding" do
+ s = "\xDF".force_encoding(Encoding::UTF_8)
+ s.valid_encoding?.should be_false
+ "".send(@method).should be_an_instance_of(Enumerator)
+ end
+
+ it "raises an ArgumentError when self has an invalid encoding and a method is called on the returned Enumerator" do
+ s = "\xDF".force_encoding(Encoding::UTF_8)
+ s.valid_encoding?.should be_false
+ lambda { s.send(@method).to_a }.should raise_error(ArgumentError)
+ end
+
+ it "yields each codepoint to the block if one is given" do
+ codepoints = []
+ "abcd".send(@method) do |codepoint|
+ codepoints << codepoint
+ end
+ codepoints.should == [97, 98, 99, 100]
+ end
+
+ it "raises an ArgumentError if self's encoding is invalid and a block is given" do
+ s = "\xDF".force_encoding(Encoding::UTF_8)
+ s.valid_encoding?.should be_false
+ lambda { s.send(@method) { } }.should raise_error(ArgumentError)
+ end
+
+ it "returns codepoints as Fixnums" do
+ "glark\u{20}".send(@method).to_a.each do |codepoint|
+ codepoint.should be_an_instance_of(Fixnum)
+ end
+ end
+
+ it "returns one codepoint for each character" do
+ s = "\u{9876}\u{28}\u{1987}"
+ s.send(@method).to_a.size.should == s.chars.to_a.size
+ end
+
+ it "works for multibyte characters" do
+ s = "\u{9819}"
+ s.bytesize.should == 3
+ s.send(@method).to_a.should == [38937]
+ end
+
+ it "returns the codepoint corresponding to the character's position in the String's encoding" do
+ "\u{787}".send(@method).to_a.should == [1927]
+ end
+
+ it "round-trips to the original String using Integer#chr" do
+ s = "\u{13}\u{7711}\u{1010}"
+ s2 = ""
+ s.send(@method) {|n| s2 << n.chr(Encoding::UTF_8)}
+ s.should == s2
+ end
+
+ it "is synonomous with #bytes for Strings which are single-byte optimisable" do
+ s = "(){}".encode('ascii')
+ s.ascii_only?.should be_true
+ s.send(@method).to_a.should == s.bytes.to_a
+ end
+end
Modified: MacRuby/branches/experimental/spec/frozen/core/string/shared/each_line.rb
===================================================================
--- MacRuby/branches/experimental/spec/frozen/core/string/shared/each_line.rb 2009-07-01 23:05:28 UTC (rev 1956)
+++ MacRuby/branches/experimental/spec/frozen/core/string/shared/each_line.rb 2009-07-01 23:43:49 UTC (rev 1957)
@@ -82,7 +82,7 @@
end
ruby_version_is '1.9' do
- it "not care if the string is modified while substituting" do
+ it "does not care if the string is modified while substituting" do
str = "hello\nworld."
out = []
str.send(@method){|x| out << x; str[-1] = '!' }.should == "hello\nworld!"
Added: MacRuby/branches/experimental/spec/frozen/core/string/to_c_spec.rb
===================================================================
--- MacRuby/branches/experimental/spec/frozen/core/string/to_c_spec.rb (rev 0)
+++ MacRuby/branches/experimental/spec/frozen/core/string/to_c_spec.rb 2009-07-01 23:43:49 UTC (rev 1957)
@@ -0,0 +1,101 @@
+require File.dirname(__FILE__) + '/../../spec_helper'
+
+ruby_version_is "1.9" do
+ describe "String#to_c" do
+ it "returns a Complex object" do
+ '9'.to_c.should be_an_instance_of(Complex)
+ end
+
+ it "understands integers" do
+ '20'.to_c.should == Complex(20)
+ end
+
+ it "understands negative integers" do
+ '-3'.to_c.should == Complex(-3)
+ end
+
+ it "understands fractions (numerator/denominator) for the real part" do
+ '2/3'.to_c.should == Complex(Rational(2, 3))
+ end
+
+ it "understands fractions (numerator/denominator) for the imaginary part" do
+ '4+2/3i'.to_c.should == Complex(4, Rational(2, 3))
+ end
+
+ it "understands negative fractions (-numerator/denominator) for the real part" do
+ '-2/3'.to_c.should == Complex(Rational(-2, 3))
+ end
+
+ it "understands negative fractions (-numerator/denominator) for the imaginary part" do
+ '7-2/3i'.to_c.should == Complex(7, Rational(-2, 3))
+ end
+
+ it "understands floats (a.b) for the real part" do
+ '2.3'.to_c.should == Complex(2.3)
+ end
+
+ it "understands floats (a.b) for the imaginary part" do
+ '4+2.3i'.to_c.should == Complex(4, 2.3)
+ end
+
+ it "understands negative floats (-a.b) for the real part" do
+ '-2.33'.to_c.should == Complex(-2.33)
+ end
+
+ it "understands negative floats (-a.b) for the imaginary part" do
+ '7-28.771i'.to_c.should == Complex(7, -28.771)
+ end
+
+ it "understands an integer followed by 'i' to mean that integer is the imaginary part" do
+ '35i'.to_c.should == Complex(0,35)
+ end
+
+ it "understands a negative integer followed by 'i' to mean that negative integer is the imaginary part" do
+ '-29i'.to_c.should == Complex(0,-29)
+ end
+
+ it "understands an 'i' by itself as denoting a complex number with an imaginary part of 1" do
+ 'i'.to_c.should == Complex(0,1)
+ end
+
+ it "understands a '-i' by itself as denoting a complex number with an imaginary part of -1" do
+ '-i'.to_c.should == Complex(0,-1)
+ end
+
+ it "understands 'a+bi' to mean a complex number with 'a' as the real part, 'b' as the imaginary" do
+ '79+4i'.to_c.should == Complex(79,4)
+ end
+
+ it "understands 'a-bi' to mean a complex number with 'a' as the real part, '-b' as the imaginary" do
+ '79-4i'.to_c.should == Complex(79,-4)
+ end
+
+ it "understands scientific notation for the real part" do
+ '2e3+4i'.to_c.should == Complex(2e3,4)
+ end
+
+ it "understands negative scientific notation for the real part" do
+ '-2e3+4i'.to_c.should == Complex(-2e3,4)
+ end
+
+ it "understands scientific notation for the imaginary part" do
+ '4+2e3i'.to_c.should == Complex(4, 2e3)
+ end
+
+ it "understands negative scientific notation for the imaginary part" do
+ '4-2e3i'.to_c.should == Complex(4, -2e3)
+ end
+
+ it "understands scientific notation for the real and imaginary part in the same String" do
+ '2e3+2e4i'.to_c.should == Complex(2e3,2e4)
+ end
+
+ it "understands negative scientific notation for the real and imaginary part in the same String" do
+ '-2e3-2e4i'.to_c.should == Complex(-2e3,-2e4)
+ end
+
+ it "returns a complex number with 0 as the real part, 0 as the imaginary part for unrecognised Strings" do
+ 'ruby'.to_c.should == Complex(0,0)
+ end
+ end
+end
Added: MacRuby/branches/experimental/spec/frozen/core/string/to_r_spec.rb
===================================================================
--- MacRuby/branches/experimental/spec/frozen/core/string/to_r_spec.rb (rev 0)
+++ MacRuby/branches/experimental/spec/frozen/core/string/to_r_spec.rb 2009-07-01 23:43:49 UTC (rev 1957)
@@ -0,0 +1,60 @@
+require File.dirname(__FILE__) + '/../../spec_helper'
+
+ruby_version_is "1.9" do
+ describe "String#to_r" do
+ it "returns a Rational object" do
+ String.new.to_r.should be_an_instance_of(Rational)
+ end
+
+ it "returns (0/1) for the empty String" do
+ "".to_r.should == Rational(0, 1)
+ end
+
+ it "returns (n/1) for a String starting with a decimal _n_" do
+ "2".to_r.should == Rational(2, 1)
+ "1765".to_r.should == Rational(1765, 1)
+ end
+
+ it "ignores trailing characters" do
+ "2 foo".to_r.should == Rational(2, 1)
+ "1765, ".to_r.should == Rational(1765, 1)
+ end
+
+ it "ignores leading spaces" do
+ " 2".to_r.should == Rational(2, 1)
+ " 1765, ".to_r.should == Rational(1765, 1)
+ end
+
+ it "does not ignore arbitrary, non-numeric leading characters" do
+ "The rational form of 33 is...".to_r.should_not == Rational(33, 1)
+ "a1765, ".to_r.should_not == Rational(1765, 1)
+ end
+
+ it "treats leading hypens as minus signs" do
+ "-20".to_r.should == Rational(-20, 1)
+ end
+
+ it "does not treat a leading period without a numeric prefix as a decimal point" do
+ ".9".to_r.should_not == Rational(8106479329266893, 9007199254740992)
+ end
+
+ it "understands decimal points" do
+ "3.33".to_r.should == Rational(333, 100)
+ "-3.33".to_r.should == Rational(-333, 100)
+ end
+
+ it "ignores underscores between numbers" do
+ "190_22".to_r.should == Rational(19022, 1)
+ "-190_22.7".to_r.should == Rational(-190227, 10)
+ end
+
+ it "understands a forward slash as separating the numerator from the denominator" do
+ "20/3".to_r.should == Rational(20, 3)
+ " -19.10/3".to_r.should == Rational(-191, 30)
+ end
+
+ it "returns (0/1) for Strings it can't parse" do
+ "glark".to_r.should == Rational(0,1)
+ end
+ end
+end
Modified: MacRuby/branches/experimental/spec/frozen/core/string/upto_spec.rb
===================================================================
--- MacRuby/branches/experimental/spec/frozen/core/string/upto_spec.rb 2009-07-01 23:05:28 UTC (rev 1956)
+++ MacRuby/branches/experimental/spec/frozen/core/string/upto_spec.rb 2009-07-01 23:43:49 UTC (rev 1957)
@@ -15,13 +15,13 @@
end
# This is weird but MRI behaves like that
- it "upto calls block with self even if self is less than stop but stop length is less than self length" do
+ it "calls block with self even if self is less than stop but stop length is less than self length" do
a = []
"25".upto("5") { |s| a << s }
a.should == ["25"]
end
- it "upto doesn't call block if stop is less than self and stop length is less than self length" do
+ it "doesn't call block if stop is less than self and stop length is less than self length" do
a = []
"25".upto("1") { |s| a << s }
a.should == []
@@ -76,7 +76,7 @@
end
ruby_version_is '1.9' do
- it "works with symbols to" do
+ it "works with symbols" do
"a".upto(:c).to_a.should == ["a", "b", "c"]
end
Added: MacRuby/branches/experimental/spec/frozen/core/string/valid_encoding_spec.rb
===================================================================
--- MacRuby/branches/experimental/spec/frozen/core/string/valid_encoding_spec.rb (rev 0)
+++ MacRuby/branches/experimental/spec/frozen/core/string/valid_encoding_spec.rb 2009-07-01 23:43:49 UTC (rev 1957)
@@ -0,0 +1,122 @@
+require File.dirname(__FILE__) + '/../../spec_helper'
+
+ruby_version_is "1.9" do
+ describe "String#valid_encoding?" do
+ it "returns true if the String's encoding is valid" do
+ "a".valid_encoding?.should be_true
+ "\u{8365}\u{221}".valid_encoding?.should be_true
+ end
+
+ it "returns true if self is valid in the current encoding and other encodings" do
+ str = "\x77"
+ str.force_encoding('utf-8').valid_encoding?.should be_true
+ str.force_encoding('ascii-8bit').valid_encoding?.should be_true
+ end
+
+ it "returns true for all encodings self is valid in" do
+ str = "\u{6754}"
+ str.force_encoding('ASCII-8BIT').valid_encoding?.should be_true
+ str.force_encoding('UTF-8').valid_encoding?.should be_true
+ str.force_encoding('US-ASCII').valid_encoding?.should be_false
+ str.force_encoding('Big5').valid_encoding?.should be_false
+ str.force_encoding('CP949').valid_encoding?.should be_false
+ str.force_encoding('Emacs-Mule').valid_encoding?.should be_false
+ str.force_encoding('EUC-JP').valid_encoding?.should be_false
+ str.force_encoding('EUC-KR').valid_encoding?.should be_false
+ str.force_encoding('EUC-TW').valid_encoding?.should be_false
+ str.force_encoding('GB18030').valid_encoding?.should be_false
+ str.force_encoding('GBK').valid_encoding?.should be_false
+ str.force_encoding('ISO-8859-1').valid_encoding?.should be_true
+ str.force_encoding('ISO-8859-2').valid_encoding?.should be_true
+ str.force_encoding('ISO-8859-3').valid_encoding?.should be_true
+ str.force_encoding('ISO-8859-4').valid_encoding?.should be_true
+ str.force_encoding('ISO-8859-5').valid_encoding?.should be_true
+ str.force_encoding('ISO-8859-6').valid_encoding?.should be_true
+ str.force_encoding('ISO-8859-7').valid_encoding?.should be_true
+ str.force_encoding('ISO-8859-8').valid_encoding?.should be_true
+ str.force_encoding('ISO-8859-9').valid_encoding?.should be_true
+ str.force_encoding('ISO-8859-10').valid_encoding?.should be_true
+ str.force_encoding('ISO-8859-11').valid_encoding?.should be_true
+ str.force_encoding('ISO-8859-13').valid_encoding?.should be_true
+ str.force_encoding('ISO-8859-14').valid_encoding?.should be_true
+ str.force_encoding('ISO-8859-15').valid_encoding?.should be_true
+ str.force_encoding('ISO-8859-16').valid_encoding?.should be_true
+ str.force_encoding('KOI8-R').valid_encoding?.should be_true
+ str.force_encoding('KOI8-U').valid_encoding?.should be_true
+ str.force_encoding('Shift_JIS').valid_encoding?.should be_false
+ str.force_encoding('UTF-16BE').valid_encoding?.should be_false
+ str.force_encoding('UTF-16LE').valid_encoding?.should be_false
+ str.force_encoding('UTF-32BE').valid_encoding?.should be_false
+ str.force_encoding('UTF-32LE').valid_encoding?.should be_false
+ str.force_encoding('Windows-1251').valid_encoding?.should be_true
+ str.force_encoding('IBM437').valid_encoding?.should be_true
+ str.force_encoding('IBM737').valid_encoding?.should be_true
+ str.force_encoding('IBM775').valid_encoding?.should be_true
+ str.force_encoding('CP850').valid_encoding?.should be_true
+ str.force_encoding('IBM852').valid_encoding?.should be_true
+ str.force_encoding('CP852').valid_encoding?.should be_true
+ str.force_encoding('IBM855').valid_encoding?.should be_true
+ str.force_encoding('CP855').valid_encoding?.should be_true
+ str.force_encoding('IBM857').valid_encoding?.should be_true
+ str.force_encoding('IBM860').valid_encoding?.should be_true
+ str.force_encoding('IBM861').valid_encoding?.should be_true
+ str.force_encoding('IBM862').valid_encoding?.should be_true
+ str.force_encoding('IBM863').valid_encoding?.should be_true
+ str.force_encoding('IBM864').valid_encoding?.should be_true
+ str.force_encoding('IBM865').valid_encoding?.should be_true
+ str.force_encoding('IBM866').valid_encoding?.should be_true
+ str.force_encoding('IBM869').valid_encoding?.should be_true
+ str.force_encoding('Windows-1258').valid_encoding?.should be_true
+ str.force_encoding('GB1988').valid_encoding?.should be_true
+ str.force_encoding('macCentEuro').valid_encoding?.should be_true
+ str.force_encoding('macCroatian').valid_encoding?.should be_true
+ str.force_encoding('macCyrillic').valid_encoding?.should be_true
+ str.force_encoding('macGreek').valid_encoding?.should be_true
+ str.force_encoding('macIceland').valid_encoding?.should be_true
+ str.force_encoding('macRoman').valid_encoding?.should be_true
+ str.force_encoding('macRomania').valid_encoding?.should be_true
+ str.force_encoding('macThai').valid_encoding?.should be_true
+ str.force_encoding('macTurkish').valid_encoding?.should be_true
+ str.force_encoding('macUkraine').valid_encoding?.should be_true
+ str.force_encoding('stateless-ISO-2022-JP').valid_encoding?.should be_false
+ str.force_encoding('eucJP-ms').valid_encoding?.should be_false
+ str.force_encoding('CP51932').valid_encoding?.should be_false
+ str.force_encoding('GB2312').valid_encoding?.should be_false
+ str.force_encoding('GB12345').valid_encoding?.should be_false
+ str.force_encoding('ISO-2022-JP').valid_encoding?.should be_true
+ str.force_encoding('ISO-2022-JP-2').valid_encoding?.should be_true
+ str.force_encoding('CP50221').valid_encoding?.should be_true
+ str.force_encoding('Windows-1252').valid_encoding?.should be_true
+ str.force_encoding('Windows-1250').valid_encoding?.should be_true
+ str.force_encoding('Windows-1256').valid_encoding?.should be_true
+ str.force_encoding('Windows-1253').valid_encoding?.should be_true
+ str.force_encoding('Windows-1255').valid_encoding?.should be_true
+ str.force_encoding('Windows-1254').valid_encoding?.should be_true
+ str.force_encoding('TIS-620').valid_encoding?.should be_true
+ str.force_encoding('Windows-874').valid_encoding?.should be_true
+ str.force_encoding('Windows-1257').valid_encoding?.should be_true
+ str.force_encoding('Windows-31J').valid_encoding?.should be_false
+ str.force_encoding('MacJapanese').valid_encoding?.should be_false
+ str.force_encoding('UTF-7').valid_encoding?.should be_true
+ str.force_encoding('UTF8-MAC').valid_encoding?.should be_true
+ end
+
+ it "returns false if self is valid in one encoding, but invalid in the one it's tagged with" do
+ str = "\u{8765}"
+ str.valid_encoding?.should be_true
+ str = str.force_encoding('ascii')
+ str.valid_encoding?.should be_false
+ end
+
+ it "returns false if self contains a character invalid in the associated encoding" do
+ "abc\x80".force_encoding('ascii').valid_encoding?.should be_false
+ end
+
+ it "returns false if a valid String had an invalid character appended to it" do
+ str = "a"
+ str.valid_encoding?.should be_true
+ str << "\xDD".force_encoding('utf-8')
+ str.valid_encoding?.should be_false
+ end
+ end
+end
Modified: MacRuby/branches/experimental/spec/frozen/core/struct/new_spec.rb
===================================================================
--- MacRuby/branches/experimental/spec/frozen/core/struct/new_spec.rb 2009-07-01 23:05:28 UTC (rev 1956)
+++ MacRuby/branches/experimental/spec/frozen/core/struct/new_spec.rb 2009-07-01 23:43:49 UTC (rev 1957)
@@ -99,14 +99,14 @@
end
ruby_version_is ""..."1.9" do
- it "instance_eval's a passed block" do
+ it "processes passed block with instance_eval" do
klass = Struct.new(:something) { @something_else = 'something else entirely!' }
klass.instance_variables.should include('@something_else')
end
end
ruby_version_is "1.9" do
- it "instance_eval's a passed block" do
+ it "processes passed block with instance_eval" do
klass = Struct.new(:something) { @something_else = 'something else entirely!' }
klass.instance_variables.should include(:@something_else)
end
Modified: MacRuby/branches/experimental/spec/frozen/language/versions/method_1.9.rb
===================================================================
--- MacRuby/branches/experimental/spec/frozen/language/versions/method_1.9.rb 2009-07-01 23:05:28 UTC (rev 1956)
+++ MacRuby/branches/experimental/spec/frozen/language/versions/method_1.9.rb 2009-07-01 23:43:49 UTC (rev 1957)
@@ -29,6 +29,11 @@
fooP1O1RQ0B(1, 2, 3, 4) { |z| z }.should == [1, 2, [3, 4], 5]
end
+ it "works with vestigial trailing ',' in call" do
+ def fooP1Q0(a); [a]; end
+ fooP1Q0(1,).should == [1]
+ end
+
# it "with lambda as block argument is ok" do
# def foo(a,&b); [a,yield(b)] end
Modified: MacRuby/branches/experimental/spec/frozen/library/complex/abs2_spec.rb
===================================================================
--- MacRuby/branches/experimental/spec/frozen/library/complex/abs2_spec.rb 2009-07-01 23:05:28 UTC (rev 1956)
+++ MacRuby/branches/experimental/spec/frozen/library/complex/abs2_spec.rb 2009-07-01 23:43:49 UTC (rev 1957)
@@ -1,13 +1,8 @@
-require File.dirname(__FILE__) + '/../../spec_helper'
+require File.dirname(__FILE__) + '/../../shared/complex/abs2'
require 'complex'
-describe "Complex#abs2" do
- it "returns the sum of the squares of the real and imaginary parts" do
- Complex(1, -2).abs2.should == 1 + 4
- Complex(-0.1, 0.2).abs2.should be_close(0.01 + 0.04, TOLERANCE)
- # Guard against Mathn library
- conflicts_with :Prime do
- Complex(0).abs2.should == 0
- end
+ruby_version_is ""..."1.9" do
+ describe "Complex#abs2" do
+ it_behaves_like(:complex_abs2, :abs2)
end
end
Modified: MacRuby/branches/experimental/spec/frozen/library/complex/abs_spec.rb
===================================================================
--- MacRuby/branches/experimental/spec/frozen/library/complex/abs_spec.rb 2009-07-01 23:05:28 UTC (rev 1956)
+++ MacRuby/branches/experimental/spec/frozen/library/complex/abs_spec.rb 2009-07-01 23:43:49 UTC (rev 1957)
@@ -1,13 +1,8 @@
-require File.dirname(__FILE__) + '/../../spec_helper'
+require File.dirname(__FILE__) + '/../../shared/complex/abs'
require 'complex'
-describe "Complex#abs" do
- it "returns the modulus: |a + bi| = sqrt((a ^ 2) + (b ^ 2))" do
- Complex(0, 0).abs.should == 0
- Complex(3, 4).abs.should == 5 # well-known integer case
- Complex(-3, 4).abs.should == 5
- Complex(1, -1).abs.should be_close(Math.sqrt(2), TOLERANCE)
- Complex(6.5, 0).abs.should be_close(6.5, TOLERANCE)
- Complex(0, -7.2).abs.should be_close(7.2, TOLERANCE)
+ruby_version_is ""..."1.9" do
+ describe "Complex#abs" do
+ it_behaves_like(:complex_abs, :abs)
end
end
Modified: MacRuby/branches/experimental/spec/frozen/library/complex/angle_spec.rb
===================================================================
--- MacRuby/branches/experimental/spec/frozen/library/complex/angle_spec.rb 2009-07-01 23:05:28 UTC (rev 1956)
+++ MacRuby/branches/experimental/spec/frozen/library/complex/angle_spec.rb 2009-07-01 23:43:49 UTC (rev 1957)
@@ -1,6 +1,8 @@
require File.dirname(__FILE__) + '/../../spec_helper'
-require File.dirname(__FILE__) + '/shared/arg.rb'
+require File.dirname(__FILE__) + '/../../shared/complex/arg'
-describe "Complex#angle" do
- it_behaves_like(:complex_arg, :angle)
+ruby_version_is ""..."1.9" do
+ describe "Complex#angle" do
+ it_behaves_like(:complex_arg, :angle)
+ end
end
Modified: MacRuby/branches/experimental/spec/frozen/library/complex/arg_spec.rb
===================================================================
--- MacRuby/branches/experimental/spec/frozen/library/complex/arg_spec.rb 2009-07-01 23:05:28 UTC (rev 1956)
+++ MacRuby/branches/experimental/spec/frozen/library/complex/arg_spec.rb 2009-07-01 23:43:49 UTC (rev 1957)
@@ -1,6 +1,8 @@
require File.dirname(__FILE__) + '/../../spec_helper'
-require File.dirname(__FILE__) + '/shared/arg.rb'
+require File.dirname(__FILE__) + '/../../shared/complex/arg'
-describe "Complex#arg" do
- it_behaves_like(:complex_arg, :arg)
+ruby_version_is ""..."1.9" do
+ describe "Complex#arg" do
+ it_behaves_like(:complex_arg, :arg)
+ end
end
Modified: MacRuby/branches/experimental/spec/frozen/library/complex/coerce_spec.rb
===================================================================
--- MacRuby/branches/experimental/spec/frozen/library/complex/coerce_spec.rb 2009-07-01 23:05:28 UTC (rev 1956)
+++ MacRuby/branches/experimental/spec/frozen/library/complex/coerce_spec.rb 2009-07-01 23:43:49 UTC (rev 1957)
@@ -1,43 +1,9 @@
-require File.dirname(__FILE__) + '/../../spec_helper'
+require File.dirname(__FILE__) + '/../../shared/complex/coerce'
require 'complex'
require "rational"
-describe "Complex#coerce" do
- before(:each) do
- @one = Complex.new!(1)
+ruby_version_is ""..."1.9" do
+ describe "Complex#coerce" do
+ it_behaves_like(:complex_coerce, :coerce)
end
-
- it "returns an array containing other and self as Complex when other is an Integer" do
- result = @one.coerce(2)
- result.should == [2, 1]
- result.first.should be_kind_of(Complex)
- result.last.should be_kind_of(Complex)
- end
-
- it "returns an array containing other and self as Complex when other is a Float" do
- result = @one.coerce(20.5)
- result.should == [20.5, 1]
- result.first.should be_kind_of(Complex)
- result.last.should be_kind_of(Complex)
- end
-
- it "returns an array containing other and self as Complex when other is a Bignum" do
- result = @one.coerce(4294967296)
- result.should == [4294967296, 1]
- result.first.should be_kind_of(Complex)
- result.last.should be_kind_of(Complex)
- end
-
- it "returns an array containing other and self as Complex when other is a Rational" do
- result = @one.coerce(Rational(5,6))
- result.should == [Rational(5,6), 1]
- result.first.should be_kind_of(Complex)
- result.last.should be_kind_of(Complex)
- end
-
- it "raises a TypeError when other is a String" do
- lambda { @one.coerce("20") }.should raise_error(TypeError)
- lambda { @one.coerce(nil) }.should raise_error(TypeError)
- lambda { @one.coerce(false) }.should raise_error(TypeError)
- end
-end
\ No newline at end of file
+end
Modified: MacRuby/branches/experimental/spec/frozen/library/complex/comparison_spec.rb
===================================================================
--- MacRuby/branches/experimental/spec/frozen/library/complex/comparison_spec.rb 2009-07-01 23:05:28 UTC (rev 1956)
+++ MacRuby/branches/experimental/spec/frozen/library/complex/comparison_spec.rb 2009-07-01 23:43:49 UTC (rev 1957)
@@ -1,20 +1,22 @@
require File.dirname(__FILE__) + '/../../spec_helper'
require 'complex'
-describe "Complex#<=>" do
- it "compares the absolute values of self and other" do
- (Complex(1, 2) <=> Complex(2, 1)).should == 0
- (Complex(-3, -10) <=> Complex(2, 1)).should > 0
- (Complex(3, 5) <=> Complex(100.0, -190.5)).should < 0
-
- (Complex(3, 4) <=> 5).should == 0
- (Complex(3, 4) <=> -5).should == 0
- (Complex(-3, -4) <=> -5).should == 0
-
- (Complex(3, 4) <=> 6).should < 0
- (Complex(3, 4) <=> -4).should > 0
+ruby_version_is ""..."1.9" do
+ describe "Complex#<=>" do
+ it "compares the absolute values of self and other" do
+ (Complex(1, 2) <=> Complex(2, 1)).should == 0
+ (Complex(-3, -10) <=> Complex(2, 1)).should > 0
+ (Complex(3, 5) <=> Complex(100.0, -190.5)).should < 0
+
+ (Complex(3, 4) <=> 5).should == 0
+ (Complex(3, 4) <=> -5).should == 0
+ (Complex(-3, -4) <=> -5).should == 0
+
+ (Complex(3, 4) <=> 6).should < 0
+ (Complex(3, 4) <=> -4).should > 0
- (Complex(3, 4) <=> 6.0).should < 0
- (Complex(3, 4) <=> -4.0).should > 0
+ (Complex(3, 4) <=> 6.0).should < 0
+ (Complex(3, 4) <=> -4.0).should > 0
+ end
end
end
Modified: MacRuby/branches/experimental/spec/frozen/library/complex/conj_spec.rb
===================================================================
--- MacRuby/branches/experimental/spec/frozen/library/complex/conj_spec.rb 2009-07-01 23:05:28 UTC (rev 1956)
+++ MacRuby/branches/experimental/spec/frozen/library/complex/conj_spec.rb 2009-07-01 23:43:49 UTC (rev 1957)
@@ -1,6 +1,8 @@
require File.dirname(__FILE__) + '/../../spec_helper'
-require File.dirname(__FILE__) + '/shared/conjugate.rb'
+require File.dirname(__FILE__) + '/../../shared/complex/conjugate'
-describe "Complex#conj" do
- it_behaves_like(:complex_conjugate, :conj)
+ruby_version_is ""..."1.9" do
+ describe "Complex#conj" do
+ it_behaves_like(:complex_conjugate, :conj)
+ end
end
Modified: MacRuby/branches/experimental/spec/frozen/library/complex/conjugate_spec.rb
===================================================================
--- MacRuby/branches/experimental/spec/frozen/library/complex/conjugate_spec.rb 2009-07-01 23:05:28 UTC (rev 1956)
+++ MacRuby/branches/experimental/spec/frozen/library/complex/conjugate_spec.rb 2009-07-01 23:43:49 UTC (rev 1957)
@@ -1,6 +1,8 @@
require File.dirname(__FILE__) + '/../../spec_helper'
-require File.dirname(__FILE__) + '/shared/conjugate.rb'
+require File.dirname(__FILE__) + '/../../shared/complex/conjugate'
-describe "Complex#conjugate" do
- it_behaves_like(:complex_conjugate, :conjugate)
+ruby_version_is ""..."1.9" do
+ describe "Complex#conjugate" do
+ it_behaves_like(:complex_conjugate, :conjugate)
+ end
end
Modified: MacRuby/branches/experimental/spec/frozen/library/complex/denominator_spec.rb
===================================================================
--- MacRuby/branches/experimental/spec/frozen/library/complex/denominator_spec.rb 2009-07-01 23:05:28 UTC (rev 1956)
+++ MacRuby/branches/experimental/spec/frozen/library/complex/denominator_spec.rb 2009-07-01 23:43:49 UTC (rev 1957)
@@ -1,4 +1,4 @@
-require File.dirname(__FILE__) + '/../../spec_helper'
+require File.dirname(__FILE__) + '/../../shared/complex/denominator'
require 'complex'
# FIXME:
@@ -11,14 +11,8 @@
# not mention a dependency for rational.
require "rational"
-describe "Complex#denominator" do
- it "returns the least common multiple denominator of the real and imaginary parts" do
- Complex(3, 4).denominator.should == 1
- Complex(3, bignum_value).denominator.should == 1
-
- Complex(3, Rational(3,4)).denominator.should == 4
-
- Complex(Rational(4,8), Rational(3,4)).denominator.should == 4
- Complex(Rational(3,8), Rational(3,4)).denominator.should == 8
+ruby_version_is ""..."1.9" do
+ describe "Complex#denominator" do
+ it_behaves_like(:complex_denominator, :denominator)
end
-end
\ No newline at end of file
+end
Modified: MacRuby/branches/experimental/spec/frozen/library/complex/divide_spec.rb
===================================================================
--- MacRuby/branches/experimental/spec/frozen/library/complex/divide_spec.rb 2009-07-01 23:05:28 UTC (rev 1956)
+++ MacRuby/branches/experimental/spec/frozen/library/complex/divide_spec.rb 2009-07-01 23:43:49 UTC (rev 1957)
@@ -1,55 +1,24 @@
-require File.dirname(__FILE__) + '/../../spec_helper'
+require File.dirname(__FILE__) + '/../../shared/complex/divide'
require 'complex'
-describe "Complex#/ with Complex" do
- it "divides according to the usual rule for complex numbers" do
- a = Complex((1 * 10) - (2 * 20), (1 * 20) + (2 * 10))
- b = Complex(1, 2)
- (a / b).should == Complex(10, 20)
+ruby_version_is ""..."1.9" do
+ describe "Complex#/ with Complex" do
+ it_behaves_like(:complex_divide_complex, :/)
+ end
- c = Complex((1.5 * 100.2) - (2.1 * -30.3), (1.5 * -30.3) + (2.1 * 100.2))
- d = Complex(1.5, 2.1)
- # remember the floating-point arithmetic
- (c / d).should be_close(Complex(100.2, -30.3), TOLERANCE)
+ describe "Complex#/ with Fixnum" do
+ it_behaves_like(:complex_divide_fixnum, :/)
end
-end
-describe "Complex#/ with Fixnum" do
- it "divides both parts of the Complex number" do
- (Complex(20, 40) / 2).should == Complex(10, 20)
- (Complex(30, 30) / 10).should == Complex(3, 3)
+ describe "Complex#/ with Bignum" do
+ it_behaves_like(:complex_divide_bignum, :/)
end
- it "raises a ZeroDivisionError when given zero" do
- lambda { Complex(20, 40) / 0 }.should raise_error(ZeroDivisionError)
+ describe "Complex#/ with Float" do
+ it_behaves_like(:complex_divide_float, :/)
end
-end
-describe "Complex#/ with Bignum" do
- it "divides both parts of the Complex number" do
- (Complex(20, 40) / 2).should == Complex(10, 20)
- (Complex(15, 16) / 2.0).should be_close(Complex(7.5, 8), TOLERANCE)
+ describe "Complex#/ with Object" do
+ it_behaves_like(:complex_divide_object, :/)
end
end
-
-describe "Complex#/ with Float" do
- it "divides both parts of the Complex number" do
- (Complex(3, 9) / 1.5).should == Complex(2, 6)
- (Complex(15, 16) / 2.0).should be_close(Complex(7.5, 8), TOLERANCE)
- end
-
- it "returns Complex(Infinity, Infinity) when given zero" do
- (Complex(20, 40) / 0.0).inspect.should == "Complex(Infinity, Infinity)"
- (Complex(-20, -40) / 0.0).inspect.should == "Complex(-Infinity, -Infinity)"
- end
-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([4, 2])
- (value / obj).should == 2
- end
-end
\ No newline at end of file
Modified: MacRuby/branches/experimental/spec/frozen/library/complex/equal_value_spec.rb
===================================================================
--- MacRuby/branches/experimental/spec/frozen/library/complex/equal_value_spec.rb 2009-07-01 23:05:28 UTC (rev 1956)
+++ MacRuby/branches/experimental/spec/frozen/library/complex/equal_value_spec.rb 2009-07-01 23:43:49 UTC (rev 1957)
@@ -1,63 +1,16 @@
-require File.dirname(__FILE__) + '/../../spec_helper'
+require File.dirname(__FILE__) + '/../../shared/complex/equal_value'
require 'complex'
-describe "Complex#== with Complex" do
- it "returns true when self and other have numerical equality" do
- Complex(1, 2).should == Complex(1, 2)
- Complex(3, 9).should == Complex(3, 9)
- Complex(-3, -9).should == Complex(-3, -9)
-
- Complex(1, 2).should_not == Complex(3, 4)
- Complex(3, 9).should_not == Complex(9, 3)
-
- Complex(1.0, 2.0).should == Complex(1, 2)
- Complex(3.0, 9.0).should_not == Complex(9.0, 3.0)
-
- Complex(1.5, 2.5).should == Complex(1.5, 2.5)
- Complex(1.5, 2.5).should == Complex(1.5, 2.5)
- Complex(-1.5, 2.5).should == Complex(-1.5, 2.5)
-
- Complex(1.5, 2.5).should_not == Complex(2.5, 1.5)
- Complex(3.75, 2.5).should_not == Complex(1.5, 2.5)
-
- Complex(bignum_value, 2.5).should == Complex(bignum_value, 2.5)
- Complex(3.75, bignum_value).should_not == Complex(1.5, bignum_value)
+ruby_version_is ""..."1.9" do
+ describe "Complex#== with Complex" do
+ it_behaves_like(:complex_equal_value_complex, :shared => true)
end
-end
-describe "Complex#== with Numeric" do
- it "returns true when self's imaginery part is 0 and the real part and other have numerical equality" do
- Complex(3, 0).should == 3
- Complex(-3, 0).should == -3
-
- Complex(3.5, 0).should == 3.5
- Complex(-3.5, 0).should == -3.5
-
- Complex(bignum_value, 0).should == bignum_value
- Complex(-bignum_value, 0).should == -bignum_value
-
- Complex(3.0, 0).should == 3
- Complex(-3.0, 0).should == -3
-
- Complex(3, 0).should_not == 4
- Complex(-3, 0).should_not == -4
-
- Complex(3.5, 0).should_not == -4.5
- Complex(-3.5, 0).should_not == 2.5
-
- Complex(bignum_value, 0).should_not == bignum_value(10)
- Complex(-bignum_value, 0).should_not == -bignum_value(20)
+ describe "Complex#== with Numeric" do
+ it_behaves_like(:complex_equal_value_numeric, :shared => true)
end
-end
-describe "Complex#== with Object" do
- # Fixnum#==, Float#== and Bignum#== only return booleans - Bug?
- it "calls other#== with self" do
- value = Complex(3, 0)
-
- obj = mock("Object")
- obj.should_receive(:==).with(value).and_return(:expected)
-
- (value == obj).should == :expected
+ describe "Complex#== with Object" do
+ it_behaves_like(:complex_equal_value_object, :shared => true)
end
-end
\ No newline at end of file
+end
Modified: MacRuby/branches/experimental/spec/frozen/library/complex/exponent_spec.rb
===================================================================
--- MacRuby/branches/experimental/spec/frozen/library/complex/exponent_spec.rb 2009-07-01 23:05:28 UTC (rev 1956)
+++ MacRuby/branches/experimental/spec/frozen/library/complex/exponent_spec.rb 2009-07-01 23:43:49 UTC (rev 1957)
@@ -1,54 +1,25 @@
-require File.dirname(__FILE__) + '/../../spec_helper'
+require File.dirname(__FILE__) + '/../../shared/complex/exponent'
require "complex"
require "rational"
-describe "Complex#** when given 0" do
- it "returns Complex(1)" do
- (Complex(3, 4) ** 0).should eql(Complex(1))
- (Complex(10, 20) ** 0.0).should eql(Complex(1))
+ruby_version_is ""..."1.9" do
+ describe "Complex#** when given 0" do
+ it_behaves_like(:complex_exponent_zero, :**)
end
-end
-describe "Complex#** with Complex" do
- it "returns self raised to the given power" do
- (Complex(2, 1) ** Complex(2, 1)).should be_close(Complex(-0.504824688978319, 3.10414407699553), TOLERANCE)
- (Complex(2, 1) ** Complex(3, 4)).should be_close(Complex(-0.179174656916581, -1.74071656397662), TOLERANCE)
-
- (Complex(2, 1) ** Complex(-2, -1)).should be_close(Complex(-0.051041070450869, -0.313849223270419), TOLERANCE)
- (Complex(-2, -1) ** Complex(2, 1)).should be_close(Complex(-11.6819929610857, 71.8320439736158), TOLERANCE)
+ describe "Complex#** with Complex" do
+ it_behaves_like(:complex_exponent_complex, :**)
end
-end
-describe "Complex#** with Integer" do
- it "returns self raised to the given power" do
- (Complex(2, 1) ** 2).should == Complex(3, 4)
- (Complex(3, 4) ** 2).should == Complex(-7, 24)
- (Complex(3, 4) ** -2).should be_close(Complex(-0.0112, -0.0384), TOLERANCE)
-
-
- (Complex(2, 1) ** 2.5).should be_close(Complex(2.99179707178602, 6.85206901006896), TOLERANCE)
- (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)
-
- # NOTE: Takes way too long...
- #(Complex(2, 1) ** bignum_value)
+ describe "Complex#** with Integer" do
+ it_behaves_like(:complex_exponent_integer, :**)
end
-end
-describe "Complex#** with Rational" do
- it "returns self raised to the given power" do
- (Complex(2, 1) ** Rational(3, 4)).should be_close(Complex(1.71913265276568, 0.623124744394697), TOLERANCE)
- (Complex(2, 1) ** Rational(4, 3)).should be_close(Complex(2.3828547125173, 1.69466313833091), TOLERANCE)
- (Complex(2, 1) ** Rational(-4, 3)).should be_close(Complex(0.278700377879388, -0.198209003071003), TOLERANCE)
+ describe "Complex#** with Rational" do
+ it_behaves_like(:complex_exponent_rational, :**)
end
-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
+ describe "Complex#** with Object" do
+ it_behaves_like(:complex_exponent_object, :**)
end
-end
\ No newline at end of file
+end
Deleted: MacRuby/branches/experimental/spec/frozen/library/complex/shared/arg.rb
===================================================================
--- MacRuby/branches/experimental/spec/frozen/library/complex/shared/arg.rb 2009-07-01 23:05:28 UTC (rev 1956)
+++ MacRuby/branches/experimental/spec/frozen/library/complex/shared/arg.rb 2009-07-01 23:43:49 UTC (rev 1957)
@@ -1,11 +0,0 @@
-require 'complex'
-
-describe :complex_arg, :shared => true do
- it "returns the argument -- i.e., the angle from (1, 0) in the complex plane" do
- TwoPi = 2 * Math::PI
- (Complex(1, 0).send(@method) % TwoPi).should be_close(0, TOLERANCE)
- (Complex(0, 2).send(@method) % TwoPi).should be_close(Math::PI * 0.5, TOLERANCE)
- (Complex(-100, 0).send(@method) % TwoPi).should be_close(Math::PI, TOLERANCE)
- (Complex(0, -75.3).send(@method) % TwoPi).should be_close(Math::PI * 1.5, TOLERANCE)
- end
-end
Deleted: MacRuby/branches/experimental/spec/frozen/library/complex/shared/conjugate.rb
===================================================================
--- MacRuby/branches/experimental/spec/frozen/library/complex/shared/conjugate.rb 2009-07-01 23:05:28 UTC (rev 1956)
+++ MacRuby/branches/experimental/spec/frozen/library/complex/shared/conjugate.rb 2009-07-01 23:43:49 UTC (rev 1957)
@@ -1,10 +0,0 @@
-require 'complex'
-
-describe :complex_conjugate, :shared => true do
- it "returns the complex conjugate: conj a + bi = a - bi" do
- Complex(3, 5).send(@method).should == Complex(3, -5)
- Complex(3, -5).send(@method).should == Complex(3, 5)
- Complex(-3.0, 5.2).send(@method).should be_close(Complex(-3.0, -5.2), TOLERANCE)
- Complex(3.0, -5.2).send(@method).should be_close(Complex(3.0, 5.2), TOLERANCE)
- end
-end
Added: MacRuby/branches/experimental/spec/frozen/library/stringio/codepoints.rb
===================================================================
--- MacRuby/branches/experimental/spec/frozen/library/stringio/codepoints.rb (rev 0)
+++ MacRuby/branches/experimental/spec/frozen/library/stringio/codepoints.rb 2009-07-01 23:43:49 UTC (rev 1957)
@@ -0,0 +1,11 @@
+# -*- encoding: utf-8 -*-
+require File.dirname(__FILE__) + '/../../spec_helper'
+require File.dirname(__FILE__) + '/fixtures/classes'
+require File.dirname(__FILE__) + '/shared/codepoints'
+
+# See redmine #1667
+describe "StringIO#codepoints" do
+ ruby_version_is "1.9.2" do
+ it_behaves_like(:stringio_codepoints, :codepoints)
+ end
+end
Added: MacRuby/branches/experimental/spec/frozen/library/stringio/each_codepoint.rb
===================================================================
--- MacRuby/branches/experimental/spec/frozen/library/stringio/each_codepoint.rb (rev 0)
+++ MacRuby/branches/experimental/spec/frozen/library/stringio/each_codepoint.rb 2009-07-01 23:43:49 UTC (rev 1957)
@@ -0,0 +1,12 @@
+# -*- encoding: utf-8 -*-
+require File.dirname(__FILE__) + '/../../spec_helper'
+require File.dirname(__FILE__) + '/fixtures/classes'
+require File.dirname(__FILE__) + '/shared/codepoints'
+
+# See redmine #1667
+describe "StringIO#each_codepoint" do
+ ruby_version_is "1.9.2" do
+ it_behaves_like(:stringio_codepoints, :codepoints)
+ end
+end
+
Added: MacRuby/branches/experimental/spec/frozen/library/stringio/shared/codepoints.rb
===================================================================
--- MacRuby/branches/experimental/spec/frozen/library/stringio/shared/codepoints.rb (rev 0)
+++ MacRuby/branches/experimental/spec/frozen/library/stringio/shared/codepoints.rb 2009-07-01 23:43:49 UTC (rev 1957)
@@ -0,0 +1,45 @@
+# -*- encoding: utf-8 -*-
+describe :stringio_codepoints, :shared => true do
+ before(:each) do
+ @io = StringIO.new("∂φ/∂x = gaîté")
+ @enum = @io.send(@method)
+ end
+
+ it "returns an Enumerator" do
+ @enum.should be_an_instance_of(enumerator_class)
+ end
+
+ it "yields each codepoint code in turn" do
+ @enum.to_a.should == [8706, 966, 47, 8706, 120, 32, 61, 32, 103, 97, 238, 116, 233]
+ end
+
+ it "yields each codepoint starting from the current position" do
+ @io.pos = 15
+ @enum.to_a.should == [238, 116, 233]
+ end
+
+ it "raises an error if reading invalid sequence" do
+ @io.pos = 1 # inside of a multibyte sequence
+ lambda { @enum.first }.should raise_error(ArgumentError)
+ end
+
+ it "raises an IOError if not readable" do
+ @io.close_read
+ lambda { @enum.to_a }.should raise_error(IOError)
+
+ io = StringIO.new("xyz", "w")
+ lambda { io.send(@method).to_a }.should raise_error(IOError)
+ end
+
+
+ it "calls the given block" do
+ r = []
+ @io.send(@method){|c| r << c }
+ r.should == [8706, 966, 47, 8706, 120, 32, 61, 32, 103, 97, 238, 116, 233]
+ end
+
+ it "returns self" do
+ @io.send(@method) {|l| l }.should equal(@io)
+ end
+
+end
\ No newline at end of file
Copied: MacRuby/branches/experimental/spec/frozen/shared/complex/abs.rb (from rev 1956, MacRuby/branches/experimental/spec/frozen/library/complex/abs_spec.rb)
===================================================================
--- MacRuby/branches/experimental/spec/frozen/shared/complex/abs.rb (rev 0)
+++ MacRuby/branches/experimental/spec/frozen/shared/complex/abs.rb 2009-07-01 23:43:49 UTC (rev 1957)
@@ -0,0 +1,13 @@
+require File.dirname(__FILE__) + '/../../spec_helper'
+require 'complex'
+
+describe :complex_abs, :shared => true do
+ it "returns the modulus: |a + bi| = sqrt((a ^ 2) + (b ^ 2))" do
+ Complex(0, 0).abs.should == 0
+ Complex(3, 4).abs.should == 5 # well-known integer case
+ Complex(-3, 4).abs.should == 5
+ Complex(1, -1).abs.should be_close(Math.sqrt(2), TOLERANCE)
+ Complex(6.5, 0).abs.should be_close(6.5, TOLERANCE)
+ Complex(0, -7.2).abs.should be_close(7.2, TOLERANCE)
+ end
+end
Copied: MacRuby/branches/experimental/spec/frozen/shared/complex/abs2.rb (from rev 1956, MacRuby/branches/experimental/spec/frozen/library/complex/abs2_spec.rb)
===================================================================
--- MacRuby/branches/experimental/spec/frozen/shared/complex/abs2.rb (rev 0)
+++ MacRuby/branches/experimental/spec/frozen/shared/complex/abs2.rb 2009-07-01 23:43:49 UTC (rev 1957)
@@ -0,0 +1,13 @@
+require File.dirname(__FILE__) + '/../../spec_helper'
+require 'complex'
+
+describe :complex_abs2, :shared => true do
+ it "returns the sum of the squares of the real and imaginary parts" do
+ Complex(1, -2).abs2.should == 1 + 4
+ Complex(-0.1, 0.2).abs2.should be_close(0.01 + 0.04, TOLERANCE)
+ # Guard against Mathn library
+ conflicts_with :Prime do
+ Complex(0).abs2.should == 0
+ end
+ end
+end
Copied: MacRuby/branches/experimental/spec/frozen/shared/complex/arg.rb (from rev 1956, MacRuby/branches/experimental/spec/frozen/library/complex/shared/arg.rb)
===================================================================
--- MacRuby/branches/experimental/spec/frozen/shared/complex/arg.rb (rev 0)
+++ MacRuby/branches/experimental/spec/frozen/shared/complex/arg.rb 2009-07-01 23:43:49 UTC (rev 1957)
@@ -0,0 +1,11 @@
+require 'complex'
+
+describe :complex_arg, :shared => true do
+ it "returns the argument -- i.e., the angle from (1, 0) in the complex plane" do
+ TwoPi = 2 * Math::PI
+ (Complex(1, 0).send(@method) % TwoPi).should be_close(0, TOLERANCE)
+ (Complex(0, 2).send(@method) % TwoPi).should be_close(Math::PI * 0.5, TOLERANCE)
+ (Complex(-100, 0).send(@method) % TwoPi).should be_close(Math::PI, TOLERANCE)
+ (Complex(0, -75.3).send(@method) % TwoPi).should be_close(Math::PI * 1.5, TOLERANCE)
+ end
+end
Copied: MacRuby/branches/experimental/spec/frozen/shared/complex/coerce.rb (from rev 1956, MacRuby/branches/experimental/spec/frozen/library/complex/coerce_spec.rb)
===================================================================
--- MacRuby/branches/experimental/spec/frozen/shared/complex/coerce.rb (rev 0)
+++ MacRuby/branches/experimental/spec/frozen/shared/complex/coerce.rb 2009-07-01 23:43:49 UTC (rev 1957)
@@ -0,0 +1,43 @@
+require File.dirname(__FILE__) + '/../../spec_helper'
+require 'complex'
+require "rational"
+
+describe :complex_coerce, :shared => true do
+ before(:each) do
+ @one = Complex(1)
+ end
+
+ it "returns an array containing other and self as Complex when other is an Integer" do
+ result = @one.coerce(2)
+ result.should == [2, 1]
+ result.first.should be_kind_of(Complex)
+ result.last.should be_kind_of(Complex)
+ end
+
+ it "returns an array containing other and self as Complex when other is a Float" do
+ result = @one.coerce(20.5)
+ result.should == [20.5, 1]
+ result.first.should be_kind_of(Complex)
+ result.last.should be_kind_of(Complex)
+ end
+
+ it "returns an array containing other and self as Complex when other is a Bignum" do
+ result = @one.coerce(4294967296)
+ result.should == [4294967296, 1]
+ result.first.should be_kind_of(Complex)
+ result.last.should be_kind_of(Complex)
+ end
+
+ it "returns an array containing other and self as Complex when other is a Rational" do
+ result = @one.coerce(Rational(5,6))
+ result.should == [Rational(5,6), 1]
+ result.first.should be_kind_of(Complex)
+ result.last.should be_kind_of(Complex)
+ end
+
+ it "raises a TypeError when other is a String" do
+ lambda { @one.coerce("20") }.should raise_error(TypeError)
+ lambda { @one.coerce(nil) }.should raise_error(TypeError)
+ lambda { @one.coerce(false) }.should raise_error(TypeError)
+ end
+end
Copied: MacRuby/branches/experimental/spec/frozen/shared/complex/conjugate.rb (from rev 1956, MacRuby/branches/experimental/spec/frozen/library/complex/shared/conjugate.rb)
===================================================================
--- MacRuby/branches/experimental/spec/frozen/shared/complex/conjugate.rb (rev 0)
+++ MacRuby/branches/experimental/spec/frozen/shared/complex/conjugate.rb 2009-07-01 23:43:49 UTC (rev 1957)
@@ -0,0 +1,10 @@
+require 'complex'
+
+describe :complex_conjugate, :shared => true do
+ it "returns the complex conjugate: conj a + bi = a - bi" do
+ Complex(3, 5).send(@method).should == Complex(3, -5)
+ Complex(3, -5).send(@method).should == Complex(3, 5)
+ Complex(-3.0, 5.2).send(@method).should be_close(Complex(-3.0, -5.2), TOLERANCE)
+ Complex(3.0, -5.2).send(@method).should be_close(Complex(3.0, 5.2), TOLERANCE)
+ end
+end
Added: MacRuby/branches/experimental/spec/frozen/shared/complex/denominator.rb
===================================================================
--- MacRuby/branches/experimental/spec/frozen/shared/complex/denominator.rb (rev 0)
+++ MacRuby/branches/experimental/spec/frozen/shared/complex/denominator.rb 2009-07-01 23:43:49 UTC (rev 1957)
@@ -0,0 +1,13 @@
+require File.dirname(__FILE__) + '/../../spec_helper'
+
+describe :complex_denominator, :shared => true do
+ it "returns the least common multiple denominator of the real and imaginary parts" do
+ Complex(3, 4).denominator.should == 1
+ Complex(3, bignum_value).denominator.should == 1
+
+ Complex(3, Rational(3,4)).denominator.should == 4
+
+ Complex(Rational(4,8), Rational(3,4)).denominator.should == 4
+ Complex(Rational(3,8), Rational(3,4)).denominator.should == 8
+ end
+end
Copied: MacRuby/branches/experimental/spec/frozen/shared/complex/divide.rb (from rev 1956, MacRuby/branches/experimental/spec/frozen/library/complex/divide_spec.rb)
===================================================================
--- MacRuby/branches/experimental/spec/frozen/shared/complex/divide.rb (rev 0)
+++ MacRuby/branches/experimental/spec/frozen/shared/complex/divide.rb 2009-07-01 23:43:49 UTC (rev 1957)
@@ -0,0 +1,64 @@
+require File.dirname(__FILE__) + '/../../spec_helper'
+require 'complex'
+
+describe :complex_divide_complex, :shared => true do
+ it "divides according to the usual rule for complex numbers" do
+ a = Complex((1 * 10) - (2 * 20), (1 * 20) + (2 * 10))
+ b = Complex(1, 2)
+ (a / b).should == Complex(10, 20)
+
+ c = Complex((1.5 * 100.2) - (2.1 * -30.3), (1.5 * -30.3) + (2.1 * 100.2))
+ d = Complex(1.5, 2.1)
+ # remember the floating-point arithmetic
+ (c / d).should be_close(Complex(100.2, -30.3), TOLERANCE)
+ end
+end
+
+describe :complex_divide_fixnum, :shared => true do
+ it "divides both parts of the Complex number" do
+ (Complex(20, 40) / 2).should == Complex(10, 20)
+ (Complex(30, 30) / 10).should == Complex(3, 3)
+ end
+
+ it "raises a ZeroDivisionError when given zero" do
+ lambda { Complex(20, 40) / 0 }.should raise_error(ZeroDivisionError)
+ end
+end
+
+describe :complex_divide_bignum, :shared => true do
+ it "divides both parts of the Complex number" do
+ (Complex(20, 40) / 2).should == Complex(10, 20)
+ (Complex(15, 16) / 2.0).should be_close(Complex(7.5, 8), TOLERANCE)
+ end
+end
+
+describe :complex_divide_float, :shared => true do
+ it "divides both parts of the Complex number" do
+ (Complex(3, 9) / 1.5).should == Complex(2, 6)
+ (Complex(15, 16) / 2.0).should be_close(Complex(7.5, 8), TOLERANCE)
+ end
+
+ ruby_version_is ""..."1.9" do
+ it "returns Complex(Infinity, Infinity) when given zero" do
+ (Complex(20, 40) / 0.0).inspect.should == "Complex(Infinity, Infinity)"
+ (Complex(-20, -40) / 0.0).inspect.should == "Complex(-Infinity, -Infinity)"
+ end
+ end
+
+ ruby_version_is "1.9" do
+ it "returns (Infinity+Infinity*i) when given zero" do
+ (Complex(20, 40) / 0.0).inspect.should == "(Infinity+Infinity*i)"
+ (Complex(-20, -40) / 0.0).inspect.should == "(-Infinity-Infinity*i)"
+ end
+ end
+end
+
+describe :complex_divide_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([4, 2])
+ (value / obj).should == 2
+ end
+end
Copied: MacRuby/branches/experimental/spec/frozen/shared/complex/equal_value.rb (from rev 1956, MacRuby/branches/experimental/spec/frozen/library/complex/equal_value_spec.rb)
===================================================================
--- MacRuby/branches/experimental/spec/frozen/shared/complex/equal_value.rb (rev 0)
+++ MacRuby/branches/experimental/spec/frozen/shared/complex/equal_value.rb 2009-07-01 23:43:49 UTC (rev 1957)
@@ -0,0 +1,63 @@
+require File.dirname(__FILE__) + '/../../spec_helper'
+require 'complex'
+
+describe :complex_equal_value_complex, :shared => true do
+ it "returns true when self and other have numerical equality" do
+ Complex(1, 2).should == Complex(1, 2)
+ Complex(3, 9).should == Complex(3, 9)
+ Complex(-3, -9).should == Complex(-3, -9)
+
+ Complex(1, 2).should_not == Complex(3, 4)
+ Complex(3, 9).should_not == Complex(9, 3)
+
+ Complex(1.0, 2.0).should == Complex(1, 2)
+ Complex(3.0, 9.0).should_not == Complex(9.0, 3.0)
+
+ Complex(1.5, 2.5).should == Complex(1.5, 2.5)
+ Complex(1.5, 2.5).should == Complex(1.5, 2.5)
+ Complex(-1.5, 2.5).should == Complex(-1.5, 2.5)
+
+ Complex(1.5, 2.5).should_not == Complex(2.5, 1.5)
+ Complex(3.75, 2.5).should_not == Complex(1.5, 2.5)
+
+ Complex(bignum_value, 2.5).should == Complex(bignum_value, 2.5)
+ Complex(3.75, bignum_value).should_not == Complex(1.5, bignum_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
+ Complex(3, 0).should == 3
+ Complex(-3, 0).should == -3
+
+ Complex(3.5, 0).should == 3.5
+ Complex(-3.5, 0).should == -3.5
+
+ Complex(bignum_value, 0).should == bignum_value
+ Complex(-bignum_value, 0).should == -bignum_value
+
+ Complex(3.0, 0).should == 3
+ Complex(-3.0, 0).should == -3
+
+ Complex(3, 0).should_not == 4
+ Complex(-3, 0).should_not == -4
+
+ Complex(3.5, 0).should_not == -4.5
+ Complex(-3.5, 0).should_not == 2.5
+
+ Complex(bignum_value, 0).should_not == bignum_value(10)
+ Complex(-bignum_value, 0).should_not == -bignum_value(20)
+ end
+end
+
+describe :complex_equal_value_object, :shared => true do
+ # Fixnum#==, Float#== and Bignum#== only return booleans - Bug?
+ it "calls other#== with self" do
+ value = Complex(3, 0)
+
+ obj = mock("Object")
+ obj.should_receive(:==).with(value).and_return(:expected)
+
+ (value == obj).should == :expected
+ end
+end
Copied: MacRuby/branches/experimental/spec/frozen/shared/complex/exponent.rb (from rev 1956, MacRuby/branches/experimental/spec/frozen/library/complex/exponent_spec.rb)
===================================================================
--- MacRuby/branches/experimental/spec/frozen/shared/complex/exponent.rb (rev 0)
+++ MacRuby/branches/experimental/spec/frozen/shared/complex/exponent.rb 2009-07-01 23:43:49 UTC (rev 1957)
@@ -0,0 +1,52 @@
+require File.dirname(__FILE__) + '/../../spec_helper'
+
+describe :complex_exponent_zero, :shared => true do
+ it "returns Complex(1)" do
+ (Complex(3, 4) ** 0).should eql(Complex(1))
+ (Complex(10, 20) ** 0.0).should eql(Complex(1.0, 0.0))
+ end
+end
+
+describe :complex_exponent_complex, :shared => true do
+ it "returns self raised to the given power" do
+ (Complex(2, 1) ** Complex(2, 1)).should be_close(Complex(-0.504824688978319, 3.10414407699553), TOLERANCE)
+ (Complex(2, 1) ** Complex(3, 4)).should be_close(Complex(-0.179174656916581, -1.74071656397662), TOLERANCE)
+
+ (Complex(2, 1) ** Complex(-2, -1)).should be_close(Complex(-0.051041070450869, -0.313849223270419), TOLERANCE)
+ (Complex(-2, -1) ** Complex(2, 1)).should be_close(Complex(-11.6819929610857, 71.8320439736158), TOLERANCE)
+ end
+end
+
+describe :complex_exponent_integer, :shared => true do
+ it "returns self raised to the given power" do
+ (Complex(2, 1) ** 2).should == Complex(3, 4)
+ (Complex(3, 4) ** 2).should == Complex(-7, 24)
+ (Complex(3, 4) ** -2).should be_close(Complex(-0.0112, -0.0384), TOLERANCE)
+
+
+ (Complex(2, 1) ** 2.5).should be_close(Complex(2.99179707178602, 6.85206901006896), TOLERANCE)
+ (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)
+
+ # NOTE: Takes way too long...
+ #(Complex(2, 1) ** bignum_value)
+ end
+end
+
+describe :complex_exponent_rational, :shared => true do
+ it "returns self raised to the given power" do
+ (Complex(2, 1) ** Rational(3, 4)).should be_close(Complex(1.71913265276568, 0.623124744394697), TOLERANCE)
+ (Complex(2, 1) ** Rational(4, 3)).should be_close(Complex(2.3828547125173, 1.69466313833091), TOLERANCE)
+ (Complex(2, 1) ** Rational(-4, 3)).should be_close(Complex(0.278700377879388, -0.198209003071003), TOLERANCE)
+ end
+end
+
+describe :complex_exponent_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/rect.rb (from rev 1956, MacRuby/branches/experimental/spec/frozen/core/complex/shared/rect.rb)
===================================================================
--- MacRuby/branches/experimental/spec/frozen/shared/complex/rect.rb (rev 0)
+++ MacRuby/branches/experimental/spec/frozen/shared/complex/rect.rb 2009-07-01 23:43:49 UTC (rev 1957)
@@ -0,0 +1,45 @@
+require File.dirname(__FILE__) + '/../../spec_helper'
+
+describe :complex_rect, :shared => true do
+ before(:each) do
+ @numbers = [
+ Complex(1),
+ Complex(0, 20),
+ Complex(0, 0),
+ Complex(0.0),
+ Complex(9999999**99),
+ Complex(-20),
+ Complex.polar(76, 10)
+ ]
+ end
+
+ it "returns an Array" do
+ @numbers.each do |number|
+ number.send(@method).should be_an_instance_of(Array)
+ end
+ end
+
+ it "returns a two-element Array" do
+ @numbers.each do |number|
+ number.send(@method).size.should == 2
+ end
+ end
+
+ it "returns the real part of self as the first element" do
+ @numbers.each do |number|
+ number.send(@method).first.should == number.real
+ end
+ end
+
+ it "returns the imaginary part of self as the last element" do
+ @numbers.each do |number|
+ number.send(@method).last.should == number.imaginary
+ 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/shared/rational/div.rb
===================================================================
--- MacRuby/branches/experimental/spec/frozen/shared/rational/div.rb 2009-07-01 23:05:28 UTC (rev 1956)
+++ MacRuby/branches/experimental/spec/frozen/shared/rational/div.rb 2009-07-01 23:43:49 UTC (rev 1957)
@@ -39,9 +39,17 @@
end
end
- it "raises a FloatDomainError when the argument is 0.0" do
- lambda { Rational(3, 4).div(0.0) }.should raise_error(FloatDomainError)
- end
+ ruby_version_is ""..."1.9" do
+ it "raises a FloatDomainError when the argument is 0.0" do
+ lambda { Rational(3, 4).div(0.0) }.should raise_error(FloatDomainError)
+ end
+ end
+
+ ruby_version_is "1.9" do
+ it "raises a ZeroDivisionError when the argument is 0.0" do
+ lambda { Rational(3, 4).div(0.0) }.should raise_error(ZeroDivisionError)
+ end
+ end
end
describe :rational_div_int, :shared => true do
Modified: MacRuby/branches/experimental/spec/frozen/shared/rational/divmod.rb
===================================================================
--- MacRuby/branches/experimental/spec/frozen/shared/rational/divmod.rb 2009-07-01 23:05:28 UTC (rev 1956)
+++ MacRuby/branches/experimental/spec/frozen/shared/rational/divmod.rb 2009-07-01 23:43:49 UTC (rev 1957)
@@ -39,7 +39,15 @@
end
end
- it "raises a FloatDomainError when passed 0" do
- lambda { Rational(7, 4).divmod(0.0) }.should raise_error(FloatDomainError)
+ ruby_version_is ""..."1.9" do
+ it "raises a FloatDomainError when passed 0" do
+ lambda { Rational(7, 4).divmod(0.0) }.should raise_error(FloatDomainError)
+ end
end
+
+ ruby_version_is "1.9" do
+ it "raises a ZeroDivisionError when passed 0" do
+ lambda { Rational(7, 4).divmod(0.0) }.should raise_error(ZeroDivisionError)
+ end
+ end
end
Modified: MacRuby/branches/experimental/spec/frozen/shared/rational/exponent.rb
===================================================================
--- MacRuby/branches/experimental/spec/frozen/shared/rational/exponent.rb 2009-07-01 23:05:28 UTC (rev 1956)
+++ MacRuby/branches/experimental/spec/frozen/shared/rational/exponent.rb 2009-07-01 23:43:49 UTC (rev 1957)
@@ -40,10 +40,17 @@
(Rational(3, 4) ** Rational(-4, 3)).should be_close(1.46752322173095, TOLERANCE)
(Rational(3, 4) ** Rational(4, -3)).should be_close(1.46752322173095, TOLERANCE)
end
+
+ it "returns a complex number when self is negative and the passed argument is not 0" do
+ (Rational(-3, 4) ** Rational(-4, 3)).should == Complex(
+ -0.7337616108654732, 1.2709123906625817)
+ end
end
- it "returns NaN when self is negative and the passed argument is not 0" do
- (Rational(-3, 4) ** Rational(-4, 3)).nan?.should be_true
+ ruby_version_is ""..."1.9" do
+ it "returns NaN when self is negative and the passed argument is not 0" do
+ (Rational(-3, 4) ** Rational(-4, 3)).nan?.should be_true
+ end
end
end
end
@@ -80,16 +87,35 @@
(Rational(3, 1) ** -1.5).should be_close(0.192450089729875, TOLERANCE)
end
- it "returns 1.0 when the passed argument is 0" do
- (Rational(3, 4) ** 0.0).should eql(1.0)
- (Rational(-3, 4) ** 0.0).should eql(1.0)
- (Rational(-3, 4) ** 0.0).should eql(1.0)
+ ruby_version_is ""..."1.9" do
+ it "returns NaN if self is negative and the passed argument is not 0" do
+ (Rational(-3, 2) ** 1.5).nan?.should be_true
+ (Rational(3, -2) ** 1.5).nan?.should be_true
+ (Rational(3, -2) ** -1.5).nan?.should be_true
+ end
+
+ it "returns 1.0 when the passed argument is 0.0" do
+ (Rational(3, 4) ** 0.0).should eql(1.0)
+ (Rational(-3, 4) ** 0.0).should eql(1.0)
+ (Rational(-3, 4) ** 0.0).should eql(1.0)
+ end
end
-
- it "returns NaN if self is negative and the passed argument is not 0" do
- (Rational(-3, 2) ** 1.5).nan?.should be_true
- (Rational(3, -2) ** 1.5).nan?.should be_true
- (Rational(3, -2) ** -1.5).nan?.should be_true
+
+ ruby_version_is "1.9" do
+ it "returns a complex number if self is negative and the passed argument is not 0" do
+ (Rational(-3, 2) ** 1.5).should == Complex(
+ -3.374618290464398e-16, -1.8371173070873836)
+ (Rational(3, -2) ** 1.5).should == Complex(
+ -3.374618290464398e-16, -1.8371173070873836)
+ (Rational(3, -2) ** -1.5).should == Complex(
+ -9.998869008783402e-17, 0.5443310539518174)
+ end
+
+ it "returns Complex(1.0) when the passed argument is 0.0" do
+ (Rational(3, 4) ** 0.0).should == Complex(1.0)
+ (Rational(-3, 4) ** 0.0).should == Complex(1.0)
+ (Rational(-3, 4) ** 0.0).should == Complex(1.0)
+ end
end
end
Modified: MacRuby/branches/experimental/spec/frozen/shared/rational/modulo.rb
===================================================================
--- MacRuby/branches/experimental/spec/frozen/shared/rational/modulo.rb 2009-07-01 23:05:28 UTC (rev 1956)
+++ MacRuby/branches/experimental/spec/frozen/shared/rational/modulo.rb 2009-07-01 23:43:49 UTC (rev 1957)
@@ -3,32 +3,44 @@
describe :rational_modulo, :shared => true do
it "returns the remainder when this value is divided by other" do
- (Rational(2, 3) % Rational(2, 3)).should == Rational(0, 1)
- (Rational(4, 3) % Rational(2, 3)).should == Rational(0, 1)
- (Rational(2, -3) % Rational(-2, 3)).should == Rational(0, 1)
- (Rational(0, -1) % -1).should == Rational(0, 1)
+ Rational(2, 3).send(@method, Rational(2, 3)).should == Rational(0, 1)
+ Rational(4, 3).send(@method, Rational(2, 3)).should == Rational(0, 1)
+ Rational(2, -3).send(@method, Rational(-2, 3)).should == Rational(0, 1)
+ Rational(0, -1).send(@method, -1).should == Rational(0, 1)
- (Rational(7, 4) % Rational(1, 2)).should == Rational(1, 4)
- (Rational(7, 4) % 1).should == Rational(3, 4)
- (Rational(7, 4) % Rational(1, 7)).should == Rational(1, 28)
+ Rational(7, 4).send(@method, Rational(1, 2)).should == Rational(1, 4)
+ Rational(7, 4).send(@method, 1).should == Rational(3, 4)
+ Rational(7, 4).send(@method, Rational(1, 7)).should == Rational(1, 28)
- (Rational(3, 4) % -1).should == Rational(-1, 4)
- (Rational(1, -5) % -1).should == Rational(-1, 5)
+ Rational(3, 4).send(@method, -1).should == Rational(-1, 4)
+ Rational(1, -5).send(@method, -1).should == Rational(-1, 5)
end
it "returns a Float value when the argument is Float" do
- (Rational(7, 4) % 1.0).should be_kind_of(Float)
- (Rational(7, 4) % 1.0).should == 0.75
- (Rational(7, 4) % 0.26).should be_close(0.19, 0.0001)
+ Rational(7, 4).send(@method, 1.0).should be_kind_of(Float)
+ Rational(7, 4).send(@method, 1.0).should == 0.75
+ Rational(7, 4).send(@method, 0.26).should be_close(0.19, 0.0001)
end
it "raises ZeroDivisionError on zero denominator" do
- lambda { Rational(3, 5) % Rational(0, 1) }.should raise_error(ZeroDivisionError)
- lambda { Rational(0, 1) % Rational(0, 1) }.should raise_error(ZeroDivisionError)
- lambda { Rational(3, 5) % 0 }.should raise_error(ZeroDivisionError)
+ lambda { Rational(3, 5).send(@method, Rational(0, 1)) }.should
+ raise_error(ZeroDivisionError)
+ lambda { Rational(0, 1).send(@method, Rational(0, 1)) }.should
+ raise_error(ZeroDivisionError)
+ lambda { Rational(3, 5).send(@method, 0) }.should
+ raise_error(ZeroDivisionError)
end
- it "raises FloatDomainError when the argument is 0.0" do
- lambda { Rational(3, 5) % 0.0 }.should raise_error(FloatDomainError)
+ ruby_version_is ""..."1.9" do
+ it "raises FloatDomainError when the argument is 0.0" do
+ lambda { Rational(3, 5) % 0.0 }.should raise_error(FloatDomainError)
+ end
end
+
+ ruby_version_is "1.9" do
+ it "raises a ZeroDivisionError when the argument is 0.0" do
+ lambda { Rational(3, 5).send(@method, 0.0) }.should
+ raise_error(ZeroDivisionError)
+ end
+ end
end
Modified: MacRuby/branches/experimental/spec/frozen/upstream
===================================================================
--- MacRuby/branches/experimental/spec/frozen/upstream 2009-07-01 23:05:28 UTC (rev 1956)
+++ MacRuby/branches/experimental/spec/frozen/upstream 2009-07-01 23:43:49 UTC (rev 1957)
@@ -1 +1 @@
-7072d6def04d6fd23244839986e234da76d9a5a0
\ No newline at end of file
+7e9a0d56fb3b981bf7985f313b0bd9c3e79e7e74
\ No newline at end of file
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macosforge.org/pipermail/macruby-changes/attachments/20090701/b11069dd/attachment-0001.html>
More information about the macruby-changes
mailing list