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 2021-11-29 15:50:28 +01:00
parent e6d93a27af
commit 67a1e22589
62 changed files with 656 additions and 59 deletions

View file

@ -1,7 +1,15 @@
require_relative '../../spec_helper'
require_relative 'fixtures/classes'
describe "MatchData#captures" do
it "returns an array of the match captures" do
/(.)(.)(\d+)(\d)/.match("THX1138.").captures.should == ["H","X","113","8"]
end
ruby_version_is "3.0" do
it "returns instances of String when given a String subclass" do
str = MatchDataSpecs::MyString.new("THX1138: The Movie")
/(.)(.)(\d+)(\d)/.match(str).captures.each { |c| c.should be_an_instance_of(String) }
end
end
end

View file

@ -1,4 +1,5 @@
require_relative '../../spec_helper'
require_relative 'fixtures/classes'
describe "MatchData#[]" do
it "acts as normal array indexing [index]" do
@ -20,6 +21,13 @@ describe "MatchData#[]" do
it "supports ranges [start..end]" do
/(.)(.)(\d+)(\d)/.match("THX1138.")[1..3].should == %w|H X 113|
end
ruby_version_is "3.0" do
it "returns instances of String when given a String subclass" do
str = MatchDataSpecs::MyString.new("THX1138.")
/(.)(.)(\d+)(\d)/.match(str)[0..-1].each { |m| m.should be_an_instance_of(String) }
end
end
end
describe "MatchData#[Symbol]" do

View file

@ -0,0 +1,3 @@
module MatchDataSpecs
class MyString < String; end
end

View file

@ -1,4 +1,5 @@
require_relative '../../spec_helper'
require_relative 'fixtures/classes'
describe "MatchData#post_match" do
it "returns the string after the match equiv. special var $'" do
@ -33,4 +34,11 @@ 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
ruby_version_is "3.0" do
it "returns an instance of String when given a String subclass" do
str = MatchDataSpecs::MyString.new("THX1138: The Movie")
/(.)(.)(\d+)(\d)/.match(str).post_match.should be_an_instance_of(String)
end
end
end

View file

@ -1,4 +1,5 @@
require_relative '../../spec_helper'
require_relative 'fixtures/classes'
describe "MatchData#pre_match" do
it "returns the string before the match, equiv. special var $`" do
@ -33,4 +34,11 @@ 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
ruby_version_is "3.0" do
it "returns an instance of String when given a String subclass" do
str = MatchDataSpecs::MyString.new("THX1138: The Movie")
/(.)(.)(\d+)(\d)/.match(str).pre_match.should be_an_instance_of(String)
end
end
end

View file

@ -1,7 +1,15 @@
require_relative '../../spec_helper'
require_relative 'fixtures/classes'
describe "MatchData#to_a" do
it "returns an array of matches" do
/(.)(.)(\d+)(\d)/.match("THX1138.").to_a.should == ["HX1138", "H", "X", "113", "8"]
end
ruby_version_is "3.0" do
it "returns instances of String when given a String subclass" do
str = MatchDataSpecs::MyString.new("THX1138.")
/(.)(.)(\d+)(\d)/.match(str)[0..-1].to_a.each { |m| m.should be_an_instance_of(String) }
end
end
end

View file

@ -1,7 +1,15 @@
require_relative '../../spec_helper'
require_relative 'fixtures/classes'
describe "MatchData#to_s" do
it "returns the entire matched string" do
/(.)(.)(\d+)(\d)/.match("THX1138.").to_s.should == "HX1138"
end
ruby_version_is "3.0" do
it "returns an instance of String when given a String subclass" do
str = MatchDataSpecs::MyString.new("THX1138.")
/(.)(.)(\d+)(\d)/.match(str).to_s.should be_an_instance_of(String)
end
end
end