diff options
author | Benoit Daloze <[email protected]> | 2023-01-05 19:05:29 +0100 |
---|---|---|
committer | Benoit Daloze <[email protected]> | 2023-01-05 19:05:29 +0100 |
commit | bbf54ec334fe2edd7669a944d88d17efde49a412 () | |
tree | 2941c7b711319b295aa3664b6a2b984e70a523b7 /spec/ruby | |
parent | cd5e6cc0ea48353c88d921b885b552dc76da255c (diff) |
Update to ruby/spec@9d69b95
113 files changed, 1954 insertions, 236 deletions
@@ -1,3 +1,4 @@ require_relative 'shared/keep_if' describe "Array#keep_if" do @@ -45,8 +45,18 @@ describe :array_pack_8bit, shared: true do [1, 2, 3, 4, 5].pack(pack_format('*')).should == "\x01\x02\x03\x04\x05" end - it "ignores NULL bytes between directives" do - [1, 2, 3].pack(pack_format("\000", 2)).should == "\x01\x02" end it "ignores spaces between directives" do @@ -27,6 +27,42 @@ describe :array_pack_basic_non_float, shared: true do [@obj, @obj].pack("a \t\n\v\f\r"+pack_format).should be_an_instance_of(String) end it "calls #to_str to coerce the directives string" do d = mock("pack directive") d.should_receive(:to_str).and_return("x"+pack_format) @@ -39,6 +75,10 @@ describe :array_pack_basic_float, shared: true do [9.3, 4.7].pack(" \t\n\v\f\r"+pack_format).should be_an_instance_of(String) end it "calls #to_str to coerce the directives string" do d = mock("pack directive") d.should_receive(:to_str).and_return("x"+pack_format) @@ -25,8 +25,18 @@ describe :array_pack_float_le, shared: true do [2.9, 1.4, 8.2].pack(pack_format("*")).should == "\x9a\x999@33\xb3?33\x03A" end - it "ignores NULL bytes between directives" do - [5.3, 9.2].pack(pack_format("\000", 2)).should == "\x9a\x99\xa9@33\x13A" end it "ignores spaces between directives" do @@ -74,6 +84,11 @@ describe :array_pack_float_be, shared: true do it "converts an Integer to a Float" do [8].pack(pack_format).should == "A\x00\x00\x00" end it "raises a TypeError if passed a String representation of a floating point number" do @@ -88,8 +103,18 @@ describe :array_pack_float_be, shared: true do [2.9, 1.4, 8.2].pack(pack_format("*")).should == "@9\x99\x9a?\xb333A\x0333" end - it "ignores NULL bytes between directives" do - [5.3, 9.2].pack(pack_format("\000", 2)).should == "@\xa9\x99\x9aA\x1333" end it "ignores spaces between directives" do @@ -129,6 +154,11 @@ describe :array_pack_double_le, shared: true do it "converts an Integer to a Float" do [8].pack(pack_format).should == "\x00\x00\x00\x00\x00\x00\x20@" end it "raises a TypeError if passed a String representation of a floating point number" do @@ -143,8 +173,18 @@ describe :array_pack_double_le, shared: true do [2.9, 1.4, 8.2].pack(pack_format("*")).should == "333333\x07@ffffff\xf6?ffffff\x20@" end - it "ignores NULL bytes between directives" do - [5.3, 9.2].pack(pack_format("\000", 2)).should == "333333\x15@ffffff\x22@" end it "ignores spaces between directives" do @@ -202,8 +242,18 @@ describe :array_pack_double_be, shared: true do [2.9, 1.4, 8.2].pack(pack_format("*")).should == "@\x07333333?\xf6ffffff@\x20ffffff" end - it "ignores NULL bytes between directives" do - [5.3, 9.2].pack(pack_format("\000", 2)).should == "@\x15333333@\x22ffffff" end it "ignores spaces between directives" do @@ -41,9 +41,19 @@ describe :array_pack_16bit_le, shared: true do str.should == "\x78\x65\xcd\xab\x21\x43" end - it "ignores NULL bytes between directives" do - str = [0x1243_6578, 0xdef0_abcd].pack(pack_format("\000", 2)) - str.should == "\x78\x65\xcd\xab" end it "ignores spaces between directives" do @@ -93,9 +103,19 @@ describe :array_pack_16bit_be, shared: true do str.should == "\x65\x78\xab\xcd\x43\x21" end - it "ignores NULL bytes between directives" do - str = [0x1243_6578, 0xdef0_abcd].pack(pack_format("\000", 2)) - str.should == "\x65\x78\xab\xcd" end it "ignores spaces between directives" do @@ -145,9 +165,19 @@ describe :array_pack_32bit_le, shared: true do str.should == "\x78\x65\x43\x12\xcd\xab\xf0\xde\x21\x43\x65\x78" end - it "ignores NULL bytes between directives" do - str = [0x1243_6578, 0xdef0_abcd].pack(pack_format("\000", 2)) - str.should == "\x78\x65\x43\x12\xcd\xab\xf0\xde" end it "ignores spaces between directives" do @@ -197,9 +227,19 @@ describe :array_pack_32bit_be, shared: true do str.should == "\x12\x43\x65\x78\xde\xf0\xab\xcd\x78\x65\x43\x21" end - it "ignores NULL bytes between directives" do - str = [0x1243_6578, 0xdef0_abcd].pack(pack_format("\000", 2)) - str.should == "\x12\x43\x65\x78\xde\xf0\xab\xcd" end it "ignores spaces between directives" do @@ -309,9 +349,19 @@ describe :array_pack_64bit_le, shared: true do str.should == "\x56\x78\x12\x34\xcd\xab\xf0\xde\xf0\xde\xba\xdc\x21\x43\x65\x78" end - it "ignores NULL bytes between directives" do - str = [0xdef0_abcd_3412_7856, 0x7865_4321_dcba_def0].pack(pack_format("\000", 2)) - str.should == "\x56\x78\x12\x34\xcd\xab\xf0\xde\xf0\xde\xba\xdc\x21\x43\x65\x78" end it "ignores spaces between directives" do @@ -369,9 +419,19 @@ describe :array_pack_64bit_be, shared: true do str.should == "\xde\xf0\xab\xcd\x34\x12\x78\x56\x78\x65\x43\x21\xdc\xba\xde\xf0" end - it "ignores NULL bytes between directives" do - str = [0xdef0_abcd_3412_7856, 0x7865_4321_dcba_def0].pack(pack_format("\000", 2)) - str.should == "\xde\xf0\xab\xcd\x34\x12\x78\x56\x78\x65\x43\x21\xdc\xba\xde\xf0" end it "ignores spaces between directives" do @@ -37,8 +37,14 @@ describe :array_pack_float, shared: true do -> { ["a"].pack(pack_format) }.should raise_error(TypeError) end - it "raises a TypeError when the object does not respond to #to_f" do - obj = mock('not an float') -> { [obj].pack(pack_format) }.should raise_error(TypeError) end end @@ -67,8 +67,18 @@ describe :array_pack_unicode, shared: true do -> { [obj].pack("U") }.should raise_error(TypeError) end - it "ignores NULL bytes between directives" do - [1, 2, 3].pack("U\x00U").should == "\x01\x02" end it "ignores spaces between directives" do @@ -24,8 +24,18 @@ describe "Array#pack with format 'w'" do [obj].pack("w").should == "\x05" end - it "ignores NULL bytes between directives" do - [1, 2, 3].pack("w\x00w").should == "\x01\x02" end it "ignores spaces between directives" do @@ -22,6 +22,11 @@ describe :array_unshift, shared: true do a.should == [3, 4] end it "quietly ignores unshifting nothing" do [].send(@method).should == [] end @@ -43,4 +48,17 @@ describe :array_unshift, shared: true do it "raises a FrozenError on a frozen array when the array would not be modified" do -> { ArraySpecs.frozen_array.send(@method) }.should raise_error(FrozenError) end end @@ -1,6 +1,7 @@ require_relative '../../spec_helper' require_relative 'fixtures/classes' describe "Array#values_at" do it "returns an array of elements at the indexes when passed indexes" do [1, 2, 3, 4, 5].values_at().should == [] @@ -62,4 +62,10 @@ describe "Array#zip" do it "does not return subclass instance on Array subclasses" do ArraySpecs::MyArray[1, 2, 3].zip(["a", "b"]).should be_an_instance_of(Array) end end @@ -31,6 +31,28 @@ ruby_version_is '3.1' do ModuleSpecs::Parent.subclasses.should == ModuleSpecs::Parent.subclasses.uniq end def assert_subclasses(mod,subclasses) mod.subclasses.sort_by(&:inspect).should == subclasses.sort_by(&:inspect) end @@ -20,6 +20,18 @@ describe "Dir.home" do Dir.home.should_not.frozen? end platform_is :windows do ruby_version_is "3.0" do it "returns the home directory with forward slashs and as UTF-8" do @@ -29,23 +41,21 @@ describe "Dir.home" do home.encoding.should == Encoding::UTF_8 end end - end - end - platform_is :windows do - it "retrieves the directory from HOME, USERPROFILE, HOMEDRIVE/HOMEPATH and the WinAPI in that order" do - old_dirs = [ENV.delete('HOME'), ENV.delete('USERPROFILE'), ENV.delete('HOMEDRIVE'), ENV.delete('HOMEPATH')] - Dir.home.should == old_dirs[1].gsub("\\", "/") - ENV['HOMEDRIVE'] = "C:" - ENV['HOMEPATH'] = "\\rubyspec\\home1" - Dir.home.should == "C:/rubyspec/home1" - ENV['USERPROFILE'] = "C:\\rubyspec\\home2" - Dir.home.should == "C:/rubyspec/home2" - ENV['HOME'] = "C:\\rubyspec\\home3" - Dir.home.should == "C:/rubyspec/home3" - ensure - ENV['HOME'], ENV['USERPROFILE'], ENV['HOMEDRIVE'], ENV['HOMEPATH'] = *old_dirs end end @@ -65,6 +75,10 @@ describe "Dir.home" do it "returns a non-frozen string" do Dir.home(ENV['USER']).should_not.frozen? end end it "raises an ArgumentError if the named user doesn't exist" do @@ -46,7 +46,7 @@ describe "Dir.mkdir" do end end - it "calls #to_path on non-String arguments" do DirSpecs.clear_dirs p = mock('path') p.should_receive(:to_path).and_return(DirSpecs.mock_dir('nonexisting')) @@ -54,6 +54,22 @@ describe "Dir.mkdir" do DirSpecs.clear_dirs end it "raises a SystemCallError if any of the directories in the path before the last does not exist" do -> { Dir.mkdir "#{DirSpecs.nonexistent}/subdir" }.should raise_error(SystemCallError) end @@ -38,4 +38,9 @@ describe "Enumerable#zip" do multi.zip(multi).should == [[[1, 2], [1, 2]], [[3, 4, 5], [3, 4, 5]], [[6, 7, 8, 9], [6, 7, 8, 9]]] end end @@ -7,9 +7,25 @@ describe "Float#<=>" do ((bignum_value*1.1) <=> bignum_value).should == 1 end - it "returns nil when either argument is NaN" do - (nan_value <=> 71.2).should be_nil - (1771.176 <=> nan_value).should be_nil end it "returns nil when the given argument is not a Float" do @@ -49,21 +65,10 @@ describe "Float#<=>" do }.should raise_error(TypeError, "coerce must return [x, y]") end - # The 4 tests below are taken from matz's revision 23730 for Ruby trunk - # - it "returns 1 when self is Infinity and other is an Integer" do (infinity_value <=> Float::MAX.to_i*2).should == 1 - end - - it "returns -1 when self is negative and other is Infinity" do (-Float::MAX.to_i*2 <=> infinity_value).should == -1 - end - - it "returns -1 when self is -Infinity and other is negative" do (-infinity_value <=> -Float::MAX.to_i*2).should == -1 - end - - it "returns 1 when self is negative and other is -Infinity" do (-Float::MAX.to_i*2 <=> -infinity_value).should == 1 end @@ -23,7 +23,7 @@ describe "Float#divmod" do # Behaviour established as correct in r23953 it "raises a FloatDomainError if other is NaN" do - -> { 1.divmod(nan_value) }.should raise_error(FloatDomainError) end # Behaviour established as correct in r23953 @@ -14,4 +14,25 @@ describe "Float#>" do -> { 5.0 > "4" }.should raise_error(ArgumentError) -> { 5.0 > mock('x') }.should raise_error(ArgumentError) end end @@ -14,4 +14,25 @@ describe "Float#>=" do -> { 5.0 >= "4" }.should raise_error(ArgumentError) -> { 5.0 >= mock('x') }.should raise_error(ArgumentError) end end @@ -14,4 +14,25 @@ describe "Float#<" do -> { 5.0 < "4" }.should raise_error(ArgumentError) -> { 5.0 < mock('x') }.should raise_error(ArgumentError) end end @@ -15,4 +15,25 @@ describe "Float#<=" do -> { 5.0 <= "4" }.should raise_error(ArgumentError) -> { 5.0 <= mock('x') }.should raise_error(ArgumentError) end end @@ -14,4 +14,25 @@ describe :float_equal, shared: true do 1.0.send(@method, x).should == false 2.0.send(@method, x).should == true end end @@ -216,6 +216,10 @@ describe "IO#gets" do @io.gets(nil, 0).should == "" @io.gets("", 0).should == "" end end describe "IO#gets" do @@ -92,8 +92,13 @@ describe "IO#lineno=" do @io.lineno.should == 92233 end - it "raises TypeError on nil argument" do - -> { @io.lineno = nil }.should raise_error(TypeError) end it "sets the current line number to the given value" do @@ -1,6 +1,8 @@ require_relative '../../spec_helper' require_relative 'shared/new' describe "IO.new" do it_behaves_like :io_new, :new end @@ -51,6 +51,10 @@ describe "IO#readline" do it "returns an empty string when passed 0 as a limit" do @io.readline(0).should == "" end end describe "when passed separator and limit" do @@ -106,6 +106,10 @@ describe "IO#readlines" do it "raises ArgumentError when passed 0 as a limit" do -> { @io.readlines(0) }.should raise_error(ArgumentError) end end describe "when passed chomp" do @@ -77,6 +77,10 @@ describe :io_each, shared: true do -> { @io.send(@method, 0){} }.should raise_error(ArgumentError) end end end describe "when passed a String containing one space as a separator" do @@ -1,5 +1,7 @@ require_relative '../fixtures/classes' # This group of specs may ONLY contain specs that do successfully create # an IO instance from the file descriptor returned by #new_fd helper. describe :io_new, shared: true do @@ -60,7 +60,13 @@ describe :io_set_pos, shared: true do end end - it "does not accept Integers that don't fit in a C long" do File.open @fname do |io| -> { io.send @method, 2**128 }.should raise_error(RangeError) end @@ -79,6 +79,10 @@ describe :io_readlines_options_19, shared: true do (result ? result : ScratchPad.recorded).should == IOSpecs.lines end ruby_bug "#18767", ""..."3.3" do describe "when passed limit" do it "raises ArgumentError when passed 0 as a limit" do @@ -4,7 +4,7 @@ require_relative 'fixtures/classes' require_relative 'shared/pos' describe "IO#sysseek" do - it_behaves_like :io_set_pos, :seek end describe "IO#sysseek" do @@ -88,12 +88,12 @@ describe :kernel_load, shared: true do describe "when passed true for 'wrap'" do it "loads from an existing path" do - path = File.expand_path "wrap_fixture.rb", CODE_LOADING_DIR @object.load(path, true).should be_true end it "sets the enclosing scope to an anonymous module" do - path = File.expand_path "wrap_fixture.rb", CODE_LOADING_DIR @object.load(path, true) Object.const_defined?(:LoadSpecWrap).should be_false @@ -103,14 +103,14 @@ describe :kernel_load, shared: true do end it "allows referencing outside namespaces" do - path = File.expand_path "wrap_fixture.rb", CODE_LOADING_DIR @object.load(path, true) ScratchPad.recorded[0].should equal(String) end it "sets self as a copy of the top-level main" do - path = File.expand_path "wrap_fixture.rb", CODE_LOADING_DIR @object.load(path, true) top_level = ScratchPad.recorded[2] @@ -127,7 +127,7 @@ describe :kernel_load, shared: true do main_ancestors = main.singleton_class.ancestors[1..-1] main_ancestors.first.should == mod - path = File.expand_path "wrap_fixture.rb", CODE_LOADING_DIR @object.load(path, true) top_level = ScratchPad.recorded[2] @@ -157,7 +157,7 @@ describe :kernel_load, shared: true do describe "when passed a module for 'wrap'" do ruby_version_is "3.1" do it "sets the enclosing scope to the supplied module" do - path = File.expand_path "wrap_fixture.rb", CODE_LOADING_DIR mod = Module.new @object.load(path, mod) @@ -167,6 +167,25 @@ describe :kernel_load, shared: true do wrap_module = ScratchPad.recorded[1] wrap_module.should == mod end end end @@ -1,3 +1,5 @@ describe "Kernel#singleton_class" do it "returns class extended from an object" do x = Object.new @@ -1,5 +1,6 @@ # -*- encoding: binary -*- require_relative '../../spec_helper' require_relative 'fixtures/marshal_data' describe "Marshal.dump" do @@ -106,7 +107,7 @@ describe "Marshal.dump" do end describe "with an object responding to #_dump" do - it "dumps the object returned by #marshal_dump" do Marshal.dump(UserDefined.new).should == "\004\bu:\020UserDefined\022\004\b[\a:\nstuff;\000" end @@ -122,6 +123,34 @@ describe "Marshal.dump" do m.should_not_receive(:_dump) Marshal.dump(m) end end describe "with a Class" do @@ -185,6 +214,20 @@ describe "Marshal.dump" do [Marshal, -2**64, "\004\bl-\n\000\000\000\000\000\000\000\000\001\000"], ].should be_computed_by(:dump) end end describe "with a String" do @@ -0,0 +1,4 @@ @@ -1,21 +1,76 @@ require_relative '../../spec_helper' -describe "MatchData#values_at" do - it "returns an array of the matching value" do - /(.)(.)(\d+)(\d)/.match("THX1138: The Movie").values_at(0, 2, -2).should == ["HX1138", "X", "113"] end - describe "when passed a Range" do - it "returns an array of the matching value" do - /(.)(.)(\d+)(\d)/.match("THX1138: The Movie").values_at(2..4, 0..1).should == ["X", "113", "8", "HX1138", "H"] end end - it 'slices captures with the given names' do - /(?<a>.)(?<b>.)(?<c>.)/.match('012').values_at(:c, :a).should == ['2', '0'] end - it 'takes names and indices' do /\A(?<a>.)(?<b>.)\z/.match('01').values_at(0, 1, 2, :a, :b).should == ['01', '0', '1', '0', '1'] end end @@ -388,6 +388,7 @@ module ModuleSpecs # empty modules module M1; end module M2; end module Autoload def self.use_ex1 @@ -104,9 +104,9 @@ describe "Module#include" do class A; include M; end class B < A; include M; end - all = [A,B,M] - (B.ancestors & all).should == [B, A, M] end end @@ -611,6 +611,18 @@ describe "Module#prepend" do ScratchPad.recorded.should == [[:prepend_features, c], [:prepended, c]] end it "detects cyclic prepends" do -> { module ModuleSpecs::P @@ -169,4 +169,26 @@ describe "ObjectSpace.define_finalizer" do ruby_exe(code).lines.sort.should == ["finalized1\n", "finalized2\n"] end end @@ -1,3 +1,4 @@ describe "Process::Constants" do platform_is :darwin, :netbsd, :freebsd do @@ -42,5 +42,34 @@ describe "Process.detach" do thr.pid.should == pid end end end @@ -477,6 +477,16 @@ describe "Process.spawn" do # redirection it "redirects STDOUT to the given file descriptor if out: Integer" do File.open(@name, 'w') do |file| -> do @@ -7,7 +7,7 @@ describe "Process.times" do # TODO: Intel C Compiler does not work this example # http://rubyci.s3.amazonaws.com/icc-x64/ruby-master/log/20221013T030005Z.fail.html.gz - unless RbConfig::CONFIG['CC'].include?("icx") it "returns current cpu times" do t = Process.times user = t.utime @@ -7,6 +7,10 @@ describe "Queue#initialize" do q.should.empty? end ruby_version_is '3.1' do it "adds all elements of the passed Enumerable to self" do q = Queue.new([1, 2, 3]) @@ -30,9 +34,16 @@ describe "Queue#initialize" do q.should.empty? end - it "raises if the provided Enumerable does not respond to #to_a" do enumerable = MockObject.new('mock-enumerable') -> { Queue.new(enumerable) }.should raise_error(TypeError, "can't convert MockObject into Array") end end end @@ -0,0 +1,34 @@ @@ -0,0 +1,27 @@ @@ -0,0 +1,27 @@ @@ -2,7 +2,7 @@ require_relative '../../spec_helper' describe "Regexp#initialize" do it "is a private method" do - Regexp.should have_private_method(:initialize) end ruby_version_is ""..."3.0" do @@ -221,6 +221,18 @@ describe "Signal.trap" do Signal.trap(:HUP, @saved_trap).should equal(@proc) end # See man 2 signal %w[KILL STOP].each do |signal| it "raises ArgumentError or Errno::EINVAL for SIG#{signal}" do @@ -24,4 +24,10 @@ describe "String#byteslice on on non ASCII strings" do "\u3042".byteslice(1..2).should == "\x81\x82".force_encoding("UTF-8") "\u3042".byteslice(-1).should == "\x82".force_encoding("UTF-8") end end @@ -91,6 +91,10 @@ describe "String#capitalize" do StringSpecs::MyString.new("Hello").capitalize.should be_an_instance_of(String) end end end describe "String#capitalize!" do @@ -1,5 +1,4 @@ require_relative 'shared/chars' -require_relative 'shared/each_char_without_block' describe "String#chars" do it_behaves_like :string_chars, :chars @@ -7,4 +6,10 @@ describe "String#chars" do it "returns an array when no block given" do "hello".chars.should == ['h', 'e', 'l', 'l', 'o'] end end @@ -40,6 +40,10 @@ describe "String#chomp" do "".chomp.should == "" end ruby_version_is ''...'3.0' do it "returns subclass instances when called on a subclass" do str = StringSpecs::MyString.new("hello\n").chomp @@ -60,6 +60,10 @@ describe "String#chop" do StringSpecs::MyString.new("hello\n").chop.should be_an_instance_of(String) end end end describe "String#chop!" do @@ -54,4 +54,8 @@ describe "String#clone" do orig.should == "xtring" clone.should == "string" end end @@ -51,6 +51,10 @@ describe "String#delete_prefix" do s.delete_prefix('hell').should be_an_instance_of(String) end end end describe "String#delete_prefix!" do @@ -95,6 +95,10 @@ describe "String#delete" do StringSpecs::MyString.new("oh no!!!").delete("!").should be_an_instance_of(String) end end end describe "String#delete!" do @@ -51,6 +51,10 @@ describe "String#delete_suffix" do s.delete_suffix('ello').should be_an_instance_of(String) end end end describe "String#delete_suffix!" do @@ -8,6 +8,10 @@ describe "String#downcase" do "hello".downcase.should == "hello" end describe "full Unicode case mapping" do it "works for all of Unicode with no option" do "ÄÖÜ".downcase.should == "äöü" @@ -350,7 +350,7 @@ describe "String#dump" do ].should be_computed_by(:dump) end - it "returns a string with multi-byte UTF-8 characters replaced by \\u{} notation with upper-case hex digits" do [ [0200.chr('utf-8'), '"\u0080"'], [0201.chr('utf-8'), '"\u0081"'], [0202.chr('utf-8'), '"\u0082"'], @@ -382,15 +382,21 @@ describe "String#dump" do [0235.chr('utf-8'), '"\u009D"'], [0236.chr('utf-8'), '"\u009E"'], [0237.chr('utf-8'), '"\u009F"'], ].should be_computed_by(:dump) end it "includes .force_encoding(name) if the encoding isn't ASCII compatible" do "\u{876}".encode('utf-16be').dump.should.end_with?(".force_encoding(\"UTF-16BE\")") "\u{876}".encode('utf-16le').dump.should.end_with?(".force_encoding(\"UTF-16LE\")") end - it "keeps origin encoding" do "foo".encode("ISO-8859-1").dump.encoding.should == Encoding::ISO_8859_1 "foo".encode('windows-1251').dump.encoding.should == Encoding::Windows_1251 1.chr.dump.encoding.should == Encoding::US_ASCII @@ -58,4 +58,8 @@ describe "String#dup" do orig.should == "c" copy.should == "b" end end @@ -1,7 +1,6 @@ require_relative '../../spec_helper' require_relative 'fixtures/classes' require_relative 'shared/each_line' -require_relative 'shared/each_line_without_block' describe "String#lines" do it_behaves_like :string_each_line, :lines @@ -37,6 +37,10 @@ describe "String#reverse" do str.reverse.should == "體黑正\xDE\xDF軟微" end end describe "String#reverse!" do @@ -69,6 +69,12 @@ describe "String#scan" do it "does not raise any errors when passed a multi-byte string" do "あああaaaあああ".scan("あああ").should == ["あああ", "あああ"] end end describe "String#scan with pattern and block" do @@ -31,6 +31,11 @@ describe "String#scrub with a default replacement" do input.scrub.should == "abc?????" end ruby_version_is '3.0' do it "returns String instances when called on a subclass" do StringSpecs::MyString.new("foo").scrub.should be_an_instance_of(String) @@ -80,6 +85,11 @@ describe "String#scrub with a custom replacement" do block.should raise_error(ArgumentError) end it "raises TypeError when a non String replacement is given" do x81 = [0x81].pack('C').force_encoding('utf-8') block = -> { "foo#{x81}".scrub(1) } @@ -122,6 +122,12 @@ describe :string_each_line, shared: true do out.should == ["hello\n", "world."] end it "raises a TypeError when the separator can't be converted to a string" do -> { "hello world".send(@method, false) {} }.should raise_error(TypeError) -> { "hello world".send(@method, mock('x')) {} }.should raise_error(TypeError) @@ -33,4 +33,19 @@ describe :string_partition, shared: true do end end end end @@ -80,7 +80,7 @@ describe :string_slice_index_length, shared: true do "hello there".send(@method, -3,2).should == "er" end - it "returns a string with the same encoding" do s = "hello there" s.send(@method, 1, 9).encoding.should == s.encoding @@ -206,6 +206,10 @@ describe :string_slice_range, shared: true do "x".send(@method, 1..-1).should == "" end it "returns nil if the beginning of the range falls outside of self" do "hello there".send(@method, 12..-1).should == nil "hello there".send(@method, 20..25).should == nil @@ -328,7 +332,8 @@ describe :string_slice_regexp, shared: true do "hello there".send(@method, /xyz/).should == nil end - not_supported_on :opal do end ruby_version_is ''...'3.0' do @@ -391,6 +396,10 @@ describe :string_slice_regexp_index, shared: true do $~[1].should == nil end it "calls to_int on the given index" do obj = mock('2') obj.should_receive(:to_int).and_return(2) @@ -2,6 +2,10 @@ require_relative '../../../spec_helper' require_relative '../fixtures/classes' describe :string_strip, shared: true do ruby_version_is '3.0' do it "returns String instances when called on a subclass" do StringSpecs::MyString.new(" hello ").send(@method).should be_an_instance_of(String) @@ -74,6 +74,10 @@ describe :string_succ, shared: true do StringSpecs::MyString.new("z").send(@method).should be_an_instance_of(String) end end end describe :string_succ_bang, shared: true do @@ -246,6 +246,13 @@ describe "String#split with String" do it "doesn't split on non-ascii whitespace" do "a\u{2008}b".split(" ").should == ["a\u{2008}b"] end end describe "String#split with Regexp" do @@ -443,13 +450,12 @@ describe "String#split with Regexp" do end end - it "retains the encoding of the source string" do ary = "а б в".split encodings = ary.map { |s| s.encoding } encodings.should == [Encoding::UTF_8, Encoding::UTF_8, Encoding::UTF_8] end - it "splits a string on each character for a multibyte encoding and empty split" do "That's why efficiency could not be helped".split("").size.should == 39 end @@ -598,4 +604,11 @@ describe "String#split with Regexp" do -> { "hello".split(false) }.should raise_error(TypeError) -> { "hello".split(Object.new) }.should raise_error(TypeError) end end @@ -64,6 +64,11 @@ describe "String#squeeze" do "hello room".squeeze(other_string, other_string2).should == "hello rom" end it "raises a TypeError when one set arg can't be converted to a string" do -> { "hello world".squeeze([]) }.should raise_error(TypeError) -> { "hello world".squeeze(Object.new)}.should raise_error(TypeError) @@ -9,6 +9,10 @@ describe "String#swapcase" do "+++---111222???".swapcase.should == "+++---111222???" end describe "full Unicode case mapping" do it "works for all of Unicode with no option" do "äÖü".swapcase.should == "ÄöÜ" @@ -389,7 +389,7 @@ describe "String#undump" do '"\\bv".force_encoding("UTF-16BE")'.undump.should == "\u0876".encode('utf-16be') end - it "keeps origin encoding" do '"foo"'.encode("ISO-8859-1").undump.encoding.should == Encoding::ISO_8859_1 '"foo"'.encode('windows-1251').undump.encoding.should == Encoding::Windows_1251 end @@ -86,8 +86,18 @@ describe "String#unpack with format 'B'" do ].should be_computed_by(:unpack, "BBB") end - it "ignores NULL bytes between directives" do - "\x80\x00".unpack("B\x00B").should == ["1", "0"] end it "ignores spaces between directives" do @@ -182,8 +192,18 @@ describe "String#unpack with format 'b'" do ].should be_computed_by(:unpack, "bbb") end - it "ignores NULL bytes between directives" do - "\x01\x00".unpack("b\x00b").should == ["1", "0"] end it "ignores spaces between directives" do @@ -35,8 +35,18 @@ describe :string_unpack_8bit, shared: true do ].should be_computed_by(:unpack, unpack_format(3)) end - it "ignores NULL bytes between directives" do - "abc".unpack(unpack_format("\000", 2)).should == [97, 98] end it "ignores spaces between directives" do @@ -56,8 +56,18 @@ describe "String#unpack with format 'H'" do ].should be_computed_by(:unpack, "HHH") end - it "ignores NULL bytes between directives" do - "\x01\x10".unpack("H\x00H").should == ["0", "1"] end it "ignores spaces between directives" do @@ -121,8 +131,18 @@ describe "String#unpack with format 'h'" do ].should be_computed_by(:unpack, "hhh") end - it "ignores NULL bytes between directives" do - "\x01\x10".unpack("h\x00h").should == ["1", "0"] end it "ignores spaces between directives" do @@ -8,20 +8,6 @@ describe :string_unpack_basic, shared: true do d.should_receive(:to_str).and_return("a"+unpack_format) "abc".unpack(d).should be_an_instance_of(Array) end - - it "raises a TypeError when passed nil" do - -> { "abc".unpack(nil) }.should raise_error(TypeError) - end - - it "raises a TypeError when passed an Integer" do - -> { "abc".unpack(1) }.should raise_error(TypeError) - end - - ruby_version_is "3.1" do - it "starts unpacking from the given offset" do - "abc".unpack("CC", offset: 1).should == [98, 99] - end - end end describe :string_unpack_no_platform, shared: true do @@ -32,18 +18,4 @@ describe :string_unpack_no_platform, shared: true do it "raises an ArgumentError when the format modifier is '!'" do -> { "abcdefgh".unpack(unpack_format("!")) }.should raise_error(ArgumentError) end - - ruby_version_is "3.1" do - it "raises an ArgumentError when the offset is negative" do - -> { "a".unpack("C", offset: -1) }.should raise_error(ArgumentError) - end - - it "returns nil if the offset is at the end of the string" do - "a".unpack("C", offset: 1).should == [nil] - end - - it "raises an ArgumentError when the offset is larget than the string" do - -> { "a".unpack("C", offset: 2) }.should raise_error(ArgumentError) - end - end end @@ -56,9 +56,19 @@ describe :string_unpack_float_le, shared: true do [nan_value].pack(unpack_format).unpack(unpack_format).first.nan?.should be_true end - it "ignores NULL bytes between directives" do - array = "\x9a\x999@33\xb3?".unpack(unpack_format("\000", 2)) - array.should == [2.9000000953674316, 1.399999976158142] end it "ignores spaces between directives" do @@ -123,9 +133,19 @@ describe :string_unpack_float_be, shared: true do [nan_value].pack(unpack_format).unpack(unpack_format).first.nan?.should be_true end - it "ignores NULL bytes between directives" do - array = "@9\x99\x9a?\xb333".unpack(unpack_format("\000", 2)) - array.should == [2.9000000953674316, 1.399999976158142] end it "ignores spaces between directives" do @@ -193,8 +213,18 @@ describe :string_unpack_double_le, shared: true do [nan_value].pack(unpack_format).unpack(unpack_format).first.nan?.should be_true end - it "ignores NULL bytes between directives" do - "333333\x07@ffffff\xf6?".unpack(unpack_format("\000", 2)).should == [2.9, 1.4] end it "ignores spaces between directives" do @@ -261,8 +291,18 @@ describe :string_unpack_double_be, shared: true do [nan_value].pack(unpack_format).unpack(unpack_format).first.nan?.should be_true end - it "ignores NULL bytes between directives" do - "@\x07333333?\xf6ffffff".unpack(unpack_format("\000", 2)).should == [2.9, 1.4] end it "ignores spaces between directives" do @@ -32,8 +32,18 @@ describe :string_unpack_16bit_le, shared: true do ].should be_computed_by(:unpack, unpack_format(3)) end - it "ignores NULL bytes between directives" do - "abcd".unpack(unpack_format("\000", 2)).should == [25185, 25699] end it "ignores spaces between directives" do @@ -85,8 +95,18 @@ describe :string_unpack_16bit_be, shared: true do ].should be_computed_by(:unpack, unpack_format(3)) end - it "ignores NULL bytes between directives" do - "badc".unpack(unpack_format("\000", 2)).should == [25185, 25699] end it "ignores spaces between directives" do @@ -139,8 +159,18 @@ describe :string_unpack_32bit_le, shared: true do ].should be_computed_by(:unpack, unpack_format(3)) end - it "ignores NULL bytes between directives" do - "abcdefgh".unpack(unpack_format("\000", 2)).should == [1684234849, 1751606885] end it "ignores spaces between directives" do @@ -193,8 +223,18 @@ describe :string_unpack_32bit_be, shared: true do ].should be_computed_by(:unpack, unpack_format(3)) end - it "ignores NULL bytes between directives" do - "dcbahgfe".unpack(unpack_format("\000", 2)).should == [1684234849, 1751606885] end it "ignores spaces between directives" do @@ -243,9 +283,19 @@ describe :string_unpack_64bit_le, shared: true do "abc".unpack(unpack_format('*')).should == [] end - it "ignores NULL bytes between directives" do - array = "abcdefghabghefcd".unpack(unpack_format("\000", 2)) - array.should == [7523094288207667809, 7233738012216484449] end it "ignores spaces between directives" do @@ -305,9 +355,19 @@ describe :string_unpack_64bit_be, shared: true do "abc".unpack(unpack_format('*')).should == [] end - it "ignores NULL bytes between directives" do - array = "hgfedcbadcfehgba".unpack(unpack_format("\000", 2)) - array.should == [7523094288207667809, 7233738012216484449] end it "ignores spaces between directives" do @@ -50,8 +50,18 @@ describe :string_unpack_unicode, shared: true do "\xc2\x80".unpack("UUUU").should == [0x80] end - it "ignores NULL bytes between directives" do - "\x01\x02".unpack("U\x00U").should == [1, 2] end it "ignores spaces between directives" do @@ -15,8 +15,18 @@ describe "String#unpack with directive 'w'" do ].should be_computed_by(:unpack, "w") end - it "ignores NULL bytes between directives" do - "\x01\x02\x03".unpack("w\x00w").should == [1, 2] end it "ignores spaces between directives" do @@ -15,16 +15,22 @@ describe "String#unpack1" do "ZA".unpack1("B*", offset: 1).should == "01000001" end it "raises an ArgumentError when the offset is negative" do - -> { "a".unpack1("C", offset: -1) }.should raise_error(ArgumentError) end it "returns nil if the offset is at the end of the string" do "a".unpack1("C", offset: 1).should == nil end - it "raises an ArgumentError when the offset is larget than the string" do - -> { "a".unpack1("C", offset: 2) }.should raise_error(ArgumentError) end end end @@ -0,0 +1,34 @@ @@ -8,6 +8,10 @@ describe "String#upcase" do "hello".upcase.should == "HELLO" end describe "full Unicode case mapping" do it "works for all of Unicode with no option" do "äöü".upcase.should == "ÄÖÜ" @@ -0,0 +1,214 @@ @@ -1,16 +1,59 @@ require_relative '../../spec_helper' require_relative 'fixtures/classes' describe "Struct#values_at" do - it "returns an array of values" do clazz = Struct.new(:name, :director, :year) - movie = clazz.new('Sympathy for Mr. Vengeance', 'Chan-wook Park', 2002) - movie.values_at(0, 1).should == ['Sympathy for Mr. Vengeance', 'Chan-wook Park'] - movie.values_at(0..2).should == ['Sympathy for Mr. Vengeance', 'Chan-wook Park', 2002] end it "fails when passed unsupported types" do - car = StructClasses::Car.new('Ford', 'Ranger') - -> { car.values_at('make') }.should raise_error(TypeError) end end @@ -6,4 +6,11 @@ describe :symbol_id2name, shared: true do :@ruby.send(@method).should == "@ruby" :@@ruby.send(@method).should == "@@ruby" end end @@ -251,6 +251,22 @@ describe "Time.at" do time.to_i.should == @epoch_time end it "could be a timezone object" do zone = TimeSpecs::TimezoneWithName.new(name: "Asia/Colombo") time = Time.at(@epoch_time, in: zone) @@ -29,10 +29,10 @@ describe "Time#localtime" do time.localtime.should equal(time) end - it "raises a RuntimeError if the time has a different time zone" do time = Time.gm(2007, 1, 9, 12, 0, 0) time.freeze - -> { time.localtime }.should raise_error(RuntimeError) end end @@ -79,6 +79,18 @@ describe "Time#localtime" do t.utc_offset.should == -3600 end platform_is_not :windows do it "changes the timezone according to the set one" do t = Time.new(2005, 2, 27, 22, 50, 0, -3600) @@ -58,6 +58,32 @@ describe "Time.new with a utc_offset argument" do Time.new(2000, 1, 1, 0, 0, 0, "-04:10:43").utc_offset.should == -15043 end describe "with an argument that responds to #to_str" do it "coerces using #to_str" do o = mock('string') @@ -66,6 +92,57 @@ describe "Time.new with a utc_offset argument" do end end it "returns a local Time if the argument is nil" do with_timezone("PST", -8) do t = Time.new(2000, 1, 1, 0, 0, 0, nil) @@ -93,7 +170,12 @@ describe "Time.new with a utc_offset argument" do end it "raises ArgumentError if the String argument is not in an ASCII-compatible encoding" do - -> { Time.new(2000, 1, 1, 0, 0, 0, "-04:10".encode("UTF-16LE")) }.should raise_error(ArgumentError) end it "raises ArgumentError if the argument represents a value less than or equal to -86400 seconds" do @@ -106,19 +188,9 @@ describe "Time.new with a utc_offset argument" do -> { Time.new(2000, 1, 1, 0, 0, 0, 86400) }.should raise_error(ArgumentError) end - it "raises ArgumentError if the seconds argument is negative" do - -> { Time.new(2000, 1, 1, 0, 0, -1) }.should raise_error(ArgumentError) - end - it "raises ArgumentError if the utc_offset argument is greater than or equal to 10e9" do -> { Time.new(2000, 1, 1, 0, 0, 0, 1000000000) }.should raise_error(ArgumentError) end - - it "raises ArgumentError if the month is greater than 12" do - # For some reason MRI uses a different message for month in 13-15 and month>=16 - -> { Time.new(2000, 13, 1, 0, 0, 0, "+01:00") }.should raise_error(ArgumentError, /(mon|argument) out of range/) - -> { Time.new(2000, 16, 1, 0, 0, 0, "+01:00") }.should raise_error(ArgumentError, "argument out of range") - end end describe "Time.new with a timezone argument" do @@ -22,11 +22,11 @@ describe :time_gmtime, shared: true do time.send(@method).should equal(time) end - it "raises a RuntimeError if the time is not UTC" do with_timezone("CST", -6) do time = Time.now time.freeze - -> { time.send(@method) }.should raise_error(RuntimeError) end end end @@ -145,9 +145,10 @@ describe :time_params, shared: true do end it "raises an ArgumentError for out of range month" do -> { - Time.send(@method, 2008, 13, 31, 23, 59, 59) - }.should raise_error(ArgumentError) end it "raises an ArgumentError for out of range day" do @@ -169,9 +170,13 @@ describe :time_params, shared: true do end it "raises an ArgumentError for out of range second" do -> { Time.send(@method, 2008, 12, 31, 23, 59, 61) - }.should raise_error(ArgumentError) end it "raises ArgumentError when given 9 arguments" do @@ -52,10 +52,42 @@ describe "Time#strftime" do ruby_version_is "3.1" do it "supports RFC 3339 UTC for unknown offset local time, -0000, as %-z" do - @time.strftime("%z").should == "+0000" - @time.strftime("%-z").should == "-0000" - @time.strftime("%-:z").should == "-00:00" - @time.strftime("%-::z").should == "-00:00:00" end end end @@ -4,8 +4,45 @@ require_relative 'shared/gmtime' require_relative 'shared/time_params' describe "Time#utc?" do - it "returns true if time represents a time in UTC (GMT)" do - Time.now.should_not.utc? end end @@ -52,14 +52,28 @@ describe "Time#zone" do end it "doesn't raise errors for a Time with a fixed offset" do - -> { - Time.new(2001, 1, 1, 0, 0, 0, "+05:00").zone - }.should_not raise_error end end it "returns UTC when called on a UTC time" do Time.now.utc.zone.should == "UTC" end platform_is_not :aix, :windows do @@ -16,6 +16,15 @@ describe 'TracePoint#inspect' do TracePoint.new(:line) {}.inspect.should == '#<TracePoint:disabled>' end it 'returns a String showing the event, path and line' do inspect = nil line = nil @@ -2,7 +2,10 @@ class LoadSpecWrap ScratchPad << String end def load_wrap_specs_top_level_method end ScratchPad << method(:load_wrap_specs_top_level_method).owner @@ -103,7 +103,7 @@ describe "The 'case'-construct" do $1.should == "42" end - it "tests with a regexp interpolated within another regexp" do digits = '\d+' case "foo44" when /oo(#{digits})/ @@ -116,7 +116,7 @@ describe "The 'case'-construct" do $1.should == "44" end - it "tests with a string interpolated in a regexp" do digits_regexp = /\d+/ case "foo43" when /oo(#{digits_regexp})/ @@ -609,6 +609,11 @@ describe "Regexp with character classes" do "루비(Ruby)".match(/\p{Hangul}+/u).to_a.should == ["루비"] end ruby_bug "#17340", ''...'3.0' do it "raises a RegexpError for an unterminated unicode property" do -> { Regexp.new('\p{') }.should raise_error(RegexpError) @@ -0,0 +1,20 @@ @@ -2,11 +2,6 @@ require_relative '../../spec_helper' require_relative 'shared/civil' require 'date' -describe "Date#civil" do - it_behaves_like :date_civil, :civil -end - - describe "Date.civil" do - it "needs to be reviewed for spec completeness" end @@ -0,0 +1,5 @@ @@ -0,0 +1,15 @@ @@ -12,7 +12,7 @@ describe "OpenSSL::X509::Name.verify" do cert.public_key = key.public_key cert.not_before = Time.now - 10 cert.not_after = cert.not_before + 365 * 24 * 60 * 60 - cert.sign key, OpenSSL::Digest.new('SHA1') store = OpenSSL::X509::Store.new store.add_cert(cert) [store.verify(cert), store.error, store.error_string].should == [true, 0, "ok"] @@ -28,7 +28,7 @@ describe "OpenSSL::X509::Name.verify" do cert.public_key = key.public_key cert.not_before = Time.now - 10 cert.not_after = Time.now - 5 - cert.sign key, OpenSSL::Digest.new('SHA1') store = OpenSSL::X509::Store.new store.add_cert(cert) store.verify(cert).should == false @@ -163,6 +163,91 @@ describe "StringIO#initialize when passed [Object]" do end end describe "StringIO#initialize when passed no arguments" do before :each do @io = StringIO.allocate @@ -0,0 +1,8 @@ @@ -66,6 +66,28 @@ describe :stringio_write_string, shared: true do @io.tainted?.should be_false end end end describe :stringio_write_not_writable, shared: true do @@ -182,6 +182,46 @@ VALUE io_spec_rb_thread_fd_writable(VALUE self, VALUE io) { return Qnil; } VALUE io_spec_rb_io_binmode(VALUE self, VALUE io) { return rb_io_binmode(io); } @@ -256,6 +296,9 @@ void Init_io_spec(void) { rb_define_method(cls, "rb_io_wait_writable", io_spec_rb_io_wait_writable, 1); rb_define_method(cls, "rb_thread_wait_fd", io_spec_rb_thread_wait_fd, 1); rb_define_method(cls, "rb_thread_fd_writable", io_spec_rb_thread_fd_writable, 1); rb_define_method(cls, "rb_wait_for_single_fd", io_spec_rb_wait_for_single_fd, 4); rb_define_method(cls, "rb_io_binmode", io_spec_rb_io_binmode, 1); rb_define_method(cls, "rb_fd_fix_cloexec", io_spec_rb_fd_fix_cloexec, 1); @@ -262,6 +262,21 @@ describe "C-API IO function" do end end platform_is_not :windows do describe "rb_io_wait_readable" do it "returns false if there is no error condition" do @@ -65,40 +65,40 @@ describe :kernel_Rational, shared: true do r_s.should == r r_s.should_not == f_r end - describe "when passed a Numeric" do - it "calls #to_r to convert the first argument to a Rational" do - num = RationalSpecs::SubNumeric.new(2) - Rational(num).should == Rational(2) - end end - describe "when passed a Complex" do - it "returns a Rational from the real part if the imaginary part is 0" do - Rational(Complex(1, 0)).should == Rational(1) - end - - it "raises a RangeError if the imaginary part is not 0" do - -> { Rational(Complex(1, 2)) }.should raise_error(RangeError) - end end - it "raises a TypeError if the first argument is nil" do - -> { Rational(nil) }.should raise_error(TypeError) end - it "raises a TypeError if the second argument is nil" do - -> { Rational(1, nil) }.should raise_error(TypeError) - end - it "raises a TypeError if the first argument is a Symbol" do - -> { Rational(:sym) }.should raise_error(TypeError) - end - it "raises a TypeError if the second argument is a Symbol" do - -> { Rational(1, :sym) }.should raise_error(TypeError) - end end describe "when passed exception: false" do |