From 8db4f25bf4327f169902afd9ea8f4b03b65656f0 Mon Sep 17 00:00:00 2001 From: Benoit Daloze Date: Mon, 28 Mar 2022 17:47:04 +0200 Subject: Update to ruby/spec@aaf998f --- spec/ruby/core/string/append_spec.rb | 5 +++++ spec/ruby/core/string/comparison_spec.rb | 4 ++++ spec/ruby/core/string/lstrip_spec.rb | 4 ++-- spec/ruby/core/string/rindex_spec.rb | 6 +++++- spec/ruby/core/string/shared/eql.rb | 4 ++++ spec/ruby/core/string/split_spec.rb | 7 +++++++ spec/ruby/core/string/strip_spec.rb | 4 ++-- 7 files changed, 29 insertions(+), 5 deletions(-) (limited to 'spec/ruby/core/string') diff --git a/spec/ruby/core/string/append_spec.rb b/spec/ruby/core/string/append_spec.rb index 1e1667f617..e001257621 100644 --- a/spec/ruby/core/string/append_spec.rb +++ b/spec/ruby/core/string/append_spec.rb @@ -5,4 +5,9 @@ require_relative 'shared/concat' describe "String#<<" do it_behaves_like :string_concat, :<< it_behaves_like :string_concat_encoding, :<< + + it "raises an ArgumentError when given the incorrect number of arguments" do + -> { "hello".send(:<<) }.should raise_error(ArgumentError) + -> { "hello".send(:<<, "one", "two") }.should raise_error(ArgumentError) + end end diff --git a/spec/ruby/core/string/comparison_spec.rb b/spec/ruby/core/string/comparison_spec.rb index 01199274b6..91cfdca25a 100644 --- a/spec/ruby/core/string/comparison_spec.rb +++ b/spec/ruby/core/string/comparison_spec.rb @@ -75,6 +75,10 @@ describe "String#<=> with String" do (xff_1 <=> xff_2).should == -1 (xff_2 <=> xff_1).should == 1 end + + it "returns 0 when comparing 2 empty strings but one is not ASCII-compatible" do + ("" <=> "".force_encoding('iso-2022-jp')).should == 0 + end end # Note: This is inconsistent with Array#<=> which calls #to_ary instead of diff --git a/spec/ruby/core/string/lstrip_spec.rb b/spec/ruby/core/string/lstrip_spec.rb index 20e4cdeabd..8b5dd1b467 100644 --- a/spec/ruby/core/string/lstrip_spec.rb +++ b/spec/ruby/core/string/lstrip_spec.rb @@ -12,7 +12,7 @@ describe "String#lstrip" do "hello".lstrip.should == "hello" end - ruby_version_is '3.1' do + ruby_version_is '3.0' do it "strips leading \\0" do "\x00hello".lstrip.should == "hello" "\000 \000hello\000 \000".lstrip.should == "hello\000 \000" @@ -35,7 +35,7 @@ describe "String#lstrip!" do a.should == "hello " end - ruby_version_is '3.1' do + ruby_version_is '3.0' do it "strips leading \\0" do a = "\000 \000hello\000 \000" a.lstrip! diff --git a/spec/ruby/core/string/rindex_spec.rb b/spec/ruby/core/string/rindex_spec.rb index 7a6af0c9d0..a3b437a1e4 100644 --- a/spec/ruby/core/string/rindex_spec.rb +++ b/spec/ruby/core/string/rindex_spec.rb @@ -4,13 +4,17 @@ require_relative 'fixtures/classes' require_relative 'fixtures/utf-8-encoding' describe "String#rindex with object" do - it "raises a TypeError if obj isn't a String, Integer or Regexp" do + it "raises a TypeError if obj isn't a String or Regexp" do not_supported_on :opal do -> { "hello".rindex(:sym) }.should raise_error(TypeError) end -> { "hello".rindex(mock('x')) }.should raise_error(TypeError) end + it "raises a TypeError if obj is an Integer" do + -> { "hello".rindex(42) }.should raise_error(TypeError) + end + it "doesn't try to convert obj to an integer via to_int" do obj = mock('x') obj.should_not_receive(:to_int) diff --git a/spec/ruby/core/string/shared/eql.rb b/spec/ruby/core/string/shared/eql.rb index b57d6895ff..6f268c929c 100644 --- a/spec/ruby/core/string/shared/eql.rb +++ b/spec/ruby/core/string/shared/eql.rb @@ -31,4 +31,8 @@ describe :string_eql_value, shared: true do a.send(@method, b).should be_true b.send(@method, a).should be_true end + + it "returns true when comparing 2 empty strings but one is not ASCII-compatible" do + "".send(@method, "".force_encoding('iso-2022-jp')).should == true + end end diff --git a/spec/ruby/core/string/split_spec.rb b/spec/ruby/core/string/split_spec.rb index 2e03955a26..2da71948b3 100644 --- a/spec/ruby/core/string/split_spec.rb +++ b/spec/ruby/core/string/split_spec.rb @@ -589,4 +589,11 @@ describe "String#split with Regexp" do end end end + + it "raises a TypeError when not called with nil, String, or Regexp" do + -> { "hello".split(42) }.should raise_error(TypeError) + -> { "hello".split(:ll) }.should raise_error(TypeError) + -> { "hello".split(false) }.should raise_error(TypeError) + -> { "hello".split(Object.new) }.should raise_error(TypeError) + end end diff --git a/spec/ruby/core/string/strip_spec.rb b/spec/ruby/core/string/strip_spec.rb index 8517bf2d2a..da06862d06 100644 --- a/spec/ruby/core/string/strip_spec.rb +++ b/spec/ruby/core/string/strip_spec.rb @@ -11,7 +11,7 @@ describe "String#strip" do "\tgoodbye\r\v\n".strip.should == "goodbye" end - ruby_version_is '3.1' do + ruby_version_is '3.0' do it "returns a copy of self without leading and trailing NULL bytes and whitespace" do " \x00 goodbye \x00 ".strip.should == "goodbye" end @@ -43,7 +43,7 @@ describe "String#strip!" do a.should == "hello" end - ruby_version_is '3.1' do + ruby_version_is '3.0' do it "removes leading and trailing NULL bytes and whitespace" do a = "\000 goodbye \000" a.strip! -- cgit v1.2.3