File tree Expand file tree Collapse file tree 2 files changed +29
-1
lines changed Expand file tree Collapse file tree 2 files changed +29
-1
lines changed Original file line number Diff line number Diff line change 36
36
match_data = /(.)(.)(\d +)(\d )/ . match ( "THX1138." )
37
37
match_data . begin ( obj ) . should == 2
38
38
end
39
+
40
+ it "raises IndexError if index is out of matches" do
41
+ match_data = /(?<f>foo)(?<b>bar)/ . match ( "foobar" )
42
+
43
+ -> {
44
+ match_data . begin ( -1 )
45
+ } . should raise_error ( IndexError , "index -1 out of matches" )
46
+
47
+ -> {
48
+ match_data . begin ( 3 )
49
+ } . should raise_error ( IndexError , "index 3 out of matches" )
50
+ end
39
51
end
40
52
41
53
context "when passed a String argument" do
68
80
match_data = /(?<æ>.)(.)(?<b>\d +)(\d )/ . match ( "THX1138." )
69
81
match_data . begin ( "æ" ) . should == 1
70
82
end
83
+
84
+ it "raises IndexError if there is no group with the provided name" do
85
+ match_data = /(?<f>foo)(?<b>bar)/ . match ( "foobar" )
86
+
87
+ -> {
88
+ match_data . begin ( "y" )
89
+ } . should raise_error ( IndexError , "undefined group name reference: y" )
90
+ end
71
91
end
72
92
73
93
context "when passed a Symbol argument" do
100
120
match_data = /(?<æ>.)(.)(?<b>\d +)(\d )/ . match ( "THX1138." )
101
121
match_data . begin ( :æ ) . should == 1
102
122
end
123
+
124
+ it "raises IndexError if there is no group with the provided name" do
125
+ match_data = /(?<f>foo)(?<b>bar)/ . match ( "foobar" )
126
+
127
+ -> {
128
+ match_data . begin ( :y )
129
+ } . should raise_error ( IndexError , "undefined group name reference: y" )
130
+ end
103
131
end
104
132
end
Original file line number Diff line number Diff line change @@ -60,7 +60,7 @@ def obj.to_int; 2; end
60
60
m . byteoffset ( obj ) . should == [ 3 , 6 ]
61
61
end
62
62
63
- it "raises IndexError if there is no group with provided name" do
63
+ it "raises IndexError if there is no group with the provided name" do
64
64
m = /(?<f>foo)(?<b>bar)/ . match ( "foobar" )
65
65
66
66
-> {
You can’t perform that action at this time.
0 commit comments