1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00
This commit is contained in:
Benoit Daloze 2019-04-28 23:20:11 +02:00
parent 994833085a
commit 79671ec57e
135 changed files with 4415 additions and 4885 deletions

View file

@ -26,7 +26,6 @@ describe "ARGF.gets" do
end
end
with_feature :encoding do
before :each do
@external = Encoding.default_external
@internal = Encoding.default_internal
@ -46,6 +45,5 @@ describe "ARGF.gets" do
@argf.gets.encoding.should == Encoding::US_ASCII
end
end
end
end

View file

@ -62,7 +62,6 @@ describe "ARGF.read" do
end
end
with_feature :encoding do
before :each do
@external = Encoding.default_external
@ -83,5 +82,4 @@ describe "ARGF.read" do
@argf.read.encoding.should == Encoding::US_ASCII
end
end
end
end

View file

@ -11,12 +11,10 @@ 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
end
it "calls #to_path to convert a pattern" do
obj = mock('file_one.ext')

View file

@ -18,7 +18,6 @@ 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
@ -28,5 +27,4 @@ describe :dir_path, shared: true do
dir.close
end
end
end
end

View file

@ -1,9 +1,7 @@
describe :dir_pwd, shared: true do
with_feature :encoding do
before :each do
@fs_encoding = Encoding.find('filesystem')
end
end
it "returns the current working directory" do
pwd = Dir.send(@method)
@ -36,7 +34,6 @@ 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
@ -45,5 +42,4 @@ describe :dir_pwd, shared: true do
enc.should equal(@fs_encoding)
end
end
end
end

View file

@ -1,7 +1,6 @@
require_relative '../../spec_helper'
with_feature :encoding do
describe "Encoding.aliases" do
describe "Encoding.aliases" do
it "returns a Hash" do
Encoding.aliases.should be_an_instance_of(Hash)
end
@ -41,5 +40,4 @@ with_feature :encoding do
Encoding.find(aliased).should == Encoding.find(original)
end
end
end
end

View file

@ -1,7 +1,6 @@
require_relative '../../spec_helper'
with_feature :encoding do
describe "Encoding#ascii_compatible?" 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
@ -9,5 +8,4 @@ with_feature :encoding do
it "returns false if self does not represent an ASCII-compatible encoding" do
Encoding::UTF_16LE.ascii_compatible?.should be_false
end
end
end

View file

@ -2,10 +2,9 @@
require_relative '../../spec_helper'
with_feature :encoding do
# TODO: add IO
# TODO: add IO
describe "Encoding.compatible? String, String" do
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
@ -162,9 +161,9 @@ with_feature :encoding do
Encoding.compatible?(@str, "").should == Encoding::UTF_7
end
end
end
end
describe "Encoding.compatible? String, Regexp" do
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
@ -185,9 +184,9 @@ with_feature :encoding do
[Encoding, "\x82\xa0".force_encoding("shift_jis"), Encoding::Shift_JIS],
].should be_computed_by(:compatible?, /abc/)
end
end
end
describe "Encoding.compatible? String, Symbol" do
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
@ -208,9 +207,9 @@ with_feature :encoding do
[Encoding, "\x82\xa0".force_encoding("shift_jis"), Encoding::Shift_JIS],
].should be_computed_by(:compatible?, :abc)
end
end
end
describe "Encoding.compatible? String, Encoding" do
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
@ -239,17 +238,17 @@ with_feature :encoding do
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
end
describe "Encoding.compatible? Regexp, String" do
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
end
end
describe "Encoding.compatible? Regexp, Regexp" do
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
@ -261,9 +260,9 @@ with_feature :encoding do
[Encoding, Regexp.new("\x82\xa0".force_encoding("shift_jis")), Encoding::Shift_JIS],
].should be_computed_by(:compatible?, /abc/)
end
end
end
describe "Encoding.compatible? Regexp, Symbol" do
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
@ -275,16 +274,16 @@ with_feature :encoding do
[Encoding, Regexp.new("\x82\xa0".force_encoding("shift_jis")), Encoding::Shift_JIS],
].should be_computed_by(:compatible?, /abc/)
end
end
end
describe "Encoding.compatible? Symbol, String" do
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
end
describe "Encoding.compatible? Symbol, Regexp" do
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
@ -301,9 +300,9 @@ with_feature :encoding do
[Encoding, :abc, d, Encoding::Shift_JIS],
].should be_computed_by(:compatible?)
end
end
end
describe "Encoding.compatible? Symbol, Symbol" do
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
@ -315,9 +314,9 @@ with_feature :encoding do
[Encoding, "\x82\xa0".force_encoding("shift_jis").to_sym, Encoding::Shift_JIS],
].should be_computed_by(:compatible?, :abc)
end
end
end
describe "Encoding.compatible? Encoding, Encoding" do
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],
@ -351,9 +350,9 @@ with_feature :encoding do
[Encoding, Encoding::UTF_7, Encoding::UTF_7, Encoding::UTF_7],
].should be_computed_by(:compatible?)
end
end
end
describe "Encoding.compatible? Object, Object" do
describe "Encoding.compatible? Object, Object" do
it "returns nil for Object, String" do
Encoding.compatible?(Object.new, "abc").should be_nil
end
@ -377,5 +376,4 @@ with_feature :encoding do
it "returns nil for Symbol, Object" do
Encoding.compatible?(:sym, Object.new).should be_nil
end
end
end

View file

@ -1,7 +1,6 @@
require_relative '../../../spec_helper'
with_feature :encoding do
describe "Encoding::Converter.asciicompat_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
@ -35,5 +34,4 @@ with_feature :encoding do
Encoding::Converter.asciicompat_encoding('internal').should be_nil
Encoding.default_internal = internal
end
end
end

View file

@ -1,7 +1,6 @@
require_relative '../../../spec_helper'
with_feature :encoding do
describe "Encoding::Converter::INVALID_MASK" do
describe "Encoding::Converter::INVALID_MASK" do
it "exists" do
Encoding::Converter.should have_constant(:INVALID_MASK)
end
@ -9,9 +8,9 @@ with_feature :encoding do
it "has a Fixnum value" do
Encoding::Converter::INVALID_MASK.should be_an_instance_of(Fixnum)
end
end
end
describe "Encoding::Converter::INVALID_REPLACE" do
describe "Encoding::Converter::INVALID_REPLACE" do
it "exists" do
Encoding::Converter.should have_constant(:INVALID_REPLACE)
end
@ -19,9 +18,9 @@ with_feature :encoding do
it "has a Fixnum value" do
Encoding::Converter::INVALID_REPLACE.should be_an_instance_of(Fixnum)
end
end
end
describe "Encoding::Converter::UNDEF_MASK" do
describe "Encoding::Converter::UNDEF_MASK" do
it "exists" do
Encoding::Converter.should have_constant(:UNDEF_MASK)
end
@ -29,9 +28,9 @@ with_feature :encoding do
it "has a Fixnum value" do
Encoding::Converter::UNDEF_MASK.should be_an_instance_of(Fixnum)
end
end
end
describe "Encoding::Converter::UNDEF_REPLACE" do
describe "Encoding::Converter::UNDEF_REPLACE" do
it "exists" do
Encoding::Converter.should have_constant(:UNDEF_REPLACE)
end
@ -39,9 +38,9 @@ with_feature :encoding do
it "has a Fixnum value" do
Encoding::Converter::UNDEF_REPLACE.should be_an_instance_of(Fixnum)
end
end
end
describe "Encoding::Converter::UNDEF_HEX_CHARREF" do
describe "Encoding::Converter::UNDEF_HEX_CHARREF" do
it "exists" do
Encoding::Converter.should have_constant(:UNDEF_HEX_CHARREF)
end
@ -49,9 +48,9 @@ with_feature :encoding do
it "has a Fixnum value" do
Encoding::Converter::UNDEF_HEX_CHARREF.should be_an_instance_of(Fixnum)
end
end
end
describe "Encoding::Converter::PARTIAL_INPUT" do
describe "Encoding::Converter::PARTIAL_INPUT" do
it "exists" do
Encoding::Converter.should have_constant(:PARTIAL_INPUT)
end
@ -59,9 +58,9 @@ with_feature :encoding do
it "has a Fixnum value" do
Encoding::Converter::PARTIAL_INPUT.should be_an_instance_of(Fixnum)
end
end
end
describe "Encoding::Converter::AFTER_OUTPUT" do
describe "Encoding::Converter::AFTER_OUTPUT" do
it "exists" do
Encoding::Converter.should have_constant(:AFTER_OUTPUT)
end
@ -69,9 +68,9 @@ with_feature :encoding do
it "has a Fixnum value" do
Encoding::Converter::AFTER_OUTPUT.should be_an_instance_of(Fixnum)
end
end
end
describe "Encoding::Converter::UNIVERSAL_NEWLINE_DECORATOR" do
describe "Encoding::Converter::UNIVERSAL_NEWLINE_DECORATOR" do
it "exists" do
Encoding::Converter.should have_constant(:UNIVERSAL_NEWLINE_DECORATOR)
end
@ -79,9 +78,9 @@ with_feature :encoding do
it "has a Fixnum value" do
Encoding::Converter::UNIVERSAL_NEWLINE_DECORATOR.should be_an_instance_of(Fixnum)
end
end
end
describe "Encoding::Converter::CRLF_NEWLINE_DECORATOR" do
describe "Encoding::Converter::CRLF_NEWLINE_DECORATOR" do
it "exists" do
Encoding::Converter.should have_constant(:CRLF_NEWLINE_DECORATOR)
end
@ -89,9 +88,9 @@ with_feature :encoding do
it "has a Fixnum value" do
Encoding::Converter::CRLF_NEWLINE_DECORATOR.should be_an_instance_of(Fixnum)
end
end
end
describe "Encoding::Converter::CR_NEWLINE_DECORATOR" do
describe "Encoding::Converter::CR_NEWLINE_DECORATOR" do
it "exists" do
Encoding::Converter.should have_constant(:CR_NEWLINE_DECORATOR)
end
@ -99,9 +98,9 @@ with_feature :encoding do
it "has a Fixnum value" do
Encoding::Converter::CR_NEWLINE_DECORATOR.should be_an_instance_of(Fixnum)
end
end
end
describe "Encoding::Converter::XML_TEXT_DECORATOR" do
describe "Encoding::Converter::XML_TEXT_DECORATOR" do
it "exists" do
Encoding::Converter.should have_constant(:XML_TEXT_DECORATOR)
end
@ -109,9 +108,9 @@ with_feature :encoding do
it "has a Fixnum value" do
Encoding::Converter::XML_TEXT_DECORATOR.should be_an_instance_of(Fixnum)
end
end
end
describe "Encoding::Converter::XML_ATTR_CONTENT_DECORATOR" do
describe "Encoding::Converter::XML_ATTR_CONTENT_DECORATOR" do
it "exists" do
Encoding::Converter.should have_constant(:XML_ATTR_CONTENT_DECORATOR)
end
@ -119,9 +118,9 @@ with_feature :encoding do
it "has a Fixnum value" do
Encoding::Converter::XML_ATTR_CONTENT_DECORATOR.should be_an_instance_of(Fixnum)
end
end
end
describe "Encoding::Converter::XML_ATTR_QUOTE_DECORATOR" do
describe "Encoding::Converter::XML_ATTR_QUOTE_DECORATOR" do
it "exists" do
Encoding::Converter.should have_constant(:XML_ATTR_QUOTE_DECORATOR)
end
@ -129,5 +128,4 @@ with_feature :encoding do
it "has a Fixnum value" do
Encoding::Converter::XML_ATTR_QUOTE_DECORATOR.should be_an_instance_of(Fixnum)
end
end
end

View file

@ -1,8 +1,7 @@
# -*- encoding: binary -*-
require_relative '../../../spec_helper'
with_feature :encoding do
describe "Encoding::Converter#convert" 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)
@ -43,5 +42,4 @@ with_feature :encoding do
ec.finish
lambda { ec.convert("\u{65}") }.should raise_error(ArgumentError)
end
end
end

View file

@ -1,7 +1,6 @@
require_relative '../../../spec_helper'
with_feature :encoding do
describe "Encoding::Converter#convpath" 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]]
@ -22,5 +21,4 @@ with_feature :encoding do
ec = Encoding::Converter.new("ASCII", "UTF-8", {crlf_newline: false})
ec.convpath.last.should_not == "crlf_newline"
end
end
end

View file

@ -1,7 +1,6 @@
require_relative '../../../spec_helper'
with_feature :encoding do
describe "Encoding::Converter#destination_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
@ -9,5 +8,4 @@ with_feature :encoding do
ec = Encoding::Converter.new('SJIS','EUC-JP')
ec.destination_encoding.should == Encoding::EUC_JP
end
end
end

View file

@ -1,7 +1,6 @@
require_relative '../../../spec_helper'
with_feature :encoding do
describe "Encoding::Converter#finish" do
describe "Encoding::Converter#finish" do
before :each do
@ec = Encoding::Converter.new("utf-8", "iso-2022-jp")
end
@ -34,5 +33,4 @@ with_feature :encoding do
@ec.finish.should == ""
@ec.finish.should == ""
end
end
end

View file

@ -1,8 +1,7 @@
# -*- encoding: binary -*-
require_relative '../../../spec_helper'
with_feature :encoding do
describe "Encoding::Converter#last_error" 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
@ -89,5 +88,4 @@ with_feature :encoding do
ec.last_error.message.should == exception.message
ec.last_error.message.should include "from ISO-8859-1 to UTF-8 to Big5"
end
end
end

View file

@ -1,8 +1,7 @@
# -*- encoding: ascii-8bit -*-
require_relative '../../../spec_helper'
with_feature :encoding do
describe "Encoding::Converter.new" 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
@ -117,5 +116,4 @@ with_feature :encoding do
end
end
end
end
end

View file

@ -1,8 +1,7 @@
# -*- encoding: binary -*-
require_relative '../../../spec_helper'
with_feature :encoding do
describe "Encoding::Converter#primitive_convert" do
describe "Encoding::Converter#primitive_convert" do
before :each do
@ec = Encoding::Converter.new("utf-8", "iso-8859-1")
end
@ -209,5 +208,4 @@ with_feature :encoding do
dest.should == "abcd"
end
end
end

View file

@ -1,8 +1,7 @@
# -*- encoding: binary -*-
require_relative '../../../spec_helper'
with_feature :encoding do
describe "Encoding::Converter#primitive_errinfo" 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]
@ -66,5 +65,4 @@ with_feature :encoding do
lambda { ec.finish }.should raise_error(Encoding::InvalidByteSequenceError)
ec.primitive_errinfo.should == [:incomplete_input, "EUC-JP", "UTF-8", "\xA4", ""]
end
end
end

View file

@ -1,8 +1,7 @@
# -*- encoding: binary -*-
require_relative '../../../spec_helper'
with_feature :encoding do
describe "Encoding::Converter#putback" 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)
@ -45,5 +44,4 @@ with_feature :encoding do
ec.putback.should == "a".force_encoding("utf-16le")
ec.putback.should == ""
end
end
end

View file

@ -1,7 +1,6 @@
require_relative '../../../spec_helper'
with_feature :encoding do
describe "Encoding::Converter#replacement" 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 == "?"
@ -17,9 +16,9 @@ with_feature :encoding do
ec.replacement.should == "\u{fffd}".force_encoding('utf-8')
ec.replacement.encoding.should == Encoding::UTF_8
end
end
end
describe "Encoding::Converter#replacement=" do
describe "Encoding::Converter#replacement=" do
it "accepts a String argument" do
ec = Encoding::Converter.new("utf-8", "us-ascii")
ec.replacement = "!"
@ -70,5 +69,4 @@ with_feature :encoding do
status.should == :finished
dest.should == "!!123"
end
end
end

View file

@ -1,7 +1,6 @@
require_relative '../../../spec_helper'
with_feature :encoding do
describe "Encoding::Converter.search_convpath" 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]]
@ -30,5 +29,4 @@ with_feature :encoding do
Encoding::Converter.search_convpath(Encoding::ASCII_8BIT, Encoding::Emacs_Mule)
end.should raise_error(Encoding::ConverterNotFoundError)
end
end
end

View file

@ -1,7 +1,6 @@
require_relative '../../../spec_helper'
with_feature :encoding do
describe "Encoding::Converter#source_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
@ -9,5 +8,4 @@ with_feature :encoding do
ec = Encoding::Converter.new('Shift_JIS','EUC-JP')
ec.source_encoding.should == Encoding::SHIFT_JIS
end
end
end

View file

@ -1,7 +1,6 @@
require_relative '../../spec_helper'
with_feature :encoding do
describe "Encoding.default_external" do
describe "Encoding.default_external" do
before :each do
@original_encoding = Encoding.default_external
end
@ -18,9 +17,9 @@ with_feature :encoding do
Encoding.default_external = Encoding::SHIFT_JIS
Encoding.default_external.should == Encoding::SHIFT_JIS
end
end
end
describe "Encoding.default_external=" do
describe "Encoding.default_external=" do
before :each do
@original_encoding = Encoding.default_external
end
@ -61,5 +60,4 @@ with_feature :encoding do
it "raises an ArgumentError if the argument is nil" do
lambda { Encoding.default_external = nil }.should raise_error(ArgumentError)
end
end
end

View file

@ -1,7 +1,6 @@
require_relative '../../spec_helper'
with_feature :encoding do
describe "Encoding.default_internal" do
describe "Encoding.default_internal" do
before :each do
@original_encoding = Encoding.default_internal
end
@ -28,9 +27,9 @@ with_feature :encoding do
Encoding.default_internal = Encoding::ASCII_8BIT
Encoding.default_internal.should == Encoding::ASCII_8BIT
end
end
end
describe "Encoding.default_internal=" do
describe "Encoding.default_internal=" do
before :each do
@original_encoding = Encoding.default_internal
end
@ -72,5 +71,4 @@ with_feature :encoding do
Encoding.default_internal = nil
Encoding.default_internal.should be_nil
end
end
end

View file

@ -1,7 +1,6 @@
require_relative '../../spec_helper'
with_feature :encoding do
describe "Encoding#dummy?" 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
@ -12,5 +11,4 @@ with_feature :encoding do
Encoding::CP50221.dummy?.should be_true
Encoding::UTF_7.dummy?.should be_true
end
end
end

View file

@ -1,7 +1,6 @@
require_relative '../../spec_helper'
with_feature :encoding do
describe "Encoding.find" do
describe "Encoding.find" do
before :all do
@encodings = Encoding.aliases.to_a.flatten.uniq
end
@ -80,5 +79,4 @@ with_feature :encoding do
platform_is :windows do
it "needs to be reviewed for spec completeness"
end
end
end

View file

@ -1,7 +1,6 @@
require_relative '../../spec_helper'
with_feature :encoding do
describe "Encoding#inspect" do
describe "Encoding#inspect" do
it "returns a String" do
Encoding::UTF_8.inspect.should be_an_instance_of(String)
end
@ -17,5 +16,4 @@ with_feature :encoding do
enc.inspect.should =~ /#<Encoding:#{enc.name} \(dummy\)>/
end
end
end
end

View file

@ -1,7 +1,6 @@
require_relative '../fixtures/classes'
with_feature :encoding do
describe "Encoding::InvalidByteSequenceError#destination_encoding_name" do
describe "Encoding::InvalidByteSequenceError#destination_encoding_name" do
before :each do
@exception, = EncodingSpecs::InvalidByteSequenceError.exception
@exception2, = EncodingSpecs::InvalidByteSequenceErrorIndirect.exception
@ -16,5 +15,4 @@ with_feature :encoding do
@exception.destination_encoding_name.should == "ISO-8859-1"
@exception2.destination_encoding_name.should == "UTF-8"
end
end
end

View file

@ -1,7 +1,6 @@
require_relative '../fixtures/classes'
with_feature :encoding do
describe "Encoding::InvalidByteSequenceError#destination_encoding" do
describe "Encoding::InvalidByteSequenceError#destination_encoding" do
before :each do
@exception, = EncodingSpecs::InvalidByteSequenceError.exception
@exception2, = EncodingSpecs::InvalidByteSequenceErrorIndirect.exception
@ -16,5 +15,4 @@ with_feature :encoding do
@exception.destination_encoding.should == Encoding::ISO_8859_1
@exception2.destination_encoding.should == Encoding::UTF_8
end
end
end

View file

@ -1,8 +1,7 @@
# -*- encoding: binary -*-
require_relative '../fixtures/classes'
with_feature :encoding do
describe "Encoding::InvalidByteSequenceError#error_bytes" do
describe "Encoding::InvalidByteSequenceError#error_bytes" do
before :each do
@exception, @errinfo = EncodingSpecs::InvalidByteSequenceError.exception
@exception2, @errinfo2 = EncodingSpecs::InvalidByteSequenceErrorIndirect.exception
@ -28,5 +27,4 @@ with_feature :encoding do
@exception2.error_bytes.encoding.should == Encoding::ASCII_8BIT
end
end
end

View file

@ -1,8 +1,7 @@
# -*- 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
@ -27,5 +26,4 @@ with_feature :encoding do
e.incomplete_input?.should be_false
end
end
end
end

View file

@ -1,8 +1,7 @@
# -*- encoding: binary -*-
require_relative '../fixtures/classes'
with_feature :encoding do
describe "Encoding::InvalidByteSequenceError#readagain_bytes" do
describe "Encoding::InvalidByteSequenceError#readagain_bytes" do
before :each do
@exception, @errinfo = EncodingSpecs::InvalidByteSequenceError.exception
@exception2, @errinfo2 = EncodingSpecs::InvalidByteSequenceErrorIndirect.exception
@ -28,5 +27,4 @@ with_feature :encoding do
@exception2.readagain_bytes.encoding.should == Encoding::ASCII_8BIT
end
end
end

View file

@ -1,7 +1,6 @@
require_relative '../fixtures/classes'
with_feature :encoding do
describe "Encoding::UndefinedConversionError#source_encoding_name" do
describe "Encoding::UndefinedConversionError#source_encoding_name" do
before :each do
@exception, = EncodingSpecs::UndefinedConversionError.exception
@exception2, = EncodingSpecs::UndefinedConversionErrorIndirect.exception
@ -26,5 +25,4 @@ with_feature :encoding do
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
end

View file

@ -1,7 +1,6 @@
require_relative '../fixtures/classes'
with_feature :encoding do
describe "Encoding::InvalidByteSequenceError#source_encoding" do
describe "Encoding::InvalidByteSequenceError#source_encoding" do
before :each do
@exception, = EncodingSpecs::InvalidByteSequenceError.exception
@exception2, = EncodingSpecs::InvalidByteSequenceErrorIndirect.exception
@ -31,5 +30,4 @@ with_feature :encoding do
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
end

View file

@ -1,7 +1,6 @@
require_relative '../../spec_helper'
with_feature :encoding do
describe "Encoding.list" do
describe "Encoding.list" do
it "returns an Array" do
Encoding.list.should be_an_instance_of(Array)
end
@ -39,5 +38,4 @@ with_feature :encoding do
# TODO: Find example that illustrates this
it "updates the list when #find is used to load a new encoding"
end
end

View file

@ -1,7 +1,6 @@
require_relative '../../spec_helper'
with_feature :encoding do
describe "Encoding.locale_charmap" do
describe "Encoding.locale_charmap" do
it "returns a String" do
Encoding.locale_charmap.should be_an_instance_of(String)
end
@ -43,5 +42,4 @@ with_feature :encoding do
ENV['LC_ALL'] = old_lc_all
end
end
end
end

View file

@ -1,7 +1,6 @@
require_relative '../../spec_helper'
with_feature :encoding do
describe "Encoding.name_list" do
describe "Encoding.name_list" do
it "returns an Array" do
Encoding.name_list.should be_an_instance_of(Array)
end
@ -21,5 +20,4 @@ with_feature :encoding do
Encoding.name_list.include?(enc.name).should be_true
end
end
end
end

View file

@ -1,7 +1,5 @@
require_relative 'shared/name'
with_feature :encoding do
describe "Encoding#name" do
describe "Encoding#name" do
it_behaves_like :encoding_name, :name
end
end

View file

@ -1,7 +1,6 @@
require_relative '../../spec_helper'
with_feature :encoding do
describe "Encoding#names" do
describe "Encoding#names" do
it "returns an Array" do
Encoding.name_list.each do |name|
e = Encoding.find(name) or next
@ -33,5 +32,4 @@ with_feature :encoding do
aliases.each {|a| names.include?(a).should be_true}
end
end
end
end

View file

@ -1,8 +1,7 @@
# -*- encoding: binary -*-
require_relative '../../spec_helper'
with_feature :encoding do
describe "Encoding#replicate" do
describe "Encoding#replicate" do
before :all do
@i = 0
end
@ -44,5 +43,4 @@ with_feature :encoding do
e.name.should == name
e.dummy?.should be_true
end
end
end

View file

@ -1,7 +1,5 @@
require_relative 'shared/name'
with_feature :encoding do
describe "Encoding#to_s" do
describe "Encoding#to_s" do
it_behaves_like :encoding_name, :to_s
end
end

View file

@ -1,7 +1,6 @@
require_relative '../fixtures/classes'
with_feature :encoding do
describe "Encoding::UndefinedConversionError#destination_encoding_name" do
describe "Encoding::UndefinedConversionError#destination_encoding_name" do
before :each do
@exception = EncodingSpecs::UndefinedConversionError.exception
end
@ -13,5 +12,4 @@ with_feature :encoding do
it "is equal to the destination encoding name of the object that raised it" do
@exception.destination_encoding_name.should == "US-ASCII"
end
end
end

View file

@ -1,7 +1,6 @@
require_relative '../fixtures/classes'
with_feature :encoding do
describe "Encoding::UndefinedConversionError#destination_encoding" do
describe "Encoding::UndefinedConversionError#destination_encoding" do
before :each do
@exception = EncodingSpecs::UndefinedConversionError.exception
end
@ -13,5 +12,4 @@ with_feature :encoding do
it "is equal to the destination encoding of the object that raised it" do
@exception.destination_encoding.should == Encoding::US_ASCII
end
end
end

View file

@ -1,7 +1,6 @@
require_relative '../fixtures/classes'
with_feature :encoding do
describe "Encoding::UndefinedConversionError#error_char" do
describe "Encoding::UndefinedConversionError#error_char" do
before :each do
@exception = EncodingSpecs::UndefinedConversionError.exception
@exception2 = EncodingSpecs::UndefinedConversionErrorIndirect.exception
@ -25,5 +24,4 @@ with_feature :encoding do
@exception2.error_char.encoding.should == @exception2.source_encoding
end
end
end

View file

@ -1,7 +1,6 @@
require_relative '../fixtures/classes'
with_feature :encoding do
describe "Encoding::UndefinedConversionError#source_encoding_name" do
describe "Encoding::UndefinedConversionError#source_encoding_name" do
before :each do
@exception = EncodingSpecs::UndefinedConversionError.exception
@exception2 = EncodingSpecs::UndefinedConversionErrorIndirect.exception
@ -26,5 +25,4 @@ with_feature :encoding do
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
end

View file

@ -1,7 +1,6 @@
require_relative '../fixtures/classes'
with_feature :encoding do
describe "Encoding::UndefinedConversionError#source_encoding" do
describe "Encoding::UndefinedConversionError#source_encoding" do
before :each do
@exception = EncodingSpecs::UndefinedConversionError.exception
@exception2 = EncodingSpecs::UndefinedConversionErrorIndirect.exception
@ -27,5 +26,4 @@ with_feature :encoding do
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
end

View file

@ -27,8 +27,7 @@ describe "ENV.[]" do
end
end
with_feature :encoding do
describe "ENV.[]" do
describe "ENV.[]" do
before :each do
@variable = "env_element_reference_encoding_specs"
@ -62,5 +61,4 @@ with_feature :encoding do
ENV[@variable].encoding.should equal(Encoding::IBM437)
end
end
end

View file

@ -25,7 +25,6 @@ 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
@ -61,5 +60,4 @@ describe :env_each, shared: true do
end
end
end
end
end

View file

@ -24,8 +24,7 @@ describe "ENV.shift" do
end
end
with_feature :encoding do
describe "ENV.shift" do
describe "ENV.shift" do
before :each do
@orig = ENV.to_hash
@external = Encoding.default_external
@ -55,5 +54,4 @@ with_feature :encoding do
pair.first.encoding.should equal(Encoding::IBM437)
pair.last.encoding.should equal(Encoding::IBM437)
end
end
end

View file

@ -1,7 +1,6 @@
require_relative '../../spec_helper'
with_feature :fiber do
describe "Fiber.new" do
describe "Fiber.new" do
it "creates a fiber from the given block" do
fiber = Fiber.new {}
fiber.resume
@ -37,5 +36,4 @@ with_feature :fiber do
end
o.f.should == 2
end
end
end

View file

@ -1,12 +1,11 @@
require_relative '../../spec_helper'
require_relative '../../shared/fiber/resume'
with_feature :fiber do
describe "Fiber#resume" do
describe "Fiber#resume" do
it_behaves_like :fiber_resume, :resume
end
end
describe "Fiber#resume" do
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/)
@ -18,18 +17,14 @@ with_feature :fiber do
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
code = <<-RUBY
f = Fiber.new do
begin
Fiber.yield
ensure
wr.write "executed"
puts "ensure executed"
end
end
@ -46,14 +41,8 @@ with_feature :fiber do
f.resume
exit 0
end
RUBY
wr.close
Process.waitpid pid
rd.read.should == "executed"
rd.close
end
end
ruby_exe(code).should == "ensure executed\n"
end
end

View file

@ -1,7 +1,6 @@
require_relative '../../spec_helper'
with_feature :fiber do
describe "Fiber.yield" 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 }
@ -47,5 +46,4 @@ with_feature :fiber do
it "raises a FiberError if called from the root Fiber" do
lambda{ Fiber.yield }.should raise_error(FiberError)
end
end
end

View file

@ -153,7 +153,6 @@ 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"
@ -165,6 +164,5 @@ describe "File.basename" do
basename.encoding.should == Encoding::Windows_1250
end
end
end

View file

@ -19,7 +19,6 @@ describe "File.expand_path" do
end
end
with_feature :encoding do
before :each do
@external = Encoding.default_external
end
@ -27,7 +26,6 @@ describe "File.expand_path" do
after :each do
Encoding.default_external = @external
end
end
it "converts a pathname to an absolute pathname" do
File.expand_path('').should == @base
@ -136,7 +134,6 @@ 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
@ -165,7 +162,6 @@ describe "File.expand_path" do
lambda { File.expand_path("./a") }.should raise_error(Encoding::CompatibilityError)
end
end
end
it "does not modify the string argument" do
str = "./a/b/../c"

View file

@ -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
end
end

View file

@ -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

View file

@ -44,13 +44,11 @@ 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
end
ruby_version_is "2.5" do
platform_is :linux do

View file

@ -289,8 +289,7 @@ describe "Float#to_s" do
end
end
with_feature :encoding do
describe "Float#to_s" do
describe "Float#to_s" do
before :each do
@internal = Encoding.default_internal
end
@ -308,5 +307,4 @@ with_feature :encoding do
Encoding.default_internal = Encoding::IBM437
5.47.to_s.encoding.should equal(Encoding::US_ASCII)
end
end
end

View file

@ -29,7 +29,6 @@ describe "Integer#to_s" do
end
end
with_feature :encoding do
before :each do
@internal = Encoding.default_internal
end
@ -48,7 +47,6 @@ describe "Integer#to_s" do
1.to_s.encoding.should equal(Encoding::US_ASCII)
end
end
end
context "bignum" do
describe "when given a base" do
@ -76,7 +74,6 @@ describe "Integer#to_s" do
end
end
with_feature :encoding do
before :each do
@internal = Encoding.default_internal
end
@ -95,5 +92,4 @@ describe "Integer#to_s" do
bignum_value.to_s.encoding.should equal(Encoding::US_ASCII)
end
end
end
end

View file

@ -1,7 +1,6 @@
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
@ -75,9 +74,9 @@ with_feature :encoding do
@io.external_encoding.should equal(Encoding::EUC_JP)
end
end
end
end
describe "IO#external_encoding" do
describe "IO#external_encoding" do
before :each do
@external = Encoding.default_external
@internal = Encoding.default_internal
@ -214,5 +213,4 @@ with_feature :encoding do
describe "with 'a+' mode" do
it_behaves_like :io_external_encoding_write, nil, "a+"
end
end
end

View file

@ -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

View file

@ -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 = $$

View file

@ -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

View file

@ -13,15 +13,10 @@ 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
@ -30,9 +25,6 @@ describe "IO#initialize" do
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
end
it "raises a TypeError when passed an IO" do

View file

@ -1,7 +1,6 @@
require_relative '../../spec_helper'
with_feature :encoding do
describe :io_internal_encoding, shared: true do
describe :io_internal_encoding, shared: true do
describe "when Encoding.default_internal is not set" do
before :each do
Encoding.default_internal = nil
@ -94,9 +93,9 @@ with_feature :encoding do
@io.internal_encoding.should be_nil
end
end
end
end
describe "IO#internal_encoding" do
describe "IO#internal_encoding" do
before :each do
@external = Encoding.default_external
@internal = Encoding.default_internal
@ -136,5 +135,4 @@ with_feature :encoding do
describe "with 'a+' mode" do
it_behaves_like :io_internal_encoding, nil, "a+"
end
end
end

View file

@ -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,7 +153,6 @@ 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
@ -169,7 +168,6 @@ describe "IO.popen" do
internal_encoding: Encoding::EUC_JP)
@io.internal_encoding.should be_nil
end
end
context "with a leading ENV Hash" do
it "accepts a single String command" do

View file

@ -114,7 +114,6 @@ 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
@ -137,5 +136,4 @@ describe "IO#puts" do
File.binread(@name).should == "\n"
end
end
end
end

View file

@ -95,7 +95,6 @@ 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
@ -105,7 +104,6 @@ describe "IO.read" do
str = IO.read(@fname, encoding: Encoding::ISO_8859_1)
str.encoding.should == Encoding::ISO_8859_1
end
end
end
describe "IO.read from a pipe" do
@ -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,8 +454,7 @@ describe "IO.read with BOM" do
end
end
with_feature :encoding do
describe :io_read_internal_encoding, shared: true do
describe :io_read_internal_encoding, shared: true do
it "returns a transcoded String" do
@io.read.should == "ありがとう\n"
end
@ -479,9 +476,9 @@ with_feature :encoding do
buf.encoding.should equal(Encoding::UTF_8)
end
end
end
end
describe :io_read_size_internal_encoding, shared: true do
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
@ -505,9 +502,9 @@ with_feature :encoding do
buf.size.should == 0
buf.encoding.should equal(Encoding::ISO_8859_1)
end
end
end
describe "IO#read" do
describe "IO#read" do
describe "when IO#external_encoding and IO#internal_encoding are nil" do
before :each do
@name = tmp("io_read.txt")
@ -586,7 +583,6 @@ with_feature :encoding do
it_behaves_like :io_read_size_internal_encoding, nil
end
end
end
end
describe "IO#read with large data" do

View file

@ -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

View file

@ -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"

View file

@ -1,7 +1,6 @@
require_relative '../../spec_helper'
with_feature :encoding do
describe :io_set_encoding_write, shared: true 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
@ -32,9 +31,9 @@ with_feature :encoding do
@io.external_encoding.should == Encoding::IBM437
@io.internal_encoding.should == Encoding::IBM866
end
end
end
describe "IO#set_encoding when passed nil, nil" do
describe "IO#set_encoding when passed nil, nil" do
before :each do
@external = Encoding.default_external
@internal = Encoding.default_internal
@ -114,9 +113,9 @@ with_feature :encoding do
describe "with 'a+' mode" do
it_behaves_like :io_set_encoding_write, nil, "a+"
end
end
end
describe "IO#set_encoding" do
describe "IO#set_encoding" do
before :each do
@name = tmp('io_set_encoding.txt')
touch(@name)
@ -189,5 +188,4 @@ with_feature :encoding do
@io.external_encoding.should == Encoding::UTF_8
@io.internal_encoding.should == Encoding::UTF_16BE
end
end
end

View file

@ -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/)

View file

@ -28,7 +28,6 @@ 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
@ -73,7 +72,6 @@ describe "IO#write on a file" do
res = "H#{ë}ll#{ö}"
File.binread(@filename).should == res.force_encoding(Encoding::ASCII_8BIT)
end
end
end
describe "IO.write" do

View file

@ -40,8 +40,7 @@ describe "Kernel#chomp" do
it_behaves_like :kernel_chomp_private, :chomp
end
with_feature :encoding do
describe :kernel_chomp_encoded, shared: true do
describe :kernel_chomp_encoded, shared: true do
before :each do
@external = Encoding.default_external
Encoding.default_external = Encoding::UTF_8
@ -55,13 +54,12 @@ with_feature :encoding 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
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

View file

@ -28,8 +28,7 @@ describe "Kernel#chop" do
it_behaves_like :kernel_chop, "chop"
end
with_feature :encoding do
describe :kernel_chop_encoded, shared: true do
describe :kernel_chop_encoded, shared: true do
before :each do
@external = Encoding.default_external
Encoding.default_external = Encoding::UTF_8
@ -43,13 +42,12 @@ with_feature :encoding 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
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

View file

@ -204,7 +204,6 @@ 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"
@ -225,7 +224,6 @@ describe "Marshal.dump" do
Marshal.dump(["".encode("us-ascii"), "".encode("utf-8")]).should == "\x04\b[\aI\"\x00\x06:\x06EFI\"\x00\x06;\x00T"
end
end
end
describe "with a Regexp" do
it "dumps a Regexp" do
@ -541,7 +539,6 @@ 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')
@ -550,7 +547,6 @@ describe "Marshal.dump" do
Marshal.dump("test", obj)
end
end
end

View file

@ -422,7 +422,6 @@ 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"
@ -455,7 +454,6 @@ describe :marshal_load, shared: true do
result.should == str
end
end
end
describe "for a Struct" do
it "loads a extended_struct having fields with same objects" do

View file

@ -22,7 +22,6 @@ 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)
@ -32,5 +31,4 @@ describe "MatchData#post_match" do
str = "abc".force_encoding Encoding::ISO_8859_1
str.match(/c/).post_match.encoding.should equal(Encoding::ISO_8859_1)
end
end
end

View file

@ -22,7 +22,6 @@ 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)
@ -32,5 +31,4 @@ describe "MatchData#pre_match" do
str = "abc".force_encoding Encoding::ISO_8859_1
str.match(/a/).pre_match.encoding.should equal(Encoding::ISO_8859_1)
end
end
end

View file

@ -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)
code = <<-RUBY
def scoped
Proc.new { puts "finalized" }
end
handler = scoped
obj = "Test"
ObjectSpace.define_finalizer(obj, handler)
exit 0
end
RUBY
wr.close
begin
rd.read.should == "finalized"
ensure
rd.close
Process.wait pid
end
ruby_exe(code).should == "finalized\n"
end
it "calls finalizer at exit even if it is self-referencing" do
rd, wr = IO.pipe
pid = Process.fork do
rd.close
code = <<-RUBY
obj = "Test"
handler = Proc.new { wr.write "finalized"; wr.close }
handler = Proc.new { puts "finalized" }
ObjectSpace.define_finalizer(obj, handler)
exit 0
RUBY
ruby_exe(code).should == "finalized\n"
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
code = <<-RUBY
obj = Object.new
pid = Kernel::fork do
rd1.close
rd2.close
obj = mock("ObjectSpace.define_finalizer multiple")
ObjectSpace.define_finalizer(obj, Proc.new { wr1.write "finalized1"; wr1.close })
ObjectSpace.define_finalizer(obj, Proc.new { wr2.write "finalized2"; wr2.close })
ObjectSpace.define_finalizer(obj, Proc.new { STDOUT.write "finalized1\n" })
ObjectSpace.define_finalizer(obj, Proc.new { STDOUT.write "finalized2\n" })
exit 0
end
RUBY
wr1.close
wr2.close
rd1.read.should == "finalized1"
rd2.read.should == "finalized2"
rd1.close
rd2.close
Process.wait pid
end
ruby_exe(code).lines.sort.should == ["finalized1\n", "finalized2\n"]
end
end

View file

@ -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
code = <<-RUBY
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
puts Process.euid
RUBY
ruby_exe(code).should == "1\n"
end
end
end

View file

@ -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
ruby_exe("puts Process.ppid").should == "#{Process.pid}\n"
end
end

View file

@ -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

View file

@ -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

View file

@ -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
code = <<-RUBY
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
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
code = <<-RUBY
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
puts Process.uid
RUBY
ruby_exe(code).should == "1\n"
end
end
end
end
end
it "needs to be reviewed for spec completeness"
end

View file

@ -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
leaked = Process.waitall
$stderr.puts "leaked before wait2 specs: #{leaked}" unless leaked.empty?
# Ruby-space should not see PIDs used by mjit

View file

@ -44,7 +44,6 @@ 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
@ -54,14 +53,12 @@ describe "Regexp#match" do
lambda { /(.).(.)/.match("Hello, #{x96} world!", 1) }.should raise_error(ArgumentError)
end
end
end
describe "when given a negative position" do
it "matches the input at a given position" 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
@ -71,7 +68,6 @@ describe "Regexp#match" do
lambda { /(.).(.)/.match("Hello, #{x96} world!", -1) }.should raise_error(ArgumentError)
end
end
end
describe "when passed a block" do
it "yields the MatchData" do

View file

@ -2,8 +2,7 @@
require_relative '../../spec_helper'
require_relative 'fixtures/classes'
with_feature :encoding do
describe "String#ascii_only?" do
describe "String#ascii_only?" do
describe "with ASCII only characters" do
it "returns true if the encoding is UTF-8" do
[ ["hello", true],
@ -81,5 +80,4 @@ with_feature :encoding do
it "returns false when replacing an ASCII String with a non-ASCII String" do
"".replace("λ").ascii_only?.should be_false
end
end
end

View file

@ -2,7 +2,6 @@
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)
@ -20,5 +19,4 @@ describe "String#b" do
ret.tainted?.should be_true
ret.untrusted?.should be_true
end
end
end

View file

@ -36,8 +36,7 @@ describe "String#bytes" do
end
end
with_feature :encoding do
describe "String#bytes" do
describe "String#bytes" do
before :each do
@utf8 = "東京"
@ascii = 'Tokyo'
@ -53,5 +52,4 @@ with_feature :encoding do
it "is unaffected by #force_encoding" do
@utf8.force_encoding('ASCII').bytes.to_a.should == @utf8.bytes.to_a
end
end
end

View file

@ -2,8 +2,7 @@
require_relative '../../spec_helper'
require_relative 'fixtures/classes'
with_feature :encoding do
describe "#String#bytesize" do
describe "#String#bytesize" do
it "needs to be reviewed for spec completeness"
it "returns the length of self in bytes" do
@ -33,5 +32,4 @@ with_feature :encoding do
"".force_encoding('ASCII').bytesize.should == 0
"".force_encoding('UTF-8').bytesize.should == 0
end
end
end

View file

@ -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
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
end

View file

@ -104,7 +104,6 @@ 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
@ -129,5 +128,4 @@ describe "String#center with length, padding" do
end.should raise_error(Encoding::CompatibilityError)
end
end
end
end

View file

@ -330,8 +330,7 @@ describe "String#chomp!" do
end
end
with_feature :encoding do
describe "String#chomp" do
describe "String#chomp" do
before :each do
@before_separator = $/
end
@ -358,9 +357,9 @@ with_feature :encoding do
str = "abc\r\n".encode "utf-32be"
str.chomp.should == "abc".encode("utf-32be")
end
end
end
describe "String#chomp!" do
describe "String#chomp!" do
before :each do
@before_separator = $/
end
@ -387,5 +386,4 @@ with_feature :encoding do
str = "abc\r\n".encode "utf-32be"
str.chomp!.should == "abc".encode("utf-32be")
end
end
end

View file

@ -27,7 +27,6 @@ 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
@ -40,7 +39,6 @@ describe "String#chop" do
str = "abc\r\n".encode "utf-32be"
str.chop.should == "abc".encode("utf-32be")
end
end
it "returns an empty string when applied to an empty string" do
"".chop.should == ""
@ -91,7 +89,6 @@ 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
@ -104,7 +101,6 @@ describe "String#chop!" do
str = "abc\r\n".encode "utf-32be"
str.chop!.should == "abc".encode("utf-32be")
end
end
it "returns self if modifications were made" do
str = "hello"

View file

@ -1,7 +1,6 @@
require_relative '../../spec_helper'
with_feature :encoding do
describe "String#chr" do
describe "String#chr" do
it "returns a copy of self" do
s = 'e'
s.should_not equal s.chr
@ -40,5 +39,4 @@ with_feature :encoding do
four.bytesize.should == 4
"#{three}#{four}".chr.should == three
end
end
end

View file

@ -1,7 +1,6 @@
require_relative '../../spec_helper'
with_feature :encoding do
describe "String#clear" do
describe "String#clear" do
before :each do
@s = "Jolene"
end
@ -35,5 +34,4 @@ with_feature :encoding do
lambda { @s.clear }.should raise_error(frozen_error_class)
lambda { "".freeze.clear }.should raise_error(frozen_error_class)
end
end
end

View file

@ -3,8 +3,7 @@ require_relative '../../spec_helper'
require_relative 'shared/codepoints'
require_relative 'shared/each_codepoint_without_block'
with_feature :encoding do
describe "String#codepoints" do
describe "String#codepoints" do
it_behaves_like :string_codepoints, :codepoints
it "returns an Array when no block is given" do
@ -16,5 +15,4 @@ with_feature :encoding do
s.valid_encoding?.should be_false
lambda { s.codepoints }.should raise_error(ArgumentError)
end
end
end

View file

@ -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
end
end

View file

@ -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
describe "String#each_codepoint" do
it_behaves_like :string_codepoints, :each_codepoint
it_behaves_like :string_each_codepoint_without_block, :each_codepoint
end
end

Some files were not shown because too many files have changed in this diff Show more