aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBenoit Daloze <eregontp@gmail.com>2019-04-28 23:20:11 +0200
committerBenoit Daloze <eregontp@gmail.com>2019-04-28 23:20:11 +0200
commit79671ec57e59091260a0bc3d40a31d31d9c72a94 (patch)
tree2f59a8727b8f63f9e79d50352fa4f78a7cc00234
parent994833085ae06afbe94d30ab183d80e0234fbe14 (diff)
downloadruby-79671ec57e59091260a0bc3d40a31d31d9c72a94.tar.gz
Update to ruby/spec@7de852d
-rw-r--r--spec/ruby/core/argf/gets_spec.rb30
-rw-r--r--spec/ruby/core/argf/read_spec.rb30
-rw-r--r--spec/ruby/core/dir/shared/glob.rb8
-rw-r--r--spec/ruby/core/dir/shared/path.rb16
-rw-r--r--spec/ruby/core/dir/shared/pwd.rb20
-rw-r--r--spec/ruby/core/encoding/aliases_spec.rb60
-rw-r--r--spec/ruby/core/encoding/ascii_compatible_spec.rb14
-rw-r--r--spec/ruby/core/encoding/compatible_spec.rb570
-rw-r--r--spec/ruby/core/encoding/converter/asciicompat_encoding_spec.rb58
-rw-r--r--spec/ruby/core/encoding/converter/constants_spec.rb182
-rw-r--r--spec/ruby/core/encoding/converter/convert_spec.rb70
-rw-r--r--spec/ruby/core/encoding/converter/convpath_spec.rb36
-rw-r--r--spec/ruby/core/encoding/converter/destination_encoding_spec.rb14
-rw-r--r--spec/ruby/core/encoding/converter/finish_spec.rb54
-rw-r--r--spec/ruby/core/encoding/converter/last_error_spec.rb154
-rw-r--r--spec/ruby/core/encoding/converter/new_spec.rb194
-rw-r--r--spec/ruby/core/encoding/converter/primitive_convert_spec.rb414
-rw-r--r--spec/ruby/core/encoding/converter/primitive_errinfo_spec.rb110
-rw-r--r--spec/ruby/core/encoding/converter/putback_spec.rb74
-rw-r--r--spec/ruby/core/encoding/converter/replacement_spec.rb116
-rw-r--r--spec/ruby/core/encoding/converter/search_convpath_spec.rb50
-rw-r--r--spec/ruby/core/encoding/converter/source_encoding_spec.rb14
-rw-r--r--spec/ruby/core/encoding/default_external_spec.rb94
-rw-r--r--spec/ruby/core/encoding/default_internal_spec.rb120
-rw-r--r--spec/ruby/core/encoding/dummy_spec.rb20
-rw-r--r--spec/ruby/core/encoding/find_spec.rb118
-rw-r--r--spec/ruby/core/encoding/inspect_spec.rb24
-rw-r--r--spec/ruby/core/encoding/invalid_byte_sequence_error/destination_encoding_name_spec.rb26
-rw-r--r--spec/ruby/core/encoding/invalid_byte_sequence_error/destination_encoding_spec.rb26
-rw-r--r--spec/ruby/core/encoding/invalid_byte_sequence_error/error_bytes_spec.rb42
-rw-r--r--spec/ruby/core/encoding/invalid_byte_sequence_error/incomplete_input_spec.rb40
-rw-r--r--spec/ruby/core/encoding/invalid_byte_sequence_error/readagain_bytes_spec.rb42
-rw-r--r--spec/ruby/core/encoding/invalid_byte_sequence_error/source_encoding_name_spec.rb44
-rw-r--r--spec/ruby/core/encoding/invalid_byte_sequence_error/source_encoding_spec.rb52
-rw-r--r--spec/ruby/core/encoding/list_spec.rb58
-rw-r--r--spec/ruby/core/encoding/locale_charmap_spec.rb68
-rw-r--r--spec/ruby/core/encoding/name_list_spec.rb30
-rw-r--r--spec/ruby/core/encoding/name_spec.rb6
-rw-r--r--spec/ruby/core/encoding/names_spec.rb48
-rw-r--r--spec/ruby/core/encoding/replicate_spec.rb74
-rw-r--r--spec/ruby/core/encoding/to_s_spec.rb6
-rw-r--r--spec/ruby/core/encoding/undefined_conversion_error/destination_encoding_name_spec.rb20
-rw-r--r--spec/ruby/core/encoding/undefined_conversion_error/destination_encoding_spec.rb20
-rw-r--r--spec/ruby/core/encoding/undefined_conversion_error/error_char_spec.rb38
-rw-r--r--spec/ruby/core/encoding/undefined_conversion_error/source_encoding_name_spec.rb44
-rw-r--r--spec/ruby/core/encoding/undefined_conversion_error/source_encoding_spec.rb46
-rw-r--r--spec/ruby/core/env/element_reference_spec.rb52
-rw-r--r--spec/ruby/core/env/shared/each.rb48
-rw-r--r--spec/ruby/core/env/shift_spec.rb50
-rw-r--r--spec/ruby/core/fiber/new_spec.rb60
-rw-r--r--spec/ruby/core/fiber/resume_spec.rb87
-rw-r--r--spec/ruby/core/fiber/yield_spec.rb76
-rw-r--r--spec/ruby/core/file/basename_spec.rb18
-rw-r--r--spec/ruby/core/file/expand_path_spec.rb54
-rw-r--r--spec/ruby/core/file/extname_spec.rb8
-rw-r--r--spec/ruby/core/file/open_spec.rb19
-rw-r--r--spec/ruby/core/file/shared/path.rb10
-rw-r--r--spec/ruby/core/float/to_s_spec.rb30
-rw-r--r--spec/ruby/core/integer/to_s_spec.rb56
-rw-r--r--spec/ruby/core/io/external_encoding_spec.rb302
-rw-r--r--spec/ruby/core/io/fixtures/classes.rb4
-rw-r--r--spec/ruby/core/io/foreach_spec.rb2
-rw-r--r--spec/ruby/core/io/gets_spec.rb8
-rw-r--r--spec/ruby/core/io/initialize_spec.rb32
-rw-r--r--spec/ruby/core/io/internal_encoding_spec.rb228
-rw-r--r--spec/ruby/core/io/popen_spec.rb28
-rw-r--r--spec/ruby/core/io/puts_spec.rb32
-rw-r--r--spec/ruby/core/io/read_spec.rb206
-rw-r--r--spec/ruby/core/io/readlines_spec.rb6
-rw-r--r--spec/ruby/core/io/reopen_spec.rb17
-rw-r--r--spec/ruby/core/io/set_encoding_spec.rb286
-rw-r--r--spec/ruby/core/io/shared/write.rb6
-rw-r--r--spec/ruby/core/io/write_spec.rb68
-rw-r--r--spec/ruby/core/kernel/chomp_spec.rb36
-rw-r--r--spec/ruby/core/kernel/chop_spec.rb36
-rw-r--r--spec/ruby/core/marshal/dump_spec.rb46
-rw-r--r--spec/ruby/core/marshal/shared/load.rb62
-rw-r--r--spec/ruby/core/matchdata/post_match_spec.rb16
-rw-r--r--spec/ruby/core/matchdata/pre_match_spec.rb16
-rw-r--r--spec/ruby/core/objectspace/define_finalizer_spec.rb89
-rw-r--r--spec/ruby/core/process/euid_spec.rb25
-rw-r--r--spec/ruby/core/process/ppid_spec.rb20
-rw-r--r--spec/ruby/core/process/setpgid_spec.rb3
-rw-r--r--spec/ruby/core/process/setsid_spec.rb37
-rw-r--r--spec/ruby/core/process/uid_spec.rb55
-rw-r--r--spec/ruby/core/process/wait2_spec.rb4
-rw-r--r--spec/ruby/core/regexp/match_spec.rb30
-rw-r--r--spec/ruby/core/string/ascii_only_spec.rb126
-rw-r--r--spec/ruby/core/string/b_spec.rb30
-rw-r--r--spec/ruby/core/string/bytes_spec.rb26
-rw-r--r--spec/ruby/core/string/bytesize_spec.rb48
-rw-r--r--spec/ruby/core/string/byteslice_spec.rb14
-rw-r--r--spec/ruby/core/string/center_spec.rb42
-rw-r--r--spec/ruby/core/string/chomp_spec.rb88
-rw-r--r--spec/ruby/core/string/chop_spec.rb40
-rw-r--r--spec/ruby/core/string/chr_spec.rb78
-rw-r--r--spec/ruby/core/string/clear_spec.rb58
-rw-r--r--spec/ruby/core/string/codepoints_spec.rb20
-rw-r--r--spec/ruby/core/string/downcase_spec.rb6
-rw-r--r--spec/ruby/core/string/each_codepoint_spec.rb8
-rw-r--r--spec/ruby/core/string/element_set_spec.rb362
-rw-r--r--spec/ruby/core/string/encode_spec.rb232
-rw-r--r--spec/ruby/core/string/encoding_spec.rb364
-rw-r--r--spec/ruby/core/string/force_encoding_spec.rb106
-rw-r--r--spec/ruby/core/string/index_spec.rb60
-rw-r--r--spec/ruby/core/string/insert_spec.rb32
-rw-r--r--spec/ruby/core/string/ljust_spec.rb42
-rw-r--r--spec/ruby/core/string/match_spec.rb18
-rw-r--r--spec/ruby/core/string/ord_spec.rb38
-rw-r--r--spec/ruby/core/string/reverse_spec.rb16
-rw-r--r--spec/ruby/core/string/rindex_spec.rb28
-rw-r--r--spec/ruby/core/string/rjust_spec.rb42
-rw-r--r--spec/ruby/core/string/shared/chars.rb92
-rw-r--r--spec/ruby/core/string/shared/length.rb22
-rw-r--r--spec/ruby/core/string/slice_spec.rb78
-rw-r--r--spec/ruby/core/string/split_spec.rb22
-rw-r--r--spec/ruby/core/string/tr_s_spec.rb72
-rw-r--r--spec/ruby/core/string/tr_spec.rb44
-rw-r--r--spec/ruby/core/string/valid_encoding_spec.rb236
-rw-r--r--spec/ruby/core/thread/shared/exit.rb22
-rw-r--r--spec/ruby/core/time/_load_spec.rb12
-rw-r--r--spec/ruby/core/time/shared/inspect.rb6
-rw-r--r--spec/ruby/default.mspec9
-rw-r--r--spec/ruby/language/predefined_spec.rb220
-rw-r--r--spec/ruby/language/string_spec.rb42
-rw-r--r--spec/ruby/library/fiber/alive_spec.rb74
-rw-r--r--spec/ruby/library/fiber/current_spec.rb80
-rw-r--r--spec/ruby/library/fiber/resume_spec.rb16
-rw-r--r--spec/ruby/library/fiber/transfer_spec.rb136
-rw-r--r--spec/ruby/library/socket/addrinfo/ip_address_spec.rb19
-rw-r--r--spec/ruby/library/socket/spec_helper.rb4
-rw-r--r--spec/ruby/library/stringio/getch_spec.rb16
-rw-r--r--spec/ruby/optional/capi/io_spec.rb8
-rw-r--r--spec/ruby/shared/string/times.rb10
-rw-r--r--spec/ruby/shared/time/strftime_for_date.rb10
135 files changed, 4183 insertions, 4653 deletions
diff --git a/spec/ruby/core/argf/gets_spec.rb b/spec/ruby/core/argf/gets_spec.rb
index 5863147ec8..cc7673b190 100644
--- a/spec/ruby/core/argf/gets_spec.rb
+++ b/spec/ruby/core/argf/gets_spec.rb
@@ -26,25 +26,23 @@ describe "ARGF.gets" do
end
end
- with_feature :encoding do
- before :each do
- @external = Encoding.default_external
- @internal = Encoding.default_internal
+ before :each do
+ @external = Encoding.default_external
+ @internal = Encoding.default_internal
- Encoding.default_external = Encoding::UTF_8
- Encoding.default_internal = nil
- end
+ Encoding.default_external = Encoding::UTF_8
+ Encoding.default_internal = nil
+ end
- after :each do
- Encoding.default_external = @external
- Encoding.default_internal = @internal
- end
+ after :each do
+ Encoding.default_external = @external
+ Encoding.default_internal = @internal
+ end
- it "reads the contents of the file with default encoding" do
- Encoding.default_external = Encoding::US_ASCII
- argf [@file1_name, @file2_name] do
- @argf.gets.encoding.should == Encoding::US_ASCII
- end
+ it "reads the contents of the file with default encoding" do
+ Encoding.default_external = Encoding::US_ASCII
+ argf [@file1_name, @file2_name] do
+ @argf.gets.encoding.should == Encoding::US_ASCII
end
end
diff --git a/spec/ruby/core/argf/read_spec.rb b/spec/ruby/core/argf/read_spec.rb
index b889605572..bbeef95456 100644
--- a/spec/ruby/core/argf/read_spec.rb
+++ b/spec/ruby/core/argf/read_spec.rb
@@ -62,26 +62,24 @@ describe "ARGF.read" do
end
end
- with_feature :encoding do
- before :each do
- @external = Encoding.default_external
- @internal = Encoding.default_internal
+ before :each do
+ @external = Encoding.default_external
+ @internal = Encoding.default_internal
- Encoding.default_external = Encoding::UTF_8
- Encoding.default_internal = nil
- end
+ Encoding.default_external = Encoding::UTF_8
+ Encoding.default_internal = nil
+ end
- after :each do
- Encoding.default_external = @external
- Encoding.default_internal = @internal
- end
+ after :each do
+ Encoding.default_external = @external
+ Encoding.default_internal = @internal
+ end
- it "reads the contents of the file with default encoding" do
- Encoding.default_external = Encoding::US_ASCII
- argf [@file1_name, @file2_name] do
- @argf.read.encoding.should == Encoding::US_ASCII
- end
+ it "reads the contents of the file with default encoding" do
+ Encoding.default_external = Encoding::US_ASCII
+ argf [@file1_name, @file2_name] do
+ @argf.read.encoding.should == Encoding::US_ASCII
end
end
end
diff --git a/spec/ruby/core/dir/shared/glob.rb b/spec/ruby/core/dir/shared/glob.rb
index 19f457e22a..af587dd33b 100644
--- a/spec/ruby/core/dir/shared/glob.rb
+++ b/spec/ruby/core/dir/shared/glob.rb
@@ -11,11 +11,9 @@ describe :dir_glob, shared: true do
DirSpecs.delete_mock_dirs
end
- with_feature :encoding do
- it "raises an Encoding::CompatibilityError if the argument encoding is not compatible with US-ASCII" do
- pattern = "file*".force_encoding Encoding::UTF_16BE
- lambda { Dir.send(@method, pattern) }.should raise_error(Encoding::CompatibilityError)
- end
+ it "raises an Encoding::CompatibilityError if the argument encoding is not compatible with US-ASCII" do
+ pattern = "file*".force_encoding Encoding::UTF_16BE
+ lambda { Dir.send(@method, pattern) }.should raise_error(Encoding::CompatibilityError)
end
it "calls #to_path to convert a pattern" do
diff --git a/spec/ruby/core/dir/shared/path.rb b/spec/ruby/core/dir/shared/path.rb
index fe2d61ebf7..494dcca775 100644
--- a/spec/ruby/core/dir/shared/path.rb
+++ b/spec/ruby/core/dir/shared/path.rb
@@ -18,15 +18,13 @@ describe :dir_path, shared: true do
dir.send(@method).should == DirSpecs.mock_dir
end
- with_feature :encoding do
- it "returns a String with the same encoding as the argument to .open" do
- path = DirSpecs.mock_dir.force_encoding Encoding::IBM866
- dir = Dir.open path
- begin
- dir.send(@method).encoding.should equal(Encoding::IBM866)
- ensure
- dir.close
- end
+ it "returns a String with the same encoding as the argument to .open" do
+ path = DirSpecs.mock_dir.force_encoding Encoding::IBM866
+ dir = Dir.open path
+ begin
+ dir.send(@method).encoding.should equal(Encoding::IBM866)
+ ensure
+ dir.close
end
end
end
diff --git a/spec/ruby/core/dir/shared/pwd.rb b/spec/ruby/core/dir/shared/pwd.rb
index 5f041a9d41..94fc2fa7fb 100644
--- a/spec/ruby/core/dir/shared/pwd.rb
+++ b/spec/ruby/core/dir/shared/pwd.rb
@@ -1,8 +1,6 @@
describe :dir_pwd, shared: true do
- with_feature :encoding do
- before :each do
- @fs_encoding = Encoding.find('filesystem')
- end
+ before :each do
+ @fs_encoding = Encoding.find('filesystem')
end
it "returns the current working directory" do
@@ -36,14 +34,12 @@ describe :dir_pwd, shared: true do
end
end
- with_feature :encoding do
- it "returns a String with the filesystem encoding" do
- enc = Dir.send(@method).encoding
- if @fs_encoding == Encoding::US_ASCII
- [Encoding::US_ASCII, Encoding::ASCII_8BIT].should include(enc)
- else
- enc.should equal(@fs_encoding)
- end
+ it "returns a String with the filesystem encoding" do
+ enc = Dir.send(@method).encoding
+ if @fs_encoding == Encoding::US_ASCII
+ [Encoding::US_ASCII, Encoding::ASCII_8BIT].should include(enc)
+ else
+ enc.should equal(@fs_encoding)
end
end
end
diff --git a/spec/ruby/core/encoding/aliases_spec.rb b/spec/ruby/core/encoding/aliases_spec.rb
index 22e4510993..786157981a 100644
--- a/spec/ruby/core/encoding/aliases_spec.rb
+++ b/spec/ruby/core/encoding/aliases_spec.rb
@@ -1,45 +1,43 @@
require_relative '../../spec_helper'
-with_feature :encoding do
- describe "Encoding.aliases" do
- it "returns a Hash" do
- Encoding.aliases.should be_an_instance_of(Hash)
- end
+describe "Encoding.aliases" do
+ it "returns a Hash" do
+ Encoding.aliases.should be_an_instance_of(Hash)
+ end
- it "has Strings as keys" do
- Encoding.aliases.keys.each do |key|
- key.should be_an_instance_of(String)
- end
+ 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
+ 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 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 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 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 and its value equals the name of the encoding found by the locale charmap" do
- Encoding.aliases['locale'].should == Encoding.find(Encoding.locale_charmap).name
- end
+ it "has a 'locale' key and its value equals the name of the encoding found by the locale charmap" do
+ Encoding.aliases['locale'].should == Encoding.find(Encoding.locale_charmap).name
+ end
- it "only contains valid aliased encodings" do
- Encoding.aliases.each do |aliased, original|
- Encoding.find(aliased).should == Encoding.find(original)
- end
+ it "only contains valid aliased encodings" do
+ Encoding.aliases.each do |aliased, original|
+ Encoding.find(aliased).should == Encoding.find(original)
end
end
end
diff --git a/spec/ruby/core/encoding/ascii_compatible_spec.rb b/spec/ruby/core/encoding/ascii_compatible_spec.rb
index 31ac75302e..4804300e85 100644
--- a/spec/ruby/core/encoding/ascii_compatible_spec.rb
+++ b/spec/ruby/core/encoding/ascii_compatible_spec.rb
@@ -1,13 +1,11 @@
require_relative '../../spec_helper'
-with_feature :encoding do
- describe "Encoding#ascii_compatible?" do
- it "returns true if self represents an ASCII-compatible encoding" do
- Encoding::UTF_8.ascii_compatible?.should be_true
- end
+describe "Encoding#ascii_compatible?" do
+ it "returns true if self represents an ASCII-compatible encoding" do
+ Encoding::UTF_8.ascii_compatible?.should be_true
+ end
- it "returns false if self does not represent an ASCII-compatible encoding" do
- Encoding::UTF_16LE.ascii_compatible?.should be_false
- end
+ it "returns false if self does not represent an ASCII-compatible encoding" do
+ Encoding::UTF_16LE.ascii_compatible?.should be_false
end
end
diff --git a/spec/ruby/core/encoding/compatible_spec.rb b/spec/ruby/core/encoding/compatible_spec.rb
index f35120325c..8c2e4d7e09 100644
--- a/spec/ruby/core/encoding/compatible_spec.rb
+++ b/spec/ruby/core/encoding/compatible_spec.rb
@@ -2,380 +2,378 @@
require_relative '../../spec_helper'
-with_feature :encoding do
- # TODO: add IO
+# TODO: add IO
- describe "Encoding.compatible? String, String" do
- describe "when the first's Encoding is valid US-ASCII" do
- before :each do
- @str = "abc".force_encoding Encoding::US_ASCII
- end
-
- it "returns US-ASCII when the second's is US-ASCII" do
- Encoding.compatible?(@str, "def".encode("us-ascii")).should == Encoding::US_ASCII
- end
-
- it "returns US-ASCII if the second String is ASCII-8BIT and ASCII only" do
- Encoding.compatible?(@str, "\x7f").should == Encoding::US_ASCII
- end
+describe "Encoding.compatible? String, String" do
+ describe "when the first's Encoding is valid US-ASCII" do
+ before :each do
+ @str = "abc".force_encoding Encoding::US_ASCII
+ end
- it "returns ASCII-8BIT if the second String is ASCII-8BIT but not ASCII only" do
- Encoding.compatible?(@str, "\xff").should == Encoding::ASCII_8BIT
- end
+ it "returns US-ASCII when the second's is US-ASCII" do
+ Encoding.compatible?(@str, "def".encode("us-ascii")).should == Encoding::US_ASCII
+ end
- it "returns US-ASCII if the second String is UTF-8 and ASCII only" do
- Encoding.compatible?(@str, "\x7f".encode("utf-8")).should == Encoding::US_ASCII
- end
+ it "returns US-ASCII if the second String is ASCII-8BIT and ASCII only" do
+ Encoding.compatible?(@str, "\x7f").should == Encoding::US_ASCII
+ end
- it "returns UTF-8 if the second String is UTF-8 but not ASCII only" do
- Encoding.compatible?(@str, "\u3042".encode("utf-8")).should == Encoding::UTF_8
- end
+ it "returns ASCII-8BIT if the second String is ASCII-8BIT but not ASCII only" do
+ Encoding.compatible?(@str, "\xff").should == Encoding::ASCII_8BIT
end
- describe "when the first's Encoding is ASCII compatible and ASCII only" do
- it "returns the first's Encoding if the second is ASCII compatible and ASCII only" do
- [ [Encoding, "abc".force_encoding("UTF-8"), "123".force_encoding("Shift_JIS"), Encoding::UTF_8],
- [Encoding, "123".force_encoding("Shift_JIS"), "abc".force_encoding("UTF-8"), Encoding::Shift_JIS]
- ].should be_computed_by(:compatible?)
- end
+ it "returns US-ASCII if the second String is UTF-8 and ASCII only" do
+ Encoding.compatible?(@str, "\x7f".encode("utf-8")).should == Encoding::US_ASCII
+ end
- it "returns the first's Encoding if the second is ASCII compatible and ASCII only" do
- [ [Encoding, "abc".force_encoding("ASCII-8BIT"), "123".force_encoding("US-ASCII"), Encoding::ASCII_8BIT],
- [Encoding, "123".force_encoding("US-ASCII"), "abc".force_encoding("ASCII-8BIT"), Encoding::US_ASCII]
- ].should be_computed_by(:compatible?)
- end
+ it "returns UTF-8 if the second String is UTF-8 but not ASCII only" do
+ Encoding.compatible?(@str, "\u3042".encode("utf-8")).should == Encoding::UTF_8
+ end
+ end
- it "returns the second's Encoding if the second is ASCII compatible but not ASCII only" do
- [ [Encoding, "abc".force_encoding("UTF-8"), "\xff".force_encoding("Shift_JIS"), Encoding::Shift_JIS],
- [Encoding, "123".force_encoding("Shift_JIS"), "\xff".force_encoding("UTF-8"), Encoding::UTF_8],
- [Encoding, "abc".force_encoding("ASCII-8BIT"), "\xff".force_encoding("US-ASCII"), Encoding::US_ASCII],
- [Encoding, "123".force_encoding("US-ASCII"), "\xff".force_encoding("ASCII-8BIT"), Encoding::ASCII_8BIT],
- ].should be_computed_by(:compatible?)
- end
+ describe "when the first's Encoding is ASCII compatible and ASCII only" do
+ it "returns the first's Encoding if the second is ASCII compatible and ASCII only" do
+ [ [Encoding, "abc".force_encoding("UTF-8"), "123".force_encoding("Shift_JIS"), Encoding::UTF_8],
+ [Encoding, "123".force_encoding("Shift_JIS"), "abc".force_encoding("UTF-8"), Encoding::Shift_JIS]
+ ].should be_computed_by(:compatible?)
+ end
- it "returns nil if the second's Encoding is not ASCII compatible" do
- a = "abc".force_encoding("UTF-8")
- b = "123".force_encoding("UTF-16LE")
- Encoding.compatible?(a, b).should be_nil
- end
+ it "returns the first's Encoding if the second is ASCII compatible and ASCII only" do
+ [ [Encoding, "abc".force_encoding("ASCII-8BIT"), "123".force_encoding("US-ASCII"), Encoding::ASCII_8BIT],
+ [Encoding, "123".force_encoding("US-ASCII"), "abc".force_encoding("ASCII-8BIT"), Encoding::US_ASCII]
+ ].should be_computed_by(:compatible?)
end
- describe "when the first's Encoding is ASCII compatible but not ASCII only" do
- it "returns the first's Encoding if the second's is valid US-ASCII" do
- Encoding.compatible?("\xff", "def".encode("us-ascii")).should == Encoding::ASCII_8BIT
- end
+ it "returns the second's Encoding if the second is ASCII compatible but not ASCII only" do
+ [ [Encoding, "abc".force_encoding("UTF-8"), "\xff".force_encoding("Shift_JIS"), Encoding::Shift_JIS],
+ [Encoding, "123".force_encoding("Shift_JIS"), "\xff".force_encoding("UTF-8"), Encoding::UTF_8],
+ [Encoding, "abc".force_encoding("ASCII-8BIT"), "\xff".force_encoding("US-ASCII"), Encoding::US_ASCII],
+ [Encoding, "123".force_encoding("US-ASCII"), "\xff".force_encoding("ASCII-8BIT"), Encoding::ASCII_8BIT],
+ ].should be_computed_by(:compatible?)
+ end
- it "returns the first's Encoding if the second's is UTF-8 and ASCII only" do
- Encoding.compatible?("\xff", "\u{7f}".encode("utf-8")).should == Encoding::ASCII_8BIT
- end
+ it "returns nil if the second's Encoding is not ASCII compatible" do
+ a = "abc".force_encoding("UTF-8")
+ b = "123".force_encoding("UTF-16LE")
+ Encoding.compatible?(a, b).should be_nil
+ end
+ end
- it "returns nil if the second encoding is ASCII compatible but neither String's encoding is ASCII only" do
- Encoding.compatible?("\xff", "\u3042".encode("utf-8")).should be_nil
- end
+ describe "when the first's Encoding is ASCII compatible but not ASCII only" do
+ it "returns the first's Encoding if the second's is valid US-ASCII" do
+ Encoding.compatible?("\xff", "def".encode("us-ascii")).should == Encoding::ASCII_8BIT
end
- describe "when the first's Encoding is not ASCII compatible" do
- before :each do
- @str = "abc".force_encoding Encoding::UTF_7
- end
+ it "returns the first's Encoding if the second's is UTF-8 and ASCII only" do
+ Encoding.compatible?("\xff", "\u{7f}".encode("utf-8")).should == Encoding::ASCII_8BIT
+ end
- it "returns nil when the second String is US-ASCII" do
- Encoding.compatible?(@str, "def".encode("us-ascii")).should be_nil
- end
+ it "returns nil if the second encoding is ASCII compatible but neither String's encoding is ASCII only" do
+ Encoding.compatible?("\xff", "\u3042".encode("utf-8")).should be_nil
+ end
+ end
- it "returns nil when the second String is ASCII-8BIT and ASCII only" do
- Encoding.compatible?(@str, "\x7f").should be_nil
- end
+ describe "when the first's Encoding is not ASCII compatible" do
+ before :each do
+ @str = "abc".force_encoding Encoding::UTF_7
+ end
- it "returns nil when the second String is ASCII-8BIT but not ASCII only" do
- Encoding.compatible?(@str, "\xff").should be_nil
- end
+ it "returns nil when the second String is US-ASCII" do
+ Encoding.compatible?(@str, "def".encode("us-ascii")).should be_nil
+ end
- it "returns the Encoding when the second's Encoding is not ASCII compatible but the same as the first's Encoding" do
- encoding = Encoding.compatible?(@str, "def".force_encoding("utf-7"))
- encoding.should == Encoding::UTF_7
- end
+ it "returns nil when the second String is ASCII-8BIT and ASCII only" do
+ Encoding.compatible?(@str, "\x7f").should be_nil
end
- describe "when the first's Encoding is invalid" do
- before :each do
- @str = "\xff".force_encoding Encoding::UTF_8
- end
+ it "returns nil when the second String is ASCII-8BIT but not ASCII only" do
+ Encoding.compatible?(@str, "\xff").should be_nil
+ end
- it "returns the first's Encoding when the second's Encoding is US-ASCII" do
- Encoding.compatible?(@str, "def".encode("us-ascii")).should == Encoding::UTF_8
- end
+ it "returns the Encoding when the second's Encoding is not ASCII compatible but the same as the first's Encoding" do
+ encoding = Encoding.compatible?(@str, "def".force_encoding("utf-7"))
+ encoding.should == Encoding::UTF_7
+ end
+ end
- it "returns the first's Encoding when the second String is ASCII only" do
- Encoding.compatible?(@str, "\x7f").should == Encoding::UTF_8
- end
+ describe "when the first's Encoding is invalid" do
+ before :each do
+ @str = "\xff".force_encoding Encoding::UTF_8
+ end
- it "returns nil when the second's Encoding is ASCII-8BIT but not ASCII only" do
- Encoding.compatible?(@str, "\xff").should be_nil
- end
+ it "returns the first's Encoding when the second's Encoding is US-ASCII" do
+ Encoding.compatible?(@str, "def".encode("us-ascii")).should == Encoding::UTF_8
+ end
- it "returns nil when the second's Encoding is invalid and ASCII only" do
- Encoding.compatible?(@str, "\x7f".force_encoding("utf-16be")).should be_nil
- end
+ it "returns the first's Encoding when the second String is ASCII only" do
+ Encoding.compatible?(@str, "\x7f").should == Encoding::UTF_8
+ end
- it "returns nil when the second's Encoding is invalid and not ASCII only" do
- Encoding.compatible?(@str, "\xff".force_encoding("utf-16be")).should be_nil
- end
+ it "returns nil when the second's Encoding is ASCII-8BIT but not ASCII only" do
+ Encoding.compatible?(@str, "\xff").should be_nil
+ end
- it "returns the Encoding when the second's Encoding is invalid but the same as the first" do
- Encoding.compatible?(@str, @str).should == Encoding::UTF_8
- end
+ it "returns nil when the second's Encoding is invalid and ASCII only" do
+ Encoding.compatible?(@str, "\x7f".force_encoding("utf-16be")).should be_nil
end
- describe "when the first String is empty and the second is not" do
- describe "and the first's Encoding is ASCII compatible" do
- before :each do
- @str = "".force_encoding("utf-8")
- end
+ it "returns nil when the second's Encoding is invalid and not ASCII only" do
+ Encoding.compatible?(@str, "\xff".force_encoding("utf-16be")).should be_nil
+ end
- it "returns the first's encoding when the second String is ASCII only" do
- Encoding.compatible?(@str, "def".encode("us-ascii")).should == Encoding::UTF_8
- end
+ it "returns the Encoding when the second's Encoding is invalid but the same as the first" do
+ Encoding.compatible?(@str, @str).should == Encoding::UTF_8
+ end
+ end
- it "returns the second's encoding when the second String is not ASCII only" do
- Encoding.compatible?(@str, "def".encode("utf-32le")).should == Encoding::UTF_32LE
- end
+ describe "when the first String is empty and the second is not" do
+ describe "and the first's Encoding is ASCII compatible" do
+ before :each do
+ @str = "".force_encoding("utf-8")
end
- describe "when the first's Encoding is not ASCII compatible" do
- before :each do
- @str = "".force_encoding Encoding::UTF_7
- end
+ it "returns the first's encoding when the second String is ASCII only" do
+ Encoding.compatible?(@str, "def".encode("us-ascii")).should == Encoding::UTF_8
+ end
- it "returns the second string's encoding" do
- Encoding.compatible?(@str, "def".encode("us-ascii")).should == Encoding::US_ASCII
- end
+ it "returns the second's encoding when the second String is not ASCII only" do
+ Encoding.compatible?(@str, "def".encode("utf-32le")).should == Encoding::UTF_32LE
end
end
- describe "when the second String is empty" do
+ describe "when the first's Encoding is not ASCII compatible" do
before :each do
- @str = "abc".force_encoding("utf-7")
+ @str = "".force_encoding Encoding::UTF_7
end
- it "returns the first Encoding" do
- Encoding.compatible?(@str, "").should == Encoding::UTF_7
+ it "returns the second string's encoding" do
+ Encoding.compatible?(@str, "def".encode("us-ascii")).should == Encoding::US_ASCII
end
end
end
- describe "Encoding.compatible? String, Regexp" do
- it "returns US-ASCII if both are US-ASCII" do
- str = "abc".force_encoding("us-ascii")
- Encoding.compatible?(str, /abc/).should == Encoding::US_ASCII
+ describe "when the second String is empty" do
+ before :each do
+ @str = "abc".force_encoding("utf-7")
end
- it "returns the String's Encoding if it is not US-ASCII but both are ASCII only" do
- [ [Encoding, "abc", Encoding::ASCII_8BIT],
- [Encoding, "abc".encode("utf-8"), Encoding::UTF_8],
- [Encoding, "abc".encode("euc-jp"), Encoding::EUC_JP],
- [Encoding, "abc".encode("shift_jis"), Encoding::Shift_JIS],
- ].should be_computed_by(:compatible?, /abc/)
+ it "returns the first Encoding" do
+ Encoding.compatible?(@str, "").should == Encoding::UTF_7
end
+ end
+end
- it "returns the String's Encoding if the String is not ASCII only" do
- [ [Encoding, "\xff", Encoding::ASCII_8BIT],
- [Encoding, "\u3042".encode("utf-8"), Encoding::UTF_8],
- [Encoding, "\xa4\xa2".force_encoding("euc-jp"), Encoding::EUC_JP],
- [Encoding, "\x82\xa0".force_encoding("shift_jis"), Encoding::Shift_JIS],
- ].should be_computed_by(:compatible?, /abc/)
- end
+describe "Encoding.compatible? String, Regexp" do
+ it "returns US-ASCII if both are US-ASCII" do
+ str = "abc".force_encoding("us-ascii")
+ Encoding.compatible?(str, /abc/).should == Encoding::US_ASCII
end
- describe "Encoding.compatible? String, Symbol" do
- it "returns US-ASCII if both are ASCII only" do
- str = "abc".force_encoding("us-ascii")
- Encoding.compatible?(str, :abc).should == Encoding::US_ASCII
- end
+ it "returns the String's Encoding if it is not US-ASCII but both are ASCII only" do
+ [ [Encoding, "abc", Encoding::ASCII_8BIT],
+ [Encoding, "abc".encode("utf-8"), Encoding::UTF_8],
+ [Encoding, "abc".encode("euc-jp"), Encoding::EUC_JP],
+ [Encoding, "abc".encode("shift_jis"), Encoding::Shift_JIS],
+ ].should be_computed_by(:compatible?, /abc/)
+ end
- it "returns the String's Encoding if it is not US-ASCII but both are ASCII only" do
- [ [Encoding, "abc", Encoding::ASCII_8BIT],
- [Encoding, "abc".encode("utf-8"), Encoding::UTF_8],
- [Encoding, "abc".encode("euc-jp"), Encoding::EUC_JP],
- [Encoding, "abc".encode("shift_jis"), Encoding::Shift_JIS],
- ].should be_computed_by(:compatible?, :abc)
- end
+ it "returns the String's Encoding if the String is not ASCII only" do
+ [ [Encoding, "\xff", Encoding::ASCII_8BIT],
+ [Encoding, "\u3042".encode("utf-8"), Encoding::UTF_8],
+ [Encoding, "\xa4\xa2".force_encoding("euc-jp"), Encoding::EUC_JP],
+ [Encoding, "\x82\xa0".force_encoding("shift_jis"), Encoding::Shift_JIS],
+ ].should be_computed_by(:compatible?, /abc/)
+ end
+end
- it "returns the String's Encoding if the String is not ASCII only" do
- [ [Encoding, "\xff", Encoding::ASCII_8BIT],
- [Encoding, "\u3042".encode("utf-8"), Encoding::UTF_8],
- [Encoding, "\xa4\xa2".force_encoding("euc-jp"), Encoding::EUC_JP],
- [Encoding, "\x82\xa0".force_encoding("shift_jis"), Encoding::Shift_JIS],
- ].should be_computed_by(:compatible?, :abc)
- end
+describe "Encoding.compatible? String, Symbol" do
+ it "returns US-ASCII if both are ASCII only" do
+ str = "abc".force_encoding("us-ascii")
+ Encoding.compatible?(str, :abc).should == Encoding::US_ASCII
end
- describe "Encoding.compatible? String, Encoding" do
- it "returns nil if the String's encoding is not ASCII compatible" do
- Encoding.compatible?("abc".encode("utf-32le"), Encoding::US_ASCII).should be_nil
- end
+ it "returns the String's Encoding if it is not US-ASCII but both are ASCII only" do
+ [ [Encoding, "abc", Encoding::ASCII_8BIT],
+ [Encoding, "abc".encode("utf-8"), Encoding::UTF_8],
+ [Encoding, "abc".encode("euc-jp"), Encoding::EUC_JP],
+ [Encoding, "abc".encode("shift_jis"), Encoding::Shift_JIS],
+ ].should be_computed_by(:compatible?, :abc)
+ end
- it "returns nil if the Encoding is not ASCII compatible" do
- Encoding.compatible?("abc".encode("us-ascii"), Encoding::UTF_32LE).should be_nil
- end
+ it "returns the String's Encoding if the String is not ASCII only" do
+ [ [Encoding, "\xff", Encoding::ASCII_8BIT],
+ [Encoding, "\u3042".encode("utf-8"), Encoding::UTF_8],
+ [Encoding, "\xa4\xa2".force_encoding("euc-jp"), Encoding::EUC_JP],
+ [Encoding, "\x82\xa0".force_encoding("shift_jis"), Encoding::Shift_JIS],
+ ].should be_computed_by(:compatible?, :abc)
+ end
+end
- it "returns the String's encoding if the Encoding is US-ASCII" do
- [ [Encoding, "\xff", Encoding::ASCII_8BIT],
- [Encoding, "\u3042".encode("utf-8"), Encoding::UTF_8],
- [Encoding, "\xa4\xa2".force_encoding("euc-jp"), Encoding::EUC_JP],
- [Encoding, "\x82\xa0".force_encoding("shift_jis"), Encoding::Shift_JIS],
- ].should be_computed_by(:compatible?, Encoding::US_ASCII)
- end
+describe "Encoding.compatible? String, Encoding" do
+ it "returns nil if the String's encoding is not ASCII compatible" do
+ Encoding.compatible?("abc".encode("utf-32le"), Encoding::US_ASCII).should be_nil
+ end
- it "returns the Encoding if the String's encoding is ASCII compatible and the String is ASCII only" do
- str = "abc".encode("utf-8")
+ it "returns nil if the Encoding is not ASCII compatible" do
+ Encoding.compatible?("abc".encode("us-ascii"), Encoding::UTF_32LE).should be_nil
+ end
- Encoding.compatible?(str, Encoding::ASCII_8BIT).should == Encoding::ASCII_8BIT
- Encoding.compatible?(str, Encoding::UTF_8).should == Encoding::UTF_8
- Encoding.compatible?(str, Encoding::EUC_JP).should == Encoding::EUC_JP
- Encoding.compatible?(str, Encoding::Shift_JIS).should == Encoding::Shift_JIS
- end
+ it "returns the String's encoding if the Encoding is US-ASCII" do
+ [ [Encoding, "\xff", Encoding::ASCII_8BIT],
+ [Encoding, "\u3042".encode("utf-8"), Encoding::UTF_8],
+ [Encoding, "\xa4\xa2".force_encoding("euc-jp"), Encoding::EUC_JP],
+ [Encoding, "\x82\xa0".force_encoding("shift_jis"), Encoding::Shift_JIS],
+ ].should be_computed_by(:compatible?, Encoding::US_ASCII)
+ end
- it "returns nil if the String's encoding is ASCII compatible but the string is not ASCII only" do
- Encoding.compatible?("\u3042".encode("utf-8"), Encoding::ASCII_8BIT).should be_nil
- end
+ it "returns the Encoding if the String's encoding is ASCII compatible and the String is ASCII only" do
+ str = "abc".encode("utf-8")
+
+ Encoding.compatible?(str, Encoding::ASCII_8BIT).should == Encoding::ASCII_8BIT
+ Encoding.compatible?(str, Encoding::UTF_8).should == Encoding::UTF_8
+ Encoding.compatible?(str, Encoding::EUC_JP).should == Encoding::EUC_JP
+ Encoding.compatible?(str, Encoding::Shift_JIS).should == Encoding::Shift_JIS
end
- describe "Encoding.compatible? Regexp, String" do
- it "returns US-ASCII if both are US-ASCII" do
- str = "abc".force_encoding("us-ascii")
- Encoding.compatible?(/abc/, str).should == Encoding::US_ASCII
- end
+ it "returns nil if the String's encoding is ASCII compatible but the string is not ASCII only" do
+ Encoding.compatible?("\u3042".encode("utf-8"), Encoding::ASCII_8BIT).should be_nil
+ end
+end
+describe "Encoding.compatible? Regexp, String" do
+ it "returns US-ASCII if both are US-ASCII" do
+ str = "abc".force_encoding("us-ascii")
+ Encoding.compatible?(/abc/, str).should == Encoding::US_ASCII
end
- describe "Encoding.compatible? Regexp, Regexp" do
- it "returns US-ASCII if both are US-ASCII" do
- Encoding.compatible?(/abc/, /def/).should == Encoding::US_ASCII
- end
+end
- it "returns the first's Encoding if it is not US-ASCII and not ASCII only" do
- [ [Encoding, Regexp.new("\xff"), Encoding::ASCII_8BIT],
- [Encoding, Regexp.new("\u3042".encode("utf-8")), Encoding::UTF_8],
- [Encoding, Regexp.new("\xa4\xa2".force_encoding("euc-jp")), Encoding::EUC_JP],
- [Encoding, Regexp.new("\x82\xa0".force_encoding("shift_jis")), Encoding::Shift_JIS],
- ].should be_computed_by(:compatible?, /abc/)
- end
+describe "Encoding.compatible? Regexp, Regexp" do
+ it "returns US-ASCII if both are US-ASCII" do
+ Encoding.compatible?(/abc/, /def/).should == Encoding::US_ASCII
end
- describe "Encoding.compatible? Regexp, Symbol" do
- it "returns US-ASCII if both are US-ASCII" do
- Encoding.compatible?(/abc/, :def).should == Encoding::US_ASCII
- end
+ it "returns the first's Encoding if it is not US-ASCII and not ASCII only" do
+ [ [Encoding, Regexp.new("\xff"), Encoding::ASCII_8BIT],
+ [Encoding, Regexp.new("\u3042".encode("utf-8")), Encoding::UTF_8],
+ [Encoding, Regexp.new("\xa4\xa2".force_encoding("euc-jp")), Encoding::EUC_JP],
+ [Encoding, Regexp.new("\x82\xa0".force_encoding("shift_jis")), Encoding::Shift_JIS],
+ ].should be_computed_by(:compatible?, /abc/)
+ end
+end
- it "returns the first's Encoding if it is not US-ASCII and not ASCII only" do
- [ [Encoding, Regexp.new("\xff"), Encoding::ASCII_8BIT],
- [Encoding, Regexp.new("\u3042".encode("utf-8")), Encoding::UTF_8],
- [Encoding, Regexp.new("\xa4\xa2".force_encoding("euc-jp")), Encoding::EUC_JP],
- [Encoding, Regexp.new("\x82\xa0".force_encoding("shift_jis")), Encoding::Shift_JIS],
- ].should be_computed_by(:compatible?, /abc/)
- end
+describe "Encoding.compatible? Regexp, Symbol" do
+ it "returns US-ASCII if both are US-ASCII" do
+ Encoding.compatible?(/abc/, :def).should == Encoding::US_ASCII
end
- describe "Encoding.compatible? Symbol, String" do
- it "returns US-ASCII if both are ASCII only" do
- str = "abc".force_encoding("us-ascii")
- Encoding.compatible?(str, :abc).should == Encoding::US_ASCII
- end
+ it "returns the first's Encoding if it is not US-ASCII and not ASCII only" do
+ [ [Encoding, Regexp.new("\xff"), Encoding::ASCII_8BIT],
+ [Encoding, Regexp.new("\u3042".encode("utf-8")), Encoding::UTF_8],
+ [Encoding, Regexp.new("\xa4\xa2".force_encoding("euc-jp")), Encoding::EUC_JP],
+ [Encoding, Regexp.new("\x82\xa0".force_encoding("shift_jis")), Encoding::Shift_JIS],
+ ].should be_computed_by(:compatible?, /abc/)
end
+end
- describe "Encoding.compatible? Symbol, Regexp" do
- it "returns US-ASCII if both are US-ASCII" do
- Encoding.compatible?(:abc, /def/).should == Encoding::US_ASCII
- end
+describe "Encoding.compatible? Symbol, String" do
+ it "returns US-ASCII if both are ASCII only" do
+ str = "abc".force_encoding("us-ascii")
+ Encoding.compatible?(str, :abc).should == Encoding::US_ASCII
+ end
+end
- it "returns the Regexp's Encoding if it is not US-ASCII and not ASCII only" do
- a = Regexp.new("\xff")
- b = Regexp.new("\u3042".encode("utf-8"))
- c = Regexp.new("\xa4\xa2".force_encoding("euc-jp"))
- d = Regexp.new("\x82\xa0".force_encoding("shift_jis"))
+describe "Encoding.compatible? Symbol, Regexp" do
+ it "returns US-ASCII if both are US-ASCII" do
+ Encoding.compatible?(:abc, /def/).should == Encoding::US_ASCII
+ end
- [ [Encoding, :abc, a, Encoding::ASCII_8BIT],
- [Encoding, :abc, b, Encoding::UTF_8],
- [Encoding, :abc, c, Encoding::EUC_JP],
- [Encoding, :abc, d, Encoding::Shift_JIS],
- ].should be_computed_by(:compatible?)
- end
+ it "returns the Regexp's Encoding if it is not US-ASCII and not ASCII only" do
+ a = Regexp.new("\xff")
+ b = Regexp.new("\u3042".encode("utf-8"))
+ c = Regexp.new("\xa4\xa2".force_encoding("euc-jp"))
+ d = Regexp.new("\x82\xa0".force_encoding("shift_jis"))
+
+ [ [Encoding, :abc, a, Encoding::ASCII_8BIT],
+ [Encoding, :abc, b, Encoding::UTF_8],
+ [Encoding, :abc, c, Encoding::EUC_JP],
+ [Encoding, :abc, d, Encoding::Shift_JIS],
+ ].should be_computed_by(:compatible?)
end
+end
- describe "Encoding.compatible? Symbol, Symbol" do
- it "returns US-ASCII if both are US-ASCII" do
- Encoding.compatible?(:abc, :def).should == Encoding::US_ASCII
- end
+describe "Encoding.compatible? Symbol, Symbol" do
+ it "returns US-ASCII if both are US-ASCII" do
+ Encoding.compatible?(:abc, :def).should == Encoding::US_ASCII
+ end
- it "returns the first's Encoding if it is not ASCII only" do
- [ [Encoding, "\xff".to_sym, Encoding::ASCII_8BIT],
- [Encoding, "\u3042".encode("utf-8").to_sym, Encoding::UTF_8],
- [Encoding, "\xa4\xa2".force_encoding("euc-jp").to_sym, Encoding::EUC_JP],
- [Encoding, "\x82\xa0".force_encoding("shift_jis").to_sym, Encoding::Shift_JIS],
- ].should be_computed_by(:compatible?, :abc)
- end
+ it "returns the first's Encoding if it is not ASCII only" do
+ [ [Encoding, "\xff".to_sym, Encoding::ASCII_8BIT],
+ [Encoding, "\u3042".encode("utf-8").to_sym, Encoding::UTF_8],
+ [Encoding, "\xa4\xa2".force_encoding("euc-jp").to_sym, Encoding::EUC_JP],
+ [Encoding, "\x82\xa0".force_encoding("shift_jis").to_sym, Encoding::Shift_JIS],
+ ].should be_computed_by(:compatible?, :abc)
end
+end
- describe "Encoding.compatible? Encoding, Encoding" do
- it "returns nil if one of the encodings is a dummy encoding" do
- [ [Encoding, Encoding::UTF_7, Encoding::US_ASCII, nil],
- [Encoding, Encoding::US_ASCII, Encoding::UTF_7, nil],
- [Encoding, Encoding::EUC_JP, Encoding::UTF_7, nil],
- [Encoding, Encoding::UTF_7, Encoding::EUC_JP, nil],
- [Encoding, Encoding::UTF_7, Encoding::ASCII_8BIT, nil],
- [Encoding, Encoding::ASCII_8BIT, Encoding::UTF_7, nil],
- ].should be_computed_by(:compatible?)
- end
+describe "Encoding.compatible? Encoding, Encoding" do
+ it "returns nil if one of the encodings is a dummy encoding" do
+ [ [Encoding, Encoding::UTF_7, Encoding::US_ASCII, nil],
+ [Encoding, Encoding::US_ASCII, Encoding::UTF_7, nil],
+ [Encoding, Encoding::EUC_JP, Encoding::UTF_7, nil],
+ [Encoding, Encoding::UTF_7, Encoding::EUC_JP, nil],
+ [Encoding, Encoding::UTF_7, Encoding::ASCII_8BIT, nil],
+ [Encoding, Encoding::ASCII_8BIT, Encoding::UTF_7, nil],
+ ].should be_computed_by(:compatible?)
+ end
- it "returns nil if one of the encodings is not US-ASCII" do
- [ [Encoding, Encoding::UTF_8, Encoding::ASCII_8BIT, nil],
- [Encoding, Encoding::ASCII_8BIT, Encoding::UTF_8, nil],
- [Encoding, Encoding::ASCII_8BIT, Encoding::EUC_JP, nil],
- [Encoding, Encoding::Shift_JIS, Encoding::EUC_JP, nil],
- ].should be_computed_by(:compatible?)
- end
+ it "returns nil if one of the encodings is not US-ASCII" do
+ [ [Encoding, Encoding::UTF_8, Encoding::ASCII_8BIT, nil],
+ [Encoding, Encoding::ASCII_8BIT, Encoding::UTF_8, nil],
+ [Encoding, Encoding::ASCII_8BIT, Encoding::EUC_JP, nil],
+ [Encoding, Encoding::Shift_JIS, Encoding::EUC_JP, nil],
+ ].should be_computed_by(:compatible?)
+ end
- it "returns the first if the second is US-ASCII" do
- [ [Encoding, Encoding::UTF_8, Encoding::US_ASCII, Encoding::UTF_8],
- [Encoding, Encoding::EUC_JP, Encoding::US_ASCII, Encoding::EUC_JP],
- [Encoding, Encoding::Shift_JIS, Encoding::US_ASCII, Encoding::Shift_JIS],
- [Encoding, Encoding::ASCII_8BIT, Encoding::US_ASCII, Encoding::ASCII_8BIT],
- ].should be_computed_by(:compatible?)
- end
+ it "returns the first if the second is US-ASCII" do
+ [ [Encoding, Encoding::UTF_8, Encoding::US_ASCII, Encoding::UTF_8],
+ [Encoding, Encoding::EUC_JP, Encoding::US_ASCII, Encoding::EUC_JP],
+ [Encoding, Encoding::Shift_JIS, Encoding::US_ASCII, Encoding::Shift_JIS],
+ [Encoding, Encoding::ASCII_8BIT, Encoding::US_ASCII, Encoding::ASCII_8BIT],
+ ].should be_computed_by(:compatible?)
+ end
- it "returns the Encoding if both are the same" do
- [ [Encoding, Encoding::UTF_8, Encoding::UTF_8, Encoding::UTF_8],
- [Encoding, Encoding::US_ASCII, Encoding::US_ASCII, Encoding::US_ASCII],
- [Encoding, Encoding::ASCII_8BIT, Encoding::ASCII_8BIT, Encoding::ASCII_8BIT],
- [Encoding, Encoding::UTF_7, Encoding::UTF_7, Encoding::UTF_7],
- ].should be_computed_by(:compatible?)
- end
+ it "returns the Encoding if both are the same" do
+ [ [Encoding, Encoding::UTF_8, Encoding::UTF_8, Encoding::UTF_8],
+ [Encoding, Encoding::US_ASCII, Encoding::US_ASCII, Encoding::US_ASCII],
+ [Encoding, Encoding::ASCII_8BIT, Encoding::ASCII_8BIT, Encoding::ASCII_8BIT],
+ [Encoding, Encoding::UTF_7, Encoding::UTF_7, Encoding::UTF_7],
+ ].should be_computed_by(:compatible?)
end
+end
- describe "Encoding.compatible? Object, Object" do
- it "returns nil for Object, String" do
- Encoding.compatible?(Object.new, "abc").should be_nil
- end
+describe "Encoding.compatible? Object, Object" do
+ it "returns nil for Object, String" do
+ Encoding.compatible?(Object.new, "abc").should be_nil
+ end
- it "returns nil for Object, Regexp" do
- Encoding.compatible?(Object.new, /./).should be_nil
- end
+ it "returns nil for Object, Regexp" do
+ Encoding.compatible?(Object.new, /./).should be_nil
+ end
- it "returns nil for Object, Symbol" do
- Encoding.compatible?(Object.new, :sym).should be_nil
- end
+ it "returns nil for Object, Symbol" do
+ Encoding.compatible?(Object.new, :sym).should be_nil
+ end
- it "returns nil for String, Object" do
- Encoding.compatible?("abc", Object.new).should be_nil
- end
+ it "returns nil for String, Object" do
+ Encoding.compatible?("abc", Object.new).should be_nil
+ end
- it "returns nil for Regexp, Object" do
- Encoding.compatible?(/./, Object.new).should be_nil
- end
+ it "returns nil for Regexp, Object" do
+ Encoding.compatible?(/./, Object.new).should be_nil
+ end
- it "returns nil for Symbol, Object" do
- Encoding.compatible?(:sym, Object.new).should be_nil
- end
+ it "returns nil for Symbol, Object" do
+ Encoding.compatible?(:sym, Object.new).should be_nil
end
end
diff --git a/spec/ruby/core/encoding/converter/asciicompat_encoding_spec.rb b/spec/ruby/core/encoding/converter/asciicompat_encoding_spec.rb
index f06a138ba6..e39d590e3a 100644
--- a/spec/ruby/core/encoding/converter/asciicompat_encoding_spec.rb
+++ b/spec/ruby/core/encoding/converter/asciicompat_encoding_spec.rb
@@ -1,39 +1,37 @@
require_relative '../../../spec_helper'
-with_feature :encoding 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
+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).at_least(1).times.and_return('string')
- Encoding::Converter.asciicompat_encoding(str)
- end
+ it "coerces non-String/Encoding objects with #to_str" do
+ str = mock('string')
+ str.should_receive(:to_str).at_least(1).times.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 "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 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
+ 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
- it "handles encoding names who resolve to nil encodings" do
- internal = Encoding.default_internal
- Encoding.default_internal = nil
- Encoding::Converter.asciicompat_encoding('internal').should be_nil
- Encoding.default_internal = internal
- end
+ it "handles encoding names who resolve to nil encodings" do
+ internal = Encoding.default_internal
+ Encoding.default_internal = nil
+ Encoding::Converter.asciicompat_encoding('internal').should be_nil
+ Encoding.default_internal = internal
end
end
diff --git a/spec/ruby/core/encoding/converter/constants_spec.rb b/spec/ruby/core/encoding/converter/constants_spec.rb
index 9a03f61baf..57b6a4d4e7 100644
--- a/spec/ruby/core/encoding/converter/constants_spec.rb
+++ b/spec/ruby/core/encoding/converter/constants_spec.rb
@@ -1,133 +1,131 @@
require_relative '../../../spec_helper'
-with_feature :encoding do
- describe "Encoding::Converter::INVALID_MASK" do
- it "exists" do
- Encoding::Converter.should have_constant(:INVALID_MASK)
- end
+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
+ 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
+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
+ 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
+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
+ 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
+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
+ 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
+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
+ 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
+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
+ 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
+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
+ 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
+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
+ 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
+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
+ 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
+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
+ 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
+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
+ 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
+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
+ 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
+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
+ it "has a Fixnum value" do
+ Encoding::Converter::XML_ATTR_QUOTE_DECORATOR.should be_an_instance_of(Fixnum)
end
end
diff --git a/spec/ruby/core/encoding/converter/convert_spec.rb b/spec/ruby/core/encoding/converter/convert_spec.rb
index 525e83a17f..362e027a58 100644
--- a/spec/ruby/core/encoding/converter/convert_spec.rb
+++ b/spec/ruby/core/encoding/converter/convert_spec.rb
@@ -1,47 +1,45 @@
# -*- encoding: binary -*-
require_relative '../../../spec_helper'
-with_feature :encoding 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
+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 "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 "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 "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 "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 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
+ 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
diff --git a/spec/ruby/core/encoding/converter/convpath_spec.rb b/spec/ruby/core/encoding/converter/convpath_spec.rb
index e41a6c4205..473f2db91e 100644
--- a/spec/ruby/core/encoding/converter/convpath_spec.rb
+++ b/spec/ruby/core/encoding/converter/convpath_spec.rb
@@ -1,26 +1,24 @@
require_relative '../../../spec_helper'
-with_feature :encoding do
- describe "Encoding::Converter#convpath" do
- it "returns an Array with a single element if there is a direct converter" do
- cp = Encoding::Converter.new('ASCII', 'UTF-8').convpath
- cp.should == [[Encoding::US_ASCII, Encoding::UTF_8]]
- end
+describe "Encoding::Converter#convpath" do
+ it "returns an Array with a single element if there is a direct converter" do
+ cp = Encoding::Converter.new('ASCII', 'UTF-8').convpath
+ cp.should == [[Encoding::US_ASCII, Encoding::UTF_8]]
+ end
- it "returns multiple encoding pairs when direct conversion is impossible" do
- cp = Encoding::Converter.new('ascii','Big5').convpath
- cp.should == [
- [Encoding::US_ASCII, Encoding::UTF_8],
- [Encoding::UTF_8, Encoding::Big5]
- ]
- end
+ it "returns multiple encoding pairs when direct conversion is impossible" do
+ cp = Encoding::Converter.new('ascii','Big5').convpath
+ cp.should == [
+ [Encoding::US_ASCII, Encoding::UTF_8],
+ [Encoding::UTF_8, Encoding::Big5]
+ ]
+ 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"
+ 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
+ ec = Encoding::Converter.new("ASCII", "UTF-8", {crlf_newline: false})
+ ec.convpath.last.should_not == "crlf_newline"
end
end
diff --git a/spec/ruby/core/encoding/converter/destination_encoding_spec.rb b/spec/ruby/core/encoding/converter/destination_encoding_spec.rb
index 2d0f8e0697..481a857909 100644
--- a/spec/ruby/core/encoding/converter/destination_encoding_spec.rb
+++ b/spec/ruby/core/encoding/converter/destination_encoding_spec.rb
@@ -1,13 +1,11 @@
require_relative '../../../spec_helper'
-with_feature :encoding 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
+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
+ ec = Encoding::Converter.new('SJIS','EUC-JP')
+ ec.destination_encoding.should == Encoding::EUC_JP
end
end
diff --git a/spec/ruby/core/encoding/converter/finish_spec.rb b/spec/ruby/core/encoding/converter/finish_spec.rb
index 917f3d2912..11ca7e8510 100644
--- a/spec/ruby/core/encoding/converter/finish_spec.rb
+++ b/spec/ruby/core/encoding/converter/finish_spec.rb
@@ -1,38 +1,36 @@
require_relative '../../../spec_helper'
-with_feature :encoding do
- describe "Encoding::Converter#finish" do
- before :each do
- @ec = Encoding::Converter.new("utf-8", "iso-2022-jp")
- end
+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 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 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 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 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 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
+ it "returns an empty String on subsequent invocations" do
+ @ec.finish.should == ""
+ @ec.finish.should == ""
end
end
diff --git a/spec/ruby/core/encoding/converter/last_error_spec.rb b/spec/ruby/core/encoding/converter/last_error_spec.rb
index 7275b31180..68567737b7 100644
--- a/spec/ruby/core/encoding/converter/last_error_spec.rb
+++ b/spec/ruby/core/encoding/converter/last_error_spec.rb
@@ -1,93 +1,91 @@
# -*- encoding: binary -*-
require_relative '../../../spec_helper'
-with_feature :encoding 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
+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 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 :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 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 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::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::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 #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
- -> {
- ec.convert("\xf1abcd")
- }.should raise_error(Encoding::InvalidByteSequenceError) { |e|
- exception = e
- }
- ec.last_error.should be_an_instance_of(Encoding::InvalidByteSequenceError)
- ec.last_error.message.should == exception.message
- 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
+ -> {
+ ec.convert("\xf1abcd")
+ }.should raise_error(Encoding::InvalidByteSequenceError) { |e|
+ exception = e
+ }
+ 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
- -> {
- ec.convert("\u{9899}")
- }.should raise_error(Encoding::UndefinedConversionError) { |e|
- exception = e
- }
- ec.last_error.should be_an_instance_of(Encoding::UndefinedConversionError)
- ec.last_error.message.should == exception.message
- ec.last_error.message.should include "from UTF-8 to ISO-8859-1"
- 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
+ -> {
+ ec.convert("\u{9899}")
+ }.should raise_error(Encoding::UndefinedConversionError) { |e|
+ exception = e
+ }
+ ec.last_error.should be_an_instance_of(Encoding::UndefinedConversionError)
+ ec.last_error.message.should == exception.message
+ ec.last_error.message.should include "from UTF-8 to ISO-8859-1"
+ end
- it "returns the last error of #convert with a message showing the transcoding path" do
- ec = Encoding::Converter.new("iso-8859-1", "Big5")
- exception = nil
- -> {
- ec.convert("\xE9") # é in ISO-8859-1
- }.should raise_error(Encoding::UndefinedConversionError) { |e|
- exception = e
- }
- ec.last_error.should be_an_instance_of(Encoding::UndefinedConversionError)
- ec.last_error.message.should == exception.message
- ec.last_error.message.should include "from ISO-8859-1 to UTF-8 to Big5"
- end
+ it "returns the last error of #convert with a message showing the transcoding path" do
+ ec = Encoding::Converter.new("iso-8859-1", "Big5")
+ exception = nil
+ -> {
+ ec.convert("\xE9") # é in ISO-8859-1
+ }.should raise_error(Encoding::UndefinedConversionError) { |e|
+ exception = e
+ }
+ ec.last_error.should be_an_instance_of(Encoding::UndefinedConversionError)
+ ec.last_error.message.should == exception.message
+ ec.last_error.message.should include "from ISO-8859-1 to UTF-8 to Big5"
end
end
diff --git a/spec/ruby/core/encoding/converter/new_spec.rb b/spec/ruby/core/encoding/converter/new_spec.rb
index 08c47daefc..d62b709c52 100644
--- a/spec/ruby/core/encoding/converter/new_spec.rb
+++ b/spec/ruby/core/encoding/converter/new_spec.rb
@@ -1,120 +1,118 @@
# -*- encoding: ascii-8bit -*-
require_relative '../../../spec_helper'
-with_feature :encoding do
- describe "Encoding::Converter.new" do
- it "accepts a String for the source encoding" do
- conv = Encoding::Converter.new("us-ascii", "utf-8")
- conv.source_encoding.should == Encoding::US_ASCII
- end
+describe "Encoding::Converter.new" do
+ it "accepts a String for the source encoding" do
+ conv = Encoding::Converter.new("us-ascii", "utf-8")
+ conv.source_encoding.should == Encoding::US_ASCII
+ end
- it "accepts a String for the destination encoding" do
- conv = Encoding::Converter.new("us-ascii", "utf-8")
- conv.destination_encoding.should == Encoding::UTF_8
- end
+ it "accepts a String for the destination encoding" do
+ conv = Encoding::Converter.new("us-ascii", "utf-8")
+ conv.destination_encoding.should == Encoding::UTF_8
+ end
- it "accepts an Encoding object for the source encoding" do
- conv = Encoding::Converter.new(Encoding::US_ASCII, "utf-8")
- conv.source_encoding.should == Encoding::US_ASCII
- end
+ it "accepts an Encoding object for the source encoding" do
+ conv = Encoding::Converter.new(Encoding::US_ASCII, "utf-8")
+ conv.source_encoding.should == Encoding::US_ASCII
+ end
- it "accepts an Encoding object for the destination encoding" do
- conv = Encoding::Converter.new("us-ascii", Encoding::UTF_8)
- conv.destination_encoding.should == Encoding::UTF_8
- end
+ it "accepts an Encoding object for the destination encoding" do
+ conv = Encoding::Converter.new("us-ascii", Encoding::UTF_8)
+ conv.destination_encoding.should == Encoding::UTF_8
+ end
- it "raises an Encoding::ConverterNotFoundError if both encodings are the same" do
- lambda do
- Encoding::Converter.new "utf-8", "utf-8"
- end.should raise_error(Encoding::ConverterNotFoundError)
- end
+ it "raises an Encoding::ConverterNotFoundError if both encodings are the same" do
+ lambda do
+ Encoding::Converter.new "utf-8", "utf-8"
+ end.should raise_error(Encoding::ConverterNotFoundError)
+ end
- it "calls #to_str to convert the source encoding argument to an encoding name" do
- enc = mock("us-ascii")
- enc.should_receive(:to_str).and_return("us-ascii")
- conv = Encoding::Converter.new(enc, "utf-8")
- conv.source_encoding.should == Encoding::US_ASCII
- end
+ it "calls #to_str to convert the source encoding argument to an encoding name" do
+ enc = mock("us-ascii")
+ enc.should_receive(:to_str).and_return("us-ascii")
+ conv = Encoding::Converter.new(enc, "utf-8")
+ conv.source_encoding.should == Encoding::US_ASCII
+ end
- it "calls #to_str to convert the destination encoding argument to an encoding name" do
- enc = mock("utf-8")
- enc.should_receive(:to_str).and_return("utf-8")
- conv = Encoding::Converter.new("us-ascii", enc)
- conv.destination_encoding.should == Encoding::UTF_8
- end
+ it "calls #to_str to convert the destination encoding argument to an encoding name" do
+ enc = mock("utf-8")
+ enc.should_receive(:to_str).and_return("utf-8")
+ conv = Encoding::Converter.new("us-ascii", enc)
+ conv.destination_encoding.should == Encoding::UTF_8
+ end
- it "sets replacement from the options Hash" do
- conv = Encoding::Converter.new("us-ascii", "utf-8", replace: "fubar")
- conv.replacement.should == "fubar"
- end
+ it "sets replacement from the options Hash" do
+ conv = Encoding::Converter.new("us-ascii", "utf-8", replace: "fubar")
+ conv.replacement.should == "fubar"
+ end
- it "calls #to_hash to convert the options argument to a Hash if not a Fixnum" do
- opts = mock("encoding converter options")
- opts.should_receive(:to_hash).and_return({ replace: "fubar" })
- conv = Encoding::Converter.new("us-ascii", "utf-8", opts)
- conv.replacement.should == "fubar"
- end
+ it "calls #to_hash to convert the options argument to a Hash if not a Fixnum" do
+ opts = mock("encoding converter options")
+ opts.should_receive(:to_hash).and_return({ replace: "fubar" })
+ conv = Encoding::Converter.new("us-ascii", "utf-8", opts)
+ conv.replacement.should == "fubar"
+ end
- it "calls #to_str to convert the replacement object to a String" do
- obj = mock("encoding converter replacement")
- obj.should_receive(:to_str).and_return("fubar")
- conv = Encoding::Converter.new("us-ascii", "utf-8", replace: obj)
- conv.replacement.should == "fubar"
- end
+ it "calls #to_str to convert the replacement object to a String" do
+ obj = mock("encoding converter replacement")
+ obj.should_receive(:to_str).and_return("fubar")
+ conv = Encoding::Converter.new("us-ascii", "utf-8", replace: obj)
+ conv.replacement.should == "fubar"
+ end
- it "raises a TypeError if #to_str does not return a String" do
- obj = mock("encoding converter replacement")
- obj.should_receive(:to_str).and_return(1)
+ it "raises a TypeError if #to_str does not return a String" do
+ obj = mock("encoding converter replacement")
+ obj.should_receive(:to_str).and_return(1)
- lambda do
- Encoding::Converter.new("us-ascii", "utf-8", replace: obj)
- end.should raise_error(TypeError)
- end
+ lambda do
+ Encoding::Converter.new("us-ascii", "utf-8", replace: obj)
+ end.should raise_error(TypeError)
+ end
- it "raises a TypeError if passed true for the replacement object" do
- lambda do
- Encoding::Converter.new("us-ascii", "utf-8", replace: true)
- end.should raise_error(TypeError)
- end
+ it "raises a TypeError if passed true for the replacement object" do
+ lambda do
+ Encoding::Converter.new("us-ascii", "utf-8", replace: true)
+ end.should raise_error(TypeError)
+ end
- it "raises a TypeError if passed false for the replacement object" do
- lambda do
- Encoding::Converter.new("us-ascii", "utf-8", replace: false)
- end.should raise_error(TypeError)
- end
+ it "raises a TypeError if passed false for the replacement object" do
+ lambda do
+ Encoding::Converter.new("us-ascii", "utf-8", replace: false)
+ end.should raise_error(TypeError)
+ end
- it "raises a TypeError if passed a Fixnum for the replacement object" do
- lambda do
- Encoding::Converter.new("us-ascii", "utf-8", replace: 1)
- end.should raise_error(TypeError)
- end
+ it "raises a TypeError if passed a Fixnum for the replacement object" do
+ lambda do
+ Encoding::Converter.new("us-ascii", "utf-8", replace: 1)
+ end.should raise_error(TypeError)
+ end
- it "accepts an empty String for the replacement object" do
- conv = Encoding::Converter.new("us-ascii", "utf-8", replace: "")
- conv.replacement.should == ""
- end
+ it "accepts an empty String for the replacement object" do
+ conv = Encoding::Converter.new("us-ascii", "utf-8", replace: "")
+ conv.replacement.should == ""
+ end
+
+ describe "when passed nil for the replacement object" do
+ describe "when the destination encoding is not UTF-8" do
+ it "sets the replacement String to '?'" do
+ conv = Encoding::Converter.new("us-ascii", "ascii-8bit", replace: nil)
+ conv.replacement.should == "?"
+ end
+
+ it "sets the replacement String encoding to US-ASCII" do
+ conv = Encoding::Converter.new("us-ascii", "ascii-8bit", replace: nil)
+ conv.replacement.encoding.should == Encoding::US_ASCII
+ end
+
+ it "sets the replacement String to '\\uFFFD'" do
+ conv = Encoding::Converter.new("us-ascii", "utf-8", replace: nil)
+ conv.replacement.should == "\u{fffd}".force_encoding("utf-8")
+ end
- describe "when passed nil for the replacement object" do
- describe "when the destination encoding is not UTF-8" do
- it "sets the replacement String to '?'" do
- conv = Encoding::Converter.new("us-ascii", "ascii-8bit", replace: nil)
- conv.replacement.should == "?"
- end
-
- it "sets the replacement String encoding to US-ASCII" do
- conv = Encoding::Converter.new("us-ascii", "ascii-8bit", replace: nil)
- conv.replacement.encoding.should == Encoding::US_ASCII
- end
-
- it "sets the replacement String to '\\uFFFD'" do
- conv = Encoding::Converter.new("us-ascii", "utf-8", replace: nil)
- conv.replacement.should == "\u{fffd}".force_encoding("utf-8")
- end
-
- it "sets the replacement String encoding to UTF-8" do
- conv = Encoding::Converter.new("us-ascii", "utf-8", replace: nil)
- conv.replacement.encoding.should == Encoding::UTF_8
- end
+ it "sets the replacement String encoding to UTF-8" do
+ conv = Encoding::Converter.new("us-ascii", "utf-8", replace: nil)
+ conv.replacement.encoding.should == Encoding::UTF_8
end
end
end
diff --git a/spec/ruby/core/encoding/converter/primitive_convert_spec.rb b/spec/ruby/core/encoding/converter/primitive_convert_spec.rb
index 182e321e5c..710cc262bb 100644
--- a/spec/ruby/core/encoding/converter/primitive_convert_spec.rb
+++ b/spec/ruby/core/encoding/converter/primitive_convert_spec.rb
@@ -1,213 +1,211 @@
# -*- encoding: binary -*-
require_relative '../../../spec_helper'
-with_feature :encoding do
- describe "Encoding::Converter#primitive_convert" do
- before :each do
- @ec = Encoding::Converter.new("utf-8", "iso-8859-1")
- end
-
- it "accepts a nil source buffer" do
- lambda { @ec.primitive_convert(nil,"") }.should_not raise_error
- end
-
- it "accepts a String as the source buffer" do
- lambda { @ec.primitive_convert("","") }.should_not raise_error
- end
-
- it "accepts nil for the destination byte offset" do
- lambda { @ec.primitive_convert("","", nil) }.should_not raise_error
- end
-
- it "accepts an integer for the destination byte offset" do
- lambda { @ec.primitive_convert("","a", 1) }.should_not raise_error
- end
-
- it "calls #to_int to convert the destination byte offset" do
- offset = mock("encoding primitive_convert destination byte offset")
- offset.should_receive(:to_int).and_return(2)
- @ec.primitive_convert("abc", result = " ", offset).should == :finished
- result.should == " abc"
- end
-
- it "raises an ArgumentError if the destination byte offset is greater than the bytesize of the destination buffer" do
- 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.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
- lambda { @ec.primitive_convert("","", nil, nil) }.should_not raise_error
- end
-
- it "accepts an integer for the destination bytesize" do
- 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
- 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
- lambda { @ec.primitive_convert("am","", nil, 1) }.should_not raise_error
- end
-
- it "calls #to_int to convert the destination byte size" do
- size = mock("encoding primitive_convert destination byte size")
- size.should_receive(:to_int).and_return(2)
- @ec.primitive_convert("abc", result = " ", 0, size).should == :destination_buffer_full
- result.should == "ab"
- end
-
- it "uses destination bytesize as the maximum bytesize of the destination buffer" do
- 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
- 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.primitive_convert("","",nil,nil, {after_output: true}).should == :finished
- end
-
- it "sets the destination buffer's encoding to the destination encoding if the conversion succeeded" do
- 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
- 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 "removes the undefined part from the source buffer when returning :undefined_conversion" do
- dest = "".force_encoding('utf-8')
- s = "\u{9878}abcd"
- @ec.primitive_convert(s, dest).should == :undefined_conversion
-
- s.should == "abcd"
- 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 "clears the source buffer when returning :incomplete_input" do
- ec = Encoding::Converter.new("EUC-JP", "ISO-8859-1")
- s = "\xa4"
- ec.primitive_convert(s, "").should == :incomplete_input
-
- s.should == ""
- 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 "clears the source buffer when returning :source_buffer_empty" do
- ec = Encoding::Converter.new("EUC-JP", "ISO-8859-1")
- s = "\xa4"
- ec.primitive_convert(s, "", nil, nil, partial_input: true).should == :source_buffer_empty
-
- s.should == ""
- end
-
- it "returns :undefined_conversion when a character in the source buffer is not representable in the output encoding" do
- @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.primitive_convert("\xf1abcd","").should == :invalid_byte_sequence
- end
-
- it "removes consumed and erroneous bytes from the source buffer when returning :invalid_byte_sequence" do
- ec = Encoding::Converter.new(Encoding::UTF_8, Encoding::UTF_8_MAC)
- s = "\xC3\xA1\x80\x80\xC3\xA1".force_encoding("utf-8")
- dest = "".force_encoding("utf-8")
- ec.primitive_convert(s, dest)
-
- s.should == "\x80\xC3\xA1".force_encoding("utf-8")
- end
-
- it "returns :finished when the conversion succeeded" do
- @ec.primitive_convert("glark".force_encoding('utf-8'),"").should == :finished
- end
-
- it "clears the source buffer when returning :finished" do
- s = "glark".force_encoding('utf-8')
- @ec.primitive_convert(s, "").should == :finished
-
- s.should == ""
- 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
- source.should == ""
- end
-
- it "clears the source buffer when returning :destination_buffer_full" do
- ec = Encoding::Converter.new("utf-8", "iso-2022-jp")
- s = "\u{9999}"
- destination_bytesize = s.bytesize - 1
- ec.primitive_convert(s, "", 0, destination_bytesize).should == :destination_buffer_full
-
- s.should == ""
- end
-
- it "keeps removing invalid bytes from the source buffer" do
- ec = Encoding::Converter.new(Encoding::UTF_8, Encoding::UTF_8_MAC)
- s = "\x80\x80\x80"
- dest = "".force_encoding(Encoding::UTF_8_MAC)
-
- ec.primitive_convert(s, dest)
- s.should == "\x80\x80"
- ec.primitive_convert(s, dest)
- s.should == "\x80"
- ec.primitive_convert(s, dest)
- s.should == ""
- end
-
- it "reuses read-again bytes after the first error" do
- s = "\xf1abcd"
- dest = ""
-
- @ec.primitive_convert(s, dest).should == :invalid_byte_sequence
- s.should == "bcd"
- @ec.primitive_errinfo[4].should == "a"
-
- @ec.primitive_convert(s, dest).should == :finished
- s.should == ""
-
- dest.should == "abcd"
- end
+describe "Encoding::Converter#primitive_convert" do
+ before :each do
+ @ec = Encoding::Converter.new("utf-8", "iso-8859-1")
+ end
+
+ it "accepts a nil source buffer" do
+ lambda { @ec.primitive_convert(nil,"") }.should_not raise_error
+ end
+
+ it "accepts a String as the source buffer" do
+ lambda { @ec.primitive_convert("","") }.should_not raise_error
+ end
+
+ it "accepts nil for the destination byte offset" do
+ lambda { @ec.primitive_convert("","", nil) }.should_not raise_error
+ end
+
+ it "accepts an integer for the destination byte offset" do
+ lambda { @ec.primitive_convert("","a", 1) }.should_not raise_error
+ end
+
+ it "calls #to_int to convert the destination byte offset" do
+ offset = mock("encoding primitive_convert destination byte offset")
+ offset.should_receive(:to_int).and_return(2)
+ @ec.primitive_convert("abc", result = " ", offset).should == :finished
+ result.should == " abc"
+ end
+
+ it "raises an ArgumentError if the destination byte offset is greater than the bytesize of the destination buffer" do
+ 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.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
+ lambda { @ec.primitive_convert("","", nil, nil) }.should_not raise_error
+ end
+
+ it "accepts an integer for the destination bytesize" do
+ 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
+ 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
+ lambda { @ec.primitive_convert("am","", nil, 1) }.should_not raise_error
+ end
+
+ it "calls #to_int to convert the destination byte size" do
+ size = mock("encoding primitive_convert destination byte size")
+ size.should_receive(:to_int).and_return(2)
+ @ec.primitive_convert("abc", result = " ", 0, size).should == :destination_buffer_full
+ result.should == "ab"
+ end
+
+ it "uses destination bytesize as the maximum bytesize of the destination buffer" do
+ 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
+ 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.primitive_convert("","",nil,nil, {after_output: true}).should == :finished
+ end
+
+ it "sets the destination buffer's encoding to the destination encoding if the conversion succeeded" do
+ 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
+ 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 "removes the undefined part from the source buffer when returning :undefined_conversion" do
+ dest = "".force_encoding('utf-8')
+ s = "\u{9878}abcd"
+ @ec.primitive_convert(s, dest).should == :undefined_conversion
+
+ s.should == "abcd"
+ 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 "clears the source buffer when returning :incomplete_input" do
+ ec = Encoding::Converter.new("EUC-JP", "ISO-8859-1")
+ s = "\xa4"
+ ec.primitive_convert(s, "").should == :incomplete_input
+
+ s.should == ""
+ 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 "clears the source buffer when returning :source_buffer_empty" do
+ ec = Encoding::Converter.new("EUC-JP", "ISO-8859-1")
+ s = "\xa4"
+ ec.primitive_convert(s, "", nil, nil, partial_input: true).should == :source_buffer_empty
+
+ s.should == ""
+ end
+
+ it "returns :undefined_conversion when a character in the source buffer is not representable in the output encoding" do
+ @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.primitive_convert("\xf1abcd","").should == :invalid_byte_sequence
+ end
+
+ it "removes consumed and erroneous bytes from the source buffer when returning :invalid_byte_sequence" do
+ ec = Encoding::Converter.new(Encoding::UTF_8, Encoding::UTF_8_MAC)
+ s = "\xC3\xA1\x80\x80\xC3\xA1".force_encoding("utf-8")
+ dest = "".force_encoding("utf-8")
+ ec.primitive_convert(s, dest)
+
+ s.should == "\x80\xC3\xA1".force_encoding("utf-8")
+ end
+
+ it "returns :finished when the conversion succeeded" do
+ @ec.primitive_convert("glark".force_encoding('utf-8'),"").should == :finished
+ end
+
+ it "clears the source buffer when returning :finished" do
+ s = "glark".force_encoding('utf-8')
+ @ec.primitive_convert(s, "").should == :finished
+
+ s.should == ""
+ 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
+ source.should == ""
+ end
+
+ it "clears the source buffer when returning :destination_buffer_full" do
+ ec = Encoding::Converter.new("utf-8", "iso-2022-jp")
+ s = "\u{9999}"
+ destination_bytesize = s.bytesize - 1
+ ec.primitive_convert(s, "", 0, destination_bytesize).should == :destination_buffer_full
+
+ s.should == ""
+ end
+
+ it "keeps removing invalid bytes from the source buffer" do
+ ec = Encoding::Converter.new(Encoding::UTF_8, Encoding::UTF_8_MAC)
+ s = "\x80\x80\x80"
+ dest = "".force_encoding(Encoding::UTF_8_MAC)
+
+ ec.primitive_convert(s, dest)
+ s.should == "\x80\x80"
+ ec.primitive_convert(s, dest)
+ s.should == "\x80"
+ ec.primitive_convert(s, dest)
+ s.should == ""
+ end
+
+ it "reuses read-again bytes after the first error" do
+ s = "\xf1abcd"
+ dest = ""
+
+ @ec.primitive_convert(s, dest).should == :invalid_byte_sequence
+ s.should == "bcd"
+ @ec.primitive_errinfo[4].should == "a"
+
+ @ec.primitive_convert(s, dest).should == :finished
+ s.should == ""
+
+ dest.should == "abcd"
end
end
diff --git a/spec/ruby/core/encoding/converter/primitive_errinfo_spec.rb b/spec/ruby/core/encoding/converter/primitive_errinfo_spec.rb
index 835e5517e4..e0a5378155 100644
--- a/spec/ruby/core/encoding/converter/primitive_errinfo_spec.rb
+++ b/spec/ruby/core/encoding/converter/primitive_errinfo_spec.rb
@@ -1,70 +1,68 @@
# -*- encoding: binary -*-
require_relative '../../../spec_helper'
-with_feature :encoding 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
+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 [: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 [: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 [: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 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 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, 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 #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 #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
+ 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
diff --git a/spec/ruby/core/encoding/converter/putback_spec.rb b/spec/ruby/core/encoding/converter/putback_spec.rb
index 119ac7b20e..87495eaf3f 100644
--- a/spec/ruby/core/encoding/converter/putback_spec.rb
+++ b/spec/ruby/core/encoding/converter/putback_spec.rb
@@ -1,49 +1,47 @@
# -*- encoding: binary -*-
require_relative '../../../spec_helper'
-with_feature :encoding 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
+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" 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 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 "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 "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 "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
+ 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
diff --git a/spec/ruby/core/encoding/converter/replacement_spec.rb b/spec/ruby/core/encoding/converter/replacement_spec.rb
index 506bf5c4af..a23be74e9b 100644
--- a/spec/ruby/core/encoding/converter/replacement_spec.rb
+++ b/spec/ruby/core/encoding/converter/replacement_spec.rb
@@ -1,74 +1,72 @@
require_relative '../../../spec_helper'
-with_feature :encoding 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 "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
- ec = Encoding::Converter.new("utf-8", "sjis")
- ec.replacement.should == "?"
- ec.replacement.encoding.should == Encoding::US_ASCII
- end
+ ec = Encoding::Converter.new("utf-8", "sjis")
+ ec.replacement.should == "?"
+ ec.replacement.encoding.should == Encoding::US_ASCII
+ end
- it "returns \\uFFFD 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
+ it "returns \\uFFFD 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")
- ec.replacement = "!"
- ec.replacement.should == "!"
- end
+describe "Encoding::Converter#replacement=" do
+ it "accepts a String argument" do
+ ec = Encoding::Converter.new("utf-8", "us-ascii")
+ ec.replacement = "!"
+ ec.replacement.should == "!"
+ end
- it "accepts a String argument of arbitrary length" do
- ec = Encoding::Converter.new("utf-8", "us-ascii")
- ec.replacement = "?!?" * 9999
- ec.replacement.should == "?!?" * 9999
- end
+ it "accepts a String argument of arbitrary length" do
+ ec = Encoding::Converter.new("utf-8", "us-ascii")
+ ec.replacement = "?!?" * 9999
+ ec.replacement.should == "?!?" * 9999
+ end
- it "raises a 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 "raises a 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 "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.dup, "").should == :undefined_conversion
- lambda { ec.replacement = utf8_q }.should \
- raise_error(Encoding::UndefinedConversionError)
- 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.dup, "").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.dup, "").should == :undefined_conversion
- lambda { ec.replacement = utf8_q }.should \
- raise_error(Encoding::UndefinedConversionError)
- ec.replacement.should == "?".force_encoding('us-ascii')
- 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.dup, "").should == :undefined_conversion
+ lambda { ec.replacement = utf8_q }.should \
+ raise_error(Encoding::UndefinedConversionError)
+ ec.replacement.should == "?".force_encoding('us-ascii')
+ end
- it "uses the replacement character" do
- ec = Encoding::Converter.new("utf-8", "us-ascii", :invalid => :replace, :undef => :replace)
- ec.replacement = "!"
- dest = ""
- status = ec.primitive_convert "中文123", dest
+ it "uses the replacement character" do
+ ec = Encoding::Converter.new("utf-8", "us-ascii", :invalid => :replace, :undef => :replace)
+ ec.replacement = "!"
+ dest = ""
+ status = ec.primitive_convert "中文123", dest
- status.should == :finished
- dest.should == "!!123"
- end
+ status.should == :finished
+ dest.should == "!!123"
end
end
diff --git a/spec/ruby/core/encoding/converter/search_convpath_spec.rb b/spec/ruby/core/encoding/converter/search_convpath_spec.rb
index 09db480642..03cb435528 100644
--- a/spec/ruby/core/encoding/converter/search_convpath_spec.rb
+++ b/spec/ruby/core/encoding/converter/search_convpath_spec.rb
@@ -1,34 +1,32 @@
require_relative '../../../spec_helper'
-with_feature :encoding do
- describe "Encoding::Converter.search_convpath" do
- it "returns an Array with a single element if there is a direct converter" do
- cp = Encoding::Converter.search_convpath('ASCII', 'UTF-8')
- cp.should == [[Encoding::US_ASCII, Encoding::UTF_8]]
- end
+describe "Encoding::Converter.search_convpath" do
+ it "returns an Array with a single element if there is a direct converter" do
+ cp = Encoding::Converter.search_convpath('ASCII', 'UTF-8')
+ cp.should == [[Encoding::US_ASCII, Encoding::UTF_8]]
+ end
- it "returns multiple encoding pairs when direct conversion is impossible" do
- cp = Encoding::Converter.search_convpath('ascii','Big5')
- cp.should == [
- [Encoding::US_ASCII, Encoding::UTF_8],
- [Encoding::UTF_8, Encoding::Big5]
- ]
- end
+ it "returns multiple encoding pairs when direct conversion is impossible" do
+ cp = Encoding::Converter.search_convpath('ascii','Big5')
+ cp.should == [
+ [Encoding::US_ASCII, Encoding::UTF_8],
+ [Encoding::UTF_8, Encoding::Big5]
+ ]
+ 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"
+ 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
+ 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
+ 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
diff --git a/spec/ruby/core/encoding/converter/source_encoding_spec.rb b/spec/ruby/core/encoding/converter/source_encoding_spec.rb
index 5abb009dda..6196f717bd 100644
--- a/spec/ruby/core/encoding/converter/source_encoding_spec.rb
+++ b/spec/ruby/core/encoding/converter/source_encoding_spec.rb
@@ -1,13 +1,11 @@
require_relative '../../../spec_helper'
-with_feature :encoding 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
+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('Shift_JIS','EUC-JP')
- ec.source_encoding.should == Encoding::SHIFT_JIS
- end
+ ec = Encoding::Converter.new('Shift_JIS','EUC-JP')
+ ec.source_encoding.should == Encoding::SHIFT_JIS
end
end
diff --git a/spec/ruby/core/encoding/default_external_spec.rb b/spec/ruby/core/encoding/default_external_spec.rb
index 3de52043e2..8973490901 100644
--- a/spec/ruby/core/encoding/default_external_spec.rb
+++ b/spec/ruby/core/encoding/default_external_spec.rb
@@ -1,65 +1,63 @@
require_relative '../../spec_helper'
-with_feature :encoding do
- describe "Encoding.default_external" do
- before :each do
- @original_encoding = Encoding.default_external
- end
+describe "Encoding.default_external" do
+ before :each do
+ @original_encoding = Encoding.default_external
+ end
- after :each do
- Encoding.default_external = @original_encoding
- end
+ after :each 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 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::SHIFT_JIS
- Encoding.default_external.should == Encoding::SHIFT_JIS
- end
+ it "returns the default external encoding" do
+ Encoding.default_external = Encoding::SHIFT_JIS
+ Encoding.default_external.should == Encoding::SHIFT_JIS
end
+end
- describe "Encoding.default_external=" do
- before :each do
- @original_encoding = Encoding.default_external
- end
+describe "Encoding.default_external=" do
+ before :each do
+ @original_encoding = Encoding.default_external
+ end
- after :each do
- Encoding.default_external = @original_encoding
- end
+ after :each do
+ Encoding.default_external = @original_encoding
+ end
- it "sets the default external encoding" do
- Encoding.default_external = Encoding::SHIFT_JIS
- Encoding.default_external.should == Encoding::SHIFT_JIS
- Encoding.find('external').should == Encoding::SHIFT_JIS
- end
+ it "sets the default external encoding" do
+ Encoding.default_external = Encoding::SHIFT_JIS
+ Encoding.default_external.should == Encoding::SHIFT_JIS
+ Encoding.find('external').should == Encoding::SHIFT_JIS
+ end
- platform_is_not :windows do
- it "also sets the filesystem encoding" do
- Encoding.default_external = Encoding::SHIFT_JIS
- Encoding.find('filesystem').should == Encoding::SHIFT_JIS
- end
+ platform_is_not :windows do
+ it "also sets the filesystem encoding" do
+ Encoding.default_external = Encoding::SHIFT_JIS
+ Encoding.find('filesystem').should == Encoding::SHIFT_JIS
end
+ end
- it "can accept a name of an encoding as a String" do
- Encoding.default_external = 'Shift_JIS'
- Encoding.default_external.should == Encoding::SHIFT_JIS
- end
+ it "can accept a name of an encoding as a String" do
+ Encoding.default_external = 'Shift_JIS'
+ 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).at_least(1).and_return('US-ASCII')
- Encoding.default_external = string
- Encoding.default_external.should == Encoding::ASCII
- end
+ it "calls #to_s on arguments that are neither Strings nor Encodings" do
+ string = mock('string')
+ string.should_receive(:to_str).at_least(1).and_return('US-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 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
+ it "raises an ArgumentError if the argument is nil" do
+ lambda { Encoding.default_external = nil }.should raise_error(ArgumentError)
end
end
diff --git a/spec/ruby/core/encoding/default_internal_spec.rb b/spec/ruby/core/encoding/default_internal_spec.rb
index 5ff475454b..d8bbb2d11d 100644
--- a/spec/ruby/core/encoding/default_internal_spec.rb
+++ b/spec/ruby/core/encoding/default_internal_spec.rb
@@ -1,76 +1,74 @@
require_relative '../../spec_helper'
-with_feature :encoding 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
+describe "Encoding.default_internal" do
+ before :each do
+ @original_encoding = Encoding.default_internal
end
- 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
+end
- after :each do
- Encoding.default_internal = @original_encoding
- end
+describe "Encoding.default_internal=" do
+ before :each do
+ @original_encoding = Encoding.default_internal
+ end
- it "sets the default internal encoding" do
- Encoding.default_internal = Encoding::SHIFT_JIS
- Encoding.default_internal.should == Encoding::SHIFT_JIS
- end
+ after :each do
+ Encoding.default_internal = @original_encoding
+ end
- it "can accept a name of an encoding as a String" do
- Encoding.default_internal = 'Shift_JIS'
- Encoding.default_internal.should == Encoding::SHIFT_JIS
- end
+ it "sets the default internal encoding" do
+ Encoding.default_internal = Encoding::SHIFT_JIS
+ Encoding.default_internal.should == Encoding::SHIFT_JIS
+ end
- it "calls #to_str to convert an object to a String" do
- obj = mock('string')
- obj.should_receive(:to_str).at_least(1).times.and_return('ascii')
+ it "can accept a name of an encoding as a String" do
+ Encoding.default_internal = 'Shift_JIS'
+ Encoding.default_internal.should == Encoding::SHIFT_JIS
+ end
- Encoding.default_internal = obj
- Encoding.default_internal.should == Encoding::ASCII
- end
+ it "calls #to_str to convert an object to a String" do
+ obj = mock('string')
+ obj.should_receive(:to_str).at_least(1).times.and_return('ascii')
- it "raises a TypeError if #to_str does not return a String" do
- obj = mock('string')
- obj.should_receive(:to_str).at_least(1).times.and_return(1)
+ Encoding.default_internal = obj
+ Encoding.default_internal.should == Encoding::ASCII
+ end
+
+ it "raises a TypeError if #to_str does not return a String" do
+ obj = mock('string')
+ obj.should_receive(:to_str).at_least(1).times.and_return(1)
- lambda { Encoding.default_internal = obj }.should raise_error(TypeError)
- end
+ lambda { Encoding.default_internal = obj }.should raise_error(TypeError)
+ end
- it "raises a TypeError when passed an object not providing #to_str" do
- lambda { Encoding.default_internal = mock("encoding") }.should raise_error(TypeError)
- end
+ it "raises a TypeError when passed an object not providing #to_str" do
+ lambda { Encoding.default_internal = mock("encoding") }.should raise_error(TypeError)
+ end
- it "accepts an argument of nil to unset the default internal encoding" do
- Encoding.default_internal = nil
- Encoding.default_internal.should be_nil
- end
+ it "accepts an argument of nil to unset the default internal encoding" do
+ Encoding.default_internal = nil
+ Encoding.default_internal.should be_nil
end
end
diff --git a/spec/ruby/core/encoding/dummy_spec.rb b/spec/ruby/core/encoding/dummy_spec.rb
index ef634829d1..75ffcd5a4e 100644
--- a/spec/ruby/core/encoding/dummy_spec.rb
+++ b/spec/ruby/core/encoding/dummy_spec.rb
@@ -1,16 +1,14 @@
require_relative '../../spec_helper'
-with_feature :encoding 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
+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
- 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
+ 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
diff --git a/spec/ruby/core/encoding/find_spec.rb b/spec/ruby/core/encoding/find_spec.rb
index 3b00de27d4..5635a51c69 100644
--- a/spec/ruby/core/encoding/find_spec.rb
+++ b/spec/ruby/core/encoding/find_spec.rb
@@ -1,84 +1,82 @@
require_relative '../../spec_helper'
-with_feature :encoding do
- describe "Encoding.find" do
- before :all do
- @encodings = Encoding.aliases.to_a.flatten.uniq
- end
+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
+ 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
+ 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 "raises a TypeError if passed a Symbol" do
- lambda { Encoding.find(:"utf-8") }.should raise_error(TypeError)
- end
+ it "raises a TypeError if passed a Symbol" do
+ lambda { Encoding.find(:"utf-8") }.should raise_error(TypeError)
+ end
- it "returns the passed Encoding object" do
- Encoding.find(Encoding::UTF_8).should == Encoding::UTF_8
- end
+ it "returns the passed Encoding object" do
+ Encoding.find(Encoding::UTF_8).should == Encoding::UTF_8
+ end
- it "accepts encoding names as Strings" do
- Encoding.list.each do |enc|
- Encoding.find(enc.name).should == enc
- 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 = Class.new do
- attr_writer :encoding_name
- def to_str; @encoding_name; end
- end.new
+ it "accepts any object as encoding name, if it responds to #to_str" do
+ obj = Class.new do
+ attr_writer :encoding_name
+ def to_str; @encoding_name; end
+ end.new
- Encoding.list.each do |enc|
- obj.encoding_name = enc.name
- Encoding.find(obj).should == enc
- 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
+ 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
+ it "raises an ArgumentError if the given encoding does not exist" do
+ lambda { Encoding.find('dh2dh278d') }.should raise_error(ArgumentError)
+ end
- # Not sure how to do a better test, since locale depends on weird platform-specific stuff
- it "supports the 'locale' encoding alias" do
- enc = Encoding.find('locale')
- enc.should_not == nil
- end
+ # Not sure how to do a better test, since locale depends on weird platform-specific stuff
+ it "supports the 'locale' encoding alias" do
+ enc = Encoding.find('locale')
+ enc.should_not == nil
+ end
- it "returns default external encoding for the 'external' encoding alias" do
- enc = Encoding.find('external')
- enc.should == Encoding.default_external
- end
+ it "returns default external encoding for the 'external' encoding alias" do
+ enc = Encoding.find('external')
+ enc.should == Encoding.default_external
+ end
- it "returns default internal encoding for the 'internal' encoding alias" do
- enc = Encoding.find('internal')
- enc.should == Encoding.default_internal
- end
+ it "returns default internal encoding for the 'internal' encoding alias" do
+ enc = Encoding.find('internal')
+ enc.should == Encoding.default_internal
+ end
- platform_is_not :windows do
- it "uses default external encoding for the 'filesystem' encoding alias" do
- enc = Encoding.find('filesystem')
- enc.should == Encoding.default_external
- end
+ platform_is_not :windows do
+ it "uses default external encoding for the 'filesystem' encoding alias" do
+ enc = Encoding.find('filesystem')
+ enc.should == Encoding.default_external
end
+ end
- platform_is :windows do
- it "needs to be reviewed for spec completeness"
- end
+ platform_is :windows do
+ it "needs to be reviewed for spec completeness"
end
end
diff --git a/spec/ruby/core/encoding/inspect_spec.rb b/spec/ruby/core/encoding/inspect_spec.rb
index 9da9275eae..9a930b2a77 100644
--- a/spec/ruby/core/encoding/inspect_spec.rb
+++ b/spec/ruby/core/encoding/inspect_spec.rb
@@ -1,21 +1,19 @@
require_relative '../../spec_helper'
-with_feature :encoding do
- describe "Encoding#inspect" do
- it "returns a String" do
- Encoding::UTF_8.inspect.should be_an_instance_of(String)
- end
+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
+ 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
+ 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
diff --git a/spec/ruby/core/encoding/invalid_byte_sequence_error/destination_encoding_name_spec.rb b/spec/ruby/core/encoding/invalid_byte_sequence_error/destination_encoding_name_spec.rb
index 51c802f7e1..f5fa6f55e3 100644
--- a/spec/ruby/core/encoding/invalid_byte_sequence_error/destination_encoding_name_spec.rb
+++ b/spec/ruby/core/encoding/invalid_byte_sequence_error/destination_encoding_name_spec.rb
@@ -1,20 +1,18 @@
require_relative '../fixtures/classes'
-with_feature :encoding do
- describe "Encoding::InvalidByteSequenceError#destination_encoding_name" do
- before :each do
- @exception, = EncodingSpecs::InvalidByteSequenceError.exception
- @exception2, = EncodingSpecs::InvalidByteSequenceErrorIndirect.exception
- end
+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 "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
+ 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
diff --git a/spec/ruby/core/encoding/invalid_byte_sequence_error/destination_encoding_spec.rb b/spec/ruby/core/encoding/invalid_byte_sequence_error/destination_encoding_spec.rb
index d9e63a6779..43be3ddd71 100644
--- a/spec/ruby/core/encoding/invalid_byte_sequence_error/destination_encoding_spec.rb
+++ b/spec/ruby/core/encoding/invalid_byte_sequence_error/destination_encoding_spec.rb
@@ -1,20 +1,18 @@
require_relative '../fixtures/classes'
-with_feature :encoding do
- describe "Encoding::InvalidByteSequenceError#destination_encoding" do
- before :each do
- @exception, = EncodingSpecs::InvalidByteSequenceError.exception
- @exception2, = EncodingSpecs::InvalidByteSequenceErrorIndirect.exception
- end
+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 "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
+ 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
diff --git a/spec/ruby/core/encoding/invalid_byte_sequence_error/error_bytes_spec.rb b/spec/ruby/core/encoding/invalid_byte_sequence_error/error_bytes_spec.rb
index 79b381a370..4b24e1611b 100644
--- a/spec/ruby/core/encoding/invalid_byte_sequence_error/error_bytes_spec.rb
+++ b/spec/ruby/core/encoding/invalid_byte_sequence_error/error_bytes_spec.rb
@@ -1,32 +1,30 @@
# -*- encoding: binary -*-
require_relative '../fixtures/classes'
-with_feature :encoding do
- describe "Encoding::InvalidByteSequenceError#error_bytes" do
- before :each do
- @exception, @errinfo = EncodingSpecs::InvalidByteSequenceError.exception
- @exception2, @errinfo2 = EncodingSpecs::InvalidByteSequenceErrorIndirect.exception
- end
+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 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]
+ 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
+ @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
+ 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
+ @exception2.error_bytes.encoding.should == Encoding::ASCII_8BIT
end
end
diff --git a/spec/ruby/core/encoding/invalid_byte_sequence_error/incomplete_input_spec.rb b/spec/ruby/core/encoding/invalid_byte_sequence_error/incomplete_input_spec.rb
index f89c0d8c03..e3ef3e4557 100644
--- a/spec/ruby/core/encoding/invalid_byte_sequence_error/incomplete_input_spec.rb
+++ b/spec/ruby/core/encoding/invalid_byte_sequence_error/incomplete_input_spec.rb
@@ -1,31 +1,29 @@
# -*- encoding: binary -*-
require_relative '../../../spec_helper'
-with_feature :encoding do
- describe "Encoding::InvalidByteSequenceError#incomplete_input?" do
+describe "Encoding::InvalidByteSequenceError#incomplete_input?" do
- it "returns nil by default" do
- Encoding::InvalidByteSequenceError.new.incomplete_input?.should be_nil
- end
+ 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
+ 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
+ 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
diff --git a/spec/ruby/core/encoding/invalid_byte_sequence_error/readagain_bytes_spec.rb b/spec/ruby/core/encoding/invalid_byte_sequence_error/readagain_bytes_spec.rb
index 4270a0647a..6f0ff524f5 100644
--- a/spec/ruby/core/encoding/invalid_byte_sequence_error/readagain_bytes_spec.rb
+++ b/spec/ruby/core/encoding/invalid_byte_sequence_error/readagain_bytes_spec.rb
@@ -1,32 +1,30 @@
# -*- encoding: binary -*-
require_relative '../fixtures/classes'
-with_feature :encoding do
- describe "Encoding::InvalidByteSequenceError#readagain_bytes" do
- before :each do
- @exception, @errinfo = EncodingSpecs::InvalidByteSequenceError.exception
- @exception2, @errinfo2 = EncodingSpecs::InvalidByteSequenceErrorIndirect.exception
- end
+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 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]
+ 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
+ @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
+ 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
+ @exception2.readagain_bytes.encoding.should == Encoding::ASCII_8BIT
end
end
diff --git a/spec/ruby/core/encoding/invalid_byte_sequence_error/source_encoding_name_spec.rb b/spec/ruby/core/encoding/invalid_byte_sequence_error/source_encoding_name_spec.rb
index bd31c03eee..bd3a51cbc5 100644
--- a/spec/ruby/core/encoding/invalid_byte_sequence_error/source_encoding_name_spec.rb
+++ b/spec/ruby/core/encoding/invalid_byte_sequence_error/source_encoding_name_spec.rb
@@ -1,30 +1,28 @@
require_relative '../fixtures/classes'
-with_feature :encoding do
- describe "Encoding::UndefinedConversionError#source_encoding_name" do
- before :each do
- @exception, = EncodingSpecs::UndefinedConversionError.exception
- @exception2, = EncodingSpecs::UndefinedConversionErrorIndirect.exception
- end
+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 "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
+ 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 occurred" do
- @exception2.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 occurred" do
+ @exception2.source_encoding_name.should == 'UTF-8'
end
end
diff --git a/spec/ruby/core/encoding/invalid_byte_sequence_error/source_encoding_spec.rb b/spec/ruby/core/encoding/invalid_byte_sequence_error/source_encoding_spec.rb
index 3f36d504d5..f43d6d5830 100644
--- a/spec/ruby/core/encoding/invalid_byte_sequence_error/source_encoding_spec.rb
+++ b/spec/ruby/core/encoding/invalid_byte_sequence_error/source_encoding_spec.rb
@@ -1,35 +1,33 @@
require_relative '../fixtures/classes'
-with_feature :encoding do
- describe "Encoding::InvalidByteSequenceError#source_encoding" do
- before :each do
- @exception, = EncodingSpecs::InvalidByteSequenceError.exception
- @exception2, = EncodingSpecs::InvalidByteSequenceErrorIndirect.exception
- end
+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 "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
+ 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.
+ # 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 occurred" do
- @exception2.source_encoding.should == Encoding::EUC_JP
- end
+ # 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 occurred" do
+ @exception2.source_encoding.should == Encoding::EUC_JP
end
end
diff --git a/spec/ruby/core/encoding/list_spec.rb b/spec/ruby/core/encoding/list_spec.rb
index b1e08c7a2e..2a2078974e 100644
--- a/spec/ruby/core/encoding/list_spec.rb
+++ b/spec/ruby/core/encoding/list_spec.rb
@@ -1,43 +1,41 @@
require_relative '../../spec_helper'
-with_feature :encoding 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
+describe "Encoding.list" do
+ it "returns an Array" do
+ Encoding.list.should be_an_instance_of(Array)
+ end
- it "returns each encoding only once" do
- orig = Encoding.list.map {|e| e.name}
- orig.should == orig.uniq
+ it "returns an Array of Encoding objects" do
+ Encoding.list.each do |enc|
+ enc.should be_an_instance_of(Encoding)
end
+ end
- it "includes the default external encoding" do
- Encoding.list.include?(Encoding.default_external).should be_true
- end
+ it "returns each encoding only once" do
+ orig = Encoding.list.map {|e| e.name}
+ orig.should == orig.uniq
+ 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 the default external encoding" do
+ Encoding.list.include?(Encoding.default_external).should be_true
+ 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
+ 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 dummy encodings" do
- Encoding.list.select {|e| e.dummy?}.should_not == []
+ 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
- # TODO: Find example that illustrates this
- it "updates the list when #find is used to load a new encoding"
+ 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
diff --git a/spec/ruby/core/encoding/locale_charmap_spec.rb b/spec/ruby/core/encoding/locale_charmap_spec.rb
index 54dad396fd..5963a8beb5 100644
--- a/spec/ruby/core/encoding/locale_charmap_spec.rb
+++ b/spec/ruby/core/encoding/locale_charmap_spec.rb
@@ -1,47 +1,45 @@
require_relative '../../spec_helper'
-with_feature :encoding do
- describe "Encoding.locale_charmap" do
- it "returns a String" do
- Encoding.locale_charmap.should be_an_instance_of(String)
- end
+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 :linux do
- it "returns a value based on the LC_ALL environment variable" do
- old_lc_all = ENV['LC_ALL']
- ENV['LC_ALL'] = 'C'
- ruby_exe("print Encoding.locale_charmap").should == 'ANSI_X3.4-1968'
- ENV['LC_ALL'] = old_lc_all
- end
+ # FIXME: Get this working on Windows
+ platform_is :linux do
+ it "returns a value based on the LC_ALL environment variable" do
+ old_lc_all = ENV['LC_ALL']
+ ENV['LC_ALL'] = 'C'
+ ruby_exe("print Encoding.locale_charmap").should == 'ANSI_X3.4-1968'
+ ENV['LC_ALL'] = old_lc_all
end
+ end
- platform_is :freebsd, :openbsd, :darwin do
- it "returns a value based on the LC_ALL environment variable" do
- old_lc_all = ENV['LC_ALL']
- ENV['LC_ALL'] = 'C'
- ruby_exe("print Encoding.locale_charmap").should == 'US-ASCII'
- ENV['LC_ALL'] = old_lc_all
- end
+ platform_is :freebsd, :openbsd, :darwin do
+ it "returns a value based on the LC_ALL environment variable" do
+ old_lc_all = ENV['LC_ALL']
+ ENV['LC_ALL'] = 'C'
+ ruby_exe("print Encoding.locale_charmap").should == 'US-ASCII'
+ ENV['LC_ALL'] = old_lc_all
end
+ end
- platform_is :netbsd do
- it "returns a value based on the LC_ALL environment variable" do
- old_lc_all = ENV['LC_ALL']
- ENV['LC_ALL'] = 'C'
- ruby_exe("print Encoding.locale_charmap").should == '646'
- ENV['LC_ALL'] = old_lc_all
- end
+ platform_is :netbsd do
+ it "returns a value based on the LC_ALL environment variable" do
+ old_lc_all = ENV['LC_ALL']
+ ENV['LC_ALL'] = 'C'
+ ruby_exe("print Encoding.locale_charmap").should == '646'
+ ENV['LC_ALL'] = old_lc_all
end
+ end
- platform_is :bsd, :darwin, :linux do
- it "is unaffected by assigning to ENV['LC_ALL'] in the same process" do
- old_charmap = Encoding.locale_charmap
- old_lc_all = ENV['LC_ALL']
- ENV['LC_ALL'] = 'C'
- Encoding.locale_charmap.should == old_charmap
- ENV['LC_ALL'] = old_lc_all
- end
+ platform_is :bsd, :darwin, :linux do
+ it "is unaffected by assigning to ENV['LC_ALL'] in the same process" do
+ old_charmap = Encoding.locale_charmap
+ old_lc_all = ENV['LC_ALL']
+ ENV['LC_ALL'] = 'C'
+ Encoding.locale_charmap.should == old_charmap
+ ENV['LC_ALL'] = old_lc_all
end
end
end
diff --git a/spec/ruby/core/encoding/name_list_spec.rb b/spec/ruby/core/encoding/name_list_spec.rb
index 6e02347bfd..836381c4d8 100644
--- a/spec/ruby/core/encoding/name_list_spec.rb
+++ b/spec/ruby/core/encoding/name_list_spec.rb
@@ -1,25 +1,23 @@
require_relative '../../spec_helper'
-with_feature :encoding do
- describe "Encoding.name_list" do
- it "returns an Array" do
- Encoding.name_list.should be_an_instance_of(Array)
- end
+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 "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
+ 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
+ it "includes all non-dummy encodings" do
+ Encoding.list.each do |enc|
+ Encoding.name_list.include?(enc.name).should be_true
end
end
end
diff --git a/spec/ruby/core/encoding/name_spec.rb b/spec/ruby/core/encoding/name_spec.rb
index 1632137f95..5eadb1d2f5 100644
--- a/spec/ruby/core/encoding/name_spec.rb
+++ b/spec/ruby/core/encoding/name_spec.rb
@@ -1,7 +1,5 @@
require_relative 'shared/name'
-with_feature :encoding do
- describe "Encoding#name" do
- it_behaves_like :encoding_name, :name
- end
+describe "Encoding#name" do
+ it_behaves_like :encoding_name, :name
end
diff --git a/spec/ruby/core/encoding/names_spec.rb b/spec/ruby/core/encoding/names_spec.rb
index c0f84c9b2b..9ded043bbb 100644
--- a/spec/ruby/core/encoding/names_spec.rb
+++ b/spec/ruby/core/encoding/names_spec.rb
@@ -1,37 +1,35 @@
require_relative '../../spec_helper'
-with_feature :encoding 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
+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
+ 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
+ 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
+ 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
diff --git a/spec/ruby/core/encoding/replicate_spec.rb b/spec/ruby/core/encoding/replicate_spec.rb
index 2e1d75f1d0..717e9cea72 100644
--- a/spec/ruby/core/encoding/replicate_spec.rb
+++ b/spec/ruby/core/encoding/replicate_spec.rb
@@ -1,48 +1,46 @@
# -*- encoding: binary -*-
require_relative '../../spec_helper'
-with_feature :encoding do
- describe "Encoding#replicate" do
- before :all do
- @i = 0
- end
+describe "Encoding#replicate" do
+ before :all do
+ @i = 0
+ end
- before :each do
- @i += 1
- @prefix = "RS#{@i}"
- end
+ before :each do
+ @i += 1
+ @prefix = "RS#{@i}"
+ end
- it "returns a replica of ASCII" do
- name = @prefix + '-ASCII'
- e = Encoding::ASCII.replicate(name)
- e.name.should == name
- "a".force_encoding(e).valid_encoding?.should be_true
- "\x80".force_encoding(e).valid_encoding?.should be_false
- end
+ it "returns a replica of ASCII" do
+ name = @prefix + '-ASCII'
+ e = Encoding::ASCII.replicate(name)
+ e.name.should == name
+ "a".force_encoding(e).valid_encoding?.should be_true
+ "\x80".force_encoding(e).valid_encoding?.should be_false
+ end
- it "returns a replica of UTF-8" do
- name = @prefix + 'UTF-8'
- e = Encoding::UTF_8.replicate(name)
- e.name.should == name
- "a".force_encoding(e).valid_encoding?.should be_true
- "\u3042".force_encoding(e).valid_encoding?.should be_true
- "\x80".force_encoding(e).valid_encoding?.should be_false
- end
+ it "returns a replica of UTF-8" do
+ name = @prefix + 'UTF-8'
+ e = Encoding::UTF_8.replicate(name)
+ e.name.should == name
+ "a".force_encoding(e).valid_encoding?.should be_true
+ "\u3042".force_encoding(e).valid_encoding?.should be_true
+ "\x80".force_encoding(e).valid_encoding?.should be_false
+ end
- it "returns a replica of UTF-16BE" do
- name = @prefix + 'UTF-16-BE'
- e = Encoding::UTF_16BE.replicate(name)
- e.name.should == name
- "a".force_encoding(e).valid_encoding?.should be_false
- "\x30\x42".force_encoding(e).valid_encoding?.should be_true
- "\x80".force_encoding(e).valid_encoding?.should be_false
- end
+ it "returns a replica of UTF-16BE" do
+ name = @prefix + 'UTF-16-BE'
+ e = Encoding::UTF_16BE.replicate(name)
+ e.name.should == name
+ "a".force_encoding(e).valid_encoding?.should be_false
+ "\x30\x42".force_encoding(e).valid_encoding?.should be_true
+ "\x80".force_encoding(e).valid_encoding?.should be_false
+ end
- it "returns a replica of ISO-2022-JP" do
- name = @prefix + 'ISO-2022-JP'
- e = Encoding::ISO_2022_JP.replicate(name)
- e.name.should == name
- e.dummy?.should be_true
- end
+ it "returns a replica of ISO-2022-JP" do
+ name = @prefix + 'ISO-2022-JP'
+ e = Encoding::ISO_2022_JP.replicate(name)
+ e.name.should == name
+ e.dummy?.should be_true
end
end
diff --git a/spec/ruby/core/encoding/to_s_spec.rb b/spec/ruby/core/encoding/to_s_spec.rb
index e554bc3fee..82d282386b 100644
--- a/spec/ruby/core/encoding/to_s_spec.rb
+++ b/spec/ruby/core/encoding/to_s_spec.rb
@@ -1,7 +1,5 @@
require_relative 'shared/name'
-with_feature :encoding do
- describe "Encoding#to_s" do
- it_behaves_like :encoding_name, :to_s
- end
+describe "Encoding#to_s" do
+ it_behaves_like :encoding_name, :to_s
end
diff --git a/spec/ruby/core/encoding/undefined_conversion_error/destination_encoding_name_spec.rb b/spec/ruby/core/encoding/undefined_conversion_error/destination_encoding_name_spec.rb
index a40f295fcf..106fc7ecac 100644
--- a/spec/ruby/core/encoding/undefined_conversion_error/destination_encoding_name_spec.rb
+++ b/spec/ruby/core/encoding/undefined_conversion_error/destination_encoding_name_spec.rb
@@ -1,17 +1,15 @@
require_relative '../fixtures/classes'
-with_feature :encoding do
- describe "Encoding::UndefinedConversionError#destination_encoding_name" do
- before :each do
- @exception = EncodingSpecs::UndefinedConversionError.exception
- end
+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 "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
+ it "is equal to the destination encoding name of the object that raised it" do
+ @exception.destination_encoding_name.should == "US-ASCII"
end
end
diff --git a/spec/ruby/core/encoding/undefined_conversion_error/destination_encoding_spec.rb b/spec/ruby/core/encoding/undefined_conversion_error/destination_encoding_spec.rb
index 579b0a37f8..c6e24732fd 100644
--- a/spec/ruby/core/encoding/undefined_conversion_error/destination_encoding_spec.rb
+++ b/spec/ruby/core/encoding/undefined_conversion_error/destination_encoding_spec.rb
@@ -1,17 +1,15 @@
require_relative '../fixtures/classes'
-with_feature :encoding do
- describe "Encoding::UndefinedConversionError#destination_encoding" do
- before :each do
- @exception = EncodingSpecs::UndefinedConversionError.exception
- end
+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 "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
+ it "is equal to the destination encoding of the object that raised it" do
+ @exception.destination_encoding.should == Encoding::US_ASCII
end
end
diff --git a/spec/ruby/core/encoding/undefined_conversion_error/error_char_spec.rb b/spec/ruby/core/encoding/undefined_conversion_error/error_char_spec.rb
index 740cd17e30..780d81c1ee 100644
--- a/spec/ruby/core/encoding/undefined_conversion_error/error_char_spec.rb
+++ b/spec/ruby/core/encoding/undefined_conversion_error/error_char_spec.rb
@@ -1,29 +1,27 @@
require_relative '../fixtures/classes'
-with_feature :encoding do
- describe "Encoding::UndefinedConversionError#error_char" do
- before :each do
- @exception = EncodingSpecs::UndefinedConversionError.exception
- @exception2 = EncodingSpecs::UndefinedConversionErrorIndirect.exception
- end
+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 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}"
+ 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
+ @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
+ it "uses the source encoding" do
+ @exception.error_char.encoding.should == @exception.source_encoding
- @exception2.error_char.encoding.should == @exception2.source_encoding
- end
+ @exception2.error_char.encoding.should == @exception2.source_encoding
end
end
diff --git a/spec/ruby/core/encoding/undefined_conversion_error/source_encoding_name_spec.rb b/spec/ruby/core/encoding/undefined_conversion_error/source_encoding_name_spec.rb
index 79a59ff1e9..3b697cb82f 100644
--- a/spec/ruby/core/encoding/undefined_conversion_error/source_encoding_name_spec.rb
+++ b/spec/ruby/core/encoding/undefined_conversion_error/source_encoding_name_spec.rb
@@ -1,30 +1,28 @@
require_relative '../fixtures/classes'
-with_feature :encoding do
- describe "Encoding::UndefinedConversionError#source_encoding_name" do
- before :each do
- @exception = EncodingSpecs::UndefinedConversionError.exception
- @exception2 = EncodingSpecs::UndefinedConversionErrorIndirect.exception
- end
+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 "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
+ 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 occurred" do
- @exception2.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 occurred" do
+ @exception2.source_encoding_name.should == 'UTF-8'
end
end
diff --git a/spec/ruby/core/encoding/undefined_conversion_error/source_encoding_spec.rb b/spec/ruby/core/encoding/undefined_conversion_error/source_encoding_spec.rb
index 29be837e13..9101d51e11 100644
--- a/spec/ruby/core/encoding/undefined_conversion_error/source_encoding_spec.rb
+++ b/spec/ruby/core/encoding/undefined_conversion_error/source_encoding_spec.rb
@@ -1,31 +1,29 @@
require_relative '../fixtures/classes'
-with_feature :encoding do
- describe "Encoding::UndefinedConversionError#source_encoding" do
- before :each do
- @exception = EncodingSpecs::UndefinedConversionError.exception
- @exception2 = EncodingSpecs::UndefinedConversionErrorIndirect.exception
- end
+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 "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
+ 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 occurred" do
- @exception2.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 occurred" do
+ @exception2.source_encoding.should == Encoding::UTF_8
end
end
diff --git a/spec/ruby/core/env/element_reference_spec.rb b/spec/ruby/core/env/element_reference_spec.rb
index f9b9fe5f49..0a10cd27b8 100644
--- a/spec/ruby/core/env/element_reference_spec.rb
+++ b/spec/ruby/core/env/element_reference_spec.rb
@@ -27,40 +27,38 @@ describe "ENV.[]" do
end
end
-with_feature :encoding do
- describe "ENV.[]" do
- before :each do
- @variable = "env_element_reference_encoding_specs"
+describe "ENV.[]" do
+ before :each do
+ @variable = "env_element_reference_encoding_specs"
- @external = Encoding.default_external
- @internal = Encoding.default_internal
+ @external = Encoding.default_external
+ @internal = Encoding.default_internal
- Encoding.default_external = Encoding::ASCII_8BIT
- end
+ Encoding.default_external = Encoding::ASCII_8BIT
+ end
- after :each do
- Encoding.default_external = @external
- Encoding.default_internal = @internal
+ after :each do
+ Encoding.default_external = @external
+ Encoding.default_internal = @internal
- ENV.delete @variable
- end
+ ENV.delete @variable
+ end
- it "uses the locale encoding if Encoding.default_internal is nil" do
- Encoding.default_internal = nil
+ it "uses the locale encoding if Encoding.default_internal is nil" do
+ Encoding.default_internal = nil
- locale = Encoding.find('locale')
- locale = Encoding::ASCII_8BIT if locale == Encoding::US_ASCII
- ENV[@variable] = "\xC3\xB8"
- ENV[@variable].encoding.should == locale
- end
+ locale = Encoding.find('locale')
+ locale = Encoding::ASCII_8BIT if locale == Encoding::US_ASCII
+ ENV[@variable] = "\xC3\xB8"
+ ENV[@variable].encoding.should == locale
+ end
- it "transcodes from the locale encoding to Encoding.default_internal if set" do
- # We cannot reliably know the locale encoding, so we merely check that
- # the result string has the expected encoding.
- ENV[@variable] = ""
- Encoding.default_internal = Encoding::IBM437
+ it "transcodes from the locale encoding to Encoding.default_internal if set" do
+ # We cannot reliably know the locale encoding, so we merely check that
+ # the result string has the expected encoding.
+ ENV[@variable] = ""
+ Encoding.default_internal = Encoding::IBM437
- ENV[@variable].encoding.should equal(Encoding::IBM437)
- end
+ ENV[@variable].encoding.should equal(Encoding::IBM437)
end
end
diff --git a/spec/ruby/core/env/shared/each.rb b/spec/ruby/core/env/shared/each.rb
index d6cbc93f9a..4039dd1f83 100644
--- a/spec/ruby/core/env/shared/each.rb
+++ b/spec/ruby/core/env/shared/each.rb
@@ -25,39 +25,37 @@ describe :env_each, shared: true do
end
it_should_behave_like :enumeratorized_with_origin_size
- with_feature :encoding do
- describe "with encoding" do
- before :each do
- @external = Encoding.default_external
- @internal = Encoding.default_internal
+ describe "with encoding" do
+ before :each do
+ @external = Encoding.default_external
+ @internal = Encoding.default_internal
- Encoding.default_external = Encoding::ASCII_8BIT
+ Encoding.default_external = Encoding::ASCII_8BIT
- @locale_encoding = Encoding.find "locale"
- end
+ @locale_encoding = Encoding.find "locale"
+ end
- after :each do
- Encoding.default_external = @external
- Encoding.default_internal = @internal
- end
+ after :each do
+ Encoding.default_external = @external
+ Encoding.default_internal = @internal
+ end
- it "uses the locale encoding when Encoding.default_internal is nil" do
- Encoding.default_internal = nil
+ it "uses the locale encoding when Encoding.default_internal is nil" do
+ Encoding.default_internal = nil
- ENV.send(@method) do |key, value|
- key.encoding.should equal(@locale_encoding)
- value.encoding.should equal(@locale_encoding)
- end
+ ENV.send(@method) do |key, value|
+ key.encoding.should equal(@locale_encoding)
+ value.encoding.should equal(@locale_encoding)
end
+ end
- it "transcodes from the locale encoding to Encoding.default_internal if set" do
- Encoding.default_internal = internal = Encoding::IBM437
+ it "transcodes from the locale encoding to Encoding.default_internal if set" do
+ Encoding.default_internal = internal = Encoding::IBM437
- ENV.send(@method) do |key, value|
- key.encoding.should equal(internal)
- if value.ascii_only?
- value.encoding.should equal(internal)
- end
+ ENV.send(@method) do |key, value|
+ key.encoding.should equal(internal)
+ if value.ascii_only?
+ value.encoding.should equal(internal)
end
end
end
diff --git a/spec/ruby/core/env/shift_spec.rb b/spec/ruby/core/env/shift_spec.rb
index c5ecc3641e..8a74f4ecac 100644
--- a/spec/ruby/core/env/shift_spec.rb
+++ b/spec/ruby/core/env/shift_spec.rb
@@ -24,36 +24,34 @@ describe "ENV.shift" do
end
end
-with_feature :encoding do
- describe "ENV.shift" do
- before :each do
- @orig = ENV.to_hash
- @external = Encoding.default_external
- @internal = Encoding.default_internal
-
- Encoding.default_external = Encoding::ASCII_8BIT
- end
+describe "ENV.shift" do
+ before :each do
+ @orig = ENV.to_hash
+ @external = Encoding.default_external
+ @internal = Encoding.default_internal
- after :each do
- Encoding.default_external = @external
- Encoding.default_internal = @internal
- ENV.replace @orig
- end
+ Encoding.default_external = Encoding::ASCII_8BIT
+ end
- it "uses the locale encoding if Encoding.default_internal is nil" do
- Encoding.default_internal = nil
+ after :each do
+ Encoding.default_external = @external
+ Encoding.default_internal = @internal
+ ENV.replace @orig
+ end
- pair = ENV.shift
- pair.first.encoding.should equal(Encoding.find("locale"))
- pair.last.encoding.should equal(Encoding.find("locale"))
- end
+ it "uses the locale encoding if Encoding.default_internal is nil" do
+ Encoding.default_internal = nil
- it "transcodes from the locale encoding to Encoding.default_internal if set" do
- Encoding.default_internal = Encoding::IBM437
+ pair = ENV.shift
+ pair.first.encoding.should equal(Encoding.find("locale"))
+ pair.last.encoding.should equal(Encoding.find("locale"))
+ end
- pair = ENV.shift
- pair.first.encoding.should equal(Encoding::IBM437)
- pair.last.encoding.should equal(Encoding::IBM437)
- end
+ it "transcodes from the locale encoding to Encoding.default_internal if set" do
+ Encoding.default_internal = Encoding::IBM437
+
+ pair = ENV.shift
+ pair.first.encoding.should equal(Encoding::IBM437)
+ pair.last.encoding.should equal(Encoding::IBM437)
end
end
diff --git a/spec/ruby/core/fiber/new_spec.rb b/spec/ruby/core/fiber/new_spec.rb
index 734db0682e..c2175cb612 100644
--- a/spec/ruby/core/fiber/new_spec.rb
+++ b/spec/ruby/core/fiber/new_spec.rb
@@ -1,41 +1,39 @@
require_relative '../../spec_helper'
-with_feature :fiber do
- describe "Fiber.new" do
- it "creates a fiber from the given block" do
- fiber = Fiber.new {}
- fiber.resume
- fiber.should be_an_instance_of(Fiber)
- end
+describe "Fiber.new" do
+ it "creates a fiber from the given block" do
+ fiber = Fiber.new {}
+ fiber.resume
+ fiber.should be_an_instance_of(Fiber)
+ end
- it "creates a fiber from a subclass" do
- class MyFiber < Fiber
- end
- fiber = MyFiber.new {}
- fiber.resume
- fiber.should be_an_instance_of(MyFiber)
+ it "creates a fiber from a subclass" do
+ class MyFiber < Fiber
end
+ fiber = MyFiber.new {}
+ fiber.resume
+ fiber.should be_an_instance_of(MyFiber)
+ end
- it "raises an ArgumentError if called without a block" do
- lambda { Fiber.new }.should raise_error(ArgumentError)
- end
+ it "raises an ArgumentError if called without a block" do
+ lambda { Fiber.new }.should raise_error(ArgumentError)
+ end
- it "does not invoke the block" do
- invoked = false
- fiber = Fiber.new { invoked = true }
- invoked.should be_false
- fiber.resume
- end
+ it "does not invoke the block" do
+ invoked = false
+ fiber = Fiber.new { invoked = true }
+ invoked.should be_false
+ fiber.resume
+ end
- it "closes over lexical environments" do
- o = Object.new
- def o.f
- a = 1
- f = Fiber.new { a = 2 }
- f.resume
- a
- end
- o.f.should == 2
+ it "closes over lexical environments" do
+ o = Object.new
+ def o.f
+ a = 1
+ f = Fiber.new { a = 2 }
+ f.resume
+ a
end
+ o.f.should == 2
end
end
diff --git a/spec/ruby/core/fiber/resume_spec.rb b/spec/ruby/core/fiber/resume_spec.rb
index d05e62c455..97495c5059 100644
--- a/spec/ruby/core/fiber/resume_spec.rb
+++ b/spec/ruby/core/fiber/resume_spec.rb
@@ -1,59 +1,48 @@
require_relative '../../spec_helper'
require_relative '../../shared/fiber/resume'
-with_feature :fiber do
- describe "Fiber#resume" do
- it_behaves_like :fiber_resume, :resume
+describe "Fiber#resume" do
+ it_behaves_like :fiber_resume, :resume
+end
+
+describe "Fiber#resume" do
+ it "raises a FiberError if the Fiber tries to resume itself" do
+ fiber = Fiber.new { fiber.resume }
+ -> { fiber.resume }.should raise_error(FiberError, /double resume/)
+ end
+
+ it "returns control to the calling Fiber if called from one" do
+ fiber1 = Fiber.new { :fiber1 }
+ fiber2 = Fiber.new { fiber1.resume; :fiber2 }
+ fiber2.resume.should == :fiber2
end
- describe "Fiber#resume" do
- it "raises a FiberError if the Fiber tries to resume itself" do
- fiber = Fiber.new { fiber.resume }
- -> { fiber.resume }.should raise_error(FiberError, /double resume/)
- end
-
- it "returns control to the calling Fiber if called from one" do
- fiber1 = Fiber.new { :fiber1 }
- fiber2 = Fiber.new { fiber1.resume; :fiber2 }
- fiber2.resume.should == :fiber2
- end
-
- with_feature :fork do
- # Redmine #595
- it "executes the ensure clause" do
- rd, wr = IO.pipe
-
- pid = Kernel::fork do
- rd.close
- f = Fiber.new do
- begin
- Fiber.yield
- ensure
- wr.write "executed"
- end
- end
-
- # The apparent issue is that when Fiber.yield executes, control
- # "leaves" the "ensure block" and so the ensure clause should run. But
- # control really does NOT leave the ensure block when Fiber.yield
- # executes. It merely pauses there. To require ensure to run when a
- # Fiber is suspended then makes ensure-in-a-Fiber-context different
- # than ensure-in-a-Thread-context and this would be very confusing.
- f.resume
-
- # When we execute the second #resume call, the ensure block DOES exit,
- # the ensure clause runs.
- f.resume
-
- exit 0
+ # Redmine #595
+ it "executes the ensure clause" do
+ code = <<-RUBY
+ f = Fiber.new do
+ begin
+ Fiber.yield
+ ensure
+ puts "ensure executed"
end
+ end
- wr.close
- Process.waitpid pid
+ # The apparent issue is that when Fiber.yield executes, control
+ # "leaves" the "ensure block" and so the ensure clause should run. But
+ # control really does NOT leave the ensure block when Fiber.yield
+ # executes. It merely pauses there. To require ensure to run when a
+ # Fiber is suspended then makes ensure-in-a-Fiber-context different
+ # than ensure-in-a-Thread-context and this would be very confusing.
+ f.resume
- rd.read.should == "executed"
- rd.close
- end
- end
+ # When we execute the second #resume call, the ensure block DOES exit,
+ # the ensure clause runs.
+ f.resume
+
+ exit 0
+ RUBY
+
+ ruby_exe(code).should == "ensure executed\n"
end
end
diff --git a/spec/ruby/core/fiber/yield_spec.rb b/spec/ruby/core/fiber/yield_spec.rb
index d002b29cf6..4e241d5921 100644
--- a/spec/ruby/core/fiber/yield_spec.rb
+++ b/spec/ruby/core/fiber/yield_spec.rb
@@ -1,51 +1,49 @@
require_relative '../../spec_helper'
-with_feature :fiber do
- describe "Fiber.yield" do
- it "passes control to the Fiber's caller" do
- step = 0
- fiber = Fiber.new { step = 1; Fiber.yield; step = 2; Fiber.yield; step = 3 }
- fiber.resume
- step.should == 1
- fiber.resume
- step.should == 2
- end
-
- it "returns its arguments to the caller" do
- fiber = Fiber.new { true; Fiber.yield :glark; true }
- fiber.resume.should == :glark
- fiber.resume
- end
+describe "Fiber.yield" do
+ it "passes control to the Fiber's caller" do
+ step = 0
+ fiber = Fiber.new { step = 1; Fiber.yield; step = 2; Fiber.yield; step = 3 }
+ fiber.resume
+ step.should == 1
+ fiber.resume
+ step.should == 2
+ end
- it "returns nil to the caller if given no arguments" do
- fiber = Fiber.new { true; Fiber.yield; true }
- fiber.resume.should be_nil
- fiber.resume
- end
+ it "returns its arguments to the caller" do
+ fiber = Fiber.new { true; Fiber.yield :glark; true }
+ fiber.resume.should == :glark
+ fiber.resume
+ end
- it "returns to the Fiber the value of the #resume call that invoked it" do
- fiber = Fiber.new { Fiber.yield.should == :caller }
- fiber.resume
- fiber.resume :caller
- end
+ it "returns nil to the caller if given no arguments" do
+ fiber = Fiber.new { true; Fiber.yield; true }
+ fiber.resume.should be_nil
+ fiber.resume
+ end
- it "does not propagate or reraise a rescued exception" do
- fiber = Fiber.new do
- begin
- raise "an error in a Fiber"
- rescue
- Fiber.yield :first
- end
+ it "returns to the Fiber the value of the #resume call that invoked it" do
+ fiber = Fiber.new { Fiber.yield.should == :caller }
+ fiber.resume
+ fiber.resume :caller
+ end
- :second
+ it "does not propagate or reraise a rescued exception" do
+ fiber = Fiber.new do
+ begin
+ raise "an error in a Fiber"
+ rescue
+ Fiber.yield :first
end
- fiber.resume.should == :first
- fiber.resume.should == :second
+ :second
end
- it "raises a FiberError if called from the root Fiber" do
- lambda{ Fiber.yield }.should raise_error(FiberError)
- end
+ fiber.resume.should == :first
+ fiber.resume.should == :second
+ end
+
+ it "raises a FiberError if called from the root Fiber" do
+ lambda{ Fiber.yield }.should raise_error(FiberError)
end
end
diff --git a/spec/ruby/core/file/basename_spec.rb b/spec/ruby/core/file/basename_spec.rb
index 671955302a..50365b1125 100644
--- a/spec/ruby/core/file/basename_spec.rb
+++ b/spec/ruby/core/file/basename_spec.rb
@@ -153,18 +153,16 @@ describe "File.basename" do
end
end
- with_feature :encoding do
- it "returns the extension for a multibyte filename" do
- File.basename('/path/Офис.m4a').should == "Офис.m4a"
- end
-
- it "returns the basename with the same encoding as the original" do
- basename = File.basename('C:/Users/Scuby Pagrubý'.encode(Encoding::Windows_1250))
- basename.should == 'Scuby Pagrubý'.encode(Encoding::Windows_1250)
- basename.encoding.should == Encoding::Windows_1250
- end
+ it "returns the extension for a multibyte filename" do
+ File.basename('/path/Офис.m4a').should == "Офис.m4a"
+ end
+ it "returns the basename with the same encoding as the original" do
+ basename = File.basename('C:/Users/Scuby Pagrubý'.encode(Encoding::Windows_1250))
+ basename.should == 'Scuby Pagrubý'.encode(Encoding::Windows_1250)
+ basename.encoding.should == Encoding::Windows_1250
end
+
end
diff --git a/spec/ruby/core/file/expand_path_spec.rb b/spec/ruby/core/file/expand_path_spec.rb
index 5bb60d2c23..90aa44e2c4 100644
--- a/spec/ruby/core/file/expand_path_spec.rb
+++ b/spec/ruby/core/file/expand_path_spec.rb
@@ -19,14 +19,12 @@ describe "File.expand_path" do
end
end
- with_feature :encoding do
- before :each do
- @external = Encoding.default_external
- end
+ before :each do
+ @external = Encoding.default_external
+ end
- after :each do
- Encoding.default_external = @external
- end
+ after :each do
+ Encoding.default_external = @external
end
it "converts a pathname to an absolute pathname" do
@@ -136,34 +134,32 @@ describe "File.expand_path" do
end
end
- with_feature :encoding do
- it "returns a String in the same encoding as the argument" do
- Encoding.default_external = Encoding::SHIFT_JIS
+ it "returns a String in the same encoding as the argument" do
+ Encoding.default_external = Encoding::SHIFT_JIS
- path = "./a".force_encoding Encoding::CP1251
- File.expand_path(path).encoding.should equal(Encoding::CP1251)
+ path = "./a".force_encoding Encoding::CP1251
+ File.expand_path(path).encoding.should equal(Encoding::CP1251)
- weird_path = [222, 173, 190, 175].pack('C*')
- File.expand_path(weird_path).encoding.should equal(Encoding::ASCII_8BIT)
- end
+ weird_path = [222, 173, 190, 175].pack('C*')
+ File.expand_path(weird_path).encoding.should equal(Encoding::ASCII_8BIT)
+ end
- platform_is_not :windows do
- it "expands a path when the default external encoding is ASCII-8BIT" do
- Encoding.default_external = Encoding::ASCII_8BIT
- path_8bit = [222, 173, 190, 175].pack('C*')
- File.expand_path( path_8bit, @rootdir).should == "#{@rootdir}" + path_8bit
- end
+ platform_is_not :windows do
+ it "expands a path when the default external encoding is ASCII-8BIT" do
+ Encoding.default_external = Encoding::ASCII_8BIT
+ path_8bit = [222, 173, 190, 175].pack('C*')
+ File.expand_path( path_8bit, @rootdir).should == "#{@rootdir}" + path_8bit
end
+ end
- it "expands a path with multi-byte characters" do
- File.expand_path("Ångström").should == "#{@base}/Ångström"
- end
+ it "expands a path with multi-byte characters" do
+ File.expand_path("Ångström").should == "#{@base}/Ångström"
+ end
- platform_is_not :windows do
- it "raises an Encoding::CompatibilityError if the external encoding is not compatible" do
- Encoding.default_external = Encoding::UTF_16BE
- lambda { File.expand_path("./a") }.should raise_error(Encoding::CompatibilityError)
- end
+ platform_is_not :windows do
+ it "raises an Encoding::CompatibilityError if the external encoding is not compatible" do
+ Encoding.default_external = Encoding::UTF_16BE
+ lambda { File.expand_path("./a") }.should raise_error(Encoding::CompatibilityError)
end
end
diff --git a/spec/ruby/core/file/extname_spec.rb b/spec/ruby/core/file/extname_spec.rb
index 1513b30e90..7632b6adc0 100644
--- a/spec/ruby/core/file/extname_spec.rb
+++ b/spec/ruby/core/file/extname_spec.rb
@@ -44,11 +44,9 @@ describe "File.extname" do
lambda { File.extname("foo.bar", "foo.baz") }.should raise_error(ArgumentError)
end
- with_feature :encoding do
-
- it "returns the extension for a multibyte filename" do
- File.extname('Имя.m4a').should == ".m4a"
- end
+ it "returns the extension for a multibyte filename" do
+ File.extname('Имя.m4a').should == ".m4a"
end
+
end
diff --git a/spec/ruby/core/file/open_spec.rb b/spec/ruby/core/file/open_spec.rb
index 9e98d3d88a..14be5aa32a 100644
--- a/spec/ruby/core/file/open_spec.rb
+++ b/spec/ruby/core/file/open_spec.rb
@@ -165,23 +165,6 @@ describe "File.open" do
File.exist?(@file).should == true
end
- without_feature :mjit do # [ruby-core:90895] MJIT worker may leave fd open in a forked child. TODO: consider acquiring GVL from MJIT worker.
- it "opens a file with a file descriptor d and a block" do
- @fh = File.open(@file)
- @fh.should be_kind_of(File)
-
- lambda {
- File.open(@fh.fileno) do |fh|
- @fd = fh.fileno
- @fh.close
- end
- }.should raise_error(Errno::EBADF)
- lambda { File.open(@fd) }.should raise_error(Errno::EBADF)
-
- File.exist?(@file).should == true
- end
- end
-
it "opens a file that no exists when use File::WRONLY mode" do
lambda { File.open(@nonexistent, File::WRONLY) }.should raise_error(Errno::ENOENT)
end
@@ -673,7 +656,7 @@ describe "File.open when passed a file descriptor" do
before do
@content = "File#open when passed a file descriptor"
@name = tmp("file_open_with_fd.txt")
- @fd = new_fd @name, fmode("w:utf-8")
+ @fd = new_fd @name, "w:utf-8"
@file = nil
end
diff --git a/spec/ruby/core/file/shared/path.rb b/spec/ruby/core/file/shared/path.rb
index 503e485f1e..9df3416c89 100644
--- a/spec/ruby/core/file/shared/path.rb
+++ b/spec/ruby/core/file/shared/path.rb
@@ -44,12 +44,10 @@ describe :file_path, shared: true do
end
end
- with_feature :encoding do
- it "preserves the encoding of the path" do
- path = @path.force_encoding("euc-jp")
- @file = File.new path
- @file.send(@method).encoding.should == Encoding.find("euc-jp")
- end
+ it "preserves the encoding of the path" do
+ path = @path.force_encoding("euc-jp")
+ @file = File.new path
+ @file.send(@method).encoding.should == Encoding.find("euc-jp")
end
ruby_version_is "2.5" do
diff --git a/spec/ruby/core/float/to_s_spec.rb b/spec/ruby/core/float/to_s_spec.rb
index db375bfc0e..ad04bc4fb6 100644
--- a/spec/ruby/core/float/to_s_spec.rb
+++ b/spec/ruby/core/float/to_s_spec.rb
@@ -289,24 +289,22 @@ describe "Float#to_s" do
end
end
-with_feature :encoding do
- describe "Float#to_s" do
- before :each do
- @internal = Encoding.default_internal
- end
+describe "Float#to_s" do
+ before :each do
+ @internal = Encoding.default_internal
+ end
- after :each do
- Encoding.default_internal = @internal
- end
+ after :each do
+ Encoding.default_internal = @internal
+ end
- it "returns a String in US-ASCII encoding when Encoding.default_internal is nil" do
- Encoding.default_internal = nil
- 1.23.to_s.encoding.should equal(Encoding::US_ASCII)
- end
+ it "returns a String in US-ASCII encoding when Encoding.default_internal is nil" do
+ Encoding.default_internal = nil
+ 1.23.to_s.encoding.should equal(Encoding::US_ASCII)
+ end
- it "returns a String in US-ASCII encoding when Encoding.default_internal is not nil" do
- Encoding.default_internal = Encoding::IBM437
- 5.47.to_s.encoding.should equal(Encoding::US_ASCII)
- end
+ it "returns a String in US-ASCII encoding when Encoding.default_internal is not nil" do
+ Encoding.default_internal = Encoding::IBM437
+ 5.47.to_s.encoding.should equal(Encoding::US_ASCII)
end
end
diff --git a/spec/ruby/core/integer/to_s_spec.rb b/spec/ruby/core/integer/to_s_spec.rb
index c980be535a..687dc9d18f 100644
--- a/spec/ruby/core/integer/to_s_spec.rb
+++ b/spec/ruby/core/integer/to_s_spec.rb
@@ -29,24 +29,22 @@ describe "Integer#to_s" do
end
end
- with_feature :encoding do
- before :each do
- @internal = Encoding.default_internal
- end
+ before :each do
+ @internal = Encoding.default_internal
+ end
- after :each do
- Encoding.default_internal = @internal
- end
+ after :each do
+ Encoding.default_internal = @internal
+ end
- it "returns a String in US-ASCII encoding when Encoding.default_internal is nil" do
- Encoding.default_internal = nil
- 1.to_s.encoding.should equal(Encoding::US_ASCII)
- end
+ it "returns a String in US-ASCII encoding when Encoding.default_internal is nil" do
+ Encoding.default_internal = nil
+ 1.to_s.encoding.should equal(Encoding::US_ASCII)
+ end
- it "returns a String in US-ASCII encoding when Encoding.default_internal is not nil" do
- Encoding.default_internal = Encoding::IBM437
- 1.to_s.encoding.should equal(Encoding::US_ASCII)
- end
+ it "returns a String in US-ASCII encoding when Encoding.default_internal is not nil" do
+ Encoding.default_internal = Encoding::IBM437
+ 1.to_s.encoding.should equal(Encoding::US_ASCII)
end
end
@@ -76,24 +74,22 @@ describe "Integer#to_s" do
end
end
- with_feature :encoding do
- before :each do
- @internal = Encoding.default_internal
- end
+ before :each do
+ @internal = Encoding.default_internal
+ end
- after :each do
- Encoding.default_internal = @internal
- end
+ after :each do
+ Encoding.default_internal = @internal
+ end
- it "returns a String in US-ASCII encoding when Encoding.default_internal is nil" do
- Encoding.default_internal = nil
- bignum_value.to_s.encoding.should equal(Encoding::US_ASCII)
- end
+ it "returns a String in US-ASCII encoding when Encoding.default_internal is nil" do
+ Encoding.default_internal = nil
+ bignum_value.to_s.encoding.should equal(Encoding::US_ASCII)
+ end
- it "returns a String in US-ASCII encoding when Encoding.default_internal is not nil" do
- Encoding.default_internal = Encoding::IBM437
- bignum_value.to_s.encoding.should equal(Encoding::US_ASCII)
- end
+ it "returns a String in US-ASCII encoding when Encoding.default_internal is not nil" do
+ Encoding.default_internal = Encoding::IBM437
+ bignum_value.to_s.encoding.should equal(Encoding::US_ASCII)
end
end
end
diff --git a/spec/ruby/core/io/external_encoding_spec.rb b/spec/ruby/core/io/external_encoding_spec.rb
index e625484670..3581019207 100644
--- a/spec/ruby/core/io/external_encoding_spec.rb
+++ b/spec/ruby/core/io/external_encoding_spec.rb
@@ -1,218 +1,216 @@
require_relative '../../spec_helper'
-with_feature :encoding do
- describe :io_external_encoding_write, shared: true do
+describe :io_external_encoding_write, shared: true do
+ describe "when Encoding.default_internal is nil" do
+ before :each do
+ Encoding.default_internal = nil
+ end
+
+ it "returns nil" do
+ @io = new_io @name, @object
+ Encoding.default_external = Encoding::IBM437
+ @io.external_encoding.should be_nil
+ end
+
+ it "returns the external encoding specified when the instance was created" do
+ @io = new_io @name, "#{@object}:ibm866"
+ Encoding.default_external = Encoding::IBM437
+ @io.external_encoding.should equal(Encoding::IBM866)
+ end
+
+ it "returns the encoding set by #set_encoding" do
+ @io = new_io @name, "#{@object}:ibm866"
+ @io.set_encoding Encoding::EUC_JP, nil
+ @io.external_encoding.should equal(Encoding::EUC_JP)
+ end
+ end
+
+ describe "when Encoding.default_external != Encoding.default_internal" do
+ before :each do
+ Encoding.default_external = Encoding::IBM437
+ Encoding.default_internal = Encoding::IBM866
+ end
+
+ it "returns the value of Encoding.default_external when the instance was created" do
+ @io = new_io @name, @object
+ Encoding.default_external = Encoding::UTF_8
+ @io.external_encoding.should equal(Encoding::IBM437)
+ end
+
+ it "returns the external encoding specified when the instance was created" do
+ @io = new_io @name, "#{@object}:ibm866"
+ Encoding.default_external = Encoding::IBM437
+ @io.external_encoding.should equal(Encoding::IBM866)
+ end
+
+ it "returns the encoding set by #set_encoding" do
+ @io = new_io @name, "#{@object}:ibm866"
+ @io.set_encoding Encoding::EUC_JP, nil
+ @io.external_encoding.should equal(Encoding::EUC_JP)
+ end
+ end
+
+ describe "when Encoding.default_external == Encoding.default_internal" do
+ before :each do
+ Encoding.default_external = Encoding::IBM866
+ Encoding.default_internal = Encoding::IBM866
+ end
+
+ it "returns the value of Encoding.default_external when the instance was created" do
+ @io = new_io @name, @object
+ Encoding.default_external = Encoding::UTF_8
+ @io.external_encoding.should equal(Encoding::IBM866)
+ end
+
+ it "returns the external encoding specified when the instance was created" do
+ @io = new_io @name, "#{@object}:ibm866"
+ Encoding.default_external = Encoding::IBM437
+ @io.external_encoding.should equal(Encoding::IBM866)
+ end
+
+ it "returns the encoding set by #set_encoding" do
+ @io = new_io @name, "#{@object}:ibm866"
+ @io.set_encoding Encoding::EUC_JP, nil
+ @io.external_encoding.should equal(Encoding::EUC_JP)
+ end
+ end
+end
+
+describe "IO#external_encoding" do
+ before :each do
+ @external = Encoding.default_external
+ @internal = Encoding.default_internal
+
+ @name = tmp("io_external_encoding")
+ touch(@name)
+ end
+
+ after :each do
+ Encoding.default_external = @external
+ Encoding.default_internal = @internal
+
+ @io.close if @io
+ rm_r @name
+ end
+
+ describe "with 'r' mode" do
describe "when Encoding.default_internal is nil" do
before :each do
Encoding.default_internal = nil
+ Encoding.default_external = Encoding::IBM866
end
- it "returns nil" do
- @io = new_io @name, @object
+ it "returns Encoding.default_external if the external encoding is not set" do
+ @io = new_io @name, "r"
+ @io.external_encoding.should equal(Encoding::IBM866)
+ end
+
+ it "returns Encoding.default_external when that encoding is changed after the instance is created" do
+ @io = new_io @name, "r"
Encoding.default_external = Encoding::IBM437
- @io.external_encoding.should be_nil
+ @io.external_encoding.should equal(Encoding::IBM437)
end
it "returns the external encoding specified when the instance was created" do
- @io = new_io @name, "#{@object}:ibm866"
+ @io = new_io @name, "r:utf-8"
Encoding.default_external = Encoding::IBM437
- @io.external_encoding.should equal(Encoding::IBM866)
+ @io.external_encoding.should equal(Encoding::UTF_8)
end
it "returns the encoding set by #set_encoding" do
- @io = new_io @name, "#{@object}:ibm866"
+ @io = new_io @name, "r:utf-8"
@io.set_encoding Encoding::EUC_JP, nil
@io.external_encoding.should equal(Encoding::EUC_JP)
end
end
- describe "when Encoding.default_external != Encoding.default_internal" do
+ describe "when Encoding.default_external == Encoding.default_internal" do
before :each do
- Encoding.default_external = Encoding::IBM437
+ Encoding.default_external = Encoding::IBM866
Encoding.default_internal = Encoding::IBM866
end
it "returns the value of Encoding.default_external when the instance was created" do
- @io = new_io @name, @object
- Encoding.default_external = Encoding::UTF_8
- @io.external_encoding.should equal(Encoding::IBM437)
+ @io = new_io @name, "r"
+ Encoding.default_external = Encoding::IBM437
+ @io.external_encoding.should equal(Encoding::IBM866)
end
it "returns the external encoding specified when the instance was created" do
- @io = new_io @name, "#{@object}:ibm866"
+ @io = new_io @name, "r:utf-8"
Encoding.default_external = Encoding::IBM437
- @io.external_encoding.should equal(Encoding::IBM866)
+ @io.external_encoding.should equal(Encoding::UTF_8)
end
it "returns the encoding set by #set_encoding" do
- @io = new_io @name, "#{@object}:ibm866"
+ @io = new_io @name, "r:utf-8"
@io.set_encoding Encoding::EUC_JP, nil
@io.external_encoding.should equal(Encoding::EUC_JP)
end
end
- describe "when Encoding.default_external == Encoding.default_internal" do
+ describe "when Encoding.default_external != Encoding.default_internal" do
before :each do
- Encoding.default_external = Encoding::IBM866
+ Encoding.default_external = Encoding::IBM437
Encoding.default_internal = Encoding::IBM866
end
- it "returns the value of Encoding.default_external when the instance was created" do
- @io = new_io @name, @object
- Encoding.default_external = Encoding::UTF_8
- @io.external_encoding.should equal(Encoding::IBM866)
- end
it "returns the external encoding specified when the instance was created" do
- @io = new_io @name, "#{@object}:ibm866"
+ @io = new_io @name, "r:utf-8"
Encoding.default_external = Encoding::IBM437
- @io.external_encoding.should equal(Encoding::IBM866)
+ @io.external_encoding.should equal(Encoding::UTF_8)
end
it "returns the encoding set by #set_encoding" do
- @io = new_io @name, "#{@object}:ibm866"
+ @io = new_io @name, "r:utf-8"
@io.set_encoding Encoding::EUC_JP, nil
@io.external_encoding.should equal(Encoding::EUC_JP)
end
end
end
- describe "IO#external_encoding" do
- before :each do
- @external = Encoding.default_external
- @internal = Encoding.default_internal
-
- @name = tmp("io_external_encoding")
- touch(@name)
- end
-
- after :each do
- Encoding.default_external = @external
- Encoding.default_internal = @internal
-
- @io.close if @io
- rm_r @name
- end
-
- describe "with 'r' mode" do
- describe "when Encoding.default_internal is nil" do
- before :each do
- Encoding.default_internal = nil
- Encoding.default_external = Encoding::IBM866
- end
-
- it "returns Encoding.default_external if the external encoding is not set" do
- @io = new_io @name, "r"
- @io.external_encoding.should equal(Encoding::IBM866)
- end
-
- it "returns Encoding.default_external when that encoding is changed after the instance is created" do
- @io = new_io @name, "r"
- Encoding.default_external = Encoding::IBM437
- @io.external_encoding.should equal(Encoding::IBM437)
- end
-
- it "returns the external encoding specified when the instance was created" do
- @io = new_io @name, "r:utf-8"
- Encoding.default_external = Encoding::IBM437
- @io.external_encoding.should equal(Encoding::UTF_8)
- end
-
- it "returns the encoding set by #set_encoding" do
- @io = new_io @name, "r:utf-8"
- @io.set_encoding Encoding::EUC_JP, nil
- @io.external_encoding.should equal(Encoding::EUC_JP)
- end
- end
-
- describe "when Encoding.default_external == Encoding.default_internal" do
- before :each do
- Encoding.default_external = Encoding::IBM866
- Encoding.default_internal = Encoding::IBM866
- end
-
- it "returns the value of Encoding.default_external when the instance was created" do
- @io = new_io @name, "r"
- Encoding.default_external = Encoding::IBM437
- @io.external_encoding.should equal(Encoding::IBM866)
- end
-
- it "returns the external encoding specified when the instance was created" do
- @io = new_io @name, "r:utf-8"
- Encoding.default_external = Encoding::IBM437
- @io.external_encoding.should equal(Encoding::UTF_8)
- end
-
- it "returns the encoding set by #set_encoding" do
- @io = new_io @name, "r:utf-8"
- @io.set_encoding Encoding::EUC_JP, nil
- @io.external_encoding.should equal(Encoding::EUC_JP)
- end
- end
-
- describe "when Encoding.default_external != Encoding.default_internal" do
- before :each do
- Encoding.default_external = Encoding::IBM437
- Encoding.default_internal = Encoding::IBM866
- end
-
-
- it "returns the external encoding specified when the instance was created" do
- @io = new_io @name, "r:utf-8"
- Encoding.default_external = Encoding::IBM437
- @io.external_encoding.should equal(Encoding::UTF_8)
- end
-
- it "returns the encoding set by #set_encoding" do
- @io = new_io @name, "r:utf-8"
- @io.set_encoding Encoding::EUC_JP, nil
- @io.external_encoding.should equal(Encoding::EUC_JP)
- end
- end
+ describe "with 'rb' mode" do
+ it "returns Encoding::ASCII_8BIT" do
+ @io = new_io @name, "rb"
+ @io.external_encoding.should equal(Encoding::ASCII_8BIT)
end
- describe "with 'rb' mode" do
- it "returns Encoding::ASCII_8BIT" do
- @io = new_io @name, "rb"
- @io.external_encoding.should equal(Encoding::ASCII_8BIT)
- end
-
- it "returns the external encoding specified by the mode argument" do
- @io = new_io @name, "rb:ibm437"
- @io.external_encoding.should equal(Encoding::IBM437)
- end
- end
-
- describe "with 'r+' mode" do
- it_behaves_like :io_external_encoding_write, nil, "r+"
+ it "returns the external encoding specified by the mode argument" do
+ @io = new_io @name, "rb:ibm437"
+ @io.external_encoding.should equal(Encoding::IBM437)
end
+ end
- describe "with 'w' mode" do
- it_behaves_like :io_external_encoding_write, nil, "w"
- end
+ describe "with 'r+' mode" do
+ it_behaves_like :io_external_encoding_write, nil, "r+"
+ end
- describe "with 'wb' mode" do
- it "returns Encoding::ASCII_8BIT" do
- @io = new_io @name, "wb"
- @io.external_encoding.should equal(Encoding::ASCII_8BIT)
- end
+ describe "with 'w' mode" do
+ it_behaves_like :io_external_encoding_write, nil, "w"
+ end
- it "returns the external encoding specified by the mode argument" do
- @io = new_io @name, "wb:ibm437"
- @io.external_encoding.should equal(Encoding::IBM437)
- end
+ describe "with 'wb' mode" do
+ it "returns Encoding::ASCII_8BIT" do
+ @io = new_io @name, "wb"
+ @io.external_encoding.should equal(Encoding::ASCII_8BIT)
end
- describe "with 'w+' mode" do
- it_behaves_like :io_external_encoding_write, nil, "w+"
+ it "returns the external encoding specified by the mode argument" do
+ @io = new_io @name, "wb:ibm437"
+ @io.external_encoding.should equal(Encoding::IBM437)
end
+ end
- describe "with 'a' mode" do
- it_behaves_like :io_external_encoding_write, nil, "a"
- end
+ describe "with 'w+' mode" do
+ it_behaves_like :io_external_encoding_write, nil, "w+"
+ end
- describe "with 'a+' mode" do
- it_behaves_like :io_external_encoding_write, nil, "a+"
- end
+ describe "with 'a' mode" do
+ it_behaves_like :io_external_encoding_write, nil, "a"
+ end
+
+ describe "with 'a+' mode" do
+ it_behaves_like :io_external_encoding_write, nil, "a+"
end
end
diff --git a/spec/ruby/core/io/fixtures/classes.rb b/spec/ruby/core/io/fixtures/classes.rb
index a771e3d929..460dd62387 100644
--- a/spec/ruby/core/io/fixtures/classes.rb
+++ b/spec/ruby/core/io/fixtures/classes.rb
@@ -118,10 +118,10 @@ module IOSpecs
# Creates an IO instance for an existing fixture file. The
# file should obviously not be deleted.
- def self.io_fixture(name, options_or_mode="r:utf-8")
+ def self.io_fixture(name, mode = "r:utf-8")
path = fixture __FILE__, name
name = path if File.exist? path
- new_io name, options_or_mode
+ new_io(name, mode)
end
# Returns a closed instance of IO that was opened to reference
diff --git a/spec/ruby/core/io/foreach_spec.rb b/spec/ruby/core/io/foreach_spec.rb
index c5c1178787..c2276cf544 100644
--- a/spec/ruby/core/io/foreach_spec.rb
+++ b/spec/ruby/core/io/foreach_spec.rb
@@ -24,7 +24,7 @@ describe "IO.foreach" do
ScratchPad.recorded.should == ["hello\n", "line2\n"]
end
- with_feature :fork do
+ platform_is_not :windows do
it "gets data from a fork when passed -" do
parent_pid = $$
diff --git a/spec/ruby/core/io/gets_spec.rb b/spec/ruby/core/io/gets_spec.rb
index 525c7547cd..ac763f2a13 100644
--- a/spec/ruby/core/io/gets_spec.rb
+++ b/spec/ruby/core/io/gets_spec.rb
@@ -156,11 +156,11 @@ describe "IO#gets" do
end
it "raises an IOError if the stream is opened for append only" do
- lambda { File.open(@name, fmode("a:utf-8")) { |f| f.gets } }.should raise_error(IOError)
+ lambda { File.open(@name, "a:utf-8") { |f| f.gets } }.should raise_error(IOError)
end
it "raises an IOError if the stream is opened for writing only" do
- lambda { File.open(@name, fmode("w:utf-8")) { |f| f.gets } }.should raise_error(IOError)
+ lambda { File.open(@name, "w:utf-8") { |f| f.gets } }.should raise_error(IOError)
end
end
@@ -168,7 +168,7 @@ describe "IO#gets" do
before :each do
@name = tmp("io_gets")
touch(@name) { |f| f.write "one\n\ntwo\n\nthree\nfour\n" }
- @io = new_io @name, fmode("r:utf-8")
+ @io = new_io @name, "r:utf-8"
end
after :each do
@@ -232,7 +232,7 @@ describe "IO#gets" do
# create data "朝日" + "\xE3\x81" * 100 to avoid utf-8 conflicts
data = "朝日" + ([227,129].pack('C*') * 100).force_encoding('utf-8')
touch(@name) { |f| f.write data }
- @io = new_io @name, fmode("r:utf-8")
+ @io = new_io @name, "r:utf-8"
end
after :each do
diff --git a/spec/ruby/core/io/initialize_spec.rb b/spec/ruby/core/io/initialize_spec.rb
index 5bf194f15c..4858e0360c 100644
--- a/spec/ruby/core/io/initialize_spec.rb
+++ b/spec/ruby/core/io/initialize_spec.rb
@@ -13,26 +13,18 @@ describe "IO#initialize" do
rm_r @name
end
- # File descriptor numbers are not predictable in multi-threaded code;
- # MJIT will be opening/closing files the background
- without_feature :mjit do
- it "reassociates the IO instance with the new descriptor when passed a Fixnum" do
- fd = new_fd @name, "r:utf-8"
- @io.send :initialize, fd, 'r'
- @io.fileno.should == fd
- # initialize has closed the old descriptor
- lambda { IO.for_fd(@fd).close }.should raise_error(Errno::EBADF)
- end
-
- it "calls #to_int to coerce the object passed as an fd" do
- obj = mock('fileno')
- fd = new_fd @name, "r:utf-8"
- obj.should_receive(:to_int).and_return(fd)
- @io.send :initialize, obj, 'r'
- @io.fileno.should == fd
- # initialize has closed the old descriptor
- lambda { IO.for_fd(@fd).close }.should raise_error(Errno::EBADF)
- end
+ it "reassociates the IO instance with the new descriptor when passed a Fixnum" do
+ fd = new_fd @name, "r:utf-8"
+ @io.send :initialize, fd, 'r'
+ @io.fileno.should == fd
+ end
+
+ it "calls #to_int to coerce the object passed as an fd" do
+ obj = mock('fileno')
+ fd = new_fd @name, "r:utf-8"
+ obj.should_receive(:to_int).and_return(fd)
+ @io.send :initialize, obj, 'r'
+ @io.fileno.should == fd
end
it "raises a TypeError when passed an IO" do
diff --git a/spec/ruby/core/io/internal_encoding_spec.rb b/spec/ruby/core/io/internal_encoding_spec.rb
index a4f13fa100..772cdeeaaf 100644
--- a/spec/ruby/core/io/internal_encoding_spec.rb
+++ b/spec/ruby/core/io/internal_encoding_spec.rb
@@ -1,140 +1,138 @@
require_relative '../../spec_helper'
-with_feature :encoding do
- describe :io_internal_encoding, shared: true do
- describe "when Encoding.default_internal is not set" do
- before :each do
- Encoding.default_internal = nil
- end
-
- it "returns nil if the internal encoding is not set" do
- @io = new_io @name, @object
- @io.internal_encoding.should be_nil
- end
-
- it "returns nil if Encoding.default_internal is changed after the instance is created" do
- @io = new_io @name, @object
- Encoding.default_internal = Encoding::IBM437
- @io.internal_encoding.should be_nil
- end
-
- it "returns the value set when the instance was created" do
- @io = new_io @name, "#{@object}:utf-8:euc-jp"
- Encoding.default_internal = Encoding::IBM437
- @io.internal_encoding.should equal(Encoding::EUC_JP)
- end
-
- it "returns the value set by #set_encoding" do
- @io = new_io @name, @object
- @io.set_encoding(Encoding::US_ASCII, Encoding::IBM437)
- @io.internal_encoding.should equal(Encoding::IBM437)
- end
- end
-
- describe "when Encoding.default_internal == Encoding.default_external" do
- before :each do
- Encoding.default_external = Encoding::IBM866
- Encoding.default_internal = Encoding::IBM866
- end
-
- it "returns nil" do
- @io = new_io @name, @object
- @io.internal_encoding.should be_nil
- end
-
- it "returns nil regardless of Encoding.default_internal changes" do
- @io = new_io @name, @object
- Encoding.default_internal = Encoding::IBM437
- @io.internal_encoding.should be_nil
- end
- end
-
- describe "when Encoding.default_internal != Encoding.default_external" do
- before :each do
- Encoding.default_external = Encoding::IBM437
- Encoding.default_internal = Encoding::IBM866
- end
-
- it "returns the value of Encoding.default_internal when the instance was created if the internal encoding is not set" do
- @io = new_io @name, @object
- @io.internal_encoding.should equal(Encoding::IBM866)
- end
-
- it "does not change when Encoding.default_internal is changed" do
- @io = new_io @name, @object
- Encoding.default_internal = Encoding::IBM437
- @io.internal_encoding.should equal(Encoding::IBM866)
- end
-
- it "returns the internal encoding set when the instance was created" do
- @io = new_io @name, "#{@object}:utf-8:euc-jp"
- @io.internal_encoding.should equal(Encoding::EUC_JP)
- end
-
- it "does not change when set and Encoding.default_internal is changed" do
- @io = new_io @name, "#{@object}:utf-8:euc-jp"
- Encoding.default_internal = Encoding::IBM437
- @io.internal_encoding.should equal(Encoding::EUC_JP)
- end
-
- it "returns the value set by #set_encoding" do
- @io = new_io @name, @object
- @io.set_encoding(Encoding::US_ASCII, Encoding::IBM437)
- @io.internal_encoding.should equal(Encoding::IBM437)
- end
-
- it "returns nil when Encoding.default_external is ASCII-8BIT and the internal encoding is not set" do
- Encoding.default_external = Encoding::ASCII_8BIT
- @io = new_io @name, @object
- @io.internal_encoding.should be_nil
- end
-
- it "returns nil when the external encoding is ASCII-8BIT and the internal encoding is not set" do
- @io = new_io @name, "#{@object}:ascii-8bit"
- @io.internal_encoding.should be_nil
- end
+describe :io_internal_encoding, shared: true do
+ describe "when Encoding.default_internal is not set" do
+ before :each do
+ Encoding.default_internal = nil
+ end
+
+ it "returns nil if the internal encoding is not set" do
+ @io = new_io @name, @object
+ @io.internal_encoding.should be_nil
+ end
+
+ it "returns nil if Encoding.default_internal is changed after the instance is created" do
+ @io = new_io @name, @object
+ Encoding.default_internal = Encoding::IBM437
+ @io.internal_encoding.should be_nil
+ end
+
+ it "returns the value set when the instance was created" do
+ @io = new_io @name, "#{@object}:utf-8:euc-jp"
+ Encoding.default_internal = Encoding::IBM437
+ @io.internal_encoding.should equal(Encoding::EUC_JP)
+ end
+
+ it "returns the value set by #set_encoding" do
+ @io = new_io @name, @object
+ @io.set_encoding(Encoding::US_ASCII, Encoding::IBM437)
+ @io.internal_encoding.should equal(Encoding::IBM437)
end
end
- describe "IO#internal_encoding" do
+ describe "when Encoding.default_internal == Encoding.default_external" do
before :each do
- @external = Encoding.default_external
- @internal = Encoding.default_internal
+ Encoding.default_external = Encoding::IBM866
+ Encoding.default_internal = Encoding::IBM866
+ end
+
+ it "returns nil" do
+ @io = new_io @name, @object
+ @io.internal_encoding.should be_nil
+ end
- @name = tmp("io_internal_encoding")
- touch(@name)
+ it "returns nil regardless of Encoding.default_internal changes" do
+ @io = new_io @name, @object
+ Encoding.default_internal = Encoding::IBM437
+ @io.internal_encoding.should be_nil
end
+ end
- after :each do
- @io.close if @io
- rm_r @name
+ describe "when Encoding.default_internal != Encoding.default_external" do
+ before :each do
+ Encoding.default_external = Encoding::IBM437
+ Encoding.default_internal = Encoding::IBM866
+ end
- Encoding.default_external = @external
- Encoding.default_internal = @internal
+ it "returns the value of Encoding.default_internal when the instance was created if the internal encoding is not set" do
+ @io = new_io @name, @object
+ @io.internal_encoding.should equal(Encoding::IBM866)
end
- describe "with 'r' mode" do
- it_behaves_like :io_internal_encoding, nil, "r"
+ it "does not change when Encoding.default_internal is changed" do
+ @io = new_io @name, @object
+ Encoding.default_internal = Encoding::IBM437
+ @io.internal_encoding.should equal(Encoding::IBM866)
end
- describe "with 'r+' mode" do
- it_behaves_like :io_internal_encoding, nil, "r+"
+ it "returns the internal encoding set when the instance was created" do
+ @io = new_io @name, "#{@object}:utf-8:euc-jp"
+ @io.internal_encoding.should equal(Encoding::EUC_JP)
end
- describe "with 'w' mode" do
- it_behaves_like :io_internal_encoding, nil, "w"
+ it "does not change when set and Encoding.default_internal is changed" do
+ @io = new_io @name, "#{@object}:utf-8:euc-jp"
+ Encoding.default_internal = Encoding::IBM437
+ @io.internal_encoding.should equal(Encoding::EUC_JP)
end
- describe "with 'w+' mode" do
- it_behaves_like :io_internal_encoding, nil, "w+"
+ it "returns the value set by #set_encoding" do
+ @io = new_io @name, @object
+ @io.set_encoding(Encoding::US_ASCII, Encoding::IBM437)
+ @io.internal_encoding.should equal(Encoding::IBM437)
end
- describe "with 'a' mode" do
- it_behaves_like :io_internal_encoding, nil, "a"
+ it "returns nil when Encoding.default_external is ASCII-8BIT and the internal encoding is not set" do
+ Encoding.default_external = Encoding::ASCII_8BIT
+ @io = new_io @name, @object
+ @io.internal_encoding.should be_nil
end
- describe "with 'a+' mode" do
- it_behaves_like :io_internal_encoding, nil, "a+"
+ it "returns nil when the external encoding is ASCII-8BIT and the internal encoding is not set" do
+ @io = new_io @name, "#{@object}:ascii-8bit"
+ @io.internal_encoding.should be_nil
end
end
end
+
+describe "IO#internal_encoding" do
+ before :each do
+ @external = Encoding.default_external
+ @internal = Encoding.default_internal
+
+ @name = tmp("io_internal_encoding")
+ touch(@name)
+ end
+
+ after :each do
+ @io.close if @io
+ rm_r @name
+
+ Encoding.default_external = @external
+ Encoding.default_internal = @internal
+ end
+
+ describe "with 'r' mode" do
+ it_behaves_like :io_internal_encoding, nil, "r"
+ end
+
+ describe "with 'r+' mode" do
+ it_behaves_like :io_internal_encoding, nil, "r+"
+ end
+
+ describe "with 'w' mode" do
+ it_behaves_like :io_internal_encoding, nil, "w"
+ end
+
+ describe "with 'w+' mode" do
+ it_behaves_like :io_internal_encoding, nil, "w+"
+ end
+
+ describe "with 'a' mode" do
+ it_behaves_like :io_internal_encoding, nil, "a"
+ end
+
+ describe "with 'a+' mode" do
+ it_behaves_like :io_internal_encoding, nil, "a+"
+ end
+end
diff --git a/spec/ruby/core/io/popen_spec.rb b/spec/ruby/core/io/popen_spec.rb
index d15ac48fe4..289bb076e4 100644
--- a/spec/ruby/core/io/popen_spec.rb
+++ b/spec/ruby/core/io/popen_spec.rb
@@ -136,7 +136,7 @@ describe "IO.popen" do
end
end
- with_feature :fork do
+ platform_is_not :windows do
it "starts returns a forked process if the command is -" do
io = IO.popen("-")
@@ -153,22 +153,20 @@ describe "IO.popen" do
end
end
- with_feature :encoding do
- it "has the given external encoding" do
- @io = IO.popen(ruby_cmd('exit'), external_encoding: Encoding::EUC_JP)
- @io.external_encoding.should == Encoding::EUC_JP
- end
+ it "has the given external encoding" do
+ @io = IO.popen(ruby_cmd('exit'), external_encoding: Encoding::EUC_JP)
+ @io.external_encoding.should == Encoding::EUC_JP
+ end
- it "has the given internal encoding" do
- @io = IO.popen(ruby_cmd('exit'), internal_encoding: Encoding::EUC_JP)
- @io.internal_encoding.should == Encoding::EUC_JP
- end
+ it "has the given internal encoding" do
+ @io = IO.popen(ruby_cmd('exit'), internal_encoding: Encoding::EUC_JP)
+ @io.internal_encoding.should == Encoding::EUC_JP
+ end
- it "sets the internal encoding to nil if it's the same as the external encoding" do
- @io = IO.popen(ruby_cmd('exit'), external_encoding: Encoding::EUC_JP,
- internal_encoding: Encoding::EUC_JP)
- @io.internal_encoding.should be_nil
- end
+ it "sets the internal encoding to nil if it's the same as the external encoding" do
+ @io = IO.popen(ruby_cmd('exit'), external_encoding: Encoding::EUC_JP,
+ internal_encoding: Encoding::EUC_JP)
+ @io.internal_encoding.should be_nil
end
context "with a leading ENV Hash" do
diff --git a/spec/ruby/core/io/puts_spec.rb b/spec/ruby/core/io/puts_spec.rb
index e99cffb00f..e8d599730f 100644
--- a/spec/ruby/core/io/puts_spec.rb
+++ b/spec/ruby/core/io/puts_spec.rb
@@ -114,28 +114,26 @@ describe "IO#puts" do
lambda { IOSpecs.closed_io.puts("stuff") }.should raise_error(IOError)
end
- with_feature :encoding do
- it "writes crlf when IO is opened with newline: :crlf" do
- File.open(@name, 'wt', newline: :crlf) do |file|
- file.puts
- end
- File.binread(@name).should == "\r\n"
+ it "writes crlf when IO is opened with newline: :crlf" do
+ File.open(@name, 'wt', newline: :crlf) do |file|
+ file.puts
end
+ File.binread(@name).should == "\r\n"
+ end
- it "writes cr when IO is opened with newline: :cr" do
- File.open(@name, 'wt', newline: :cr) do |file|
- file.puts
- end
- File.binread(@name).should == "\r"
+ it "writes cr when IO is opened with newline: :cr" do
+ File.open(@name, 'wt', newline: :cr) do |file|
+ file.puts
end
+ File.binread(@name).should == "\r"
+ end
- platform_is_not :windows do # https://bugs.ruby-lang.org/issues/12436
- it "writes lf when IO is opened with newline: :lf" do
- File.open(@name, 'wt', newline: :lf) do |file|
- file.puts
- end
- File.binread(@name).should == "\n"
+ platform_is_not :windows do # https://bugs.ruby-lang.org/issues/12436
+ it "writes lf when IO is opened with newline: :lf" do
+ File.open(@name, 'wt', newline: :lf) do |file|
+ file.puts
end
+ File.binread(@name).should == "\n"
end
end
end
diff --git a/spec/ruby/core/io/read_spec.rb b/spec/ruby/core/io/read_spec.rb
index 6f6713d957..ccb341a1f9 100644
--- a/spec/ruby/core/io/read_spec.rb
+++ b/spec/ruby/core/io/read_spec.rb
@@ -95,16 +95,14 @@ describe "IO.read" do
lambda { IO.read @fname, -1, -1 }.should raise_error(Errno::EINVAL)
end
- with_feature :encoding do
- it "uses the external encoding specified via the :external_encoding option" do
- str = IO.read(@fname, external_encoding: Encoding::ISO_8859_1)
- str.encoding.should == Encoding::ISO_8859_1
- end
+ it "uses the external encoding specified via the :external_encoding option" do
+ str = IO.read(@fname, external_encoding: Encoding::ISO_8859_1)
+ str.encoding.should == Encoding::ISO_8859_1
+ end
- it "uses the external encoding specified via the :encoding option" do
- str = IO.read(@fname, encoding: Encoding::ISO_8859_1)
- str.encoding.should == Encoding::ISO_8859_1
- end
+ it "uses the external encoding specified via the :encoding option" do
+ str = IO.read(@fname, encoding: Encoding::ISO_8859_1)
+ str.encoding.should == Encoding::ISO_8859_1
end
end
@@ -117,7 +115,7 @@ describe "IO.read from a pipe" do
IO.read(cmd).should == "hello\n"
end
- with_feature :fork do
+ platform_is_not :windows do
it "opens a pipe to a fork if the rest is -" do
str = IO.read("|-")
if str # parent
@@ -456,135 +454,133 @@ describe "IO.read with BOM" do
end
end
-with_feature :encoding do
- describe :io_read_internal_encoding, shared: true do
- it "returns a transcoded String" do
- @io.read.should == "ありがとう\n"
+describe :io_read_internal_encoding, shared: true do
+ it "returns a transcoded String" do
+ @io.read.should == "ありがとう\n"
+ end
+
+ it "sets the String encoding to the internal encoding" do
+ @io.read.encoding.should equal(Encoding::UTF_8)
+ end
+
+ describe "when passed nil for limit" do
+ it "sets the buffer to a transcoded String" do
+ result = @io.read(nil, buf = "")
+ buf.should equal(result)
+ buf.should == "ありがとう\n"
end
- it "sets the String encoding to the internal encoding" do
- @io.read.encoding.should equal(Encoding::UTF_8)
+ it "sets the buffer's encoding to the internal encoding" do
+ buf = "".force_encoding Encoding::ISO_8859_1
+ @io.read(nil, buf)
+ buf.encoding.should equal(Encoding::UTF_8)
end
+ end
+end
- describe "when passed nil for limit" do
- it "sets the buffer to a transcoded String" do
- result = @io.read(nil, buf = "")
- buf.should equal(result)
- buf.should == "ありがとう\n"
- end
+describe :io_read_size_internal_encoding, shared: true do
+ it "reads bytes when passed a size" do
+ @io.read(2).should == [164, 162].pack('C*').force_encoding(Encoding::ASCII_8BIT)
+ end
- it "sets the buffer's encoding to the internal encoding" do
- buf = "".force_encoding Encoding::ISO_8859_1
- @io.read(nil, buf)
- buf.encoding.should equal(Encoding::UTF_8)
- end
- end
+ it "returns a String in ASCII-8BIT when passed a size" do
+ @io.read(4).encoding.should equal(Encoding::ASCII_8BIT)
end
- describe :io_read_size_internal_encoding, shared: true do
- it "reads bytes when passed a size" do
- @io.read(2).should == [164, 162].pack('C*').force_encoding(Encoding::ASCII_8BIT)
- end
+ it "does not change the buffer's encoding when passed a limit" do
+ buf = "".force_encoding Encoding::ISO_8859_1
+ @io.read(4, buf)
+ buf.should == [164, 162, 164, 234].pack('C*').force_encoding(Encoding::ISO_8859_1)
+ buf.encoding.should equal(Encoding::ISO_8859_1)
+ end
- it "returns a String in ASCII-8BIT when passed a size" do
- @io.read(4).encoding.should equal(Encoding::ASCII_8BIT)
- end
+ it "truncates the buffer but does not change the buffer's encoding when no data remains" do
+ buf = "abc".force_encoding Encoding::ISO_8859_1
+ @io.read
- it "does not change the buffer's encoding when passed a limit" do
- buf = "".force_encoding Encoding::ISO_8859_1
- @io.read(4, buf)
- buf.should == [164, 162, 164, 234].pack('C*').force_encoding(Encoding::ISO_8859_1)
- buf.encoding.should equal(Encoding::ISO_8859_1)
+ @io.read(1, buf).should be_nil
+ buf.size.should == 0
+ buf.encoding.should equal(Encoding::ISO_8859_1)
+ end
+end
+
+describe "IO#read" do
+ describe "when IO#external_encoding and IO#internal_encoding are nil" do
+ before :each do
+ @name = tmp("io_read.txt")
+ touch(@name) { |f| f.write "\x00\x01\x02" }
+ @io = new_io @name, "r+"
end
- it "truncates the buffer but does not change the buffer's encoding when no data remains" do
- buf = "abc".force_encoding Encoding::ISO_8859_1
- @io.read
+ after :each do
+ @io.close if @io
+ rm_r @name
+ end
- @io.read(1, buf).should be_nil
- buf.size.should == 0
- buf.encoding.should equal(Encoding::ISO_8859_1)
+ it "sets the String encoding to Encoding.default_external" do
+ @io.read.encoding.should equal(Encoding.default_external)
end
end
- describe "IO#read" do
- describe "when IO#external_encoding and IO#internal_encoding are nil" do
- before :each do
- @name = tmp("io_read.txt")
- touch(@name) { |f| f.write "\x00\x01\x02" }
- @io = new_io @name, "r+"
- end
+ describe "with internal encoding" do
+ after :each do
+ @io.close if @io
+ end
- after :each do
- @io.close if @io
- rm_r @name
+ describe "not specified" do
+ before :each do
+ @io = IOSpecs.io_fixture "read_euc_jp.txt", "r:euc-jp"
end
- it "sets the String encoding to Encoding.default_external" do
- @io.read.encoding.should equal(Encoding.default_external)
+ it "does not transcode the String" do
+ @io.read.should == ("ありがとう\n").encode(Encoding::EUC_JP)
end
- end
- describe "with internal encoding" do
- after :each do
- @io.close if @io
+ it "sets the String encoding to the external encoding" do
+ @io.read.encoding.should equal(Encoding::EUC_JP)
end
- describe "not specified" do
- before :each do
- @io = IOSpecs.io_fixture "read_euc_jp.txt", "r:euc-jp"
- end
-
- it "does not transcode the String" do
- @io.read.should == ("ありがとう\n").encode(Encoding::EUC_JP)
- end
-
- it "sets the String encoding to the external encoding" do
- @io.read.encoding.should equal(Encoding::EUC_JP)
- end
+ it_behaves_like :io_read_size_internal_encoding, nil
+ end
- it_behaves_like :io_read_size_internal_encoding, nil
+ describe "specified by open mode" do
+ before :each do
+ @io = IOSpecs.io_fixture "read_euc_jp.txt", "r:euc-jp:utf-8"
end
- describe "specified by open mode" do
- before :each do
- @io = IOSpecs.io_fixture "read_euc_jp.txt", "r:euc-jp:utf-8"
- end
+ it_behaves_like :io_read_internal_encoding, nil
+ it_behaves_like :io_read_size_internal_encoding, nil
+ end
- it_behaves_like :io_read_internal_encoding, nil
- it_behaves_like :io_read_size_internal_encoding, nil
+ describe "specified by mode: option" do
+ before :each do
+ @io = IOSpecs.io_fixture "read_euc_jp.txt", mode: "r:euc-jp:utf-8"
end
- describe "specified by mode: option" do
- before :each do
- @io = IOSpecs.io_fixture "read_euc_jp.txt", mode: "r:euc-jp:utf-8"
- end
+ it_behaves_like :io_read_internal_encoding, nil
+ it_behaves_like :io_read_size_internal_encoding, nil
+ end
- it_behaves_like :io_read_internal_encoding, nil
- it_behaves_like :io_read_size_internal_encoding, nil
+ describe "specified by internal_encoding: option" do
+ before :each do
+ options = { mode: "r",
+ internal_encoding: "utf-8",
+ external_encoding: "euc-jp" }
+ @io = IOSpecs.io_fixture "read_euc_jp.txt", options
end
- describe "specified by internal_encoding: option" do
- before :each do
- options = { mode: "r",
- internal_encoding: "utf-8",
- external_encoding: "euc-jp" }
- @io = IOSpecs.io_fixture "read_euc_jp.txt", options
- end
+ it_behaves_like :io_read_internal_encoding, nil
+ it_behaves_like :io_read_size_internal_encoding, nil
+ end
- it_behaves_like :io_read_internal_encoding, nil
- it_behaves_like :io_read_size_internal_encoding, nil
+ describe "specified by encoding: option" do
+ before :each do
+ options = { mode: "r", encoding: "euc-jp:utf-8" }
+ @io = IOSpecs.io_fixture "read_euc_jp.txt", options
end
- describe "specified by encoding: option" do
- before :each do
- options = { mode: "r", encoding: "euc-jp:utf-8" }
- @io = IOSpecs.io_fixture "read_euc_jp.txt", options
- end
-
- it_behaves_like :io_read_internal_encoding, nil
- it_behaves_like :io_read_size_internal_encoding, nil
- end
+ it_behaves_like :io_read_internal_encoding, nil
+ it_behaves_like :io_read_size_internal_encoding, nil
end
end
end
diff --git a/spec/ruby/core/io/readlines_spec.rb b/spec/ruby/core/io/readlines_spec.rb
index c1ea706b26..9e145f12f4 100644
--- a/spec/ruby/core/io/readlines_spec.rb
+++ b/spec/ruby/core/io/readlines_spec.rb
@@ -112,7 +112,7 @@ describe "IO#readlines" do
lines.should == ["hello\n", "line2\n"]
end
- with_feature :fork do
+ platform_is_not :windows do
it "gets data from a fork when passed -" do
lines = IO.readlines("|-")
@@ -139,13 +139,13 @@ describe "IO#readlines" do
it "raises an IOError if the stream is opened for append only" do
lambda do
- File.open(@name, fmode("a:utf-8")) { |f| f.readlines }
+ File.open(@name, "a:utf-8") { |f| f.readlines }
end.should raise_error(IOError)
end
it "raises an IOError if the stream is opened for write only" do
lambda do
- File.open(@name, fmode("w:utf-8")) { |f| f.readlines }
+ File.open(@name, "w:utf-8") { |f| f.readlines }
end.should raise_error(IOError)
end
end
diff --git a/spec/ruby/core/io/reopen_spec.rb b/spec/ruby/core/io/reopen_spec.rb
index 53fcc9dede..84c23472b7 100644
--- a/spec/ruby/core/io/reopen_spec.rb
+++ b/spec/ruby/core/io/reopen_spec.rb
@@ -145,23 +145,6 @@ describe "IO#reopen with a String" do
File.read(@other_name).should == "new data"
end
- # File descriptor numbers are not predictable in multi-threaded code;
- # MJIT will be opening/closing files the background
- without_feature :mjit do
- it "closes the file descriptor obtained by opening the new file" do
- @io = new_io @name, "w"
-
- @other_io = File.open @other_name, "w"
- max = @other_io.fileno
- @other_io.close
-
- @io.reopen @other_name
-
- @other_io = File.open @other_name, "w"
- @other_io.fileno.should == max
- end
- end
-
it "always resets the close-on-exec flag to true on non-STDIO objects" do
@io = new_io @name, "w"
diff --git a/spec/ruby/core/io/set_encoding_spec.rb b/spec/ruby/core/io/set_encoding_spec.rb
index 9875d64ab8..a9d783325c 100644
--- a/spec/ruby/core/io/set_encoding_spec.rb
+++ b/spec/ruby/core/io/set_encoding_spec.rb
@@ -1,193 +1,191 @@
require_relative '../../spec_helper'
-with_feature :encoding do
- describe :io_set_encoding_write, shared: true do
- it "sets the encodings to nil" do
- @io = new_io @name, "#{@object}:ibm437:ibm866"
- @io.set_encoding nil, nil
+describe :io_set_encoding_write, shared: true do
+ it "sets the encodings to nil" do
+ @io = new_io @name, "#{@object}:ibm437:ibm866"
+ @io.set_encoding nil, nil
- @io.external_encoding.should be_nil
- @io.internal_encoding.should be_nil
- end
+ @io.external_encoding.should be_nil
+ @io.internal_encoding.should be_nil
+ end
- it "prevents the encodings from changing when Encoding defaults are changed" do
- @io = new_io @name, "#{@object}:utf-8:us-ascii"
- @io.set_encoding nil, nil
+ it "prevents the encodings from changing when Encoding defaults are changed" do
+ @io = new_io @name, "#{@object}:utf-8:us-ascii"
+ @io.set_encoding nil, nil
- Encoding.default_external = Encoding::IBM437
- Encoding.default_internal = Encoding::IBM866
+ Encoding.default_external = Encoding::IBM437
+ Encoding.default_internal = Encoding::IBM866
- @io.external_encoding.should be_nil
- @io.internal_encoding.should be_nil
- end
+ @io.external_encoding.should be_nil
+ @io.internal_encoding.should be_nil
+ end
- it "sets the encodings to the current Encoding defaults" do
- @io = new_io @name, @object
+ it "sets the encodings to the current Encoding defaults" do
+ @io = new_io @name, @object
- Encoding.default_external = Encoding::IBM437
- Encoding.default_internal = Encoding::IBM866
+ Encoding.default_external = Encoding::IBM437
+ Encoding.default_internal = Encoding::IBM866
- @io.set_encoding nil, nil
+ @io.set_encoding nil, nil
- @io.external_encoding.should == Encoding::IBM437
- @io.internal_encoding.should == Encoding::IBM866
- end
+ @io.external_encoding.should == Encoding::IBM437
+ @io.internal_encoding.should == Encoding::IBM866
end
+end
- describe "IO#set_encoding when passed nil, nil" do
- before :each do
- @external = Encoding.default_external
- @internal = Encoding.default_internal
+describe "IO#set_encoding when passed nil, nil" do
+ before :each do
+ @external = Encoding.default_external
+ @internal = Encoding.default_internal
- Encoding.default_external = Encoding::UTF_8
- Encoding.default_internal = nil
+ Encoding.default_external = Encoding::UTF_8
+ Encoding.default_internal = nil
- @name = tmp('io_set_encoding.txt')
- touch(@name)
- end
+ @name = tmp('io_set_encoding.txt')
+ touch(@name)
+ end
- after :each do
- Encoding.default_external = @external
- Encoding.default_internal = @internal
+ after :each do
+ Encoding.default_external = @external
+ Encoding.default_internal = @internal
- @io.close if @io and not @io.closed?
- rm_r @name
- end
+ @io.close if @io and not @io.closed?
+ rm_r @name
+ end
- describe "with 'r' mode" do
- it "sets the encodings to the current Encoding defaults" do
- @io = new_io @name, "r"
+ describe "with 'r' mode" do
+ it "sets the encodings to the current Encoding defaults" do
+ @io = new_io @name, "r"
- Encoding.default_external = Encoding::IBM437
- Encoding.default_internal = Encoding::IBM866
+ Encoding.default_external = Encoding::IBM437
+ Encoding.default_internal = Encoding::IBM866
- @io.set_encoding nil, nil
- @io.external_encoding.should equal(Encoding::IBM437)
- @io.internal_encoding.should equal(Encoding::IBM866)
- end
+ @io.set_encoding nil, nil
+ @io.external_encoding.should equal(Encoding::IBM437)
+ @io.internal_encoding.should equal(Encoding::IBM866)
+ end
- it "prevents the #internal_encoding from changing when Encoding.default_internal is changed" do
- @io = new_io @name, "r"
- @io.set_encoding nil, nil
+ it "prevents the #internal_encoding from changing when Encoding.default_internal is changed" do
+ @io = new_io @name, "r"
+ @io.set_encoding nil, nil
- Encoding.default_internal = Encoding::IBM437
+ Encoding.default_internal = Encoding::IBM437
- @io.internal_encoding.should be_nil
- end
+ @io.internal_encoding.should be_nil
+ end
- it "allows the #external_encoding to change when Encoding.default_external is changed" do
- @io = new_io @name, "r"
- @io.set_encoding nil, nil
+ it "allows the #external_encoding to change when Encoding.default_external is changed" do
+ @io = new_io @name, "r"
+ @io.set_encoding nil, nil
- Encoding.default_external = Encoding::IBM437
+ Encoding.default_external = Encoding::IBM437
- @io.external_encoding.should equal(Encoding::IBM437)
- end
+ @io.external_encoding.should equal(Encoding::IBM437)
end
+ end
- describe "with 'rb' mode" do
- it "returns Encoding.default_external" do
- @io = new_io @name, "rb"
- @io.external_encoding.should equal(Encoding::ASCII_8BIT)
+ describe "with 'rb' mode" do
+ it "returns Encoding.default_external" do
+ @io = new_io @name, "rb"
+ @io.external_encoding.should equal(Encoding::ASCII_8BIT)
- @io.set_encoding nil, nil
- @io.external_encoding.should equal(Encoding.default_external)
- end
+ @io.set_encoding nil, nil
+ @io.external_encoding.should equal(Encoding.default_external)
end
+ end
- describe "with 'r+' mode" do
- it_behaves_like :io_set_encoding_write, nil, "r+"
- end
+ describe "with 'r+' mode" do
+ it_behaves_like :io_set_encoding_write, nil, "r+"
+ end
- describe "with 'w' mode" do
- it_behaves_like :io_set_encoding_write, nil, "w"
- end
+ describe "with 'w' mode" do
+ it_behaves_like :io_set_encoding_write, nil, "w"
+ end
- describe "with 'w+' mode" do
- it_behaves_like :io_set_encoding_write, nil, "w+"
- end
+ describe "with 'w+' mode" do
+ it_behaves_like :io_set_encoding_write, nil, "w+"
+ end
- describe "with 'a' mode" do
- it_behaves_like :io_set_encoding_write, nil, "a"
- end
+ describe "with 'a' mode" do
+ it_behaves_like :io_set_encoding_write, nil, "a"
+ end
- describe "with 'a+' mode" do
- it_behaves_like :io_set_encoding_write, nil, "a+"
- end
+ describe "with 'a+' mode" do
+ it_behaves_like :io_set_encoding_write, nil, "a+"
end
+end
- describe "IO#set_encoding" do
- before :each do
- @name = tmp('io_set_encoding.txt')
- touch(@name)
- @io = new_io @name
- end
+describe "IO#set_encoding" do
+ before :each do
+ @name = tmp('io_set_encoding.txt')
+ touch(@name)
+ @io = new_io @name
+ end
- after :each do
- @io.close unless @io.closed?
- rm_r @name
- end
+ after :each do
+ @io.close unless @io.closed?
+ rm_r @name
+ end
- it "returns self" do
- @io.set_encoding(Encoding::UTF_8).should equal(@io)
- end
+ it "returns self" do
+ @io.set_encoding(Encoding::UTF_8).should equal(@io)
+ end
- it "sets the external encoding when passed an Encoding argument" do
- @io.set_encoding(Encoding::UTF_8)
- @io.external_encoding.should == Encoding::UTF_8
- @io.internal_encoding.should be_nil
- end
+ it "sets the external encoding when passed an Encoding argument" do
+ @io.set_encoding(Encoding::UTF_8)
+ @io.external_encoding.should == Encoding::UTF_8
+ @io.internal_encoding.should be_nil
+ end
- it "sets the external and internal encoding when passed two Encoding arguments" do
- @io.set_encoding(Encoding::UTF_8, Encoding::UTF_16BE)
- @io.external_encoding.should == Encoding::UTF_8
- @io.internal_encoding.should == Encoding::UTF_16BE
- end
+ it "sets the external and internal encoding when passed two Encoding arguments" do
+ @io.set_encoding(Encoding::UTF_8, Encoding::UTF_16BE)
+ @io.external_encoding.should == Encoding::UTF_8
+ @io.internal_encoding.should == Encoding::UTF_16BE
+ end
- it "sets the external encoding when passed the name of an Encoding" do
- @io.set_encoding("utf-8")
- @io.external_encoding.should == Encoding::UTF_8
- @io.internal_encoding.should be_nil
- end
+ it "sets the external encoding when passed the name of an Encoding" do
+ @io.set_encoding("utf-8")
+ @io.external_encoding.should == Encoding::UTF_8
+ @io.internal_encoding.should be_nil
+ end
- it "ignores the internal encoding if the same as external when passed Encoding objects" do
- @io.set_encoding(Encoding::UTF_8, Encoding::UTF_8)
- @io.external_encoding.should == Encoding::UTF_8
- @io.internal_encoding.should be_nil
- end
+ it "ignores the internal encoding if the same as external when passed Encoding objects" do
+ @io.set_encoding(Encoding::UTF_8, Encoding::UTF_8)
+ @io.external_encoding.should == Encoding::UTF_8
+ @io.internal_encoding.should be_nil
+ end
- it "ignores the internal encoding if the same as external when passed encoding names separated by ':'" do
- @io.set_encoding("utf-8:utf-8")
- @io.external_encoding.should == Encoding::UTF_8
- @io.internal_encoding.should be_nil
- end
+ it "ignores the internal encoding if the same as external when passed encoding names separated by ':'" do
+ @io.set_encoding("utf-8:utf-8")
+ @io.external_encoding.should == Encoding::UTF_8
+ @io.internal_encoding.should be_nil
+ end
- it "sets the external and internal encoding when passed the names of Encodings separated by ':'" do
- @io.set_encoding("utf-8:utf-16be")
- @io.external_encoding.should == Encoding::UTF_8
- @io.internal_encoding.should == Encoding::UTF_16BE
- end
+ it "sets the external and internal encoding when passed the names of Encodings separated by ':'" do
+ @io.set_encoding("utf-8:utf-16be")
+ @io.external_encoding.should == Encoding::UTF_8
+ @io.internal_encoding.should == Encoding::UTF_16BE
+ end
- it "sets the external and internal encoding when passed two String arguments" do
- @io.set_encoding("utf-8", "utf-16be")
- @io.external_encoding.should == Encoding::UTF_8
- @io.internal_encoding.should == Encoding::UTF_16BE
- end
+ it "sets the external and internal encoding when passed two String arguments" do
+ @io.set_encoding("utf-8", "utf-16be")
+ @io.external_encoding.should == Encoding::UTF_8
+ @io.internal_encoding.should == Encoding::UTF_16BE
+ end
- it "calls #to_str to convert an abject to a String" do
- obj = mock("io_set_encoding")
- obj.should_receive(:to_str).and_return("utf-8:utf-16be")
- @io.set_encoding(obj)
- @io.external_encoding.should == Encoding::UTF_8
- @io.internal_encoding.should == Encoding::UTF_16BE
- end
+ it "calls #to_str to convert an abject to a String" do
+ obj = mock("io_set_encoding")
+ obj.should_receive(:to_str).and_return("utf-8:utf-16be")
+ @io.set_encoding(obj)
+ @io.external_encoding.should == Encoding::UTF_8
+ @io.internal_encoding.should == Encoding::UTF_16BE
+ end
- it "calls #to_str to convert the second argument to a String" do
- obj = mock("io_set_encoding")
- obj.should_receive(:to_str).at_least(1).times.and_return("utf-16be")
- @io.set_encoding(Encoding::UTF_8, obj)
- @io.external_encoding.should == Encoding::UTF_8
- @io.internal_encoding.should == Encoding::UTF_16BE
- end
+ it "calls #to_str to convert the second argument to a String" do
+ obj = mock("io_set_encoding")
+ obj.should_receive(:to_str).at_least(1).times.and_return("utf-16be")
+ @io.set_encoding(Encoding::UTF_8, obj)
+ @io.external_encoding.should == Encoding::UTF_8
+ @io.internal_encoding.should == Encoding::UTF_16BE
end
end
diff --git a/spec/ruby/core/io/shared/write.rb b/spec/ruby/core/io/shared/write.rb
index 3cd4f8954e..aa6b3eedeb 100644
--- a/spec/ruby/core/io/shared/write.rb
+++ b/spec/ruby/core/io/shared/write.rb
@@ -85,7 +85,11 @@ describe :io_write, shared: true do
@r.read.should == "foo"
end
- without_feature :mjit do # [ruby-core:90895] MJIT worker may leave fd open in a forked child. TODO: consider acquiring GVL from MJIT worker.
+ # [ruby-core:90895] MJIT worker may leave fd open in a forked child.
+ # For instance, MJIT creates a worker before @r.close with fork(), @r.close happens,
+ # and the MJIT worker keeps the pipe open until the worker execve().
+ # TODO: consider acquiring GVL from MJIT worker.
+ guard_not -> { defined?(RubyVM::MJIT) && RubyVM::MJIT.enabled? } do
it "raises Errno::EPIPE if the read end is closed and does not die from SIGPIPE" do
@r.close
-> { @w.send(@method, "foo") }.should raise_error(Errno::EPIPE, /Broken pipe/)
diff --git a/spec/ruby/core/io/write_spec.rb b/spec/ruby/core/io/write_spec.rb
index 50e3df864d..5fb3941505 100644
--- a/spec/ruby/core/io/write_spec.rb
+++ b/spec/ruby/core/io/write_spec.rb
@@ -28,51 +28,49 @@ describe "IO#write on a file" do
@file.write('').should == 0
end
- with_feature :encoding do
- before :each do
- @external = Encoding.default_external
- @internal = Encoding.default_internal
+ before :each do
+ @external = Encoding.default_external
+ @internal = Encoding.default_internal
- Encoding.default_external = Encoding::UTF_8
- end
+ Encoding.default_external = Encoding::UTF_8
+ end
- after :each do
- Encoding.default_external = @external
- Encoding.default_internal = @internal
- end
+ after :each do
+ Encoding.default_external = @external
+ Encoding.default_internal = @internal
+ end
- it "returns the number of bytes written" do
- @file.write("hellø").should == 6
- end
+ it "returns the number of bytes written" do
+ @file.write("hellø").should == 6
+ end
- it "uses the encoding from the given option for non-ascii encoding" do
- File.open(@filename, "w", encoding: Encoding::UTF_32LE) do |file|
- file.write("hi").should == 8
- end
- File.binread(@filename).should == "h\u0000\u0000\u0000i\u0000\u0000\u0000"
+ it "uses the encoding from the given option for non-ascii encoding" do
+ File.open(@filename, "w", encoding: Encoding::UTF_32LE) do |file|
+ file.write("hi").should == 8
end
+ File.binread(@filename).should == "h\u0000\u0000\u0000i\u0000\u0000\u0000"
+ end
- it "uses an :open_args option" do
- IO.write(@filename, 'hi', open_args: ["w", nil, {encoding: Encoding::UTF_32LE}]).should == 8
- end
+ it "uses an :open_args option" do
+ IO.write(@filename, 'hi', open_args: ["w", nil, {encoding: Encoding::UTF_32LE}]).should == 8
+ end
- it "raises a invalid byte sequence error if invalid bytes are being written" do
- # pack "\xFEhi" to avoid utf-8 conflict
- xFEhi = ([254].pack('C*') + 'hi').force_encoding('utf-8')
- File.open(@filename, "w", encoding: Encoding::US_ASCII) do |file|
- lambda { file.write(xFEhi) }.should raise_error(Encoding::InvalidByteSequenceError)
- end
+ it "raises a invalid byte sequence error if invalid bytes are being written" do
+ # pack "\xFEhi" to avoid utf-8 conflict
+ xFEhi = ([254].pack('C*') + 'hi').force_encoding('utf-8')
+ File.open(@filename, "w", encoding: Encoding::US_ASCII) do |file|
+ lambda { file.write(xFEhi) }.should raise_error(Encoding::InvalidByteSequenceError)
end
+ end
- it "writes binary data if no encoding is given" do
- File.open(@filename, "w") do |file|
- file.write('Hëllö'.encode('ISO-8859-1'))
- end
- ë = ([235].pack('U')).encode('ISO-8859-1')
- ö = ([246].pack('U')).encode('ISO-8859-1')
- res = "H#{ë}ll#{ö}"
- File.binread(@filename).should == res.force_encoding(Encoding::ASCII_8BIT)
+ it "writes binary data if no encoding is given" do
+ File.open(@filename, "w") do |file|
+ file.write('Hëllö'.encode('ISO-8859-1'))
end
+ ë = ([235].pack('U')).encode('ISO-8859-1')
+ ö = ([246].pack('U')).encode('ISO-8859-1')
+ res = "H#{ë}ll#{ö}"
+ File.binread(@filename).should == res.force_encoding(Encoding::ASCII_8BIT)
end
end
diff --git a/spec/ruby/core/kernel/chomp_spec.rb b/spec/ruby/core/kernel/chomp_spec.rb
index e6dcc07d42..d30e77c35a 100644
--- a/spec/ruby/core/kernel/chomp_spec.rb
+++ b/spec/ruby/core/kernel/chomp_spec.rb
@@ -40,28 +40,26 @@ describe "Kernel#chomp" do
it_behaves_like :kernel_chomp_private, :chomp
end
-with_feature :encoding do
- describe :kernel_chomp_encoded, shared: true do
- before :each do
- @external = Encoding.default_external
- Encoding.default_external = Encoding::UTF_8
- end
-
- after :each do
- Encoding.default_external = @external
- end
-
- it "removes the final carriage return, newline from a multi-byte $_" do
- script = fixture __FILE__, "#{@method}.rb"
- KernelSpecs.run_with_dash_n(script).should == "あれ"
- end
+describe :kernel_chomp_encoded, shared: true do
+ before :each do
+ @external = Encoding.default_external
+ Encoding.default_external = Encoding::UTF_8
end
- describe "Kernel.chomp" do
- it_behaves_like :kernel_chomp_encoded, "chomp"
+ after :each do
+ Encoding.default_external = @external
end
- describe "Kernel#chomp" do
- it_behaves_like :kernel_chomp_encoded, "chomp_f"
+ it "removes the final carriage return, newline from a multi-byte $_" do
+ script = fixture __FILE__, "#{@method}.rb"
+ KernelSpecs.run_with_dash_n(script).should == "あれ"
end
end
+
+describe "Kernel.chomp" do
+ it_behaves_like :kernel_chomp_encoded, "chomp"
+end
+
+describe "Kernel#chomp" do
+ it_behaves_like :kernel_chomp_encoded, "chomp_f"
+end
diff --git a/spec/ruby/core/kernel/chop_spec.rb b/spec/ruby/core/kernel/chop_spec.rb
index e9338d8990..9b91c011bc 100644
--- a/spec/ruby/core/kernel/chop_spec.rb
+++ b/spec/ruby/core/kernel/chop_spec.rb
@@ -28,28 +28,26 @@ describe "Kernel#chop" do
it_behaves_like :kernel_chop, "chop"
end
-with_feature :encoding do
- describe :kernel_chop_encoded, shared: true do
- before :each do
- @external = Encoding.default_external
- Encoding.default_external = Encoding::UTF_8
- end
-
- after :each do
- Encoding.default_external = @external
- end
-
- it "removes the final multi-byte character from $_" do
- script = fixture __FILE__, "#{@method}.rb"
- KernelSpecs.run_with_dash_n(script).should == "あ"
- end
+describe :kernel_chop_encoded, shared: true do
+ before :each do
+ @external = Encoding.default_external
+ Encoding.default_external = Encoding::UTF_8
end
- describe "Kernel.chop" do
- it_behaves_like :kernel_chop_encoded, "chop"
+ after :each do
+ Encoding.default_external = @external
end
- describe "Kernel#chop" do
- it_behaves_like :kernel_chop_encoded, "chop_f"
+ it "removes the final multi-byte character from $_" do
+ script = fixture __FILE__, "#{@method}.rb"
+ KernelSpecs.run_with_dash_n(script).should == "あ"
end
end
+
+describe "Kernel.chop" do
+ it_behaves_like :kernel_chop_encoded, "chop"
+end
+
+describe "Kernel#chop" do
+ it_behaves_like :kernel_chop_encoded, "chop_f"
+end
diff --git a/spec/ruby/core/marshal/dump_spec.rb b/spec/ruby/core/marshal/dump_spec.rb
index b2120ab2e6..b041a95d4b 100644
--- a/spec/ruby/core/marshal/dump_spec.rb
+++ b/spec/ruby/core/marshal/dump_spec.rb
@@ -204,26 +204,24 @@ describe "Marshal.dump" do
Marshal.dump(str.force_encoding("binary")).should == "\x04\bI\"\x00\x06:\t@foo\"\bbar"
end
- with_feature :encoding do
- it "dumps a US-ASCII String" do
- str = "abc".force_encoding("us-ascii")
- Marshal.dump(str).should == "\x04\bI\"\babc\x06:\x06EF"
- end
+ it "dumps a US-ASCII String" do
+ str = "abc".force_encoding("us-ascii")
+ Marshal.dump(str).should == "\x04\bI\"\babc\x06:\x06EF"
+ end
- it "dumps a UTF-8 String" do
- str = "\x6d\xc3\xb6\x68\x72\x65".force_encoding("utf-8")
- Marshal.dump(str).should == "\x04\bI\"\vm\xC3\xB6hre\x06:\x06ET"
- end
+ it "dumps a UTF-8 String" do
+ str = "\x6d\xc3\xb6\x68\x72\x65".force_encoding("utf-8")
+ Marshal.dump(str).should == "\x04\bI\"\vm\xC3\xB6hre\x06:\x06ET"
+ end
- it "dumps a String in another encoding" do
- str = "\x6d\x00\xf6\x00\x68\x00\x72\x00\x65\x00".force_encoding("utf-16le")
- result = "\x04\bI\"\x0Fm\x00\xF6\x00h\x00r\x00e\x00\x06:\rencoding\"\rUTF-16LE"
- Marshal.dump(str).should == result
- end
+ it "dumps a String in another encoding" do
+ str = "\x6d\x00\xf6\x00\x68\x00\x72\x00\x65\x00".force_encoding("utf-16le")
+ result = "\x04\bI\"\x0Fm\x00\xF6\x00h\x00r\x00e\x00\x06:\rencoding\"\rUTF-16LE"
+ Marshal.dump(str).should == result
+ end
- it "dumps multiple strings using symlinks for the :E (encoding) symbol" do
- Marshal.dump(["".encode("us-ascii"), "".encode("utf-8")]).should == "\x04\b[\aI\"\x00\x06:\x06EFI\"\x00\x06;\x00T"
- end
+ it "dumps multiple strings using symlinks for the :E (encoding) symbol" do
+ Marshal.dump(["".encode("us-ascii"), "".encode("utf-8")]).should == "\x04\b[\aI\"\x00\x06:\x06EFI\"\x00\x06;\x00T"
end
end
@@ -541,17 +539,15 @@ describe "Marshal.dump" do
lambda { Marshal.dump("test", obj) }.should raise_error(TypeError)
end
- with_feature :encoding do
-
- it "calls binmode when it's defined" do
- obj = mock('test')
- obj.should_receive(:write).at_least(1)
- obj.should_receive(:binmode).at_least(1)
- Marshal.dump("test", obj)
- end
+ it "calls binmode when it's defined" do
+ obj = mock('test')
+ obj.should_receive(:write).at_least(1)
+ obj.should_receive(:binmode).at_least(1)
+ Marshal.dump("test", obj)
end
+
end
describe "when passed a StringIO" do
diff --git a/spec/ruby/core/marshal/shared/load.rb b/spec/ruby/core/marshal/shared/load.rb
index 0f1d49b115..a10885346e 100644
--- a/spec/ruby/core/marshal/shared/load.rb
+++ b/spec/ruby/core/marshal/shared/load.rb
@@ -422,38 +422,36 @@ describe :marshal_load, shared: true do
str.should be_an_instance_of(UserCustomConstructorString)
end
- with_feature :encoding do
- it "loads a US-ASCII String" do
- str = "abc".force_encoding("us-ascii")
- data = "\x04\bI\"\babc\x06:\x06EF"
- result = Marshal.send(@method, data)
- result.should == str
- result.encoding.should equal(Encoding::US_ASCII)
- end
-
- it "loads a UTF-8 String" do
- str = "\x6d\xc3\xb6\x68\x72\x65".force_encoding("utf-8")
- data = "\x04\bI\"\vm\xC3\xB6hre\x06:\x06ET"
- result = Marshal.send(@method, data)
- result.should == str
- result.encoding.should equal(Encoding::UTF_8)
- end
-
- it "loads a String in another encoding" do
- str = "\x6d\x00\xf6\x00\x68\x00\x72\x00\x65\x00".force_encoding("utf-16le")
- data = "\x04\bI\"\x0Fm\x00\xF6\x00h\x00r\x00e\x00\x06:\rencoding\"\rUTF-16LE"
- result = Marshal.send(@method, data)
- result.should == str
- result.encoding.should equal(Encoding::UTF_16LE)
- end
-
- it "loads a String as ASCII-8BIT if no encoding is specified at the end" do
- str = "\xC3\xB8".force_encoding("ASCII-8BIT")
- data = "\x04\b\"\a\xC3\xB8".force_encoding("UTF-8")
- result = Marshal.send(@method, data)
- result.encoding.should == Encoding::ASCII_8BIT
- result.should == str
- end
+ it "loads a US-ASCII String" do
+ str = "abc".force_encoding("us-ascii")
+ data = "\x04\bI\"\babc\x06:\x06EF"
+ result = Marshal.send(@method, data)
+ result.should == str
+ result.encoding.should equal(Encoding::US_ASCII)
+ end
+
+ it "loads a UTF-8 String" do
+ str = "\x6d\xc3\xb6\x68\x72\x65".force_encoding("utf-8")
+ data = "\x04\bI\"\vm\xC3\xB6hre\x06:\x06ET"
+ result = Marshal.send(@method, data)
+ result.should == str
+ result.encoding.should equal(Encoding::UTF_8)
+ end
+
+ it "loads a String in another encoding" do
+ str = "\x6d\x00\xf6\x00\x68\x00\x72\x00\x65\x00".force_encoding("utf-16le")
+ data = "\x04\bI\"\x0Fm\x00\xF6\x00h\x00r\x00e\x00\x06:\rencoding\"\rUTF-16LE"
+ result = Marshal.send(@method, data)
+ result.should == str
+ result.encoding.should equal(Encoding::UTF_16LE)
+ end
+
+ it "loads a String as ASCII-8BIT if no encoding is specified at the end" do
+ str = "\xC3\xB8".force_encoding("ASCII-8BIT")
+ data = "\x04\b\"\a\xC3\xB8".force_encoding("UTF-8")
+ result = Marshal.send(@method, data)
+ result.encoding.should == Encoding::ASCII_8BIT
+ result.should == str
end
end
diff --git a/spec/ruby/core/matchdata/post_match_spec.rb b/spec/ruby/core/matchdata/post_match_spec.rb
index 43e25561af..6e13438124 100644
--- a/spec/ruby/core/matchdata/post_match_spec.rb
+++ b/spec/ruby/core/matchdata/post_match_spec.rb
@@ -22,15 +22,13 @@ describe "MatchData#post_match" do
$'.untrusted?.should be_true
end
- with_feature :encoding do
- it "sets the encoding to the encoding of the source String" do
- str = "abc".force_encoding Encoding::EUC_JP
- str.match(/b/).post_match.encoding.should equal(Encoding::EUC_JP)
- end
+ it "sets the encoding to the encoding of the source String" do
+ str = "abc".force_encoding Encoding::EUC_JP
+ str.match(/b/).post_match.encoding.should equal(Encoding::EUC_JP)
+ end
- it "sets an empty result to the encoding of the source String" do
- str = "abc".force_encoding Encoding::ISO_8859_1
- str.match(/c/).post_match.encoding.should equal(Encoding::ISO_8859_1)
- end
+ it "sets an empty result to the encoding of the source String" do
+ str = "abc".force_encoding Encoding::ISO_8859_1
+ str.match(/c/).post_match.encoding.should equal(Encoding::ISO_8859_1)
end
end
diff --git a/spec/ruby/core/matchdata/pre_match_spec.rb b/spec/ruby/core/matchdata/pre_match_spec.rb
index f71920354c..816cc91eb2 100644
--- a/spec/ruby/core/matchdata/pre_match_spec.rb
+++ b/spec/ruby/core/matchdata/pre_match_spec.rb
@@ -22,15 +22,13 @@ describe "MatchData#pre_match" do
$`.untrusted?.should be_true
end
- with_feature :encoding do
- it "sets the encoding to the encoding of the source String" do
- str = "abc".force_encoding Encoding::EUC_JP
- str.match(/b/).pre_match.encoding.should equal(Encoding::EUC_JP)
- end
+ it "sets the encoding to the encoding of the source String" do
+ str = "abc".force_encoding Encoding::EUC_JP
+ str.match(/b/).pre_match.encoding.should equal(Encoding::EUC_JP)
+ end
- it "sets an empty result to the encoding of the source String" do
- str = "abc".force_encoding Encoding::ISO_8859_1
- str.match(/a/).pre_match.encoding.should equal(Encoding::ISO_8859_1)
- end
+ it "sets an empty result to the encoding of the source String" do
+ str = "abc".force_encoding Encoding::ISO_8859_1
+ str.match(/a/).pre_match.encoding.should equal(Encoding::ISO_8859_1)
end
end
diff --git a/spec/ruby/core/objectspace/define_finalizer_spec.rb b/spec/ruby/core/objectspace/define_finalizer_spec.rb
index e2869ee706..b7e47473a0 100644
--- a/spec/ruby/core/objectspace/define_finalizer_spec.rb
+++ b/spec/ruby/core/objectspace/define_finalizer_spec.rb
@@ -3,8 +3,6 @@ require_relative 'fixtures/classes'
# NOTE: A call to define_finalizer does not guarantee that the
# passed proc or callable will be called at any particular time.
-# It is highly questionable whether these aspects of ObjectSpace
-# should be spec'd at all.
describe "ObjectSpace.define_finalizer" do
it "raises an ArgumentError if the action does not respond to call" do
lambda {
@@ -30,72 +28,41 @@ describe "ObjectSpace.define_finalizer" do
end
# see [ruby-core:24095]
- with_feature :fork do
- it "calls finalizer on process termination" do
- rd, wr = IO.pipe
- pid = Process.fork do
- rd.close
- handler = ObjectSpaceFixtures.scoped(wr)
- obj = "Test"
- ObjectSpace.define_finalizer(obj, handler)
- exit 0
+ it "calls finalizer on process termination" do
+ code = <<-RUBY
+ def scoped
+ Proc.new { puts "finalized" }
end
+ handler = scoped
+ obj = "Test"
+ ObjectSpace.define_finalizer(obj, handler)
+ exit 0
+ RUBY
- wr.close
- begin
- rd.read.should == "finalized"
- ensure
- rd.close
- Process.wait pid
- end
- end
-
- it "calls finalizer at exit even if it is self-referencing" do
- rd, wr = IO.pipe
- pid = Process.fork do
- rd.close
- obj = "Test"
- handler = Proc.new { wr.write "finalized"; wr.close }
- ObjectSpace.define_finalizer(obj, handler)
- exit 0
- end
-
- wr.close
- begin
- rd.read.should == "finalized"
- ensure
- rd.close
- Process.wait pid
- end
- end
-
- # These specs are defined under the fork specs because there is no
- # deterministic way to force finalizers to be run, except process exit, so
- # we rely on that.
- it "allows multiple finalizers with different 'callables' to be defined" do
- rd1, wr1 = IO.pipe
- rd2, wr2 = IO.pipe
+ ruby_exe(code).should == "finalized\n"
+ end
- pid = Kernel::fork do
- rd1.close
- rd2.close
- obj = mock("ObjectSpace.define_finalizer multiple")
+ it "calls finalizer at exit even if it is self-referencing" do
+ code = <<-RUBY
+ obj = "Test"
+ handler = Proc.new { puts "finalized" }
+ ObjectSpace.define_finalizer(obj, handler)
+ exit 0
+ RUBY
- ObjectSpace.define_finalizer(obj, Proc.new { wr1.write "finalized1"; wr1.close })
- ObjectSpace.define_finalizer(obj, Proc.new { wr2.write "finalized2"; wr2.close })
+ ruby_exe(code).should == "finalized\n"
+ end
- exit 0
- end
+ it "allows multiple finalizers with different 'callables' to be defined" do
+ code = <<-RUBY
+ obj = Object.new
- wr1.close
- wr2.close
+ ObjectSpace.define_finalizer(obj, Proc.new { STDOUT.write "finalized1\n" })
+ ObjectSpace.define_finalizer(obj, Proc.new { STDOUT.write "finalized2\n" })
- rd1.read.should == "finalized1"
- rd2.read.should == "finalized2"
+ exit 0
+ RUBY
- rd1.close
- rd2.close
- Process.wait pid
- end
+ ruby_exe(code).lines.sort.should == ["finalized1\n", "finalized2\n"]
end
end
diff --git a/spec/ruby/core/process/euid_spec.rb b/spec/ruby/core/process/euid_spec.rb
index bc3f52592e..ffb71a7178 100644
--- a/spec/ruby/core/process/euid_spec.rb
+++ b/spec/ruby/core/process/euid_spec.rb
@@ -33,25 +33,12 @@ describe "Process.euid=" do
as_superuser do
describe "if run by a superuser" do
- with_feature :fork do
- it "sets the effective user id for the current process if run by a superuser" do
- read, write = IO.pipe
- pid = Process.fork do
- begin
- read.close
- Process.euid = 1
- write << Process.euid
- write.close
- rescue Exception => e
- write << e << e.backtrace
- end
- Process.exit!
- end
- write.close
- euid = read.gets
- euid.should == "1"
- Process.wait pid
- end
+ it "sets the effective user id for the current process if run by a superuser" do
+ code = <<-RUBY
+ Process.euid = 1
+ puts Process.euid
+ RUBY
+ ruby_exe(code).should == "1\n"
end
end
end
diff --git a/spec/ruby/core/process/ppid_spec.rb b/spec/ruby/core/process/ppid_spec.rb
index e0bdfef30b..7d22755c77 100644
--- a/spec/ruby/core/process/ppid_spec.rb
+++ b/spec/ruby/core/process/ppid_spec.rb
@@ -1,23 +1,7 @@
require_relative '../../spec_helper'
describe "Process.ppid" do
- with_feature :fork do
- it "returns the process id of the parent of this process" do
-
- read, write = IO.pipe
-
- child_pid = Process.fork {
- read.close
- write << "#{Process.ppid}\n"
- write.close
- exit!
- }
-
- write.close
- pid = read.gets
- read.close
- Process.wait(child_pid)
- pid.to_i.should == Process.pid
- end
+ it "returns the process id of the parent of this process" do
+ ruby_exe("puts Process.ppid").should == "#{Process.pid}\n"
end
end
diff --git a/spec/ruby/core/process/setpgid_spec.rb b/spec/ruby/core/process/setpgid_spec.rb
index 992fbc3f4d..be724e9007 100644
--- a/spec/ruby/core/process/setpgid_spec.rb
+++ b/spec/ruby/core/process/setpgid_spec.rb
@@ -1,7 +1,8 @@
require_relative '../../spec_helper'
describe "Process.setpgid" do
- with_feature :fork do
+ platform_is_not :windows do
+ # Must use fork as setpgid(2) gives EACCESS after execve()
it "sets the process group id of the specified process" do
rd, wr = IO.pipe
diff --git a/spec/ruby/core/process/setsid_spec.rb b/spec/ruby/core/process/setsid_spec.rb
index d00508a1f7..c83f912066 100644
--- a/spec/ruby/core/process/setsid_spec.rb
+++ b/spec/ruby/core/process/setsid_spec.rb
@@ -1,37 +1,16 @@
require_relative '../../spec_helper'
describe "Process.setsid" do
- with_feature :fork do
+ platform_is_not :windows do
it "establishes this process as a new session and process group leader" do
- read, write = IO.pipe
- read2, write2 = IO.pipe
- pid = Process.fork {
- begin
- read.close
- write2.close
- pgid = Process.setsid
- write << pgid
- write.close
- read2.gets
- rescue Exception => e
- write << e << e.backtrace
- end
- Process.exit!
- }
- write.close
- read2.close
- pgid_child = Integer(read.gets)
- read.close
- platform_is_not :aix, :openbsd do
- # AIX does not allow Process.getsid(pid)
- # if pid is in a different session.
- pgid = Process.getsid(pid)
- pgid_child.should == pgid
- end
- write2.close
- Process.wait pid
+ sid = Process.getsid
- pgid_child.should_not == Process.getsid
+ out = ruby_exe("p Process.getsid; p Process.setsid; p Process.getsid").lines
+ out[0].should == "#{sid}\n"
+ out[1].should == out[2]
+ out[2].should_not == "#{sid}\n"
+
+ sid.should == Process.getsid
end
end
end
diff --git a/spec/ruby/core/process/uid_spec.rb b/spec/ruby/core/process/uid_spec.rb
index 4a66beaa2a..350779aff3 100644
--- a/spec/ruby/core/process/uid_spec.rb
+++ b/spec/ruby/core/process/uid_spec.rb
@@ -18,7 +18,6 @@ describe "Process.uid" do
end
describe "Process.uid=" do
-
platform_is_not :windows do
it "raises TypeError if not passed an Integer" do
lambda { Process.uid = Object.new }.should raise_error(TypeError)
@@ -36,49 +35,23 @@ describe "Process.uid=" do
as_superuser do
describe "if run by a superuser" do
- with_feature :fork do
- it "sets the real user id for the current process" do
- read, write = IO.pipe
- pid = Process.fork do
- begin
- read.close
- Process.uid = 1
- write << Process.uid
- write.close
- rescue Exception => e
- write << e << e.backtrace
- end
- Process.exit!
- end
- write.close
- uid = read.gets
- uid.should == "1"
- Process.wait pid
- end
+ it "sets the real user id for the current process" do
+ code = <<-RUBY
+ Process.uid = 1
+ puts Process.uid
+ RUBY
+ ruby_exe(code).should == "1\n"
+ end
- it "sets the real user id if preceded by Process.euid=id" do
- read, write = IO.pipe
- pid = Process.fork do
- begin
- read.close
- Process.euid = 1
- Process.uid = 1
- write << Process.uid
- write.close
- rescue Exception => e
- write << e << e.backtrace
- end
- Process.exit!
- end
- write.close
- uid = read.gets
- uid.should == "1"
- Process.wait pid
- end
+ it "sets the real user id if preceded by Process.euid=id" do
+ code = <<-RUBY
+ Process.euid = 1
+ Process.uid = 1
+ puts Process.uid
+ RUBY
+ ruby_exe(code).should == "1\n"
end
end
end
end
-
- it "needs to be reviewed for spec completeness"
end
diff --git a/spec/ruby/core/process/wait2_spec.rb b/spec/ruby/core/process/wait2_spec.rb
index 18bf4be432..4b6491ccd2 100644
--- a/spec/ruby/core/process/wait2_spec.rb
+++ b/spec/ruby/core/process/wait2_spec.rb
@@ -8,9 +8,7 @@ describe "Process.wait2" do
# but we shouldn't reap them from Ruby-space
begin
Process.wait(-1, Process::WNOHANG)
- without_feature :mjit do
- $stderr.puts "Leaked process before wait2 specs! Waiting for it"
- end
+ $stderr.puts "Leaked process before wait2 specs! Waiting for it"
leaked = Process.waitall
$stderr.puts "leaked before wait2 specs: #{leaked}" unless leaked.empty?
# Ruby-space should not see PIDs used by mjit
diff --git a/spec/ruby/core/regexp/match_spec.rb b/spec/ruby/core/regexp/match_spec.rb
index 45ed4a5932..ebbba38211 100644
--- a/spec/ruby/core/regexp/match_spec.rb
+++ b/spec/ruby/core/regexp/match_spec.rb
@@ -44,15 +44,13 @@ describe "Regexp#match" do
/(.).(.)/.match("01234", 1).captures.should == ["1", "3"]
end
- with_feature :encoding do
- it "uses the start as a character offset" do
- /(.).(.)/.match("零一二三四", 1).captures.should == ["一", "三"]
- end
-
- it "raises an ArgumentError for an invalid encoding" do
- x96 = ([150].pack('C')).force_encoding('utf-8')
- lambda { /(.).(.)/.match("Hello, #{x96} world!", 1) }.should raise_error(ArgumentError)
- end
+ it "uses the start as a character offset" do
+ /(.).(.)/.match("零一二三四", 1).captures.should == ["一", "三"]
+ end
+
+ it "raises an ArgumentError for an invalid encoding" do
+ x96 = ([150].pack('C')).force_encoding('utf-8')
+ lambda { /(.).(.)/.match("Hello, #{x96} world!", 1) }.should raise_error(ArgumentError)
end
end
@@ -61,15 +59,13 @@ describe "Regexp#match" do
/(.).(.)/.match("01234", -4).captures.should == ["1", "3"]
end
- with_feature :encoding do
- it "uses the start as a character offset" do
- /(.).(.)/.match("零一二三四", -4).captures.should == ["一", "三"]
- end
+ it "uses the start as a character offset" do
+ /(.).(.)/.match("零一二三四", -4).captures.should == ["一", "三"]
+ end
- it "raises an ArgumentError for an invalid encoding" do
- x96 = ([150].pack('C')).force_encoding('utf-8')
- lambda { /(.).(.)/.match("Hello, #{x96} world!", -1) }.should raise_error(ArgumentError)
- end
+ it "raises an ArgumentError for an invalid encoding" do
+ x96 = ([150].pack('C')).force_encoding('utf-8')
+ lambda { /(.).(.)/.match("Hello, #{x96} world!", -1) }.should raise_error(ArgumentError)
end
end
diff --git a/spec/ruby/core/string/ascii_only_spec.rb b/spec/ruby/core/string/ascii_only_spec.rb
index 3dce10fab3..e9f2dc1a36 100644
--- a/spec/ruby/core/string/ascii_only_spec.rb
+++ b/spec/ruby/core/string/ascii_only_spec.rb
@@ -2,84 +2,82 @@
require_relative '../../spec_helper'
require_relative 'fixtures/classes'
-with_feature :encoding do
- describe "String#ascii_only?" do
- describe "with ASCII only characters" do
- it "returns true if the encoding is UTF-8" do
- [ ["hello", true],
- ["hello".encode('UTF-8'), true],
- ["hello".force_encoding('UTF-8'), true],
- ].should be_computed_by(:ascii_only?)
- end
-
- it "returns true if the encoding is 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 for all single-character UTF-8 Strings" do
- 0.upto(127) do |n|
- n.chr.ascii_only?.should be_true
- end
- end
+describe "String#ascii_only?" do
+ describe "with ASCII only characters" do
+ it "returns true if the encoding is UTF-8" do
+ [ ["hello", true],
+ ["hello".encode('UTF-8'), true],
+ ["hello".force_encoding('UTF-8'), true],
+ ].should be_computed_by(:ascii_only?)
end
- describe "with non-ASCII only characters" do
- it "returns false if the encoding is ASCII-8BIT" do
- chr = 128.chr
- chr.encoding.should == Encoding::ASCII_8BIT
- chr.ascii_only?.should be_false
- end
-
- it "returns false if the String contains any non-ASCII characters" do
- [ ["\u{6666}", false],
- ["hello, \u{6666}", false],
- ["\u{6666}".encode('UTF-8'), false],
- ["\u{6666}".force_encoding('UTF-8'), false],
- ].should be_computed_by(:ascii_only?)
- end
+ it "returns true if the encoding is 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 false if the encoding is US-ASCII" do
- [ ["\u{6666}".force_encoding(Encoding::US_ASCII), false],
- ["hello, \u{6666}".force_encoding(Encoding::US_ASCII), false],
- ].should be_computed_by(:ascii_only?)
+ it "returns true for all single-character UTF-8 Strings" do
+ 0.upto(127) do |n|
+ n.chr.ascii_only?.should be_true
end
end
+ end
- it "returns true for the empty String with an ASCII-compatible encoding" do
- "".ascii_only?.should be_true
- "".encode('UTF-8').ascii_only?.should be_true
+ describe "with non-ASCII only characters" do
+ it "returns false if the encoding is ASCII-8BIT" do
+ chr = 128.chr
+ chr.encoding.should == Encoding::ASCII_8BIT
+ chr.ascii_only?.should be_false
end
- it "returns false for the empty String with a non-ASCII-compatible encoding" do
- "".force_encoding('UTF-16LE').ascii_only?.should be_false
- "".encode('UTF-16BE').ascii_only?.should be_false
+ it "returns false if the String contains any non-ASCII characters" do
+ [ ["\u{6666}", false],
+ ["hello, \u{6666}", false],
+ ["\u{6666}".encode('UTF-8'), false],
+ ["\u{6666}".force_encoding('UTF-8'), false],
+ ].should be_computed_by(:ascii_only?)
end
- it "returns false for a non-empty String with non-ASCII-compatible encoding" do
- "\x78\x00".force_encoding("UTF-16LE").ascii_only?.should be_false
+ it "returns false if the encoding is US-ASCII" do
+ [ ["\u{6666}".force_encoding(Encoding::US_ASCII), false],
+ ["hello, \u{6666}".force_encoding(Encoding::US_ASCII), false],
+ ].should be_computed_by(:ascii_only?)
end
+ end
- it "returns false when interpolating non ascii strings" do
- base = "EU currency is"
- base.force_encoding(Encoding::US_ASCII)
- euro = "\u20AC"
- interp = "#{base} #{euro}"
- euro.ascii_only?.should be_false
- base.ascii_only?.should be_true
- interp.ascii_only?.should be_false
- end
+ it "returns true for the empty String with an ASCII-compatible encoding" do
+ "".ascii_only?.should be_true
+ "".encode('UTF-8').ascii_only?.should be_true
+ end
- it "returns false after appending non ASCII characters to an empty String" do
- ("" << "λ").ascii_only?.should be_false
- end
+ it "returns false for the empty String with a non-ASCII-compatible encoding" do
+ "".force_encoding('UTF-16LE').ascii_only?.should be_false
+ "".encode('UTF-16BE').ascii_only?.should be_false
+ end
- it "returns false when concatenating an ASCII and non-ASCII String" do
- "".concat("λ").ascii_only?.should be_false
- end
+ it "returns false for a non-empty String with non-ASCII-compatible encoding" do
+ "\x78\x00".force_encoding("UTF-16LE").ascii_only?.should be_false
+ end
- it "returns false when replacing an ASCII String with a non-ASCII String" do
- "".replace("λ").ascii_only?.should be_false
- end
+ it "returns false when interpolating non ascii strings" do
+ base = "EU currency is"
+ base.force_encoding(Encoding::US_ASCII)
+ euro = "\u20AC"
+ interp = "#{base} #{euro}"
+ euro.ascii_only?.should be_false
+ base.ascii_only?.should be_true
+ interp.ascii_only?.should be_false
+ end
+
+ it "returns false after appending non ASCII characters to an empty String" do
+ ("" << "λ").ascii_only?.should be_false
+ end
+
+ it "returns false when concatenating an ASCII and non-ASCII String" do
+ "".concat("λ").ascii_only?.should be_false
+ end
+
+ it "returns false when replacing an ASCII String with a non-ASCII String" do
+ "".replace("λ").ascii_only?.should be_false
end
end
diff --git a/spec/ruby/core/string/b_spec.rb b/spec/ruby/core/string/b_spec.rb
index 6599c23d73..638971f9ce 100644
--- a/spec/ruby/core/string/b_spec.rb
+++ b/spec/ruby/core/string/b_spec.rb
@@ -2,23 +2,21 @@
require_relative '../../spec_helper'
describe "String#b" do
- with_feature :encoding do
- it "returns an ASCII-8BIT encoded string" do
- "Hello".b.should == "Hello".force_encoding(Encoding::ASCII_8BIT)
- "こんちには".b.should == "こんちには".force_encoding(Encoding::ASCII_8BIT)
- end
+ it "returns an ASCII-8BIT encoded string" do
+ "Hello".b.should == "Hello".force_encoding(Encoding::ASCII_8BIT)
+ "こんちには".b.should == "こんちには".force_encoding(Encoding::ASCII_8BIT)
+ end
- it "returns new string without modifying self" do
- str = "こんちには"
- str.b.should_not equal(str)
- str.should == "こんちには"
- end
+ it "returns new string without modifying self" do
+ str = "こんちには"
+ str.b.should_not equal(str)
+ str.should == "こんちには"
+ end
- it "copies own tainted/untrusted status to the returning value" do
- utf_8 = "こんちには".taint.untrust
- ret = utf_8.b
- ret.tainted?.should be_true
- ret.untrusted?.should be_true
- end
+ it "copies own tainted/untrusted status to the returning value" do
+ utf_8 = "こんちには".taint.untrust
+ ret = utf_8.b
+ ret.tainted?.should be_true
+ ret.untrusted?.should be_true
end
end
diff --git a/spec/ruby/core/string/bytes_spec.rb b/spec/ruby/core/string/bytes_spec.rb
index e7d3a7fbd8..96f1ae9cf2 100644
--- a/spec/ruby/core/string/bytes_spec.rb
+++ b/spec/ruby/core/string/bytes_spec.rb
@@ -36,22 +36,20 @@ describe "String#bytes" do
end
end
-with_feature :encoding do
- describe "String#bytes" do
- before :each do
- @utf8 = "東京"
- @ascii = 'Tokyo'
- @utf8_ascii = @utf8 + @ascii
- end
+describe "String#bytes" do
+ before :each do
+ @utf8 = "東京"
+ @ascii = 'Tokyo'
+ @utf8_ascii = @utf8 + @ascii
+ end
- it "agrees with #getbyte" do
- @utf8_ascii.bytes.to_a.each_with_index do |byte,index|
- byte.should == @utf8_ascii.getbyte(index)
- end
+ it "agrees with #getbyte" do
+ @utf8_ascii.bytes.to_a.each_with_index do |byte,index|
+ byte.should == @utf8_ascii.getbyte(index)
end
+ end
- it "is unaffected by #force_encoding" do
- @utf8.force_encoding('ASCII').bytes.to_a.should == @utf8.bytes.to_a
- end
+ it "is unaffected by #force_encoding" do
+ @utf8.force_encoding('ASCII').bytes.to_a.should == @utf8.bytes.to_a
end
end
diff --git a/spec/ruby/core/string/bytesize_spec.rb b/spec/ruby/core/string/bytesize_spec.rb
index 527b4a5dd5..b63d718c6c 100644
--- a/spec/ruby/core/string/bytesize_spec.rb
+++ b/spec/ruby/core/string/bytesize_spec.rb
@@ -2,36 +2,34 @@
require_relative '../../spec_helper'
require_relative 'fixtures/classes'
-with_feature :encoding do
- describe "#String#bytesize" do
- it "needs to be reviewed for spec completeness"
+describe "#String#bytesize" do
+ it "needs to be reviewed for spec completeness"
- it "returns the length of self in bytes" do
- "hello".bytesize.should == 5
- " ".bytesize.should == 1
- end
+ it "returns the length of self in bytes" do
+ "hello".bytesize.should == 5
+ " ".bytesize.should == 1
+ end
- it "works with strings containing single UTF-8 characters" do
- "\u{6666}".bytesize.should == 3
- end
+ it "works with strings containing single UTF-8 characters" do
+ "\u{6666}".bytesize.should == 3
+ end
- it "works with pseudo-ASCII strings containing single UTF-8 characters" do
- "\u{6666}".force_encoding('ASCII').bytesize.should == 3
- end
+ it "works with pseudo-ASCII strings containing single UTF-8 characters" do
+ "\u{6666}".force_encoding('ASCII').bytesize.should == 3
+ end
- it "works with strings containing UTF-8 characters" do
- "c \u{6666}".force_encoding('UTF-8').bytesize.should == 5
- "c \u{6666}".bytesize.should == 5
- end
+ it "works with strings containing UTF-8 characters" do
+ "c \u{6666}".force_encoding('UTF-8').bytesize.should == 5
+ "c \u{6666}".bytesize.should == 5
+ end
- it "works with pseudo-ASCII strings containing UTF-8 characters" do
- "c \u{6666}".force_encoding('ASCII').bytesize.should == 5
- end
+ it "works with pseudo-ASCII strings containing UTF-8 characters" do
+ "c \u{6666}".force_encoding('ASCII').bytesize.should == 5
+ end
- it "returns 0 for the empty string" do
- "".bytesize.should == 0
- "".force_encoding('ASCII').bytesize.should == 0
- "".force_encoding('UTF-8').bytesize.should == 0
- end
+ it "returns 0 for the empty string" do
+ "".bytesize.should == 0
+ "".force_encoding('ASCII').bytesize.should == 0
+ "".force_encoding('UTF-8').bytesize.should == 0
end
end
diff --git a/spec/ruby/core/string/byteslice_spec.rb b/spec/ruby/core/string/byteslice_spec.rb
index df99db95c6..a49da040eb 100644
--- a/spec/ruby/core/string/byteslice_spec.rb
+++ b/spec/ruby/core/string/byteslice_spec.rb
@@ -17,13 +17,11 @@ describe "String#byteslice with Range" do
it_behaves_like :string_slice_range, :byteslice
end
-with_feature :encoding do
- describe "String#byteslice on on non ASCII strings" do
- it "returns byteslice of unicode strings" do
- "\u3042".byteslice(1).should == "\x81".force_encoding("UTF-8")
- "\u3042".byteslice(1, 2).should == "\x81\x82".force_encoding("UTF-8")
- "\u3042".byteslice(1..2).should == "\x81\x82".force_encoding("UTF-8")
- "\u3042".byteslice(-1).should == "\x82".force_encoding("UTF-8")
- end
+describe "String#byteslice on on non ASCII strings" do
+ it "returns byteslice of unicode strings" do
+ "\u3042".byteslice(1).should == "\x81".force_encoding("UTF-8")
+ "\u3042".byteslice(1, 2).should == "\x81\x82".force_encoding("UTF-8")
+ "\u3042".byteslice(1..2).should == "\x81\x82".force_encoding("UTF-8")
+ "\u3042".byteslice(-1).should == "\x82".force_encoding("UTF-8")
end
end
diff --git a/spec/ruby/core/string/center_spec.rb b/spec/ruby/core/string/center_spec.rb
index 145db01b70..3a9e689eac 100644
--- a/spec/ruby/core/string/center_spec.rb
+++ b/spec/ruby/core/string/center_spec.rb
@@ -104,30 +104,28 @@ describe "String#center with length, padding" do
"hello".center(6, 'X'.taint).tainted?.should be_true
end
- with_feature :encoding do
- describe "with width" do
- it "returns a String in the same encoding as the original" do
- str = "abc".force_encoding Encoding::IBM437
- result = str.center 6
- result.should == " abc "
- result.encoding.should equal(Encoding::IBM437)
- end
+ describe "with width" do
+ it "returns a String in the same encoding as the original" do
+ str = "abc".force_encoding Encoding::IBM437
+ result = str.center 6
+ result.should == " abc "
+ result.encoding.should equal(Encoding::IBM437)
+ end
+ end
+
+ describe "with width, pattern" do
+ it "returns a String in the compatible encoding" do
+ str = "abc".force_encoding Encoding::IBM437
+ result = str.center 6, "あ"
+ result.should == "あabcああ"
+ result.encoding.should equal(Encoding::UTF_8)
end
- describe "with width, pattern" do
- it "returns a String in the compatible encoding" do
- str = "abc".force_encoding Encoding::IBM437
- result = str.center 6, "あ"
- result.should == "あabcああ"
- result.encoding.should equal(Encoding::UTF_8)
- end
-
- it "raises an Encoding::CompatibilityError if the encodings are incompatible" do
- pat = "ア".encode Encoding::EUC_JP
- lambda do
- "あれ".center 5, pat
- end.should raise_error(Encoding::CompatibilityError)
- end
+ it "raises an Encoding::CompatibilityError if the encodings are incompatible" do
+ pat = "ア".encode Encoding::EUC_JP
+ lambda do
+ "あれ".center 5, pat
+ end.should raise_error(Encoding::CompatibilityError)
end
end
end
diff --git a/spec/ruby/core/string/chomp_spec.rb b/spec/ruby/core/string/chomp_spec.rb
index d6ad710382..7400d71336 100644
--- a/spec/ruby/core/string/chomp_spec.rb
+++ b/spec/ruby/core/string/chomp_spec.rb
@@ -330,62 +330,60 @@ describe "String#chomp!" do
end
end
-with_feature :encoding do
- describe "String#chomp" do
- before :each do
- @before_separator = $/
- end
+describe "String#chomp" do
+ before :each do
+ @before_separator = $/
+ end
- after :each do
- $/ = @before_separator
- end
+ after :each do
+ $/ = @before_separator
+ end
- it "does not modify a multi-byte character" do
- "あれ".chomp.should == "あれ"
- end
+ it "does not modify a multi-byte character" do
+ "あれ".chomp.should == "あれ"
+ end
- it "removes the final carriage return, newline from a multibyte String" do
- "あれ\r\n".chomp.should == "あれ"
- end
+ it "removes the final carriage return, newline from a multibyte String" do
+ "あれ\r\n".chomp.should == "あれ"
+ end
- it "removes the final carriage return, newline from a non-ASCII String" do
- str = "abc\r\n".encode "utf-32be"
- str.chomp.should == "abc".encode("utf-32be")
- end
+ it "removes the final carriage return, newline from a non-ASCII String" do
+ str = "abc\r\n".encode "utf-32be"
+ str.chomp.should == "abc".encode("utf-32be")
+ end
- it "removes the final carriage return, newline from a non-ASCII String when the record separator is changed" do
- $/ = "\n".encode("utf-8")
- str = "abc\r\n".encode "utf-32be"
- str.chomp.should == "abc".encode("utf-32be")
- end
+ it "removes the final carriage return, newline from a non-ASCII String when the record separator is changed" do
+ $/ = "\n".encode("utf-8")
+ str = "abc\r\n".encode "utf-32be"
+ str.chomp.should == "abc".encode("utf-32be")
end
+end
- describe "String#chomp!" do
- before :each do
- @before_separator = $/
- end
+describe "String#chomp!" do
+ before :each do
+ @before_separator = $/
+ end
- after :each do
- $/ = @before_separator
- end
+ after :each do
+ $/ = @before_separator
+ end
- it "returns nil when the String is not modified" do
- "あれ".chomp!.should be_nil
- end
+ it "returns nil when the String is not modified" do
+ "あれ".chomp!.should be_nil
+ end
- it "removes the final carriage return, newline from a multibyte String" do
- "あれ\r\n".chomp!.should == "あれ"
- end
+ it "removes the final carriage return, newline from a multibyte String" do
+ "あれ\r\n".chomp!.should == "あれ"
+ end
- it "removes the final carriage return, newline from a non-ASCII String" do
- str = "abc\r\n".encode "utf-32be"
- str.chomp!.should == "abc".encode("utf-32be")
- end
+ it "removes the final carriage return, newline from a non-ASCII String" do
+ str = "abc\r\n".encode "utf-32be"
+ str.chomp!.should == "abc".encode("utf-32be")
+ end
- it "removes the final carriage return, newline from a non-ASCII String when the record separator is changed" do
- $/ = "\n".encode("utf-8")
- str = "abc\r\n".encode "utf-32be"
- str.chomp!.should == "abc".encode("utf-32be")
- end
+ it "removes the final carriage return, newline from a non-ASCII String when the record separator is changed" do
+ $/ = "\n".encode("utf-8")
+ str = "abc\r\n".encode "utf-32be"
+ str.chomp!.should == "abc".encode("utf-32be")
end
end
diff --git a/spec/ruby/core/string/chop_spec.rb b/spec/ruby/core/string/chop_spec.rb
index 033a11a95b..f33da3ecc4 100644
--- a/spec/ruby/core/string/chop_spec.rb
+++ b/spec/ruby/core/string/chop_spec.rb
@@ -27,19 +27,17 @@ describe "String#chop" do
"abc\r\n\r\n".chop.should == "abc\r\n"
end
- with_feature :encoding do
- it "removes a multi-byte character" do
- "あれ".chop.should == "あ"
- end
+ it "removes a multi-byte character" do
+ "あれ".chop.should == "あ"
+ end
- it "removes the final carriage return, newline from a multibyte String" do
- "あれ\r\n".chop.should == "あれ"
- end
+ it "removes the final carriage return, newline from a multibyte String" do
+ "あれ\r\n".chop.should == "あれ"
+ end
- it "removes the final carriage return, newline from a non-ASCII String" do
- str = "abc\r\n".encode "utf-32be"
- str.chop.should == "abc".encode("utf-32be")
- end
+ it "removes the final carriage return, newline from a non-ASCII String" do
+ str = "abc\r\n".encode "utf-32be"
+ str.chop.should == "abc".encode("utf-32be")
end
it "returns an empty string when applied to an empty string" do
@@ -91,19 +89,17 @@ describe "String#chop!" do
"abc\r\n\r\n".chop!.should == "abc\r\n"
end
- with_feature :encoding do
- it "removes a multi-byte character" do
- "あれ".chop!.should == "あ"
- end
+ it "removes a multi-byte character" do
+ "あれ".chop!.should == "あ"
+ end
- it "removes the final carriage return, newline from a multibyte String" do
- "あれ\r\n".chop!.should == "あれ"
- end
+ it "removes the final carriage return, newline from a multibyte String" do
+ "あれ\r\n".chop!.should == "あれ"
+ end
- it "removes the final carriage return, newline from a non-ASCII String" do
- str = "abc\r\n".encode "utf-32be"
- str.chop!.should == "abc".encode("utf-32be")
- end
+ it "removes the final carriage return, newline from a non-ASCII String" do
+ str = "abc\r\n".encode "utf-32be"
+ str.chop!.should == "abc".encode("utf-32be")
end
it "returns self if modifications were made" do
diff --git a/spec/ruby/core/string/chr_spec.rb b/spec/ruby/core/string/chr_spec.rb
index ca56955866..9ed29542e6 100644
--- a/spec/ruby/core/string/chr_spec.rb
+++ b/spec/ruby/core/string/chr_spec.rb
@@ -1,44 +1,42 @@
require_relative '../../spec_helper'
-with_feature :encoding do
- describe "String#chr" do
- it "returns a copy of self" do
- s = 'e'
- s.should_not equal s.chr
- 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
+describe "String#chr" do
+ it "returns a copy of self" do
+ s = 'e'
+ s.should_not equal s.chr
+ 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
diff --git a/spec/ruby/core/string/clear_spec.rb b/spec/ruby/core/string/clear_spec.rb
index 8b0ff8a8e6..45d452e947 100644
--- a/spec/ruby/core/string/clear_spec.rb
+++ b/spec/ruby/core/string/clear_spec.rb
@@ -1,39 +1,37 @@
require_relative '../../spec_helper'
-with_feature :encoding do
- describe "String#clear" do
- before :each do
- @s = "Jolene"
- end
+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 "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.should equal @s
- end
+ it "returns self after emptying it" do
+ cleared = @s.clear
+ cleared.should == ""
+ cleared.should equal @s
+ 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 "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 "works with multibyte Strings" do
+ s = "\u{9765}\u{876}"
+ s.clear
+ s.should == ""
+ end
- it "raises a #{frozen_error_class} if self is frozen" do
- @s.freeze
- lambda { @s.clear }.should raise_error(frozen_error_class)
- lambda { "".freeze.clear }.should raise_error(frozen_error_class)
- end
+ it "raises a #{frozen_error_class} if self is frozen" do
+ @s.freeze
+ lambda { @s.clear }.should raise_error(frozen_error_class)
+ lambda { "".freeze.clear }.should raise_error(frozen_error_class)
end
end
diff --git a/spec/ruby/core/string/codepoints_spec.rb b/spec/ruby/core/string/codepoints_spec.rb
index bccb3d0484..e5eeb8b69d 100644
--- a/spec/ruby/core/string/codepoints_spec.rb
+++ b/spec/ruby/core/string/codepoints_spec.rb
@@ -3,18 +3,16 @@ require_relative '../../spec_helper'
require_relative 'shared/codepoints'
require_relative 'shared/each_codepoint_without_block'
-with_feature :encoding do
- describe "String#codepoints" do
- it_behaves_like :string_codepoints, :codepoints
+describe "String#codepoints" do
+ it_behaves_like :string_codepoints, :codepoints
- it "returns an Array when no block is given" do
- "abc".codepoints.should == [?a.ord, ?b.ord, ?c.ord]
- end
+ it "returns an Array when no block is given" do
+ "abc".codepoints.should == [?a.ord, ?b.ord, ?c.ord]
+ end
- it "raises an ArgumentError when no block is given if self has an invalid encoding" do
- s = "\xDF".force_encoding(Encoding::UTF_8)
- s.valid_encoding?.should be_false
- lambda { s.codepoints }.should raise_error(ArgumentError)
- end
+ it "raises an ArgumentError when no block is given if self has an invalid encoding" do
+ s = "\xDF".force_encoding(Encoding::UTF_8)
+ s.valid_encoding?.should be_false
+ lambda { s.codepoints }.should raise_error(ArgumentError)
end
end
diff --git a/spec/ruby/core/string/downcase_spec.rb b/spec/ruby/core/string/downcase_spec.rb
index 241bd8c147..9d57ea8e25 100644
--- a/spec/ruby/core/string/downcase_spec.rb
+++ b/spec/ruby/core/string/downcase_spec.rb
@@ -174,9 +174,7 @@ describe "String#downcase!" do
lambda { "hello".freeze.downcase! }.should raise_error(frozen_error_class)
end
- with_feature :encoding do
- it "sets the result String encoding to the source String encoding" do
- "ABC".downcase.encoding.should equal(Encoding::UTF_8)
- end
+ it "sets the result String encoding to the source String encoding" do
+ "ABC".downcase.encoding.should equal(Encoding::UTF_8)
end
end
diff --git a/spec/ruby/core/string/each_codepoint_spec.rb b/spec/ruby/core/string/each_codepoint_spec.rb
index 41ca527653..c11cb1beae 100644
--- a/spec/ruby/core/string/each_codepoint_spec.rb
+++ b/spec/ruby/core/string/each_codepoint_spec.rb
@@ -2,9 +2,7 @@ require_relative '../../spec_helper'
require_relative 'shared/codepoints'
require_relative 'shared/each_codepoint_without_block'
-with_feature :encoding do
- describe "String#each_codepoint" do
- it_behaves_like :string_codepoints, :each_codepoint
- it_behaves_like :string_each_codepoint_without_block, :each_codepoint
- end
+describe "String#each_codepoint" do
+ it_behaves_like :string_codepoints, :each_codepoint
+ it_behaves_like :string_each_codepoint_without_block, :each_codepoint
end
diff --git a/spec/ruby/core/string/element_set_spec.rb b/spec/ruby/core/string/element_set_spec.rb
index 340bd2b9ca..f85256d36e 100644
--- a/spec/ruby/core/string/element_set_spec.rb
+++ b/spec/ruby/core/string/element_set_spec.rb
@@ -83,68 +83,66 @@ describe "String#[]= with Fixnum index" do
lambda { "test"[1] = nil }.should raise_error(TypeError)
end
- with_feature :encoding do
- it "raises a TypeError if passed a Fixnum replacement" do
- lambda { "abc"[1] = 65 }.should raise_error(TypeError)
- end
+ it "raises a TypeError if passed a Fixnum replacement" do
+ lambda { "abc"[1] = 65 }.should raise_error(TypeError)
+ end
- it "raises an IndexError if the index is greater than character size" do
- lambda { "あれ"[4] = "a" }.should raise_error(IndexError)
- end
+ it "raises an IndexError if the index is greater than character size" do
+ lambda { "あれ"[4] = "a" }.should raise_error(IndexError)
+ end
- it "calls #to_int to convert the index" do
- index = mock("string element set")
- index.should_receive(:to_int).and_return(1)
+ it "calls #to_int to convert the index" do
+ index = mock("string element set")
+ index.should_receive(:to_int).and_return(1)
- str = "あれ"
- str[index] = "a"
- str.should == "あa"
- end
+ str = "あれ"
+ str[index] = "a"
+ str.should == "あa"
+ end
- it "raises a TypeError if #to_int does not return an Fixnum" do
- index = mock("string element set")
- index.should_receive(:to_int).and_return('1')
+ it "raises a TypeError if #to_int does not return an Fixnum" do
+ index = mock("string element set")
+ index.should_receive(:to_int).and_return('1')
- lambda { "abc"[index] = "d" }.should raise_error(TypeError)
- end
+ lambda { "abc"[index] = "d" }.should raise_error(TypeError)
+ end
- it "raises an IndexError if #to_int returns a value out of range" do
- index = mock("string element set")
- index.should_receive(:to_int).and_return(4)
+ it "raises an IndexError if #to_int returns a value out of range" do
+ index = mock("string element set")
+ index.should_receive(:to_int).and_return(4)
- lambda { "ab"[index] = "c" }.should raise_error(IndexError)
- end
+ lambda { "ab"[index] = "c" }.should raise_error(IndexError)
+ end
- it "replaces a character with a multibyte character" do
- str = "ありがとu"
- str[4] = "う"
- str.should == "ありがとう"
- end
+ it "replaces a character with a multibyte character" do
+ str = "ありがとu"
+ str[4] = "う"
+ str.should == "ありがとう"
+ end
- it "replaces a multibyte character with a character" do
- str = "ありがとう"
- str[4] = "u"
- str.should == "ありがとu"
- end
+ it "replaces a multibyte character with a character" do
+ str = "ありがとう"
+ str[4] = "u"
+ str.should == "ありがとu"
+ end
- it "replaces a multibyte character with a multibyte character" do
- str = "ありがとお"
- str[4] = "う"
- str.should == "ありがとう"
- end
+ it "replaces a multibyte character with a multibyte character" do
+ str = "ありがとお"
+ str[4] = "う"
+ str.should == "ありがとう"
+ end
- it "encodes the String in an encoding compatible with the replacement" do
- str = " ".force_encoding Encoding::US_ASCII
- rep = [160].pack('C').force_encoding Encoding::ASCII_8BIT
- str[0] = rep
- str.encoding.should equal(Encoding::ASCII_8BIT)
- end
+ it "encodes the String in an encoding compatible with the replacement" do
+ str = " ".force_encoding Encoding::US_ASCII
+ rep = [160].pack('C').force_encoding Encoding::ASCII_8BIT
+ str[0] = rep
+ str.encoding.should equal(Encoding::ASCII_8BIT)
+ end
- it "raises an Encoding::CompatibilityError if the replacement encoding is incompatible" do
- str = "あれ"
- rep = "が".encode Encoding::EUC_JP
- lambda { str[0] = rep }.should raise_error(Encoding::CompatibilityError)
- end
+ it "raises an Encoding::CompatibilityError if the replacement encoding is incompatible" do
+ str = "あれ"
+ rep = "が".encode Encoding::EUC_JP
+ lambda { str[0] = rep }.should raise_error(Encoding::CompatibilityError)
end
end
@@ -172,37 +170,35 @@ describe "String#[]= with String index" do
lambda { str["g"] = "h" }.should raise_error(IndexError)
end
- with_feature :encoding do
- it "replaces characters with a multibyte character" do
- str = "ありgaとう"
- str["ga"] = "が"
- str.should == "ありがとう"
- end
+ it "replaces characters with a multibyte character" do
+ str = "ありgaとう"
+ str["ga"] = "が"
+ str.should == "ありがとう"
+ end
- it "replaces multibyte characters with characters" do
- str = "ありがとう"
- str["が"] = "ga"
- str.should == "ありgaとう"
- end
+ it "replaces multibyte characters with characters" do
+ str = "ありがとう"
+ str["が"] = "ga"
+ str.should == "ありgaとう"
+ end
- it "replaces multibyte characters with multibyte characters" do
- str = "ありがとう"
- str["が"] = "か"
- str.should == "ありかとう"
- end
+ it "replaces multibyte characters with multibyte characters" do
+ str = "ありがとう"
+ str["が"] = "か"
+ str.should == "ありかとう"
+ end
- it "encodes the String in an encoding compatible with the replacement" do
- str = " ".force_encoding Encoding::US_ASCII
- rep = [160].pack('C').force_encoding Encoding::ASCII_8BIT
- str[" "] = rep
- str.encoding.should equal(Encoding::ASCII_8BIT)
- end
+ it "encodes the String in an encoding compatible with the replacement" do
+ str = " ".force_encoding Encoding::US_ASCII
+ rep = [160].pack('C').force_encoding Encoding::ASCII_8BIT
+ str[" "] = rep
+ str.encoding.should equal(Encoding::ASCII_8BIT)
+ end
- it "raises an Encoding::CompatibilityError if the replacement encoding is incompatible" do
- str = "あれ"
- rep = "が".encode Encoding::EUC_JP
- lambda { str["れ"] = rep }.should raise_error(Encoding::CompatibilityError)
- end
+ it "raises an Encoding::CompatibilityError if the replacement encoding is incompatible" do
+ str = "あれ"
+ rep = "が".encode Encoding::EUC_JP
+ lambda { str["れ"] = rep }.should raise_error(Encoding::CompatibilityError)
end
end
@@ -287,37 +283,35 @@ describe "String#[]= with a Regexp index" do
end
end
- with_feature :encoding do
- it "replaces characters with a multibyte character" do
- str = "ありgaとう"
- str[/ga/] = "が"
- str.should == "ありがとう"
- end
+ it "replaces characters with a multibyte character" do
+ str = "ありgaとう"
+ str[/ga/] = "が"
+ str.should == "ありがとう"
+ end
- it "replaces multibyte characters with characters" do
- str = "ありがとう"
- str[/が/] = "ga"
- str.should == "ありgaとう"
- end
+ it "replaces multibyte characters with characters" do
+ str = "ありがとう"
+ str[/が/] = "ga"
+ str.should == "ありgaとう"
+ end
- it "replaces multibyte characters with multibyte characters" do
- str = "ありがとう"
- str[/が/] = "か"
- str.should == "ありかとう"
- end
+ it "replaces multibyte characters with multibyte characters" do
+ str = "ありがとう"
+ str[/が/] = "か"
+ str.should == "ありかとう"
+ end
- it "encodes the String in an encoding compatible with the replacement" do
- str = " ".force_encoding Encoding::US_ASCII
- rep = [160].pack('C').force_encoding Encoding::ASCII_8BIT
- str[/ /] = rep
- str.encoding.should equal(Encoding::ASCII_8BIT)
- end
+ it "encodes the String in an encoding compatible with the replacement" do
+ str = " ".force_encoding Encoding::US_ASCII
+ rep = [160].pack('C').force_encoding Encoding::ASCII_8BIT
+ str[/ /] = rep
+ str.encoding.should equal(Encoding::ASCII_8BIT)
+ end
- it "raises an Encoding::CompatibilityError if the replacement encoding is incompatible" do
- str = "あれ"
- rep = "が".encode Encoding::EUC_JP
- lambda { str[/れ/] = rep }.should raise_error(Encoding::CompatibilityError)
- end
+ it "raises an Encoding::CompatibilityError if the replacement encoding is incompatible" do
+ str = "あれ"
+ rep = "が".encode Encoding::EUC_JP
+ lambda { str[/れ/] = rep }.should raise_error(Encoding::CompatibilityError)
end
end
@@ -392,55 +386,53 @@ describe "String#[]= with a Range index" do
str.should == "abcxd"
end
- with_feature :encoding do
- it "replaces characters with a multibyte character" do
- str = "ありgaとう"
- str[2..3] = "が"
- str.should == "ありがとう"
- end
+ it "replaces characters with a multibyte character" do
+ str = "ありgaとう"
+ str[2..3] = "が"
+ str.should == "ありがとう"
+ end
- it "replaces multibyte characters with characters" do
- str = "ありがとう"
- str[2...3] = "ga"
- str.should == "ありgaとう"
- end
+ it "replaces multibyte characters with characters" do
+ str = "ありがとう"
+ str[2...3] = "ga"
+ str.should == "ありgaとう"
+ end
- it "replaces multibyte characters by negative indexes" do
- str = "ありがとう"
- str[-3...-2] = "ga"
- str.should == "ありgaとう"
- end
+ it "replaces multibyte characters by negative indexes" do
+ str = "ありがとう"
+ str[-3...-2] = "ga"
+ str.should == "ありgaとう"
+ end
- it "replaces multibyte characters with multibyte characters" do
- str = "ありがとう"
- str[2..2] = "か"
- str.should == "ありかとう"
- end
+ it "replaces multibyte characters with multibyte characters" do
+ str = "ありがとう"
+ str[2..2] = "か"
+ str.should == "ありかとう"
+ end
- it "deletes a multibyte character" do
- str = "ありとう"
- str[2..3] = ""
- str.should == "あり"
- end
+ it "deletes a multibyte character" do
+ str = "ありとう"
+ str[2..3] = ""
+ str.should == "あり"
+ end
- it "inserts a multibyte character" do
- str = "ありとう"
- str[2...2] = "が"
- str.should == "ありがとう"
- end
+ it "inserts a multibyte character" do
+ str = "ありとう"
+ str[2...2] = "が"
+ str.should == "ありがとう"
+ end
- it "encodes the String in an encoding compatible with the replacement" do
- str = " ".force_encoding Encoding::US_ASCII
- rep = [160].pack('C').force_encoding Encoding::ASCII_8BIT
- str[0..1] = rep
- str.encoding.should equal(Encoding::ASCII_8BIT)
- end
+ it "encodes the String in an encoding compatible with the replacement" do
+ str = " ".force_encoding Encoding::US_ASCII
+ rep = [160].pack('C').force_encoding Encoding::ASCII_8BIT
+ str[0..1] = rep
+ str.encoding.should equal(Encoding::ASCII_8BIT)
+ end
- it "raises an Encoding::CompatibilityError if the replacement encoding is incompatible" do
- str = "あれ"
- rep = "が".encode Encoding::EUC_JP
- lambda { str[0..1] = rep }.should raise_error(Encoding::CompatibilityError)
- end
+ it "raises an Encoding::CompatibilityError if the replacement encoding is incompatible" do
+ str = "あれ"
+ rep = "が".encode Encoding::EUC_JP
+ lambda { str[0..1] = rep }.should raise_error(Encoding::CompatibilityError)
end
end
@@ -561,52 +553,50 @@ describe "String#[]= with Fixnum index, count" do
lambda { "hello"[0, 2] = 33 }.should raise_error(TypeError)
end
- with_feature :encoding do
- it "replaces characters with a multibyte character" do
- str = "ありgaとう"
- str[2, 2] = "が"
- str.should == "ありがとう"
- end
+ it "replaces characters with a multibyte character" do
+ str = "ありgaとう"
+ str[2, 2] = "が"
+ str.should == "ありがとう"
+ end
- it "replaces multibyte characters with characters" do
- str = "ありがとう"
- str[2, 1] = "ga"
- str.should == "ありgaとう"
- end
+ it "replaces multibyte characters with characters" do
+ str = "ありがとう"
+ str[2, 1] = "ga"
+ str.should == "ありgaとう"
+ end
- it "replaces multibyte characters with multibyte characters" do
- str = "ありがとう"
- str[2, 1] = "か"
- str.should == "ありかとう"
- end
+ it "replaces multibyte characters with multibyte characters" do
+ str = "ありがとう"
+ str[2, 1] = "か"
+ str.should == "ありかとう"
+ end
- it "deletes a multibyte character" do
- str = "ありとう"
- str[2, 2] = ""
- str.should == "あり"
- end
+ it "deletes a multibyte character" do
+ str = "ありとう"
+ str[2, 2] = ""
+ str.should == "あり"
+ end
- it "inserts a multibyte character" do
- str = "ありとう"
- str[2, 0] = "が"
- str.should == "ありがとう"
- end
+ it "inserts a multibyte character" do
+ str = "ありとう"
+ str[2, 0] = "が"
+ str.should == "ありがとう"
+ end
- it "raises an IndexError if the character index is out of range of a multibyte String" do
- lambda { "あれ"[3, 0] = "り" }.should raise_error(IndexError)
- end
+ it "raises an IndexError if the character index is out of range of a multibyte String" do
+ lambda { "あれ"[3, 0] = "り" }.should raise_error(IndexError)
+ end
- it "encodes the String in an encoding compatible with the replacement" do
- str = " ".force_encoding Encoding::US_ASCII
- rep = [160].pack('C').force_encoding Encoding::ASCII_8BIT
- str[0, 1] = rep
- str.encoding.should equal(Encoding::ASCII_8BIT)
- end
+ it "encodes the String in an encoding compatible with the replacement" do
+ str = " ".force_encoding Encoding::US_ASCII
+ rep = [160].pack('C').force_encoding Encoding::ASCII_8BIT
+ str[0, 1] = rep
+ str.encoding.should equal(Encoding::ASCII_8BIT)
+ end
- it "raises an Encoding::CompatibilityError if the replacement encoding is incompatible" do
- str = "あれ"
- rep = "が".encode Encoding::EUC_JP
- lambda { str[0, 1] = rep }.should raise_error(Encoding::CompatibilityError)
- end
+ it "raises an Encoding::CompatibilityError if the replacement encoding is incompatible" do
+ str = "あれ"
+ rep = "が".encode Encoding::EUC_JP
+ lambda { str[0, 1] = rep }.should raise_error(Encoding::CompatibilityError)
end
end
diff --git a/spec/ruby/core/string/encode_spec.rb b/spec/ruby/core/string/encode_spec.rb
index f582d50794..0be26011ea 100644
--- a/spec/ruby/core/string/encode_spec.rb
+++ b/spec/ruby/core/string/encode_spec.rb
@@ -2,158 +2,156 @@
require_relative '../../spec_helper'
require_relative 'shared/encode'
-with_feature :encoding do
- describe "String#encode" do
- before :each do
- @external = Encoding.default_external
- @internal = Encoding.default_internal
- end
+describe "String#encode" do
+ before :each do
+ @external = Encoding.default_external
+ @internal = Encoding.default_internal
+ end
- after :each do
- Encoding.default_external = @external
- Encoding.default_internal = @internal
- end
+ after :each do
+ Encoding.default_external = @external
+ Encoding.default_internal = @internal
+ end
- it_behaves_like :string_encode, :encode
+ it_behaves_like :string_encode, :encode
- describe "when passed no options" do
- it "returns a copy when Encoding.default_internal is nil" do
- Encoding.default_internal = nil
- str = "あ"
- str.encode.should_not equal(str)
- end
+ describe "when passed no options" do
+ it "returns a copy when Encoding.default_internal is nil" do
+ Encoding.default_internal = nil
+ str = "あ"
+ str.encode.should_not equal(str)
+ end
- it "returns a copy for a ASCII-only String when Encoding.default_internal is nil" do
- Encoding.default_internal = nil
- str = "abc"
- str.encode.should_not equal(str)
- end
+ it "returns a copy for a ASCII-only String when Encoding.default_internal is nil" do
+ Encoding.default_internal = nil
+ str = "abc"
+ str.encode.should_not equal(str)
+ end
- it "encodes an ascii substring of a binary string to UTF-8" do
- x82 = [0x82].pack('C')
- str = "#{x82}foo".force_encoding("ascii-8bit")[1..-1].encode("utf-8")
- str.should == "foo".force_encoding("utf-8")
- str.encoding.should equal(Encoding::UTF_8)
- end
+ it "encodes an ascii substring of a binary string to UTF-8" do
+ x82 = [0x82].pack('C')
+ str = "#{x82}foo".force_encoding("ascii-8bit")[1..-1].encode("utf-8")
+ str.should == "foo".force_encoding("utf-8")
+ str.encoding.should equal(Encoding::UTF_8)
end
+ end
- describe "when passed to encoding" do
- it "returns a copy when passed the same encoding as the String" do
- str = "あ"
- str.encode(Encoding::UTF_8).should_not equal(str)
- end
+ describe "when passed to encoding" do
+ it "returns a copy when passed the same encoding as the String" do
+ str = "あ"
+ str.encode(Encoding::UTF_8).should_not equal(str)
+ end
- it "round trips a String" do
- str = "abc def".force_encoding Encoding::US_ASCII
- str.encode("utf-32be").encode("ascii").should == "abc def"
- end
+ it "round trips a String" do
+ str = "abc def".force_encoding Encoding::US_ASCII
+ str.encode("utf-32be").encode("ascii").should == "abc def"
end
+ end
- describe "when passed options" do
- it "returns a copy when Encoding.default_internal is nil" do
- Encoding.default_internal = nil
- str = "あ"
- str.encode(invalid: :replace).should_not equal(str)
- end
+ describe "when passed options" do
+ it "returns a copy when Encoding.default_internal is nil" do
+ Encoding.default_internal = nil
+ str = "あ"
+ str.encode(invalid: :replace).should_not equal(str)
+ end
- it "normalizes newlines" do
- "\r\nfoo".encode(universal_newline: true).should == "\nfoo"
+ it "normalizes newlines" do
+ "\r\nfoo".encode(universal_newline: true).should == "\nfoo"
- "\rfoo".encode(universal_newline: true).should == "\nfoo"
- end
+ "\rfoo".encode(universal_newline: true).should == "\nfoo"
end
+ end
- describe "when passed to, from" do
- it "returns a copy in the destination encoding when both encodings are the same" do
- str = "あ"
- str.force_encoding("ascii-8bit")
- encoded = str.encode("utf-8", "utf-8")
-
- encoded.should_not equal(str)
- encoded.encoding.should == Encoding::UTF_8
- end
+ describe "when passed to, from" do
+ it "returns a copy in the destination encoding when both encodings are the same" do
+ str = "あ"
+ str.force_encoding("ascii-8bit")
+ encoded = str.encode("utf-8", "utf-8")
- it "returns the transcoded string" do
- str = "\x00\x00\x00\x1F"
- str.encode(Encoding::UTF_8, Encoding::UTF_16BE).should == "\u0000\u001f"
- end
+ encoded.should_not equal(str)
+ encoded.encoding.should == Encoding::UTF_8
end
- describe "when passed to, options" do
- it "returns a copy when the destination encoding is the same as the String encoding" do
- str = "あ"
- str.encode(Encoding::UTF_8, undef: :replace).should_not equal(str)
- end
+ it "returns the transcoded string" do
+ str = "\x00\x00\x00\x1F"
+ str.encode(Encoding::UTF_8, Encoding::UTF_16BE).should == "\u0000\u001f"
end
+ end
- describe "when passed to, from, options" do
- it "returns a copy when both encodings are the same" do
- str = "あ"
- str.encode("utf-8", "utf-8", invalid: :replace).should_not equal(str)
- end
+ describe "when passed to, options" do
+ it "returns a copy when the destination encoding is the same as the String encoding" do
+ str = "あ"
+ str.encode(Encoding::UTF_8, undef: :replace).should_not equal(str)
end
end
- describe "String#encode!" do
- before :each do
- @external = Encoding.default_external
- @internal = Encoding.default_internal
+ describe "when passed to, from, options" do
+ it "returns a copy when both encodings are the same" do
+ str = "あ"
+ str.encode("utf-8", "utf-8", invalid: :replace).should_not equal(str)
end
+ end
+end
- after :each do
- Encoding.default_external = @external
- Encoding.default_internal = @internal
- end
+describe "String#encode!" do
+ before :each do
+ @external = Encoding.default_external
+ @internal = Encoding.default_internal
+ end
- it_behaves_like :string_encode, :encode!
+ after :each do
+ Encoding.default_external = @external
+ Encoding.default_internal = @internal
+ end
- it "raises a #{frozen_error_class} when called on a frozen String" do
- lambda { "foo".freeze.encode!("euc-jp") }.should raise_error(frozen_error_class)
- end
+ it_behaves_like :string_encode, :encode!
- # http://redmine.ruby-lang.org/issues/show/1836
- it "raises a #{frozen_error_class} when called on a frozen String when it's a no-op" do
- lambda { "foo".freeze.encode!("utf-8") }.should raise_error(frozen_error_class)
- end
+ it "raises a #{frozen_error_class} when called on a frozen String" do
+ lambda { "foo".freeze.encode!("euc-jp") }.should raise_error(frozen_error_class)
+ end
- describe "when passed no options" do
- it "returns self when Encoding.default_internal is nil" do
- Encoding.default_internal = nil
- str = "あ"
- str.encode!.should equal(str)
- end
+ # http://redmine.ruby-lang.org/issues/show/1836
+ it "raises a #{frozen_error_class} when called on a frozen String when it's a no-op" do
+ lambda { "foo".freeze.encode!("utf-8") }.should raise_error(frozen_error_class)
+ end
+
+ describe "when passed no options" do
+ it "returns self when Encoding.default_internal is nil" do
+ Encoding.default_internal = nil
+ str = "あ"
+ str.encode!.should equal(str)
+ end
- it "returns self for a ASCII-only String when Encoding.default_internal is nil" do
- Encoding.default_internal = nil
- str = "abc"
- str.encode!.should equal(str)
- end
+ it "returns self for a ASCII-only String when Encoding.default_internal is nil" do
+ Encoding.default_internal = nil
+ str = "abc"
+ str.encode!.should equal(str)
end
+ end
- describe "when passed options" do
- it "returns self for ASCII-only String when Encoding.default_internal is nil" do
- Encoding.default_internal = nil
- str = "abc"
- str.encode!(invalid: :replace).should equal(str)
- end
+ describe "when passed options" do
+ it "returns self for ASCII-only String when Encoding.default_internal is nil" do
+ Encoding.default_internal = nil
+ str = "abc"
+ str.encode!(invalid: :replace).should equal(str)
end
+ end
- describe "when passed to encoding" do
- it "returns self" do
- str = "abc"
- result = str.encode!(Encoding::BINARY)
- result.encoding.should equal(Encoding::BINARY)
- result.should equal(str)
- end
+ describe "when passed to encoding" do
+ it "returns self" do
+ str = "abc"
+ result = str.encode!(Encoding::BINARY)
+ result.encoding.should equal(Encoding::BINARY)
+ result.should equal(str)
end
+ end
- describe "when passed to, from" do
- it "returns self" do
- str = "ああ"
- result = str.encode!("euc-jp", "utf-8")
- result.encoding.should equal(Encoding::EUC_JP)
- result.should equal(str)
- end
+ describe "when passed to, from" do
+ it "returns self" do
+ str = "ああ"
+ result = str.encode!("euc-jp", "utf-8")
+ result.encoding.should equal(Encoding::EUC_JP)
+ result.should equal(str)
end
end
end
diff --git a/spec/ruby/core/string/encoding_spec.rb b/spec/ruby/core/string/encoding_spec.rb
index b2861f2264..6182e8eb50 100644
--- a/spec/ruby/core/string/encoding_spec.rb
+++ b/spec/ruby/core/string/encoding_spec.rb
@@ -2,188 +2,186 @@
require_relative '../../spec_helper'
require_relative 'fixtures/iso-8859-9-encoding'
-with_feature :encoding 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
- str = " "
- str.encoding.should == Encoding::US_ASCII
- str += [0xDF].pack('C')
- str.ascii_only?.should be_false
- str.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
- [0xD4].pack('C').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 = "\x50"
- x50.encoding.should == Encoding::US_ASCII
- [0xD4].pack('C').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 = "\x50"
- x50.force_encoding(Encoding::SHIFT_JIS).encoding.should == Encoding::SHIFT_JIS
- xD4 = [212].pack('C')
- 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 = "\x50"
- x50.encode!(Encoding::SHIFT_JIS).encoding.should == Encoding::SHIFT_JIS
- x00 = "x\00"
- x00.encode!(Encoding::UTF_8).encoding.should == Encoding::UTF_8
- end
+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
+ str = " "
+ str.encoding.should == Encoding::US_ASCII
+ str += [0xDF].pack('C')
+ str.ascii_only?.should be_false
+ str.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
+ [0xD4].pack('C').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 = "\x50"
+ x50.encoding.should == Encoding::US_ASCII
+ [0xD4].pack('C').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 = "\x50"
+ x50.force_encoding(Encoding::SHIFT_JIS).encoding.should == Encoding::SHIFT_JIS
+ xD4 = [212].pack('C')
+ 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 = "\x50"
+ x50.encode!(Encoding::SHIFT_JIS).encoding.should == Encoding::SHIFT_JIS
+ x00 = "x\00"
+ x00.encode!(Encoding::UTF_8).encoding.should == Encoding::UTF_8
end
end
diff --git a/spec/ruby/core/string/force_encoding_spec.rb b/spec/ruby/core/string/force_encoding_spec.rb
index 06e04b8d95..83641a37b4 100644
--- a/spec/ruby/core/string/force_encoding_spec.rb
+++ b/spec/ruby/core/string/force_encoding_spec.rb
@@ -1,73 +1,71 @@
require_relative '../../spec_helper'
-with_feature :encoding do
- describe "String#force_encoding" do
- it "accepts a String as the name of an Encoding" do
- "abc".force_encoding('shift_jis').encoding.should == Encoding::Shift_JIS
- end
-
- describe "with a special encoding name" do
- before :each do
- @original_encoding = Encoding.default_internal
- end
+describe "String#force_encoding" do
+ it "accepts a String as the name of an Encoding" do
+ "abc".force_encoding('shift_jis').encoding.should == Encoding::Shift_JIS
+ end
- after :each do
- Encoding.default_internal = @original_encoding
- end
+ describe "with a special encoding name" do
+ before :each do
+ @original_encoding = Encoding.default_internal
+ end
- it "accepts valid special encoding names" do
- Encoding.default_internal = "US-ASCII"
- "abc".force_encoding("internal").encoding.should == Encoding::US_ASCII
- end
+ after :each do
+ Encoding.default_internal = @original_encoding
+ end
- it "defaults to ASCII-8BIT if special encoding name is not set" do
- Encoding.default_internal = nil
- "abc".force_encoding("internal").encoding.should == Encoding::ASCII_8BIT
- end
+ it "accepts valid special encoding names" do
+ Encoding.default_internal = "US-ASCII"
+ "abc".force_encoding("internal").encoding.should == Encoding::US_ASCII
end
- it "accepts an Encoding instance" do
- "abc".force_encoding(Encoding::SHIFT_JIS).encoding.should == Encoding::Shift_JIS
+ it "defaults to ASCII-8BIT if special encoding name is not set" do
+ Encoding.default_internal = nil
+ "abc".force_encoding("internal").encoding.should == Encoding::ASCII_8BIT
end
+ end
- it "calls #to_str to convert an object to an encoding name" do
- obj = mock("force_encoding")
- obj.should_receive(:to_str).and_return("utf-8")
+ it "accepts an Encoding instance" do
+ "abc".force_encoding(Encoding::SHIFT_JIS).encoding.should == Encoding::Shift_JIS
+ end
- "abc".force_encoding(obj).encoding.should == Encoding::UTF_8
- end
+ it "calls #to_str to convert an object to an encoding name" do
+ obj = mock("force_encoding")
+ obj.should_receive(:to_str).and_return("utf-8")
- it "raises a TypeError if #to_str does not return a String" do
- obj = mock("force_encoding")
- obj.should_receive(:to_str).and_return(1)
+ "abc".force_encoding(obj).encoding.should == Encoding::UTF_8
+ end
- lambda { "abc".force_encoding(obj) }.should raise_error(TypeError)
- end
+ it "raises a TypeError if #to_str does not return a String" do
+ obj = mock("force_encoding")
+ obj.should_receive(:to_str).and_return(1)
- it "raises a TypeError if passed nil" do
- lambda { "abc".force_encoding(nil) }.should raise_error(TypeError)
- end
+ lambda { "abc".force_encoding(obj) }.should raise_error(TypeError)
+ end
- it "returns self" do
- str = "abc"
- str.force_encoding('utf-8').should equal(str)
- end
+ it "raises a TypeError if passed nil" do
+ lambda { "abc".force_encoding(nil) }.should raise_error(TypeError)
+ end
- it "sets the encoding even if the String contents are invalid in that encoding" do
- str = "\u{9765}"
- str.force_encoding('euc-jp')
- str.encoding.should == Encoding::EUC_JP
- str.valid_encoding?.should be_false
- end
+ it "returns self" do
+ str = "abc"
+ str.force_encoding('utf-8').should equal(str)
+ end
- it "does not transcode self" do
- str = "\u{8612}"
- str.dup.force_encoding('utf-16le').should_not == str.encode('utf-16le')
- end
+ it "sets the encoding even if the String contents are invalid in that encoding" do
+ str = "\u{9765}"
+ str.force_encoding('euc-jp')
+ str.encoding.should == Encoding::EUC_JP
+ str.valid_encoding?.should be_false
+ end
- it "raises a #{frozen_error_class} if self is frozen" do
- str = "abcd".freeze
- lambda { str.force_encoding(str.encoding) }.should raise_error(frozen_error_class)
- end
+ it "does not transcode self" do
+ str = "\u{8612}"
+ str.dup.force_encoding('utf-16le').should_not == str.encode('utf-16le')
+ end
+
+ it "raises a #{frozen_error_class} if self is frozen" do
+ str = "abcd".freeze
+ lambda { str.force_encoding(str.encoding) }.should raise_error(frozen_error_class)
end
end
diff --git a/spec/ruby/core/string/index_spec.rb b/spec/ruby/core/string/index_spec.rb
index 3ed27034e1..fb5f4e75e7 100644
--- a/spec/ruby/core/string/index_spec.rb
+++ b/spec/ruby/core/string/index_spec.rb
@@ -140,25 +140,23 @@ describe "String#index with String" do
"I’ve got a multibyte character.\n".index("\n\n").should == nil
end
- with_feature :encoding do
- it "returns the character index of a multibyte character" do
- "ありがとう".index("が").should == 2
- end
+ it "returns the character index of a multibyte character" do
+ "ありがとう".index("が").should == 2
+ end
- it "returns the character index after offset" do
- "われわれ".index("わ", 1).should == 2
- end
+ it "returns the character index after offset" do
+ "われわれ".index("わ", 1).should == 2
+ end
- it "returns the character index after a partial first match" do
- "</</h".index("</h").should == 2
- end
+ it "returns the character index after a partial first match" do
+ "</</h".index("</h").should == 2
+ end
- it "raises an Encoding::CompatibilityError if the encodings are incompatible" do
- char = "れ".encode Encoding::EUC_JP
- lambda do
- "あれ".index char
- end.should raise_error(Encoding::CompatibilityError)
- end
+ it "raises an Encoding::CompatibilityError if the encodings are incompatible" do
+ char = "れ".encode Encoding::EUC_JP
+ lambda do
+ "あれ".index char
+ end.should raise_error(Encoding::CompatibilityError)
end
end
@@ -293,24 +291,22 @@ describe "String#index with Regexp" do
"RWOARW".index(/R./, obj).should == 4
end
- with_feature :encoding do
- it "returns the character index of a multibyte character" do
- "ありがとう".index(/が/).should == 2
- end
+ it "returns the character index of a multibyte character" do
+ "ありがとう".index(/が/).should == 2
+ end
- it "returns the character index after offset" do
- "われわれ".index(/わ/, 1).should == 2
- end
+ it "returns the character index after offset" do
+ "われわれ".index(/わ/, 1).should == 2
+ end
- it "treats the offset as a character index" do
- "われわわれ".index(/わ/, 3).should == 3
- end
+ it "treats the offset as a character index" do
+ "われわわれ".index(/わ/, 3).should == 3
+ end
- it "raises an Encoding::CompatibilityError if the encodings are incompatible" do
- re = Regexp.new "れ".encode(Encoding::EUC_JP)
- lambda do
- "あれ".index re
- end.should raise_error(Encoding::CompatibilityError)
- end
+ it "raises an Encoding::CompatibilityError if the encodings are incompatible" do
+ re = Regexp.new "れ".encode(Encoding::EUC_JP)
+ lambda do
+ "あれ".index re
+ end.should raise_error(Encoding::CompatibilityError)
end
end
diff --git a/spec/ruby/core/string/insert_spec.rb b/spec/ruby/core/string/insert_spec.rb
index 2c72bb5ffd..d5b9026f3d 100644
--- a/spec/ruby/core/string/insert_spec.rb
+++ b/spec/ruby/core/string/insert_spec.rb
@@ -63,22 +63,20 @@ describe "String#insert with index, other" do
lambda { str.insert(4, 'X') }.should raise_error(frozen_error_class)
end
- with_feature :encoding do
- it "inserts a character into a multibyte encoded string" do
- "ありがとう".insert(1, 'ü').should == "あüりがとう"
- end
-
- it "returns a String in the compatible encoding" do
- str = "".force_encoding(Encoding::US_ASCII)
- str.insert(0, "ありがとう")
- str.encoding.should == Encoding::UTF_8
- end
-
- it "raises an Encoding::CompatibilityError if the encodings are incompatible" do
- pat = "ア".encode Encoding::EUC_JP
- lambda do
- "あれ".insert 0, pat
- end.should raise_error(Encoding::CompatibilityError)
- end
+ it "inserts a character into a multibyte encoded string" do
+ "ありがとう".insert(1, 'ü').should == "あüりがとう"
+ end
+
+ it "returns a String in the compatible encoding" do
+ str = "".force_encoding(Encoding::US_ASCII)
+ str.insert(0, "ありがとう")
+ str.encoding.should == Encoding::UTF_8
+ end
+
+ it "raises an Encoding::CompatibilityError if the encodings are incompatible" do
+ pat = "ア".encode Encoding::EUC_JP
+ lambda do
+ "あれ".insert 0, pat
+ end.should raise_error(Encoding::CompatibilityError)
end
end
diff --git a/spec/ruby/core/string/ljust_spec.rb b/spec/ruby/core/string/ljust_spec.rb
index 5838a0c9f9..a8160c727b 100644
--- a/spec/ruby/core/string/ljust_spec.rb
+++ b/spec/ruby/core/string/ljust_spec.rb
@@ -87,30 +87,28 @@ describe "String#ljust with length, padding" do
"hello".ljust(6, 'X'.taint).tainted?.should be_true
end
- with_feature :encoding do
- describe "with width" do
- it "returns a String in the same encoding as the original" do
- str = "abc".force_encoding Encoding::IBM437
- result = str.ljust 5
- result.should == "abc "
- result.encoding.should equal(Encoding::IBM437)
- end
+ describe "with width" do
+ it "returns a String in the same encoding as the original" do
+ str = "abc".force_encoding Encoding::IBM437
+ result = str.ljust 5
+ result.should == "abc "
+ result.encoding.should equal(Encoding::IBM437)
+ end
+ end
+
+ describe "with width, pattern" do
+ it "returns a String in the compatible encoding" do
+ str = "abc".force_encoding Encoding::IBM437
+ result = str.ljust 5, "あ"
+ result.should == "abcああ"
+ result.encoding.should equal(Encoding::UTF_8)
end
- describe "with width, pattern" do
- it "returns a String in the compatible encoding" do
- str = "abc".force_encoding Encoding::IBM437
- result = str.ljust 5, "あ"
- result.should == "abcああ"
- result.encoding.should equal(Encoding::UTF_8)
- end
-
- it "raises an Encoding::CompatibilityError if the encodings are incompatible" do
- pat = "ア".encode Encoding::EUC_JP
- lambda do
- "あれ".ljust 5, pat
- end.should raise_error(Encoding::CompatibilityError)
- end
+ it "raises an Encoding::CompatibilityError if the encodings are incompatible" do
+ pat = "ア".encode Encoding::EUC_JP
+ lambda do
+ "あれ".ljust 5, pat
+ end.should raise_error(Encoding::CompatibilityError)
end
end
end
diff --git a/spec/ruby/core/string/match_spec.rb b/spec/ruby/core/string/match_spec.rb
index 67e015f23d..c5505fd382 100644
--- a/spec/ruby/core/string/match_spec.rb
+++ b/spec/ruby/core/string/match_spec.rb
@@ -43,10 +43,8 @@ describe "String#=~" do
$~.should == nil
end
- with_feature :encoding do
- it "returns the character index of a found match" do
- ("こにちわ" =~ /に/).should == 1
- end
+ it "returns the character index of a found match" do
+ ("こにちわ" =~ /に/).should == 1
end
end
@@ -64,10 +62,8 @@ describe "String#match" do
"01234".match(/(.).(.)/, 1).captures.should == ["1", "3"]
end
- with_feature :encoding do
- it "uses the start as a character offset" do
- "零一二三四".match(/(.).(.)/, 1).captures.should == ["一", "三"]
- end
+ it "uses the start as a character offset" do
+ "零一二三四".match(/(.).(.)/, 1).captures.should == ["一", "三"]
end
end
@@ -76,10 +72,8 @@ describe "String#match" do
"01234".match(/(.).(.)/, -4).captures.should == ["1", "3"]
end
- with_feature :encoding do
- it "uses the start as a character offset" do
- "零一二三四".match(/(.).(.)/, -4).captures.should == ["一", "三"]
- end
+ it "uses the start as a character offset" do
+ "零一二三四".match(/(.).(.)/, -4).captures.should == ["一", "三"]
end
end
end
diff --git a/spec/ruby/core/string/ord_spec.rb b/spec/ruby/core/string/ord_spec.rb
index 8ba110c973..63f9815ea9 100644
--- a/spec/ruby/core/string/ord_spec.rb
+++ b/spec/ruby/core/string/ord_spec.rb
@@ -1,30 +1,28 @@
require_relative '../../spec_helper'
-with_feature :encoding do
- describe "String#ord" do
- it "returns a Fixnum" do
- 'a'.ord.should be_an_instance_of(Fixnum)
- end
+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 "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
+ it "ignores subsequent characters" do
+ "\u{287}a".ord.should == "\u{287}".ord
+ end
- it "understands multibyte characters" do
- "\u{9879}".ord.should == 39033
- end
+ 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
+ it "is equivalent to #codepoints.first" do
+ "\u{981}\u{982}".ord.should == "\u{981}\u{982}".codepoints.first
+ end
- it "raises an ArgumentError if called on an empty String" do
- lambda { ''.ord }.should raise_error(ArgumentError)
- end
+ it "raises an ArgumentError if called on an empty String" do
+ lambda { ''.ord }.should raise_error(ArgumentError)
end
end
diff --git a/spec/ruby/core/string/reverse_spec.rb b/spec/ruby/core/string/reverse_spec.rb
index 7cb171cb81..f2a8b64d47 100644
--- a/spec/ruby/core/string/reverse_spec.rb
+++ b/spec/ruby/core/string/reverse_spec.rb
@@ -15,10 +15,8 @@ describe "String#reverse" do
"m".taint.reverse.tainted?.should == true
end
- with_feature :encoding do
- it "reverses a string with multi byte characters" do
- "微軟正黑體".reverse.should == "體黑正軟微"
- end
+ it "reverses a string with multi byte characters" do
+ "微軟正黑體".reverse.should == "體黑正軟微"
end
end
@@ -42,11 +40,9 @@ describe "String#reverse!" do
lambda { "".freeze.reverse! }.should raise_error(frozen_error_class)
end
- with_feature :encoding do
- it "reverses a string with multi byte characters" do
- str = "微軟正黑體"
- str.reverse!
- str.should == "體黑正軟微"
- end
+ it "reverses a string with multi byte characters" do
+ str = "微軟正黑體"
+ str.reverse!
+ str.should == "體黑正軟微"
end
end
diff --git a/spec/ruby/core/string/rindex_spec.rb b/spec/ruby/core/string/rindex_spec.rb
index 98e36785e3..f74c0115cc 100644
--- a/spec/ruby/core/string/rindex_spec.rb
+++ b/spec/ruby/core/string/rindex_spec.rb
@@ -347,22 +347,20 @@ describe "String#rindex with Regexp" do
lambda { "str".rindex(/../, nil) }.should raise_error(TypeError)
end
- with_feature :encoding do
- it "returns the reverse character index of a multibyte character" do
- "ありがりがとう".rindex("が").should == 4
- "ありがりがとう".rindex(/が/).should == 4
- end
+ it "returns the reverse character index of a multibyte character" do
+ "ありがりがとう".rindex("が").should == 4
+ "ありがりがとう".rindex(/が/).should == 4
+ end
- it "returns the character index before the finish" do
- "ありがりがとう".rindex("が", 3).should == 2
- "ありがりがとう".rindex(/が/, 3).should == 2
- end
+ it "returns the character index before the finish" do
+ "ありがりがとう".rindex("が", 3).should == 2
+ "ありがりがとう".rindex(/が/, 3).should == 2
+ end
- it "raises an Encoding::CompatibilityError if the encodings are incompatible" do
- re = Regexp.new "れ".encode(Encoding::EUC_JP)
- lambda do
- "あれ".rindex re
- end.should raise_error(Encoding::CompatibilityError)
- end
+ it "raises an Encoding::CompatibilityError if the encodings are incompatible" do
+ re = Regexp.new "れ".encode(Encoding::EUC_JP)
+ lambda do
+ "あれ".rindex re
+ end.should raise_error(Encoding::CompatibilityError)
end
end
diff --git a/spec/ruby/core/string/rjust_spec.rb b/spec/ruby/core/string/rjust_spec.rb
index c2cfae7b66..2821b018e8 100644
--- a/spec/ruby/core/string/rjust_spec.rb
+++ b/spec/ruby/core/string/rjust_spec.rb
@@ -87,30 +87,28 @@ describe "String#rjust with length, padding" do
"hello".rjust(6, 'X'.taint).tainted?.should be_true
end
- with_feature :encoding do
- describe "with width" do
- it "returns a String in the same encoding as the original" do
- str = "abc".force_encoding Encoding::IBM437
- result = str.rjust 5
- result.should == " abc"
- result.encoding.should equal(Encoding::IBM437)
- end
+ describe "with width" do
+ it "returns a String in the same encoding as the original" do
+ str = "abc".force_encoding Encoding::IBM437
+ result = str.rjust 5
+ result.should == " abc"
+ result.encoding.should equal(Encoding::IBM437)
+ end
+ end
+
+ describe "with width, pattern" do
+ it "returns a String in the compatible encoding" do
+ str = "abc".force_encoding Encoding::IBM437
+ result = str.rjust 5, "あ"
+ result.should == "ああabc"
+ result.encoding.should equal(Encoding::UTF_8)
end
- describe "with width, pattern" do
- it "returns a String in the compatible encoding" do
- str = "abc".force_encoding Encoding::IBM437
- result = str.rjust 5, "あ"
- result.should == "ああabc"
- result.encoding.should equal(Encoding::UTF_8)
- end
-
- it "raises an Encoding::CompatibilityError if the encodings are incompatible" do
- pat = "ア".encode Encoding::EUC_JP
- lambda do
- "あれ".rjust 5, pat
- end.should raise_error(Encoding::CompatibilityError)
- end
+ it "raises an Encoding::CompatibilityError if the encodings are incompatible" do
+ pat = "ア".encode Encoding::EUC_JP
+ lambda do
+ "あれ".rjust 5, pat
+ end.should raise_error(Encoding::CompatibilityError)
end
end
end
diff --git a/spec/ruby/core/string/shared/chars.rb b/spec/ruby/core/string/shared/chars.rb
index 6a2fdb483f..d37bc50675 100644
--- a/spec/ruby/core/string/shared/chars.rb
+++ b/spec/ruby/core/string/shared/chars.rb
@@ -20,61 +20,59 @@ describe :string_chars, shared: true do
["\303\207", "\342\210\202", "\303\251", "\306\222", "g"]
end
- with_feature :encoding do
- it "returns characters in the same encoding as self" do
- "&%".force_encoding('Shift_JIS').send(@method).to_a.all? {|c| c.encoding.name.should == 'Shift_JIS'}
- "&%".encode('ASCII-8BIT').send(@method).to_a.all? {|c| c.encoding.name.should == 'ASCII-8BIT'}
- end
+ it "returns characters in the same encoding as self" do
+ "&%".force_encoding('Shift_JIS').send(@method).to_a.all? {|c| c.encoding.name.should == 'Shift_JIS'}
+ "&%".encode('ASCII-8BIT').send(@method).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 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
- xA4 = [0xA4].pack('C')
- xA4.force_encoding('UTF-8')
- xA4.valid_encoding?.should be_false
- xA4.send(@method).to_a.should == [xA4.force_encoding("UTF-8")]
- end
+ it "works if the String's contents is invalid for its encoding" do
+ xA4 = [0xA4].pack('C')
+ xA4.force_encoding('UTF-8')
+ xA4.valid_encoding?.should be_false
+ xA4.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 == [[0xA4].pack('C').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 "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 == [[0xA4].pack('C').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{24B62}"
+ it "uses the String's encoding to determine what characters it contains" do
+ s = "\u{24B62}"
- s.force_encoding('UTF-8').send(@method).to_a.should == [
- s.force_encoding('UTF-8')
- ]
- s.force_encoding('BINARY').send(@method).to_a.should == [
- [0xF0].pack('C').force_encoding('BINARY'),
- [0xA4].pack('C').force_encoding('BINARY'),
- [0xAD].pack('C').force_encoding('BINARY'),
- [0xA2].pack('C').force_encoding('BINARY')
- ]
- s.force_encoding('SJIS').send(@method).to_a.should == [
- [0xF0,0xA4].pack('CC').force_encoding('SJIS'),
- [0xAD].pack('C').force_encoding('SJIS'),
- [0xA2].pack('C').force_encoding('SJIS')
- ]
- end
+ s.force_encoding('UTF-8').send(@method).to_a.should == [
+ s.force_encoding('UTF-8')
+ ]
+ s.force_encoding('BINARY').send(@method).to_a.should == [
+ [0xF0].pack('C').force_encoding('BINARY'),
+ [0xA4].pack('C').force_encoding('BINARY'),
+ [0xAD].pack('C').force_encoding('BINARY'),
+ [0xA2].pack('C').force_encoding('BINARY')
+ ]
+ s.force_encoding('SJIS').send(@method).to_a.should == [
+ [0xF0,0xA4].pack('CC').force_encoding('SJIS'),
+ [0xAD].pack('C').force_encoding('SJIS'),
+ [0xA2].pack('C').force_encoding('SJIS')
+ ]
+ end
- it "taints resulting strings when self is tainted" do
- str = "hello"
+ it "taints resulting strings when self is tainted" do
+ str = "hello"
- str.send(@method) do |x|
- x.tainted?.should == false
- end
+ str.send(@method) do |x|
+ x.tainted?.should == false
+ end
- str.dup.taint.send(@method) do |x|
- x.tainted?.should == true
- end
+ str.dup.taint.send(@method) do |x|
+ x.tainted?.should == true
end
end
end
diff --git a/spec/ruby/core/string/shared/length.rb b/spec/ruby/core/string/shared/length.rb
index 0e6e66ee1c..cea287d7a2 100644
--- a/spec/ruby/core/string/shared/length.rb
+++ b/spec/ruby/core/string/shared/length.rb
@@ -10,19 +10,17 @@ describe :string_length, shared: true do
"four".send(@method).should == 4
end
- with_feature :encoding do
- it "returns the length of a string in different encodings" do
- utf8_str = 'こにちわ' * 100
- utf8_str.size.should == 400
- utf8_str.encode(Encoding::UTF_32BE).size.should == 400
- utf8_str.encode(Encoding::SHIFT_JIS).size.should == 400
- end
+ it "returns the length of a string in different encodings" do
+ utf8_str = 'こにちわ' * 100
+ utf8_str.size.should == 400
+ utf8_str.encode(Encoding::UTF_32BE).size.should == 400
+ utf8_str.encode(Encoding::SHIFT_JIS).size.should == 400
+ end
- it "returns the length of the new self after encoding is changed" do
- str = 'こにちわ'
- str.send(@method)
+ it "returns the length of the new self after encoding is changed" do
+ str = 'こにちわ'
+ str.send(@method)
- str.force_encoding('ASCII-8BIT').send(@method).should == 12
- end
+ str.force_encoding('ASCII-8BIT').send(@method).should == 12
end
end
diff --git a/spec/ruby/core/string/slice_spec.rb b/spec/ruby/core/string/slice_spec.rb
index a3e9d6b74f..e969f85937 100644
--- a/spec/ruby/core/string/slice_spec.rb
+++ b/spec/ruby/core/string/slice_spec.rb
@@ -72,15 +72,13 @@ describe "String#slice! with index" do
"hello".slice!(obj).should == ?e
end
- with_feature :encoding do
-
- it "returns the character given by the character index" do
- "hellö there".slice!(1).should == "e"
- "hellö there".slice!(4).should == "ö"
- "hellö there".slice!(6).should == "t"
- end
+ it "returns the character given by the character index" do
+ "hellö there".slice!(1).should == "e"
+ "hellö there".slice!(4).should == "ö"
+ "hellö there".slice!(6).should == "t"
end
+
end
describe "String#slice! with index, length" do
@@ -148,19 +146,17 @@ describe "String#slice! with index, length" do
s.slice!(0, 4).should be_an_instance_of(StringSpecs::MyString)
end
- with_feature :encoding do
- it "returns the substring given by the character offsets" do
- "hellö there".slice!(1,0).should == ""
- "hellö there".slice!(1,3).should == "ell"
- "hellö there".slice!(1,6).should == "ellö t"
- "hellö there".slice!(1,9).should == "ellö ther"
- end
+ it "returns the substring given by the character offsets" do
+ "hellö there".slice!(1,0).should == ""
+ "hellö there".slice!(1,3).should == "ell"
+ "hellö there".slice!(1,6).should == "ellö t"
+ "hellö there".slice!(1,9).should == "ellö ther"
+ end
- it "treats invalid bytes as single bytes" do
- xE6xCB = [0xE6,0xCB].pack('CC').force_encoding('utf-8')
- "a#{xE6xCB}b".slice!(1, 2).should == xE6xCB
- end
+ it "treats invalid bytes as single bytes" do
+ xE6xCB = [0xE6,0xCB].pack('CC').force_encoding('utf-8')
+ "a#{xE6xCB}b".slice!(1, 2).should == xE6xCB
end
end
@@ -236,20 +232,18 @@ describe "String#slice! Range" do
a.slice!(range_incl).should == "OO"
end
- with_feature :encoding do
-
- it "returns the substring given by the character offsets of the range" do
- "hellö there".slice!(1..1).should == "e"
- "hellö there".slice!(1..3).should == "ell"
- "hellö there".slice!(1...3).should == "el"
- "hellö there".slice!(-4..-2).should == "her"
- "hellö there".slice!(-4...-2).should == "he"
- "hellö there".slice!(5..-1).should == " there"
- "hellö there".slice!(5...-1).should == " ther"
- end
+ it "returns the substring given by the character offsets of the range" do
+ "hellö there".slice!(1..1).should == "e"
+ "hellö there".slice!(1..3).should == "ell"
+ "hellö there".slice!(1...3).should == "el"
+ "hellö there".slice!(-4..-2).should == "her"
+ "hellö there".slice!(-4...-2).should == "he"
+ "hellö there".slice!(5..-1).should == " there"
+ "hellö there".slice!(5...-1).should == " ther"
end
+
it "raises a #{frozen_error_class} on a frozen instance that is modified" do
lambda { "hello".freeze.slice!(1..3) }.should raise_error(frozen_error_class)
end
@@ -305,11 +299,9 @@ describe "String#slice! with Regexp" do
s.slice!(/../).should be_an_instance_of(StringSpecs::MyString)
end
- with_feature :encoding do
- it "returns the matching portion of self with a multi byte character" do
- "hëllo there".slice!(/[ë](.)\1/).should == "ëll"
- "".slice!(//).should == ""
- end
+ it "returns the matching portion of self with a multi byte character" do
+ "hëllo there".slice!(/[ë](.)\1/).should == "ëll"
+ "".slice!(//).should == ""
end
it "sets $~ to MatchData when there is a match and nil when there's none" do
@@ -389,16 +381,14 @@ describe "String#slice! with Regexp, index" do
s.slice!(/(.)(.)/, 1).should be_an_instance_of(StringSpecs::MyString)
end
- with_feature :encoding do
- it "returns the encoding aware capture for the given index" do
- "hår".slice!(/(.)(.)(.)/, 0).should == "hår"
- "hår".slice!(/(.)(.)(.)/, 1).should == "h"
- "hår".slice!(/(.)(.)(.)/, 2).should == "å"
- "hår".slice!(/(.)(.)(.)/, 3).should == "r"
- "hår".slice!(/(.)(.)(.)/, -1).should == "r"
- "hår".slice!(/(.)(.)(.)/, -2).should == "å"
- "hår".slice!(/(.)(.)(.)/, -3).should == "h"
- end
+ it "returns the encoding aware capture for the given index" do
+ "hår".slice!(/(.)(.)(.)/, 0).should == "hår"
+ "hår".slice!(/(.)(.)(.)/, 1).should == "h"
+ "hår".slice!(/(.)(.)(.)/, 2).should == "å"
+ "hår".slice!(/(.)(.)(.)/, 3).should == "r"
+ "hår".slice!(/(.)(.)(.)/, -1).should == "r"
+ "hår".slice!(/(.)(.)(.)/, -2).should == "å"
+ "hår".slice!(/(.)(.)(.)/, -3).should == "h"
end
it "sets $~ to MatchData when there is a match and nil when there's none" do
diff --git a/spec/ruby/core/string/split_spec.rb b/spec/ruby/core/string/split_spec.rb
index 82f261b8df..6c666deb6c 100644
--- a/spec/ruby/core/string/split_spec.rb
+++ b/spec/ruby/core/string/split_spec.rb
@@ -3,19 +3,17 @@ require_relative '../../spec_helper'
require_relative 'fixtures/classes'
describe "String#split with String" do
- with_feature :encoding do
- it "throws an ArgumentError if the pattern is not a valid string" do
- str = 'проверка'
- broken_str = 'проверка'
- broken_str.force_encoding('binary')
- broken_str.chop!
- broken_str.force_encoding('utf-8')
- lambda { str.split(broken_str) }.should raise_error(ArgumentError)
- end
+ it "throws an ArgumentError if the pattern is not a valid string" do
+ str = 'проверка'
+ broken_str = 'проверка'
+ broken_str.force_encoding('binary')
+ broken_str.chop!
+ broken_str.force_encoding('utf-8')
+ lambda { str.split(broken_str) }.should raise_error(ArgumentError)
+ end
- it "splits on multibyte characters" do
- "ありがりがとう".split("が").should == ["あり", "り", "とう"]
- end
+ it "splits on multibyte characters" do
+ "ありがりがとう".split("が").should == ["あり", "り", "とう"]
end
it "returns an array of substrings based on splitting on the given string" do
diff --git a/spec/ruby/core/string/tr_s_spec.rb b/spec/ruby/core/string/tr_s_spec.rb
index 87635acf2c..b05211abc4 100644
--- a/spec/ruby/core/string/tr_s_spec.rb
+++ b/spec/ruby/core/string/tr_s_spec.rb
@@ -60,49 +60,47 @@ describe "String#tr_s" do
end
end
- with_feature :encoding do
- # http://redmine.ruby-lang.org/issues/show/1839
- it "can replace a 7-bit ASCII character with a multibyte one" do
- a = "uber"
- a.encoding.should == Encoding::UTF_8
- b = a.tr_s("u","ü")
- b.should == "über"
- b.encoding.should == Encoding::UTF_8
- end
-
- it "can replace multiple 7-bit ASCII characters with a multibyte one" do
- a = "uuuber"
- a.encoding.should == Encoding::UTF_8
- b = a.tr_s("u","ü")
- b.should == "über"
- b.encoding.should == Encoding::UTF_8
- end
+ # http://redmine.ruby-lang.org/issues/show/1839
+ it "can replace a 7-bit ASCII character with a multibyte one" do
+ a = "uber"
+ a.encoding.should == Encoding::UTF_8
+ b = a.tr_s("u","ü")
+ b.should == "über"
+ b.encoding.should == Encoding::UTF_8
+ end
- it "can replace a multibyte character with a single byte one" do
- a = "über"
- a.encoding.should == Encoding::UTF_8
- b = a.tr_s("ü","u")
- b.should == "uber"
- b.encoding.should == Encoding::UTF_8
- end
+ it "can replace multiple 7-bit ASCII characters with a multibyte one" do
+ a = "uuuber"
+ a.encoding.should == Encoding::UTF_8
+ b = a.tr_s("u","ü")
+ b.should == "über"
+ b.encoding.should == Encoding::UTF_8
+ end
- it "can replace multiple multibyte characters with a single byte one" do
- a = "üüüber"
- a.encoding.should == Encoding::UTF_8
- b = a.tr_s("ü","u")
- b.should == "uber"
- b.encoding.should == Encoding::UTF_8
- end
+ it "can replace a multibyte character with a single byte one" do
+ a = "über"
+ a.encoding.should == Encoding::UTF_8
+ b = a.tr_s("ü","u")
+ b.should == "uber"
+ b.encoding.should == Encoding::UTF_8
+ end
- it "does not replace a multibyte character where part of the bytes match the tr string" do
- str = "椎名深夏"
- a = "\u0080\u0082\u0083\u0084\u0085\u0086\u0087\u0088\u0089\u008A\u008B\u008C\u008E\u0091\u0092\u0093\u0094\u0095\u0096\u0097\u0098\u0099\u009A\u009B\u009C\u009E\u009F"
- b = "€‚ƒ„…†‡ˆ‰Š‹ŒŽ‘’“”•–—˜™š›œžŸ"
- str.tr_s(a, b).should == "椎名深夏"
- end
+ it "can replace multiple multibyte characters with a single byte one" do
+ a = "üüüber"
+ a.encoding.should == Encoding::UTF_8
+ b = a.tr_s("ü","u")
+ b.should == "uber"
+ b.encoding.should == Encoding::UTF_8
+ end
+ it "does not replace a multibyte character where part of the bytes match the tr string" do
+ str = "椎名深夏"
+ a = "\u0080\u0082\u0083\u0084\u0085\u0086\u0087\u0088\u0089\u008A\u008B\u008C\u008E\u0091\u0092\u0093\u0094\u0095\u0096\u0097\u0098\u0099\u009A\u009B\u009C\u009E\u009F"
+ b = "€‚ƒ„…†‡ˆ‰Š‹ŒŽ‘’“”•–—˜™š›œžŸ"
+ str.tr_s(a, b).should == "椎名深夏"
end
+
end
describe "String#tr_s!" do
diff --git a/spec/ruby/core/string/tr_spec.rb b/spec/ruby/core/string/tr_spec.rb
index efd5a7f638..8a33dd24f5 100644
--- a/spec/ruby/core/string/tr_spec.rb
+++ b/spec/ruby/core/string/tr_spec.rb
@@ -72,32 +72,30 @@ describe "String#tr" do
end
end
- with_feature :encoding do
- # http://redmine.ruby-lang.org/issues/show/1839
- it "can replace a 7-bit ASCII character with a multibyte one" do
- a = "uber"
- a.encoding.should == Encoding::UTF_8
- b = a.tr("u","ü")
- b.should == "über"
- b.encoding.should == Encoding::UTF_8
- end
-
- it "can replace a multibyte character with a single byte one" do
- a = "über"
- a.encoding.should == Encoding::UTF_8
- b = a.tr("ü","u")
- b.should == "uber"
- b.encoding.should == Encoding::UTF_8
- end
+ # http://redmine.ruby-lang.org/issues/show/1839
+ it "can replace a 7-bit ASCII character with a multibyte one" do
+ a = "uber"
+ a.encoding.should == Encoding::UTF_8
+ b = a.tr("u","ü")
+ b.should == "über"
+ b.encoding.should == Encoding::UTF_8
+ end
- it "does not replace a multibyte character where part of the bytes match the tr string" do
- str = "椎名深夏"
- a = "\u0080\u0082\u0083\u0084\u0085\u0086\u0087\u0088\u0089\u008A\u008B\u008C\u008E\u0091\u0092\u0093\u0094\u0095\u0096\u0097\u0098\u0099\u009A\u009B\u009C\u009E\u009F"
- b = "€‚ƒ„…†‡ˆ‰Š‹ŒŽ‘’“”•–—˜™š›œžŸ"
- str.tr(a, b).should == "椎名深夏"
- end
+ it "can replace a multibyte character with a single byte one" do
+ a = "über"
+ a.encoding.should == Encoding::UTF_8
+ b = a.tr("ü","u")
+ b.should == "uber"
+ b.encoding.should == Encoding::UTF_8
+ end
+ it "does not replace a multibyte character where part of the bytes match the tr string" do
+ str = "椎名深夏"
+ a = "\u0080\u0082\u0083\u0084\u0085\u0086\u0087\u0088\u0089\u008A\u008B\u008C\u008E\u0091\u0092\u0093\u0094\u0095\u0096\u0097\u0098\u0099\u009A\u009B\u009C\u009E\u009F"
+ b = "€‚ƒ„…†‡ˆ‰Š‹ŒŽ‘’“”•–—˜™š›œžŸ"
+ str.tr(a, b).should == "椎名深夏"
end
+
end
describe "String#tr!" do
diff --git a/spec/ruby/core/string/valid_encoding_spec.rb b/spec/ruby/core/string/valid_encoding_spec.rb
index c8cbbcf5ec..54109386ba 100644
--- a/spec/ruby/core/string/valid_encoding_spec.rb
+++ b/spec/ruby/core/string/valid_encoding_spec.rb
@@ -1,129 +1,127 @@
require_relative '../../spec_helper'
-with_feature :encoding 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
+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 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 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 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#{[0x80].pack('C')}".force_encoding('ascii').valid_encoding?.should be_false
- end
+ it "returns false if self contains a character invalid in the associated encoding" do
+ "abc#{[0x80].pack('C')}".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 << [0xDD].pack('C').force_encoding('utf-8')
- str.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 << [0xDD].pack('C').force_encoding('utf-8')
+ str.valid_encoding?.should be_false
+ end
- it "returns true if an invalid string is appended another invalid one but both make a valid string" do
- str = [0xD0].pack('C').force_encoding('utf-8')
- str.valid_encoding?.should be_false
- str << [0xBF].pack('C').force_encoding('utf-8')
- str.valid_encoding?.should be_true
- end
+ it "returns true if an invalid string is appended another invalid one but both make a valid string" do
+ str = [0xD0].pack('C').force_encoding('utf-8')
+ str.valid_encoding?.should be_false
+ str << [0xBF].pack('C').force_encoding('utf-8')
+ str.valid_encoding?.should be_true
end
end
diff --git a/spec/ruby/core/thread/shared/exit.rb b/spec/ruby/core/thread/shared/exit.rb
index 3c63517d92..4686b7b28b 100644
--- a/spec/ruby/core/thread/shared/exit.rb
+++ b/spec/ruby/core/thread/shared/exit.rb
@@ -80,19 +80,17 @@ describe :thread_exit, shared: true do
ScratchPad.recorded.should == nil
end
- with_feature :fiber do
- it "kills the entire thread when a fiber is active" do
- t = Thread.new do
- Fiber.new do
- sleep
- end.resume
- ScratchPad.record :fiber_resumed
- end
- Thread.pass while t.status and t.status != "sleep"
- t.send(@method)
- t.join
- ScratchPad.recorded.should == nil
+ it "kills the entire thread when a fiber is active" do
+ t = Thread.new do
+ Fiber.new do
+ sleep
+ end.resume
+ ScratchPad.record :fiber_resumed
end
+ Thread.pass while t.status and t.status != "sleep"
+ t.send(@method)
+ t.join
+ ScratchPad.recorded.should == nil
end
# This spec is a mess. It fails randomly, it hangs on MRI, it needs to be removed
diff --git a/spec/ruby/core/time/_load_spec.rb b/spec/ruby/core/time/_load_spec.rb
index 5f6275d46c..152934370f 100644
--- a/spec/ruby/core/time/_load_spec.rb
+++ b/spec/ruby/core/time/_load_spec.rb
@@ -43,12 +43,10 @@ describe "Time._load" do
t.to_s.should == "2010-10-22 16:57:48 UTC"
end
- with_feature :encoding do
- it "treats the data as binary data" do
- data = "\x04\bu:\tTime\r\fM\x1C\xC0\x00\x00\xD0\xBE"
- data.force_encoding Encoding::UTF_8
- t = Marshal.load(data)
- t.to_s.should == "2013-04-08 12:47:45 UTC"
- end
+ it "treats the data as binary data" do
+ data = "\x04\bu:\tTime\r\fM\x1C\xC0\x00\x00\xD0\xBE"
+ data.force_encoding Encoding::UTF_8
+ t = Marshal.load(data)
+ t.to_s.should == "2013-04-08 12:47:45 UTC"
end
end
diff --git a/spec/ruby/core/time/shared/inspect.rb b/spec/ruby/core/time/shared/inspect.rb
index c707382a6e..4133671924 100644
--- a/spec/ruby/core/time/shared/inspect.rb
+++ b/spec/ruby/core/time/shared/inspect.rb
@@ -15,9 +15,7 @@ describe :inspect, shared: true do
Time.new(2000, 1, 1, 20, 15, 01, 3600).send(@method).should == "2000-01-01 20:15:01 +0100"
end
- with_feature :encoding do
- it "returns a US-ASCII encoded string" do
- Time.now.send(@method).encoding.should equal(Encoding::US_ASCII)
- end
+ it "returns a US-ASCII encoded string" do
+ Time.now.send(@method).encoding.should equal(Encoding::US_ASCII)
end
end
diff --git a/spec/ruby/default.mspec b/spec/ruby/default.mspec
index 80d71c21e7..6fd6d2bf9c 100644
--- a/spec/ruby/default.mspec
+++ b/spec/ruby/default.mspec
@@ -29,8 +29,6 @@ class MSpecScript
set :ci_files, get(:files)
# The default implementation to run the specs.
- # TODO: this needs to be more sophisticated since the
- # executable is not consistently named.
set :target, 'ruby'
set :backtrace_filter, /mspec\//
@@ -48,11 +46,4 @@ class MSpecScript
/\wSpecs?$/,
/^CS_CONST/,
]
-
- # Enable features
- MSpec.enable_feature :fiber
- MSpec.enable_feature :fiber_library
- MSpec.enable_feature :fork if respond_to?(:fork, true)
- MSpec.enable_feature :encoding
- MSpec.enable_feature :mjit if defined?(RubyVM::MJIT) && RubyVM::MJIT.enabled?
end
diff --git a/spec/ruby/language/predefined_spec.rb b/spec/ruby/language/predefined_spec.rb
index 58201b8cbd..61ca0d8237 100644
--- a/spec/ruby/language/predefined_spec.rb
+++ b/spec/ruby/language/predefined_spec.rb
@@ -136,11 +136,9 @@ describe "Predefined global $&" do
$&.should == 'foo'
end
- with_feature :encoding do
- it "sets the encoding to the encoding of the source String" do
- "abc".force_encoding(Encoding::EUC_JP) =~ /b/
- $&.encoding.should equal(Encoding::EUC_JP)
- end
+ it "sets the encoding to the encoding of the source String" do
+ "abc".force_encoding(Encoding::EUC_JP) =~ /b/
+ $&.encoding.should equal(Encoding::EUC_JP)
end
end
@@ -151,16 +149,14 @@ describe "Predefined global $`" do
$`.should == 'bar'
end
- with_feature :encoding do
- it "sets the encoding to the encoding of the source String" do
- "abc".force_encoding(Encoding::EUC_JP) =~ /b/
- $`.encoding.should equal(Encoding::EUC_JP)
- end
+ it "sets the encoding to the encoding of the source String" do
+ "abc".force_encoding(Encoding::EUC_JP) =~ /b/
+ $`.encoding.should equal(Encoding::EUC_JP)
+ end
- it "sets an empty result to the encoding of the source String" do
- "abc".force_encoding(Encoding::ISO_8859_1) =~ /a/
- $`.encoding.should equal(Encoding::ISO_8859_1)
- end
+ it "sets an empty result to the encoding of the source String" do
+ "abc".force_encoding(Encoding::ISO_8859_1) =~ /a/
+ $`.encoding.should equal(Encoding::ISO_8859_1)
end
end
@@ -171,16 +167,14 @@ describe "Predefined global $'" do
$'.should == 'baz'
end
- with_feature :encoding do
- it "sets the encoding to the encoding of the source String" do
- "abc".force_encoding(Encoding::EUC_JP) =~ /b/
- $'.encoding.should equal(Encoding::EUC_JP)
- end
+ it "sets the encoding to the encoding of the source String" do
+ "abc".force_encoding(Encoding::EUC_JP) =~ /b/
+ $'.encoding.should equal(Encoding::EUC_JP)
+ end
- it "sets an empty result to the encoding of the source String" do
- "abc".force_encoding(Encoding::ISO_8859_1) =~ /c/
- $'.encoding.should equal(Encoding::ISO_8859_1)
- end
+ it "sets an empty result to the encoding of the source String" do
+ "abc".force_encoding(Encoding::ISO_8859_1) =~ /c/
+ $'.encoding.should equal(Encoding::ISO_8859_1)
end
end
@@ -196,11 +190,9 @@ describe "Predefined global $+" do
$+.should == 'a'
end
- with_feature :encoding do
- it "sets the encoding to the encoding of the source String" do
- "abc".force_encoding(Encoding::EUC_JP) =~ /(b)/
- $+.encoding.should equal(Encoding::EUC_JP)
- end
+ it "sets the encoding to the encoding of the source String" do
+ "abc".force_encoding(Encoding::EUC_JP) =~ /(b)/
+ $+.encoding.should equal(Encoding::EUC_JP)
end
end
@@ -225,11 +217,9 @@ describe "Predefined globals $1..N" do
test("-").should == nil
end
- with_feature :encoding do
- it "sets the encoding to the encoding of the source String" do
- "abc".force_encoding(Encoding::EUC_JP) =~ /(b)/
- $1.encoding.should equal(Encoding::EUC_JP)
- end
+ it "sets the encoding to the encoding of the source String" do
+ "abc".force_encoding(Encoding::EUC_JP) =~ /(b)/
+ $1.encoding.should equal(Encoding::EUC_JP)
end
end
@@ -1139,110 +1129,108 @@ describe "The predefined global constants" do
end
-with_feature :encoding do
- describe "The predefined global constant" do
- before :each do
- @external = Encoding.default_external
- @internal = Encoding.default_internal
- end
+describe "The predefined global constant" do
+ before :each do
+ @external = Encoding.default_external
+ @internal = Encoding.default_internal
+ end
- after :each do
- Encoding.default_external = @external
- Encoding.default_internal = @internal
- end
+ after :each do
+ Encoding.default_external = @external
+ Encoding.default_internal = @internal
+ end
- describe "STDIN" do
- it "has the same external encoding as Encoding.default_external" do
- STDIN.external_encoding.should equal(Encoding.default_external)
- end
+ describe "STDIN" do
+ it "has the same external encoding as Encoding.default_external" do
+ STDIN.external_encoding.should equal(Encoding.default_external)
+ end
- it "has the same external encoding as Encoding.default_external when that encoding is changed" do
- Encoding.default_external = Encoding::ISO_8859_16
- STDIN.external_encoding.should equal(Encoding::ISO_8859_16)
- end
+ it "has the same external encoding as Encoding.default_external when that encoding is changed" do
+ Encoding.default_external = Encoding::ISO_8859_16
+ STDIN.external_encoding.should equal(Encoding::ISO_8859_16)
+ end
- it "has the encodings set by #set_encoding" do
- code = "STDIN.set_encoding Encoding::IBM775, Encoding::IBM866; " \
- "p [STDIN.external_encoding.name, STDIN.internal_encoding.name]"
- ruby_exe(code).chomp.should == %{["IBM775", "IBM866"]}
- end
+ it "has the encodings set by #set_encoding" do
+ code = "STDIN.set_encoding Encoding::IBM775, Encoding::IBM866; " \
+ "p [STDIN.external_encoding.name, STDIN.internal_encoding.name]"
+ ruby_exe(code).chomp.should == %{["IBM775", "IBM866"]}
+ end
- it "retains the encoding set by #set_encoding when Encoding.default_external is changed" do
- code = "STDIN.set_encoding Encoding::IBM775, Encoding::IBM866; " \
- "Encoding.default_external = Encoding::ISO_8859_16;" \
- "p [STDIN.external_encoding.name, STDIN.internal_encoding.name]"
- ruby_exe(code).chomp.should == %{["IBM775", "IBM866"]}
- end
+ it "retains the encoding set by #set_encoding when Encoding.default_external is changed" do
+ code = "STDIN.set_encoding Encoding::IBM775, Encoding::IBM866; " \
+ "Encoding.default_external = Encoding::ISO_8859_16;" \
+ "p [STDIN.external_encoding.name, STDIN.internal_encoding.name]"
+ ruby_exe(code).chomp.should == %{["IBM775", "IBM866"]}
+ end
- it "has nil for the internal encoding" do
- STDIN.internal_encoding.should be_nil
- end
+ it "has nil for the internal encoding" do
+ STDIN.internal_encoding.should be_nil
+ end
- it "has nil for the internal encoding despite Encoding.default_internal being changed" do
- Encoding.default_internal = Encoding::IBM437
- STDIN.internal_encoding.should be_nil
- end
+ it "has nil for the internal encoding despite Encoding.default_internal being changed" do
+ Encoding.default_internal = Encoding::IBM437
+ STDIN.internal_encoding.should be_nil
end
+ end
- describe "STDOUT" do
- it "has nil for the external encoding" do
- STDOUT.external_encoding.should be_nil
- end
+ describe "STDOUT" do
+ it "has nil for the external encoding" do
+ STDOUT.external_encoding.should be_nil
+ end
- it "has nil for the external encoding despite Encoding.default_external being changed" do
- Encoding.default_external = Encoding::ISO_8859_1
- STDOUT.external_encoding.should be_nil
- end
+ it "has nil for the external encoding despite Encoding.default_external being changed" do
+ Encoding.default_external = Encoding::ISO_8859_1
+ STDOUT.external_encoding.should be_nil
+ end
- it "has the encodings set by #set_encoding" do
- code = "STDOUT.set_encoding Encoding::IBM775, Encoding::IBM866; " \
- "p [STDOUT.external_encoding.name, STDOUT.internal_encoding.name]"
- ruby_exe(code).chomp.should == %{["IBM775", "IBM866"]}
- end
+ it "has the encodings set by #set_encoding" do
+ code = "STDOUT.set_encoding Encoding::IBM775, Encoding::IBM866; " \
+ "p [STDOUT.external_encoding.name, STDOUT.internal_encoding.name]"
+ ruby_exe(code).chomp.should == %{["IBM775", "IBM866"]}
+ end
- it "has nil for the internal encoding" do
- STDOUT.internal_encoding.should be_nil
- end
+ it "has nil for the internal encoding" do
+ STDOUT.internal_encoding.should be_nil
+ end
- it "has nil for the internal encoding despite Encoding.default_internal being changed" do
- Encoding.default_internal = Encoding::IBM437
- STDOUT.internal_encoding.should be_nil
- end
+ it "has nil for the internal encoding despite Encoding.default_internal being changed" do
+ Encoding.default_internal = Encoding::IBM437
+ STDOUT.internal_encoding.should be_nil
end
+ end
- describe "STDERR" do
- it "has nil for the external encoding" do
- STDERR.external_encoding.should be_nil
- end
+ describe "STDERR" do
+ it "has nil for the external encoding" do
+ STDERR.external_encoding.should be_nil
+ end
- it "has nil for the external encoding despite Encoding.default_external being changed" do
- Encoding.default_external = Encoding::ISO_8859_1
- STDERR.external_encoding.should be_nil
- end
+ it "has nil for the external encoding despite Encoding.default_external being changed" do
+ Encoding.default_external = Encoding::ISO_8859_1
+ STDERR.external_encoding.should be_nil
+ end
- it "has the encodings set by #set_encoding" do
- code = "STDERR.set_encoding Encoding::IBM775, Encoding::IBM866; " \
- "p [STDERR.external_encoding.name, STDERR.internal_encoding.name]"
- ruby_exe(code).chomp.should == %{["IBM775", "IBM866"]}
- end
+ it "has the encodings set by #set_encoding" do
+ code = "STDERR.set_encoding Encoding::IBM775, Encoding::IBM866; " \
+ "p [STDERR.external_encoding.name, STDERR.internal_encoding.name]"
+ ruby_exe(code).chomp.should == %{["IBM775", "IBM866"]}
+ end
- it "has nil for the internal encoding" do
- STDERR.internal_encoding.should be_nil
- end
+ it "has nil for the internal encoding" do
+ STDERR.internal_encoding.should be_nil
+ end
- it "has nil for the internal encoding despite Encoding.default_internal being changed" do
- Encoding.default_internal = Encoding::IBM437
- STDERR.internal_encoding.should be_nil
- end
+ it "has nil for the internal encoding despite Encoding.default_internal being changed" do
+ Encoding.default_internal = Encoding::IBM437
+ STDERR.internal_encoding.should be_nil
end
+ end
- describe "ARGV" do
- it "contains Strings encoded in locale Encoding" do
- code = fixture __FILE__, "argv_encoding.rb"
- result = ruby_exe(code, args: "a b")
- encoding = Encoding.default_external
- result.chomp.should == %{["#{encoding}", "#{encoding}"]}
- end
+ describe "ARGV" do
+ it "contains Strings encoded in locale Encoding" do
+ code = fixture __FILE__, "argv_encoding.rb"
+ result = ruby_exe(code, args: "a b")
+ encoding = Encoding.default_external
+ result.chomp.should == %{["#{encoding}", "#{encoding}"]}
end
end
end
diff --git a/spec/ruby/language/string_spec.rb b/spec/ruby/language/string_spec.rb
index b198979d87..78ee5ff2c4 100644
--- a/spec/ruby/language/string_spec.rb
+++ b/spec/ruby/language/string_spec.rb
@@ -257,33 +257,31 @@ describe "Ruby String literals" do
end
-with_feature :encoding do
- describe "Ruby String interpolation" do
- it "creates a String having an Encoding compatible with all components" do
- a = "\u3042"
- b = "abc".encode("ascii-8bit")
+describe "Ruby String interpolation" do
+ it "creates a String having an Encoding compatible with all components" do
+ a = "\u3042"
+ b = "abc".encode("ascii-8bit")
- str = "#{a} x #{b}"
+ str = "#{a} x #{b}"
- str.should == "\xe3\x81\x82\x20\x78\x20\x61\x62\x63".force_encoding("utf-8")
- str.encoding.should == Encoding::UTF_8
- end
+ str.should == "\xe3\x81\x82\x20\x78\x20\x61\x62\x63".force_encoding("utf-8")
+ str.encoding.should == Encoding::UTF_8
+ end
- it "creates a String having the Encoding of the components when all are the same Encoding" do
- a = "abc".force_encoding("euc-jp")
- b = "def".force_encoding("euc-jp")
- str = '"#{a} x #{b}"'.force_encoding("euc-jp")
+ it "creates a String having the Encoding of the components when all are the same Encoding" do
+ a = "abc".force_encoding("euc-jp")
+ b = "def".force_encoding("euc-jp")
+ str = '"#{a} x #{b}"'.force_encoding("euc-jp")
- result = eval(str)
- result.should == "\x61\x62\x63\x20\x78\x20\x64\x65\x66".force_encoding("euc-jp")
- result.encoding.should == Encoding::EUC_JP
- end
+ result = eval(str)
+ result.should == "\x61\x62\x63\x20\x78\x20\x64\x65\x66".force_encoding("euc-jp")
+ result.encoding.should == Encoding::EUC_JP
+ end
- it "raises an Encoding::CompatibilityError if the Encodings are not compatible" do
- a = "\u3042"
- b = "\xff".force_encoding "ascii-8bit"
+ it "raises an Encoding::CompatibilityError if the Encodings are not compatible" do
+ a = "\u3042"
+ b = "\xff".force_encoding "ascii-8bit"
- lambda { "#{a} #{b}" }.should raise_error(Encoding::CompatibilityError)
- end
+ lambda { "#{a} #{b}" }.should raise_error(Encoding::CompatibilityError)
end
end
diff --git a/spec/ruby/library/fiber/alive_spec.rb b/spec/ruby/library/fiber/alive_spec.rb
index 72663dd173..0c20a1c6b8 100644
--- a/spec/ruby/library/fiber/alive_spec.rb
+++ b/spec/ruby/library/fiber/alive_spec.rb
@@ -1,48 +1,46 @@
require_relative '../../spec_helper'
-with_feature :fiber_library do
- require 'fiber'
+require 'fiber'
- describe "Fiber#alive?" do
- it "returns true for a Fiber that hasn't had #resume called" do
- fiber = Fiber.new { true }
- fiber.alive?.should be_true
- end
+describe "Fiber#alive?" do
+ it "returns true for a Fiber that hasn't had #resume called" do
+ fiber = Fiber.new { true }
+ fiber.alive?.should be_true
+ end
- # FIXME: Better description?
- it "returns true for a Fiber that's yielded to the caller" do
- fiber = Fiber.new { Fiber.yield }
- fiber.resume
- fiber.alive?.should be_true
- end
+ # FIXME: Better description?
+ it "returns true for a Fiber that's yielded to the caller" do
+ fiber = Fiber.new { Fiber.yield }
+ fiber.resume
+ fiber.alive?.should be_true
+ end
- it "returns true when called from its Fiber" do
- fiber = Fiber.new { fiber.alive?.should be_true }
- fiber.resume
- end
+ it "returns true when called from its Fiber" do
+ fiber = Fiber.new { fiber.alive?.should be_true }
+ fiber.resume
+ end
- it "doesn't invoke the block associated with the Fiber" do
- offthehook = mock('do not call')
- offthehook.should_not_receive(:ring)
- fiber = Fiber.new { offthehook.ring }
- fiber.alive?
- end
+ it "doesn't invoke the block associated with the Fiber" do
+ offthehook = mock('do not call')
+ offthehook.should_not_receive(:ring)
+ fiber = Fiber.new { offthehook.ring }
+ fiber.alive?
+ end
- it "returns false for a Fiber that's dead" do
- fiber = Fiber.new { true }
- fiber.resume
- lambda { fiber.resume }.should raise_error(FiberError)
- fiber.alive?.should be_false
- end
+ it "returns false for a Fiber that's dead" do
+ fiber = Fiber.new { true }
+ fiber.resume
+ lambda { fiber.resume }.should raise_error(FiberError)
+ fiber.alive?.should be_false
+ end
- it "always returns false for a dead Fiber" do
- fiber = Fiber.new { true }
- fiber.resume
- lambda { fiber.resume }.should raise_error(FiberError)
- fiber.alive?.should be_false
- lambda { fiber.resume }.should raise_error(FiberError)
- fiber.alive?.should be_false
- fiber.alive?.should be_false
- end
+ it "always returns false for a dead Fiber" do
+ fiber = Fiber.new { true }
+ fiber.resume
+ lambda { fiber.resume }.should raise_error(FiberError)
+ fiber.alive?.should be_false
+ lambda { fiber.resume }.should raise_error(FiberError)
+ fiber.alive?.should be_false
+ fiber.alive?.should be_false
end
end
diff --git a/spec/ruby/library/fiber/current_spec.rb b/spec/ruby/library/fiber/current_spec.rb
index 8b7fa7c4ca..52dff3dea1 100644
--- a/spec/ruby/library/fiber/current_spec.rb
+++ b/spec/ruby/library/fiber/current_spec.rb
@@ -1,53 +1,51 @@
require_relative '../../spec_helper'
-with_feature :fiber_library do
- require 'fiber'
+require 'fiber'
- describe "Fiber.current" do
- it "returns the root Fiber when called outside of a Fiber" do
- root = Fiber.current
- root.should be_an_instance_of(Fiber)
- # We can always transfer to the root Fiber; it will never die
- 5.times do
- root.transfer.should be_nil
- root.alive?.should be_true
- end
+describe "Fiber.current" do
+ it "returns the root Fiber when called outside of a Fiber" do
+ root = Fiber.current
+ root.should be_an_instance_of(Fiber)
+ # We can always transfer to the root Fiber; it will never die
+ 5.times do
+ root.transfer.should be_nil
+ root.alive?.should be_true
end
+ end
- it "returns the current Fiber when called from a Fiber" do
- fiber = Fiber.new do
- this = Fiber.current
- this.should be_an_instance_of(Fiber)
- this.should == fiber
- this.alive?.should be_true
- end
- fiber.resume
+ it "returns the current Fiber when called from a Fiber" do
+ fiber = Fiber.new do
+ this = Fiber.current
+ this.should be_an_instance_of(Fiber)
+ this.should == fiber
+ this.alive?.should be_true
end
+ fiber.resume
+ end
- it "returns the current Fiber when called from a Fiber that transferred to another" do
- states = []
- fiber = Fiber.new do
- states << :fiber
- this = Fiber.current
- this.should be_an_instance_of(Fiber)
- this.should == fiber
- this.alive?.should be_true
- end
-
- fiber2 = Fiber.new do
- states << :fiber2
- fiber.transfer
- flunk
- end
+ it "returns the current Fiber when called from a Fiber that transferred to another" do
+ states = []
+ fiber = Fiber.new do
+ states << :fiber
+ this = Fiber.current
+ this.should be_an_instance_of(Fiber)
+ this.should == fiber
+ this.alive?.should be_true
+ end
- fiber3 = Fiber.new do
- states << :fiber3
- fiber2.transfer
- flunk
- end
+ fiber2 = Fiber.new do
+ states << :fiber2
+ fiber.transfer
+ flunk
+ end
- fiber3.resume
- states.should == [:fiber3, :fiber2, :fiber]
+ fiber3 = Fiber.new do
+ states << :fiber3
+ fiber2.transfer
+ flunk
end
+
+ fiber3.resume
+ states.should == [:fiber3, :fiber2, :fiber]
end
end
diff --git a/spec/ruby/library/fiber/resume_spec.rb b/spec/ruby/library/fiber/resume_spec.rb
index 9789cf5b7c..3d86aed94e 100644
--- a/spec/ruby/library/fiber/resume_spec.rb
+++ b/spec/ruby/library/fiber/resume_spec.rb
@@ -1,14 +1,12 @@
require_relative '../../spec_helper'
-with_feature :fiber_library do
- require 'fiber'
+require 'fiber'
- describe "Fiber#resume" do
- it "raises a FiberError if the Fiber has transferred control to another Fiber" do
- fiber1 = Fiber.new { true }
- fiber2 = Fiber.new { fiber1.transfer; Fiber.yield }
- fiber2.resume
- lambda { fiber2.resume }.should raise_error(FiberError)
- end
+describe "Fiber#resume" do
+ it "raises a FiberError if the Fiber has transferred control to another Fiber" do
+ fiber1 = Fiber.new { true }
+ fiber2 = Fiber.new { fiber1.transfer; Fiber.yield }
+ fiber2.resume
+ lambda { fiber2.resume }.should raise_error(FiberError)
end
end
diff --git a/spec/ruby/library/fiber/transfer_spec.rb b/spec/ruby/library/fiber/transfer_spec.rb
index 22bb568840..1063bebeda 100644
--- a/spec/ruby/library/fiber/transfer_spec.rb
+++ b/spec/ruby/library/fiber/transfer_spec.rb
@@ -1,88 +1,86 @@
require_relative '../../spec_helper'
require_relative '../../shared/fiber/resume'
-with_feature :fiber_library do
- require 'fiber'
+require 'fiber'
- describe "Fiber#transfer" do
- it_behaves_like :fiber_resume, :transfer
+describe "Fiber#transfer" do
+ it_behaves_like :fiber_resume, :transfer
+end
+
+describe "Fiber#transfer" do
+ it "transfers control from one Fiber to another when called from a Fiber" do
+ fiber1 = Fiber.new { :fiber1 }
+ fiber2 = Fiber.new { fiber1.transfer; :fiber2 }
+ fiber2.resume.should == :fiber1
end
- describe "Fiber#transfer" do
- it "transfers control from one Fiber to another when called from a Fiber" do
- fiber1 = Fiber.new { :fiber1 }
- fiber2 = Fiber.new { fiber1.transfer; :fiber2 }
- fiber2.resume.should == :fiber1
- end
+ it "returns to the root Fiber when finished" do
+ f1 = Fiber.new { :fiber_1 }
+ f2 = Fiber.new { f1.transfer; :fiber_2 }
- it "returns to the root Fiber when finished" do
- f1 = Fiber.new { :fiber_1 }
- f2 = Fiber.new { f1.transfer; :fiber_2 }
+ f2.transfer.should == :fiber_1
+ f2.transfer.should == :fiber_2
+ end
- f2.transfer.should == :fiber_1
- f2.transfer.should == :fiber_2
- end
+ it "can be invoked from the same Fiber it transfers control to" do
+ states = []
+ fiber = Fiber.new { states << :start; fiber.transfer; states << :end }
+ fiber.transfer
+ states.should == [:start, :end]
- it "can be invoked from the same Fiber it transfers control to" do
- states = []
- fiber = Fiber.new { states << :start; fiber.transfer; states << :end }
- fiber.transfer
- states.should == [:start, :end]
+ states = []
+ fiber = Fiber.new { states << :start; fiber.transfer; states << :end }
+ fiber.resume
+ states.should == [:start, :end]
+ end
- states = []
- fiber = Fiber.new { states << :start; fiber.transfer; states << :end }
- fiber.resume
- states.should == [:start, :end]
- end
+ it "can transfer control to a Fiber that has transferred to another Fiber" do
+ states = []
+ fiber1 = Fiber.new { states << :fiber1 }
+ fiber2 = Fiber.new { states << :fiber2_start; fiber1.transfer; states << :fiber2_end}
+ fiber2.resume.should == [:fiber2_start, :fiber1]
+ fiber2.transfer.should == [:fiber2_start, :fiber1, :fiber2_end]
+ end
- it "can transfer control to a Fiber that has transferred to another Fiber" do
- states = []
- fiber1 = Fiber.new { states << :fiber1 }
- fiber2 = Fiber.new { states << :fiber2_start; fiber1.transfer; states << :fiber2_end}
- fiber2.resume.should == [:fiber2_start, :fiber1]
- fiber2.transfer.should == [:fiber2_start, :fiber1, :fiber2_end]
- end
+ it "raises a FiberError when transferring to a Fiber which resumes itself" do
+ fiber = Fiber.new { fiber.resume }
+ lambda { fiber.transfer }.should raise_error(FiberError)
+ end
- it "raises a FiberError when transferring to a Fiber which resumes itself" do
- fiber = Fiber.new { fiber.resume }
- lambda { fiber.transfer }.should raise_error(FiberError)
+ it "works if Fibers in different Threads each transfer to a Fiber in the same Thread" do
+ # This catches a bug where Fibers are running on a thread-pool
+ # and Fibers from a different Ruby Thread reuse the same native thread.
+ # Caching the Ruby Thread based on the native thread is not correct in that case,
+ # and the check for "fiber called across threads" in Fiber#transfer
+ # might be incorrect based on that.
+ 2.times do
+ Thread.new do
+ io_fiber = Fiber.new do |calling_fiber|
+ calling_fiber.transfer
+ end
+ io_fiber.transfer(Fiber.current)
+ value = Object.new
+ io_fiber.transfer(value).should equal value
+ end.join
end
+ end
- it "works if Fibers in different Threads each transfer to a Fiber in the same Thread" do
- # This catches a bug where Fibers are running on a thread-pool
- # and Fibers from a different Ruby Thread reuse the same native thread.
- # Caching the Ruby Thread based on the native thread is not correct in that case,
- # and the check for "fiber called across threads" in Fiber#transfer
- # might be incorrect based on that.
- 2.times do
- Thread.new do
- io_fiber = Fiber.new do |calling_fiber|
- calling_fiber.transfer
- end
- io_fiber.transfer(Fiber.current)
- value = Object.new
- io_fiber.transfer(value).should equal value
- end.join
+ it "transfers control between a non-main thread's root fiber to a child fiber and back again" do
+ states = []
+ thread = Thread.new do
+ f1 = Fiber.new do |f0|
+ states << 0
+ value2 = f0.transfer(1)
+ states << value2
+ 3
end
- end
-
- it "transfers control between a non-main thread's root fiber to a child fiber and back again" do
- states = []
- thread = Thread.new do
- f1 = Fiber.new do |f0|
- states << 0
- value2 = f0.transfer(1)
- states << value2
- 3
- end
- value1 = f1.transfer(Fiber.current)
- states << value1
- value3 = f1.transfer(2)
- states << value3
- end
- thread.join
- states.should == [0, 1, 2, 3]
+ value1 = f1.transfer(Fiber.current)
+ states << value1
+ value3 = f1.transfer(2)
+ states << value3
end
+ thread.join
+ states.should == [0, 1, 2, 3]
end
end
diff --git a/spec/ruby/library/socket/addrinfo/ip_address_spec.rb b/spec/ruby/library/socket/addrinfo/ip_address_spec.rb
index 004de37254..d53c00267a 100644
--- a/spec/ruby/library/socket/addrinfo/ip_address_spec.rb
+++ b/spec/ruby/library/socket/addrinfo/ip_address_spec.rb
@@ -63,23 +63,4 @@ describe "Addrinfo#ip_address" do
@ips.include?(addr.ip_address).should == true
end
end
-
- # On MRI calling Addrinfo#ip_address with AF_UNSPEC as the address family is
- # supposed to raise a SocketError. MRI however doesn't provide a way to
- # actually initialize an Addrinfo with AF_UNSPEC, nor does it allow stubbing
- # of any methods since Addrinfo doesn't use any Ruby methods for checking the
- # IP address. As a result we can only run this test on Rubinius.
- with_feature :pure_ruby_addrinfo do
- describe 'with a non IPv4 or IPv6 address' do
- it 'raises SocketError' do
- sockaddr = Socket.sockaddr_in(80, '127.0.0.1')
- addr = Addrinfo.new(sockaddr)
-
- addr.stub!(:ipv4?).and_return(false)
- addr.stub!(:ipv6?).and_return(false)
-
- lambda { addr.ip_address }.should raise_error(SocketError)
- end
- end
- end
end
diff --git a/spec/ruby/library/socket/spec_helper.rb b/spec/ruby/library/socket/spec_helper.rb
index 8976937ac7..1121542dd5 100644
--- a/spec/ruby/library/socket/spec_helper.rb
+++ b/spec/ruby/library/socket/spec_helper.rb
@@ -1,10 +1,6 @@
require_relative '../../spec_helper'
require 'socket'
-if %w[rbx truffleruby].include?(RUBY_ENGINE)
- MSpec.enable_feature :pure_ruby_addrinfo
-end
-
MSpec.enable_feature :sock_packet if Socket.const_defined?(:SOCK_PACKET)
MSpec.enable_feature :unix_socket unless PlatformGuard.windows?
MSpec.enable_feature :udp_cork if Socket.const_defined?(:UDP_CORK)
diff --git a/spec/ruby/library/stringio/getch_spec.rb b/spec/ruby/library/stringio/getch_spec.rb
index 06670a178c..113b4971bf 100644
--- a/spec/ruby/library/stringio/getch_spec.rb
+++ b/spec/ruby/library/stringio/getch_spec.rb
@@ -17,15 +17,13 @@ describe "StringIO#getch" do
io.getch.should == ?a
end
- with_feature :encoding do
- it "increments #pos by the byte size of the character in multibyte strings" do
- io = StringIO.new("föóbar")
-
- io.getch; io.pos.should == 1 # "f" has byte size 1
- io.getch; io.pos.should == 3 # "ö" has byte size 2
- io.getch; io.pos.should == 5 # "ó" has byte size 2
- io.getch; io.pos.should == 6 # "b" has byte size 1
- end
+ it "increments #pos by the byte size of the character in multibyte strings" do
+ io = StringIO.new("föóbar")
+
+ io.getch; io.pos.should == 1 # "f" has byte size 1
+ io.getch; io.pos.should == 3 # "ö" has byte size 2
+ io.getch; io.pos.should == 5 # "ó" has byte size 2
+ io.getch; io.pos.should == 6 # "b" has byte size 1
end
it "returns nil at the end of the string" do
diff --git a/spec/ruby/optional/capi/io_spec.rb b/spec/ruby/optional/capi/io_spec.rb
index 82dc1fc0df..622c770eef 100644
--- a/spec/ruby/optional/capi/io_spec.rb
+++ b/spec/ruby/optional/capi/io_spec.rb
@@ -9,7 +9,7 @@ describe "C-API IO function" do
@name = tmp("c_api_rb_io_specs")
touch @name
- @io = new_io @name, fmode("w:utf-8")
+ @io = new_io @name, "w:utf-8"
@io.sync = true
end
@@ -113,7 +113,7 @@ describe "C-API IO function" do
@name = tmp("c_api_io_specs")
touch @name
- @io = new_io @name, fmode("r:utf-8")
+ @io = new_io @name, "r:utf-8"
end
after :each do
@@ -193,7 +193,7 @@ describe "C-API IO function" do
@name = tmp("c_api_io_specs")
touch @name
- @rw_io = new_io @name, fmode("w+")
+ @rw_io = new_io @name, "w+"
end
after :each do
@@ -329,7 +329,7 @@ describe "rb_fd_fix_cloexec" do
@name = tmp("c_api_rb_io_specs")
touch @name
- @io = new_io @name, fmode("w:utf-8")
+ @io = new_io @name, "w:utf-8"
@io.close_on_exec = false
@io.sync = true
end
diff --git a/spec/ruby/shared/string/times.rb b/spec/ruby/shared/string/times.rb
index c44a76c9b7..e7b788d4f9 100644
--- a/spec/ruby/shared/string/times.rb
+++ b/spec/ruby/shared/string/times.rb
@@ -42,12 +42,10 @@ describe :string_times, shared: true do
end
end
- with_feature :encoding do
- it "returns a String in the same encoding as self" do
- str = "\xE3\x81\x82".force_encoding Encoding::UTF_8
- result = @object.call(str, 2)
- result.encoding.should equal(Encoding::UTF_8)
- end
+ it "returns a String in the same encoding as self" do
+ str = "\xE3\x81\x82".force_encoding Encoding::UTF_8
+ result = @object.call(str, 2)
+ result.encoding.should equal(Encoding::UTF_8)
end
platform_is wordsize: 32 do
diff --git a/spec/ruby/shared/time/strftime_for_date.rb b/spec/ruby/shared/time/strftime_for_date.rb
index f126c5a323..dbb124adc8 100644
--- a/spec/ruby/shared/time/strftime_for_date.rb
+++ b/spec/ruby/shared/time/strftime_for_date.rb
@@ -264,12 +264,10 @@ describe :strftime_date, shared: true do
@new_date[2001,3,22].strftime("%-m/%-d/%-y").should == "3/22/1"
end
- with_feature :encoding do
- it "passes the format string's encoding to the result string" do
- result = @new_date[2010,3,8].strftime("%d. März %Y")
+ it "passes the format string's encoding to the result string" do
+ result = @new_date[2010,3,8].strftime("%d. März %Y")
- result.encoding.should == Encoding::UTF_8
- result.should == "08. März 2010"
- end
+ result.encoding.should == Encoding::UTF_8
+ result.should == "08. März 2010"
end
end