aboutsummaryrefslogtreecommitdiffstats
path: root/spec/rubyspec/core/encoding/invalid_byte_sequence_error
diff options
context:
space:
mode:
Diffstat (limited to 'spec/rubyspec/core/encoding/invalid_byte_sequence_error')
-rw-r--r--spec/rubyspec/core/encoding/invalid_byte_sequence_error/destination_encoding_name_spec.rb20
-rw-r--r--spec/rubyspec/core/encoding/invalid_byte_sequence_error/destination_encoding_spec.rb20
-rw-r--r--spec/rubyspec/core/encoding/invalid_byte_sequence_error/error_bytes_spec.rb32
-rw-r--r--spec/rubyspec/core/encoding/invalid_byte_sequence_error/incomplete_input_spec.rb31
-rw-r--r--spec/rubyspec/core/encoding/invalid_byte_sequence_error/readagain_bytes_spec.rb32
-rw-r--r--spec/rubyspec/core/encoding/invalid_byte_sequence_error/source_encoding_name_spec.rb30
-rw-r--r--spec/rubyspec/core/encoding/invalid_byte_sequence_error/source_encoding_spec.rb35
7 files changed, 200 insertions, 0 deletions
diff --git a/spec/rubyspec/core/encoding/invalid_byte_sequence_error/destination_encoding_name_spec.rb b/spec/rubyspec/core/encoding/invalid_byte_sequence_error/destination_encoding_name_spec.rb
new file mode 100644
index 0000000000..790dd18655
--- /dev/null
+++ b/spec/rubyspec/core/encoding/invalid_byte_sequence_error/destination_encoding_name_spec.rb
@@ -0,0 +1,20 @@
+require File.expand_path('../../fixtures/classes', __FILE__)
+
+with_feature :encoding 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
diff --git a/spec/rubyspec/core/encoding/invalid_byte_sequence_error/destination_encoding_spec.rb b/spec/rubyspec/core/encoding/invalid_byte_sequence_error/destination_encoding_spec.rb
new file mode 100644
index 0000000000..981a62424e
--- /dev/null
+++ b/spec/rubyspec/core/encoding/invalid_byte_sequence_error/destination_encoding_spec.rb
@@ -0,0 +1,20 @@
+require File.expand_path('../../fixtures/classes', __FILE__)
+
+with_feature :encoding 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
diff --git a/spec/rubyspec/core/encoding/invalid_byte_sequence_error/error_bytes_spec.rb b/spec/rubyspec/core/encoding/invalid_byte_sequence_error/error_bytes_spec.rb
new file mode 100644
index 0000000000..633ad2e1f7
--- /dev/null
+++ b/spec/rubyspec/core/encoding/invalid_byte_sequence_error/error_bytes_spec.rb
@@ -0,0 +1,32 @@
+# -*- encoding: binary -*-
+require File.expand_path('../../fixtures/classes', __FILE__)
+
+with_feature :encoding 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
diff --git a/spec/rubyspec/core/encoding/invalid_byte_sequence_error/incomplete_input_spec.rb b/spec/rubyspec/core/encoding/invalid_byte_sequence_error/incomplete_input_spec.rb
new file mode 100644
index 0000000000..c79a6663e2
--- /dev/null
+++ b/spec/rubyspec/core/encoding/invalid_byte_sequence_error/incomplete_input_spec.rb
@@ -0,0 +1,31 @@
+# -*- encoding: binary -*-
+require File.expand_path('../../../../spec_helper', __FILE__)
+
+with_feature :encoding 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
diff --git a/spec/rubyspec/core/encoding/invalid_byte_sequence_error/readagain_bytes_spec.rb b/spec/rubyspec/core/encoding/invalid_byte_sequence_error/readagain_bytes_spec.rb
new file mode 100644
index 0000000000..31408a4320
--- /dev/null
+++ b/spec/rubyspec/core/encoding/invalid_byte_sequence_error/readagain_bytes_spec.rb
@@ -0,0 +1,32 @@
+# -*- encoding: binary -*-
+require File.expand_path('../../fixtures/classes', __FILE__)
+
+with_feature :encoding 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
diff --git a/spec/rubyspec/core/encoding/invalid_byte_sequence_error/source_encoding_name_spec.rb b/spec/rubyspec/core/encoding/invalid_byte_sequence_error/source_encoding_name_spec.rb
new file mode 100644
index 0000000000..41320c5207
--- /dev/null
+++ b/spec/rubyspec/core/encoding/invalid_byte_sequence_error/source_encoding_name_spec.rb
@@ -0,0 +1,30 @@
+require File.expand_path('../../fixtures/classes', __FILE__)
+
+with_feature :encoding 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
diff --git a/spec/rubyspec/core/encoding/invalid_byte_sequence_error/source_encoding_spec.rb b/spec/rubyspec/core/encoding/invalid_byte_sequence_error/source_encoding_spec.rb
new file mode 100644
index 0000000000..75514e5229
--- /dev/null
+++ b/spec/rubyspec/core/encoding/invalid_byte_sequence_error/source_encoding_spec.rb
@@ -0,0 +1,35 @@
+require File.expand_path('../../fixtures/classes', __FILE__)
+
+with_feature :encoding 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