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-07-27 12:40:09 +02:00
parent a06301b103
commit 5c276e1cc9
1247 changed files with 5316 additions and 5028 deletions

View file

@ -2,7 +2,7 @@ require_relative '../../../spec_helper'
describe "Encoding::Converter.asciicompat_encoding" do
it "accepts an encoding name as a String argument" do
lambda { Encoding::Converter.asciicompat_encoding('UTF-8') }.
-> { Encoding::Converter.asciicompat_encoding('UTF-8') }.
should_not raise_error
end

View file

@ -33,13 +33,13 @@ describe "Encoding::Converter#convert" do
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 \
-> { 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)
-> { ec.convert("\u{65}") }.should raise_error(ArgumentError)
end
end

View file

@ -23,7 +23,7 @@ describe "Encoding::Converter.new" do
end
it "raises an Encoding::ConverterNotFoundError if both encodings are the same" do
lambda do
-> do
Encoding::Converter.new "utf-8", "utf-8"
end.should raise_error(Encoding::ConverterNotFoundError)
end
@ -65,25 +65,25 @@ describe "Encoding::Converter.new" do
obj = mock("encoding converter replacement")
obj.should_receive(:to_str).and_return(1)
lambda do
-> 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
-> 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
-> 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
-> do
Encoding::Converter.new("us-ascii", "utf-8", replace: 1)
end.should raise_error(TypeError)
end

View file

@ -7,19 +7,19 @@ describe "Encoding::Converter#primitive_convert" do
end
it "accepts a nil source buffer" do
lambda { @ec.primitive_convert(nil,"") }.should_not raise_error
-> { @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
-> { @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
-> { @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
-> { @ec.primitive_convert("","a", 1) }.should_not raise_error
end
it "calls #to_int to convert the destination byte offset" do
@ -30,10 +30,10 @@ describe "Encoding::Converter#primitive_convert" do
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)
-> { @ec.primitive_convert("","am", 0) }.should_not raise_error
-> { @ec.primitive_convert("","am", 1) }.should_not raise_error
-> { @ec.primitive_convert("","am", 2) }.should_not raise_error
-> { @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
@ -49,19 +49,19 @@ describe "Encoding::Converter#primitive_convert" do
end
it "accepts nil for the destination bytesize" do
lambda { @ec.primitive_convert("","", nil, nil) }.should_not raise_error
-> { @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
-> { @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
-> { @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
-> { @ec.primitive_convert("am","", nil, 1) }.should_not raise_error
end
it "calls #to_int to convert the destination byte size" do

View file

@ -54,7 +54,7 @@ describe "Encoding::Converter#primitive_errinfo" do
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.convert("\xf1abcd") }.should raise_error(Encoding::InvalidByteSequenceError)
ec.primitive_errinfo.should ==
[:invalid_byte_sequence, "UTF-8", "ISO-8859-1", "\xF1", "a"]
end
@ -62,7 +62,7 @@ describe "Encoding::Converter#primitive_errinfo" do
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.finish }.should raise_error(Encoding::InvalidByteSequenceError)
ec.primitive_errinfo.should == [:incomplete_input, "EUC-JP", "UTF-8", "\xA4", ""]
end
end

View file

@ -33,7 +33,7 @@ describe "Encoding::Converter#replacement=" do
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)
-> { ec.replacement = nil }.should raise_error(TypeError)
end
it "sets #replacement" do
@ -47,7 +47,7 @@ describe "Encoding::Converter#replacement=" 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 \
-> { ec.replacement = utf8_q }.should \
raise_error(Encoding::UndefinedConversionError)
end
@ -55,7 +55,7 @@ describe "Encoding::Converter#replacement=" 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 \
-> { ec.replacement = utf8_q }.should \
raise_error(Encoding::UndefinedConversionError)
ec.replacement.should == "?".force_encoding('us-ascii')
end

View file

@ -25,7 +25,7 @@ describe "Encoding::Converter.search_convpath" do
end
it "raises an Encoding::ConverterNotFoundError if no conversion path exists" do
lambda do
-> do
Encoding::Converter.search_convpath(Encoding::BINARY, Encoding::Emacs_Mule)
end.should raise_error(Encoding::ConverterNotFoundError)
end

View file

@ -54,10 +54,10 @@ describe "Encoding.default_external=" do
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)
-> { 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)
-> { Encoding.default_external = nil }.should raise_error(ArgumentError)
end
end

View file

@ -60,11 +60,11 @@ describe "Encoding.default_internal=" 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)
-> { 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)
-> { Encoding.default_internal = mock("encoding") }.should raise_error(TypeError)
end
it "accepts an argument of nil to unset the default internal encoding" do

View file

@ -18,7 +18,7 @@ describe "Encoding.find" do
end
it "raises a TypeError if passed a Symbol" do
lambda { Encoding.find(:"utf-8") }.should raise_error(TypeError)
-> { Encoding.find(:"utf-8") }.should raise_error(TypeError)
end
it "returns the passed Encoding object" do
@ -50,7 +50,7 @@ describe "Encoding.find" do
end
it "raises an ArgumentError if the given encoding does not exist" do
lambda { Encoding.find('dh2dh278d') }.should raise_error(ArgumentError)
-> { Encoding.find('dh2dh278d') }.should raise_error(ArgumentError)
end
# Not sure how to do a better test, since locale depends on weird platform-specific stuff