diff options
Diffstat (limited to 'spec/ruby/core/matchdata/element_reference_spec.rb')
| -rw-r--r-- | spec/ruby/core/matchdata/element_reference_spec.rb | 13 |
1 files changed, 9 insertions, 4 deletions
diff --git a/spec/ruby/core/matchdata/element_reference_spec.rb b/spec/ruby/core/matchdata/element_reference_spec.rb index 1be399cfe1..5509371cd2 100644 --- a/spec/ruby/core/matchdata/element_reference_spec.rb +++ b/spec/ruby/core/matchdata/element_reference_spec.rb @@ -20,6 +20,11 @@ describe "MatchData#[]" do # negative index is larger than the number of match values /(.)(.)(\d+)(\d)/.match("THX1138.")[-30, 2].should == nil + # positive index larger than number of match values + /(.)(.)(\d+)(\d)/.match("THX1138.")[5, 2].should == [] + /(.)(.)(\d+)(\d)/.match("THX1138.")[6, 2].should == nil + /(.)(.)(\d+)(\d)/.match("THX1138.")[30, 2].should == nil + # length argument larger than number of match values is capped to match value length /(.)(.)(\d+)(\d)/.match("THX1138.")[3, 10].should == %w|113 8| @@ -50,7 +55,7 @@ describe "MatchData#[]" 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) } + /(.)(.)(\d+)(\d)/.match(str)[0..-1].each { |m| m.should.instance_of?(String) } end end @@ -103,17 +108,17 @@ describe "MatchData#[Symbol]" do it "raises an IndexError if there is no named match corresponding to the Symbol" do md = 'haystack'.match(/(?<t>t(?<a>ack))/) - -> { md[:baz] }.should raise_error(IndexError, /baz/) + -> { md[:baz] }.should.raise(IndexError, /baz/) end it "raises an IndexError if there is no named match corresponding to the String" do md = 'haystack'.match(/(?<t>t(?<a>ack))/) - -> { md['baz'] }.should raise_error(IndexError, /baz/) + -> { md['baz'] }.should.raise(IndexError, /baz/) end it "returns matches in the String's encoding" do rex = /(?<t>t(?<a>ack))/u - md = 'haystack'.force_encoding('euc-jp').match(rex) + md = 'haystack'.dup.force_encoding('euc-jp').match(rex) md[:t].encoding.should == Encoding::EUC_JP end end |
