re2 0.7.0 → 1.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/spec/kernel_spec.rb CHANGED
@@ -1,15 +1,13 @@
1
- require "spec_helper"
2
-
3
- describe Kernel do
1
+ RSpec.describe Kernel do
4
2
  describe "#RE2" do
5
3
  it "returns an RE2::Regexp instance given a pattern" do
6
- RE2('w(o)(o)').must_be_instance_of(RE2::Regexp)
4
+ expect(RE2('w(o)(o)')).to be_a(RE2::Regexp)
7
5
  end
8
6
 
9
7
  it "returns an RE2::Regexp instance given a pattern and options" do
10
8
  re = RE2('w(o)(o)', :case_sensitive => false)
11
- re.must_be_instance_of(RE2::Regexp)
12
- re.wont_be(:case_sensitive?)
9
+ expect(re).to be_a(RE2::Regexp)
10
+ expect(re).to_not be_case_sensitive
13
11
  end
14
12
  end
15
13
  end
@@ -1,94 +1,90 @@
1
1
  # encoding: utf-8
2
-
3
- require "spec_helper"
4
-
5
- describe RE2::MatchData do
6
-
2
+ RSpec.describe RE2::MatchData do
7
3
  describe "#to_a" do
8
4
  it "is populated with the match and capturing groups" do
9
5
  a = RE2::Regexp.new('w(o)(o)').match('woo').to_a
10
- a.must_equal(["woo", "o", "o"])
6
+ expect(a).to eq(["woo", "o", "o"])
11
7
  end
12
8
 
13
9
  it "populates optional capturing groups with nil if they are missing" do
14
10
  a = RE2::Regexp.new('(\d?)(a)(b)').match('ab').to_a
15
- a.must_equal(["ab", nil, "a", "b"])
11
+ expect(a).to eq(["ab", nil, "a", "b"])
16
12
  end
17
13
  end
18
14
 
19
15
  describe "#[]" do
20
16
  it "accesses capturing groups by numerical index" do
21
17
  md = RE2::Regexp.new('(\d)(\d{2})').match("123")
22
- md[1].must_equal("1")
23
- md[2].must_equal("23")
18
+ expect(md[1]).to eq("1")
19
+ expect(md[2]).to eq("23")
24
20
  end
25
21
 
26
22
  it "has the whole match as the 0th item" do
27
23
  md = RE2::Regexp.new('(\d)(\d{2})').match("123")
28
- md[0].must_equal("123")
24
+ expect(md[0]).to eq("123")
29
25
  end
30
26
 
31
27
  it "supports access by numerical ranges" do
32
28
  md = RE2::Regexp.new('(\d+) (\d+) (\d+)').match("123 456 789")
33
- md[1..3].must_equal(["123", "456", "789"])
34
- md[1...3].must_equal(["123", "456"])
29
+ expect(md[1..3]).to eq(["123", "456", "789"])
30
+ expect(md[1...3]).to eq(["123", "456"])
35
31
  end
36
32
 
37
33
  it "supports slicing" do
38
34
  md = RE2::Regexp.new('(\d+) (\d+) (\d+)').match("123 456 789")
39
- md[1, 3].must_equal(["123", "456", "789"])
40
- md[1, 2].must_equal(["123", "456"])
35
+ expect(md[1, 3]).to eq(["123", "456", "789"])
36
+ expect(md[1, 2]).to eq(["123", "456"])
41
37
  end
42
38
 
43
39
  it "returns nil if attempting to access non-existent capturing groups by index" do
44
40
  md = RE2::Regexp.new('(\d+)').match('bob 123')
45
- md[2].must_be_nil
46
- md[3].must_be_nil
41
+ expect(md[2]).to be_nil
42
+ expect(md[3]).to be_nil
47
43
  end
48
44
 
49
45
  it "allows access by string names when there are named groups" do
50
46
  md = RE2::Regexp.new('(?P<numbers>\d+)').match('bob 123')
51
- md["numbers"].must_equal("123")
47
+ expect(md["numbers"]).to eq("123")
52
48
  end
53
49
 
54
50
  it "allows access by symbol names when there are named groups" do
55
51
  md = RE2::Regexp.new('(?P<numbers>\d+)').match('bob 123')
56
- md[:numbers].must_equal("123")
52
+ expect(md[:numbers]).to eq("123")
57
53
  end
58
54
 
59
55
  it "allows access by names and indices with mixed groups" do
60
56
  md = RE2::Regexp.new('(?P<name>\w+)(\s*)(?P<numbers>\d+)').match("bob 123")
61
- md["name"].must_equal("bob")
62
- md[:name].must_equal("bob")
63
- md[2].must_equal(" ")
64
- md["numbers"].must_equal("123")
65
- md[:numbers].must_equal("123")
57
+ expect(md["name"]).to eq("bob")
58
+ expect(md[:name]).to eq("bob")
59
+ expect(md[2]).to eq(" ")
60
+ expect(md["numbers"]).to eq("123")
61
+ expect(md[:numbers]).to eq("123")
66
62
  end
67
63
 
68
64
  it "returns nil if no such named group exists" do
69
65
  md = RE2::Regexp.new('(\d+)').match("bob 123")
70
- md["missing"].must_be_nil
71
- md[:missing].must_be_nil
66
+ expect(md["missing"]).to be_nil
67
+ expect(md[:missing]).to be_nil
72
68
  end
73
69
 
74
70
  it "raises an error if given an inappropriate index" do
75
71
  md = RE2::Regexp.new('(\d+)').match("bob 123")
76
- lambda { md[nil] }.must_raise(TypeError)
72
+ expect { md[nil] }.to raise_error(TypeError)
77
73
  end
78
74
 
79
75
  if String.method_defined?(:encoding)
80
76
  it "returns UTF-8 encoded strings by default" do
81
77
  md = RE2::Regexp.new('(?P<name>\S+)').match("bob")
82
- md[0].encoding.name.must_equal("UTF-8")
83
- md["name"].encoding.name.must_equal("UTF-8")
84
- md[:name].encoding.name.must_equal("UTF-8")
78
+ expect(md[0].encoding.name).to eq("UTF-8")
79
+ expect(md["name"].encoding.name).to eq("UTF-8")
80
+ expect(md[:name].encoding.name).to eq("UTF-8")
85
81
  end
86
82
 
87
83
  it "returns Latin 1 strings encoding when utf-8 is false" do
88
84
  md = RE2::Regexp.new('(?P<name>\S+)', :utf8 => false).match('bob')
89
- md[0].encoding.name.must_equal("ISO-8859-1")
90
- md["name"].encoding.name.must_equal("ISO-8859-1")
91
- md[:name].encoding.name.must_equal("ISO-8859-1")
85
+ expect(md[0].encoding.name).to eq("ISO-8859-1")
86
+ expect(md["name"].encoding.name).to eq("ISO-8859-1")
87
+ expect(md[:name].encoding.name).to eq("ISO-8859-1")
92
88
  end
93
89
  end
94
90
  end
@@ -96,32 +92,32 @@ describe RE2::MatchData do
96
92
  describe "#string" do
97
93
  it "returns the original string to match against" do
98
94
  re = RE2::Regexp.new('(\D+)').match("bob")
99
- re.string.must_equal("bob")
95
+ expect(re.string).to eq("bob")
100
96
  end
101
97
 
102
98
  it "returns a copy, not the actual original" do
103
99
  string = "bob"
104
100
  re = RE2::Regexp.new('(\D+)').match(string)
105
- re.string.wont_be_same_as(string)
101
+ expect(re.string).to_not equal(string)
106
102
  end
107
103
 
108
104
  it "returns a frozen string" do
109
105
  re = RE2::Regexp.new('(\D+)').match("bob")
110
- re.string.must_be(:frozen?)
106
+ expect(re.string).to be_frozen
111
107
  end
112
108
  end
113
109
 
114
110
  describe "#size" do
115
111
  it "returns the number of capturing groups plus the matching string" do
116
112
  md = RE2::Regexp.new('(\d+) (\d+)').match("1234 56")
117
- md.size.must_equal(3)
113
+ expect(md.size).to eq(3)
118
114
  end
119
115
  end
120
116
 
121
117
  describe "#length" do
122
118
  it "returns the number of capturing groups plus the matching string" do
123
119
  md = RE2::Regexp.new('(\d+) (\d+)').match("1234 56")
124
- md.length.must_equal(3)
120
+ expect(md.length).to eq(3)
125
121
  end
126
122
  end
127
123
 
@@ -129,26 +125,26 @@ describe RE2::MatchData do
129
125
  it "returns the original RE2::Regexp used" do
130
126
  re = RE2::Regexp.new('(\d+)')
131
127
  md = re.match("123")
132
- md.regexp.must_be_same_as(re)
128
+ expect(md.regexp).to equal(re)
133
129
  end
134
130
  end
135
131
 
136
132
  describe "#inspect" do
137
133
  it "returns a text representation of the object and indices" do
138
134
  md = RE2::Regexp.new('(\d+) (\d+)').match("1234 56")
139
- md.inspect.must_equal('#<RE2::MatchData "1234 56" 1:"1234" 2:"56">')
135
+ expect(md.inspect).to eq('#<RE2::MatchData "1234 56" 1:"1234" 2:"56">')
140
136
  end
141
137
 
142
138
  it "represents missing matches as nil" do
143
139
  md = RE2::Regexp.new('(\d+) (\d+)?').match("1234 ")
144
- md.inspect.must_equal('#<RE2::MatchData "1234 " 1:"1234" 2:nil>')
140
+ expect(md.inspect).to eq('#<RE2::MatchData "1234 " 1:"1234" 2:nil>')
145
141
  end
146
142
  end
147
143
 
148
144
  describe "#to_s" do
149
145
  it "returns the matching part of the original string" do
150
146
  md = RE2::Regexp.new('(\d{2,5})').match("one two 23456")
151
- md.to_s.must_equal("23456")
147
+ expect(md.to_s).to eq("23456")
152
148
  end
153
149
  end
154
150
 
@@ -156,53 +152,93 @@ describe RE2::MatchData do
156
152
  it "allows the object to be expanded with an asterisk" do
157
153
  md = RE2::Regexp.new('(\d+) (\d+)').match("1234 56")
158
154
  m1, m2, m3 = *md
159
- m1.must_equal("1234 56")
160
- m2.must_equal("1234")
161
- m3.must_equal("56")
155
+ expect(m1).to eq("1234 56")
156
+ expect(m2).to eq("1234")
157
+ expect(m3).to eq("56")
162
158
  end
163
159
  end
164
160
 
165
161
  describe "#begin" do
166
162
  it "returns the offset of the start of a match by index" do
167
163
  md = RE2::Regexp.new('(wo{2})').match('a woohoo')
168
- md.string[md.begin(0)..-1].must_equal('woohoo')
164
+ expect(md.string[md.begin(0)..-1]).to eq('woohoo')
169
165
  end
170
166
 
171
167
  it "returns the offset of the start of a match by string name" do
172
168
  md = RE2::Regexp.new('(?P<foo>fo{2})').match('a foobar')
173
- md.string[md.begin('foo')..-1].must_equal('foobar')
169
+ expect(md.string[md.begin('foo')..-1]).to eq('foobar')
174
170
  end
175
171
 
176
172
  it "returns the offset of the start of a match by symbol name" do
177
173
  md = RE2::Regexp.new('(?P<foo>fo{2})').match('a foobar')
178
- md.string[md.begin(:foo)..-1].must_equal('foobar')
174
+ expect(md.string[md.begin(:foo)..-1]).to eq('foobar')
179
175
  end
180
176
 
181
177
  it "returns the offset despite multibyte characters" do
182
178
  md = RE2::Regexp.new('(Ruby)').match('I ♥ Ruby')
183
- md.string[md.begin(0)..-1].must_equal('Ruby')
179
+ expect(md.string[md.begin(0)..-1]).to eq('Ruby')
180
+ end
181
+
182
+ it "returns nil for non-existent numerical matches" do
183
+ md = RE2::Regexp.new('(\d)').match('123')
184
+ expect(md.begin(10)).to be_nil
185
+ end
186
+
187
+ it "returns nil for negative numerical matches" do
188
+ md = RE2::Regexp.new('(\d)').match('123')
189
+ expect(md.begin(-4)).to be_nil
190
+ end
191
+
192
+ it "returns nil for non-existent named matches" do
193
+ md = RE2::Regexp.new('(\d)').match('123')
194
+ expect(md.begin('foo')).to be_nil
195
+ end
196
+
197
+ it "returns nil for non-existent symbol named matches" do
198
+ md = RE2::Regexp.new('(\d)').match('123')
199
+ expect(md.begin(:foo)).to be_nil
184
200
  end
185
201
  end
186
202
 
187
203
  describe "#end" do
188
204
  it "returns the offset of the character following the end of a match" do
189
205
  md = RE2::Regexp.new('(wo{2})').match('a woohoo')
190
- md.string[0...md.end(0)].must_equal('a woo')
206
+ expect(md.string[0...md.end(0)]).to eq('a woo')
191
207
  end
192
208
 
193
209
  it "returns the offset of a match by string name" do
194
210
  md = RE2::Regexp.new('(?P<foo>fo{2})').match('a foobar')
195
- md.string[0...md.end('foo')].must_equal('a foo')
211
+ expect(md.string[0...md.end('foo')]).to eq('a foo')
196
212
  end
197
213
 
198
214
  it "returns the offset of a match by symbol name" do
199
215
  md = RE2::Regexp.new('(?P<foo>fo{2})').match('a foobar')
200
- md.string[0...md.end(:foo)].must_equal('a foo')
216
+ expect(md.string[0...md.end(:foo)]).to eq('a foo')
201
217
  end
202
218
 
203
219
  it "returns the offset despite multibyte characters" do
204
220
  md = RE2::Regexp.new('(Ruby)').match('I ♥ Ruby')
205
- md.string[0...md.end(0)].must_equal('I ♥ Ruby')
221
+ expect(md.string[0...md.end(0)]).to eq('I ♥ Ruby')
222
+ end
223
+
224
+ it "returns nil for non-existent numerical matches" do
225
+ md = RE2::Regexp.new('(\d)').match('123')
226
+ expect(md.end(10)).to be_nil
227
+ end
228
+
229
+ it "returns nil for negative numerical matches" do
230
+ md = RE2::Regexp.new('(\d)').match('123')
231
+ expect(md.end(-4)).to be_nil
232
+ end
233
+
234
+ it "returns nil for non-existent named matches" do
235
+ md = RE2::Regexp.new('(\d)').match('123')
236
+ expect(md.end('foo')).to be_nil
237
+ end
238
+
239
+ it "returns nil for non-existent symbol named matches" do
240
+ md = RE2::Regexp.new('(\d)').match('123')
241
+ expect(md.end(:foo)).to be_nil
206
242
  end
207
243
  end
208
244
  end
@@ -1,253 +1,251 @@
1
- require "spec_helper"
2
-
3
- describe RE2::Regexp do
1
+ RSpec.describe RE2::Regexp do
4
2
  describe "#initialize" do
5
3
  it "returns an instance given only a pattern" do
6
4
  re = RE2::Regexp.new('woo')
7
- re.must_be_instance_of(RE2::Regexp)
5
+ expect(re).to be_a(RE2::Regexp)
8
6
  end
9
7
 
10
8
  it "returns an instance given a pattern and options" do
11
9
  re = RE2::Regexp.new('woo', :case_sensitive => false)
12
- re.must_be_instance_of(RE2::Regexp)
10
+ expect(re).to be_a(RE2::Regexp)
13
11
  end
14
12
 
15
13
  it "raises an error if given an inappropriate type" do
16
- lambda { RE2::Regexp.new(nil) }.must_raise(TypeError)
14
+ expect { RE2::Regexp.new(nil) }.to raise_error(TypeError)
17
15
  end
18
16
  end
19
17
 
20
18
  describe "#compile" do
21
19
  it "returns an instance given only a pattern" do
22
20
  re = RE2::Regexp.compile('woo')
23
- re.must_be_instance_of(RE2::Regexp)
21
+ expect(re).to be_a(RE2::Regexp)
24
22
  end
25
23
 
26
24
  it "returns an instance given a pattern and options" do
27
25
  re = RE2::Regexp.compile('woo', :case_sensitive => false)
28
- re.must_be_instance_of(RE2::Regexp)
26
+ expect(re).to be_a(RE2::Regexp)
29
27
  end
30
28
  end
31
29
 
32
30
  describe "#options" do
33
31
  it "returns a hash of options" do
34
32
  options = RE2::Regexp.new('woo').options
35
- options.must_be_instance_of(Hash)
33
+ expect(options).to be_a(Hash)
36
34
  end
37
35
 
38
36
  it "is populated with default options when nothing has been set" do
39
37
  options = RE2::Regexp.new('woo').options
40
- assert options[:utf8]
41
- refute options[:posix_syntax]
42
- refute options[:longest_match]
43
- assert [:log_errors]
44
- refute options[:literal]
45
- refute options[:never_nl]
46
- assert options[:case_sensitive]
47
- refute options[:perl_classes]
48
- refute options[:word_boundary]
49
- refute options[:one_line]
38
+ expect(options).to include(:utf8 => true,
39
+ :posix_syntax => false,
40
+ :longest_match => false,
41
+ :log_errors => true,
42
+ :literal => false,
43
+ :never_nl => false,
44
+ :case_sensitive => true,
45
+ :perl_classes => false,
46
+ :word_boundary => false,
47
+ :one_line => false)
50
48
  end
51
49
 
52
50
  it "is populated with overridden options when specified" do
53
51
  options = RE2::Regexp.new('woo', :case_sensitive => false).options
54
- refute options[:case_sensitive]
52
+ expect(options[:case_sensitive]).to eq(false)
55
53
  end
56
54
  end
57
55
 
58
56
  describe "#error" do
59
57
  it "returns nil if there is no error" do
60
58
  error = RE2::Regexp.new('woo').error
61
- error.must_be_nil
59
+ expect(error).to be_nil
62
60
  end
63
61
 
64
62
  # Use log_errors => false to suppress RE2's logging to STDERR.
65
63
  it "contains the error string if there is an error" do
66
64
  error = RE2::Regexp.new('wo(o', :log_errors => false).error
67
- error.must_equal("missing ): wo(o")
65
+ expect(error).to eq("missing ): wo(o")
68
66
  end
69
67
  end
70
68
 
71
69
  describe "#error_arg" do
72
70
  it "returns nil if there is no error" do
73
71
  error_arg = RE2::Regexp.new('woo').error_arg
74
- error_arg.must_be_nil
72
+ expect(error_arg).to be_nil
75
73
  end
76
74
 
77
75
  it "returns the offending portin of the regexp if there is an error" do
78
76
  error_arg = RE2::Regexp.new('wo(o', :log_errors => false).error_arg
79
- error_arg.must_equal("wo(o")
77
+ expect(error_arg).to eq("wo(o")
80
78
  end
81
79
  end
82
80
 
83
81
  describe "#program_size" do
84
82
  it "returns a numeric value" do
85
83
  program_size = RE2::Regexp.new('w(o)(o)').program_size
86
- program_size.must_be_instance_of(Fixnum)
84
+ expect(program_size).to be_a(Fixnum)
87
85
  end
88
86
  end
89
87
 
90
88
  describe "#to_str" do
91
89
  it "returns the original pattern" do
92
90
  string = RE2::Regexp.new('w(o)(o)').to_str
93
- string.must_equal("w(o)(o)")
91
+ expect(string).to eq("w(o)(o)")
94
92
  end
95
93
  end
96
94
 
97
95
  describe "#pattern" do
98
96
  it "returns the original pattern" do
99
97
  pattern = RE2::Regexp.new('w(o)(o)').pattern
100
- pattern.must_equal("w(o)(o)")
98
+ expect(pattern).to eq("w(o)(o)")
101
99
  end
102
100
  end
103
101
 
104
102
  describe "#inspect" do
105
103
  it "shows the class name and original pattern" do
106
104
  string = RE2::Regexp.new('w(o)(o)').inspect
107
- string.must_equal("#<RE2::Regexp /w(o)(o)/>")
105
+ expect(string).to eq("#<RE2::Regexp /w(o)(o)/>")
108
106
  end
109
107
  end
110
108
 
111
109
  describe "#utf8?" do
112
110
  it "returns true by default" do
113
- RE2::Regexp.new('woo').must_be(:utf8?)
111
+ expect(RE2::Regexp.new('woo')).to be_utf8
114
112
  end
115
113
 
116
114
  it "can be overridden on initialization" do
117
115
  re = RE2::Regexp.new('woo', :utf8 => false)
118
- re.wont_be(:utf8?)
116
+ expect(re).to_not be_utf8
119
117
  end
120
118
  end
121
119
 
122
120
  describe "#posix_syntax?" do
123
121
  it "returns false by default" do
124
- RE2::Regexp.new('woo').wont_be(:posix_syntax?)
122
+ expect(RE2::Regexp.new('woo')).to_not be_posix_syntax
125
123
  end
126
124
 
127
125
  it "can be overridden on initialization" do
128
126
  re = RE2::Regexp.new('woo', :posix_syntax => true)
129
- re.must_be(:posix_syntax?)
127
+ expect(re).to be_posix_syntax
130
128
  end
131
129
  end
132
130
 
133
131
  describe "#literal?" do
134
132
  it "returns false by default" do
135
- RE2::Regexp.new('woo').wont_be(:literal?)
133
+ expect(RE2::Regexp.new('woo')).to_not be_literal
136
134
  end
137
135
 
138
136
  it "can be overridden on initialization" do
139
137
  re = RE2::Regexp.new('woo', :literal => true)
140
- re.must_be(:literal?)
138
+ expect(re).to be_literal
141
139
  end
142
140
  end
143
141
 
144
142
  describe "#never_nl?" do
145
143
  it "returns false by default" do
146
- RE2::Regexp.new('woo').wont_be(:never_nl?)
144
+ expect(RE2::Regexp.new('woo')).to_not be_never_nl
147
145
  end
148
146
 
149
147
  it "can be overridden on initialization" do
150
148
  re = RE2::Regexp.new('woo', :never_nl => true)
151
- re.must_be(:never_nl?)
149
+ expect(re).to be_never_nl
152
150
  end
153
151
  end
154
152
 
155
153
  describe "#case_sensitive?" do
156
154
  it "returns true by default" do
157
- RE2::Regexp.new('woo').must_be(:case_sensitive?)
155
+ expect(RE2::Regexp.new('woo')).to be_case_sensitive
158
156
  end
159
157
 
160
158
  it "can be overridden on initialization" do
161
159
  re = RE2::Regexp.new('woo', :case_sensitive => false)
162
- re.wont_be(:case_sensitive?)
160
+ expect(re).to_not be_case_sensitive
163
161
  end
164
162
  end
165
163
 
166
164
  describe "#case_insensitive?" do
167
165
  it "returns false by default" do
168
- RE2::Regexp.new('woo').wont_be(:case_insensitive?)
166
+ expect(RE2::Regexp.new('woo')).to_not be_case_insensitive
169
167
  end
170
168
 
171
169
  it "can be overridden on initialization" do
172
170
  re = RE2::Regexp.new('woo', :case_sensitive => false)
173
- re.must_be(:case_insensitive?)
171
+ expect(re).to be_case_insensitive
174
172
  end
175
173
  end
176
174
 
177
175
  describe "#casefold?" do
178
176
  it "returns true by default" do
179
- RE2::Regexp.new('woo').wont_be(:casefold?)
177
+ expect(RE2::Regexp.new('woo')).to_not be_casefold
180
178
  end
181
179
 
182
180
  it "can be overridden on initialization" do
183
181
  re = RE2::Regexp.new('woo', :case_sensitive => false)
184
- re.must_be(:casefold?)
182
+ expect(re).to be_casefold
185
183
  end
186
184
  end
187
185
 
188
186
  describe "#longest_match?" do
189
187
  it "returns false by default" do
190
- RE2::Regexp.new('woo').wont_be(:casefold?)
188
+ expect(RE2::Regexp.new('woo')).to_not be_casefold
191
189
  end
192
190
 
193
191
  it "can be overridden on initialization" do
194
192
  re = RE2::Regexp.new('woo', :longest_match => true)
195
- re.must_be(:longest_match?)
193
+ expect(re).to be_longest_match
196
194
  end
197
195
  end
198
196
 
199
197
  describe "#log_errors?" do
200
198
  it "returns true by default" do
201
- RE2::Regexp.new('woo').must_be(:log_errors?)
199
+ expect(RE2::Regexp.new('woo')).to be_log_errors
202
200
  end
203
201
 
204
202
  it "can be overridden on initialization" do
205
203
  re = RE2::Regexp.new('woo', :log_errors => false)
206
- re.wont_be(:log_errors?)
204
+ expect(re).to_not be_log_errors
207
205
  end
208
206
  end
209
207
 
210
208
  describe "#perl_classes?" do
211
209
  it "returns false by default" do
212
- RE2::Regexp.new('woo').wont_be(:perl_classes?)
210
+ expect(RE2::Regexp.new('woo')).to_not be_perl_classes
213
211
  end
214
212
 
215
213
  it "can be overridden on initialization" do
216
214
  re = RE2::Regexp.new('woo', :perl_classes => true)
217
- re.must_be(:perl_classes?)
215
+ expect(re).to be_perl_classes
218
216
  end
219
217
  end
220
218
 
221
219
  describe "#word_boundary?" do
222
220
  it "returns false by default" do
223
- RE2::Regexp.new('woo').wont_be(:word_boundary?)
221
+ expect(RE2::Regexp.new('woo')).to_not be_word_boundary
224
222
  end
225
223
 
226
224
  it "can be overridden on initialization" do
227
225
  re = RE2::Regexp.new('woo', :word_boundary => true)
228
- re.must_be(:word_boundary?)
226
+ expect(re).to be_word_boundary
229
227
  end
230
228
  end
231
229
 
232
230
  describe "#one_line?" do
233
231
  it "returns false by default" do
234
- RE2::Regexp.new('woo').wont_be(:one_line?)
232
+ expect(RE2::Regexp.new('woo')).to_not be_one_line
235
233
  end
236
234
 
237
235
  it "can be overridden on initialization" do
238
236
  re = RE2::Regexp.new('woo', :one_line => true)
239
- re.must_be(:one_line?)
237
+ expect(re).to be_one_line
240
238
  end
241
239
  end
242
240
 
243
241
  describe "#max_mem" do
244
242
  it "returns the default max memory" do
245
- RE2::Regexp.new('woo').max_mem.must_equal(8388608)
243
+ expect(RE2::Regexp.new('woo').max_mem).to eq(8388608)
246
244
  end
247
245
 
248
246
  it "can be overridden on initialization" do
249
247
  re = RE2::Regexp.new('woo', :max_mem => 1024)
250
- re.max_mem.must_equal(1024)
248
+ expect(re.max_mem).to eq(1024)
251
249
  end
252
250
  end
253
251
 
@@ -256,43 +254,43 @@ describe RE2::Regexp do
256
254
 
257
255
  it "returns match data given only text" do
258
256
  md = re.match("My name is Robert Paulson")
259
- md.must_be_instance_of(RE2::MatchData)
257
+ expect(md).to be_a(RE2::MatchData)
260
258
  end
261
259
 
262
260
  it "returns nil if there is no match for the given text" do
263
- re.match("My age is 99").must_be_nil
261
+ expect(re.match("My age is 99")).to be_nil
264
262
  end
265
263
 
266
264
  it "returns only true or false if no matches are requested" do
267
- re.match("My name is Robert Paulson", 0).must_equal(true)
268
- re.match("My age is 99", 0).must_equal(false)
265
+ expect(re.match("My name is Robert Paulson", 0)).to eq(true)
266
+ expect(re.match("My age is 99", 0)).to eq(false)
269
267
  end
270
268
 
271
269
  it "raises an exception when given nil" do
272
- lambda { re.match(nil) }.must_raise(TypeError)
270
+ expect { re.match(nil) }.to raise_error(TypeError)
273
271
  end
274
272
 
275
273
  it "raises an exception when given an inappropriate number of matches" do
276
- lambda { re.match("My name is Robert Paulson", {}) }.must_raise(TypeError)
274
+ expect { re.match("My name is Robert Paulson", {}) }.to raise_error(TypeError)
277
275
  end
278
276
 
279
277
  describe "with a specific number of matches under the total in the pattern" do
280
278
  subject { re.match("My name is Robert Paulson", 1) }
281
279
 
282
280
  it "returns a match data object" do
283
- subject.must_be_instance_of(RE2::MatchData)
281
+ expect(subject).to be_a(RE2::MatchData)
284
282
  end
285
283
 
286
284
  it "has the whole match and only the specified number of matches" do
287
- subject.size.must_equal(2)
285
+ expect(subject.size).to eq(2)
288
286
  end
289
287
 
290
288
  it "populates any specified matches" do
291
- subject[1].must_equal("Robert")
289
+ expect(subject[1]).to eq("Robert")
292
290
  end
293
291
 
294
292
  it "does not populate any matches that weren't included" do
295
- subject[2].must_be_nil
293
+ expect(subject[2]).to be_nil
296
294
  end
297
295
  end
298
296
 
@@ -300,23 +298,23 @@ describe RE2::Regexp do
300
298
  subject { re.match("My name is Robert Paulson", 5) }
301
299
 
302
300
  it "returns a match data object" do
303
- subject.must_be_instance_of(RE2::MatchData)
301
+ expect(subject).to be_a(RE2::MatchData)
304
302
  end
305
303
 
306
304
  it "has the whole match the specified number of matches" do
307
- subject.size.must_equal(6)
305
+ expect(subject.size).to eq(6)
308
306
  end
309
307
 
310
308
  it "populates any specified matches" do
311
- subject[1].must_equal("Robert")
312
- subject[2].must_equal("Paulson")
309
+ expect(subject[1]).to eq("Robert")
310
+ expect(subject[2]).to eq("Paulson")
313
311
  end
314
312
 
315
313
  it "pads the remaining matches with nil" do
316
- subject[3].must_be_nil
317
- subject[4].must_be_nil
318
- subject[5].must_be_nil
319
- subject[6].must_be_nil
314
+ expect(subject[3]).to be_nil
315
+ expect(subject[4]).to be_nil
316
+ expect(subject[5]).to be_nil
317
+ expect(subject[6]).to be_nil
320
318
  end
321
319
  end
322
320
  end
@@ -324,83 +322,83 @@ describe RE2::Regexp do
324
322
  describe "#match?" do
325
323
  it "returns only true or false if no matches are requested" do
326
324
  re = RE2::Regexp.new('My name is (\S+) (\S+)')
327
- re.match?("My name is Robert Paulson").must_equal(true)
328
- re.match?("My age is 99").must_equal(false)
325
+ expect(re.match?("My name is Robert Paulson")).to eq(true)
326
+ expect(re.match?("My age is 99")).to eq(false)
329
327
  end
330
328
  end
331
329
 
332
330
  describe "#=~" do
333
331
  it "returns only true or false if no matches are requested" do
334
332
  re = RE2::Regexp.new('My name is (\S+) (\S+)')
335
- (re =~ "My name is Robert Paulson").must_equal(true)
336
- (re =~ "My age is 99").must_equal(false)
333
+ expect(re =~ "My name is Robert Paulson").to eq(true)
334
+ expect(re =~ "My age is 99").to eq(false)
337
335
  end
338
336
  end
339
337
 
340
338
  describe "#!~" do
341
339
  it "returns only true or false if no matches are requested" do
342
340
  re = RE2::Regexp.new('My name is (\S+) (\S+)')
343
- (re !~ "My name is Robert Paulson").must_equal(false)
344
- (re !~ "My age is 99").must_equal(true)
341
+ expect(re !~ "My name is Robert Paulson").to eq(false)
342
+ expect(re !~ "My age is 99").to eq(true)
345
343
  end
346
344
  end
347
345
 
348
346
  describe "#===" do
349
347
  it "returns only true or false if no matches are requested" do
350
348
  re = RE2::Regexp.new('My name is (\S+) (\S+)')
351
- (re === "My name is Robert Paulson").must_equal(true)
352
- (re === "My age is 99").must_equal(false)
349
+ expect(re === "My name is Robert Paulson").to eq(true)
350
+ expect(re === "My age is 99").to eq(false)
353
351
  end
354
352
  end
355
353
 
356
354
  describe "#ok?" do
357
355
  it "returns true for valid regexps" do
358
- RE2::Regexp.new('woo').must_be(:ok?)
359
- RE2::Regexp.new('wo(o)').must_be(:ok?)
360
- RE2::Regexp.new('((\d)\w+){3,}').must_be(:ok?)
356
+ expect(RE2::Regexp.new('woo')).to be_ok
357
+ expect(RE2::Regexp.new('wo(o)')).to be_ok
358
+ expect(RE2::Regexp.new('((\d)\w+){3,}')).to be_ok
361
359
  end
362
360
 
363
361
  it "returns false for invalid regexps" do
364
- RE2::Regexp.new('wo(o', :log_errors => false).wont_be(:ok?)
365
- RE2::Regexp.new('wo[o', :log_errors => false).wont_be(:ok?)
366
- RE2::Regexp.new('*', :log_errors => false).wont_be(:ok?)
362
+ expect(RE2::Regexp.new('wo(o', :log_errors => false)).to_not be_ok
363
+ expect(RE2::Regexp.new('wo[o', :log_errors => false)).to_not be_ok
364
+ expect(RE2::Regexp.new('*', :log_errors => false)).to_not be_ok
367
365
  end
368
366
  end
369
367
 
370
368
  describe "#escape" do
371
369
  it "transforms a string into a regexp" do
372
- RE2::Regexp.escape("1.5-2.0?").must_equal('1\.5\-2\.0\?')
370
+ expect(RE2::Regexp.escape("1.5-2.0?")).to eq('1\.5\-2\.0\?')
373
371
  end
374
372
  end
375
373
 
376
374
  describe "#quote" do
377
375
  it "transforms a string into a regexp" do
378
- RE2::Regexp.quote("1.5-2.0?").must_equal('1\.5\-2\.0\?')
376
+ expect(RE2::Regexp.quote("1.5-2.0?")).to eq('1\.5\-2\.0\?')
379
377
  end
380
378
  end
381
379
 
382
380
  describe "#number_of_capturing_groups" do
383
381
  it "returns the number of groups in a regexp" do
384
- RE2::Regexp.new('(a)(b)(c)').number_of_capturing_groups.must_equal(3)
385
- RE2::Regexp.new('abc').number_of_capturing_groups.must_equal(0)
386
- RE2::Regexp.new('a((b)c)').number_of_capturing_groups.must_equal(2)
382
+ expect(RE2::Regexp.new('(a)(b)(c)').number_of_capturing_groups).to eq(3)
383
+ expect(RE2::Regexp.new('abc').number_of_capturing_groups).to eq(0)
384
+ expect(RE2::Regexp.new('a((b)c)').number_of_capturing_groups).to eq(2)
387
385
  end
388
386
  end
389
387
 
390
388
  describe "#named_capturing_groups" do
391
389
  it "returns a hash of names to indices" do
392
- RE2::Regexp.new('(?P<bob>a)').named_capturing_groups.must_be_instance_of(Hash)
390
+ expect(RE2::Regexp.new('(?P<bob>a)').named_capturing_groups).to be_a(Hash)
393
391
  end
394
392
 
395
393
  it "maps names to indices with only one group" do
396
394
  groups = RE2::Regexp.new('(?P<bob>a)').named_capturing_groups
397
- groups["bob"].must_equal(1)
395
+ expect(groups["bob"]).to eq(1)
398
396
  end
399
397
 
400
398
  it "maps names to indices with several groups" do
401
399
  groups = RE2::Regexp.new('(?P<bob>a)(o)(?P<rob>e)').named_capturing_groups
402
- groups["bob"].must_equal(1)
403
- groups["rob"].must_equal(3)
400
+ expect(groups["bob"]).to eq(1)
401
+ expect(groups["rob"]).to eq(3)
404
402
  end
405
403
  end
406
404
 
@@ -409,7 +407,7 @@ describe RE2::Regexp do
409
407
  r = RE2::Regexp.new('(\w+)')
410
408
  scanner = r.scan("It is a truth universally acknowledged")
411
409
 
412
- scanner.must_be_instance_of(RE2::Scanner)
410
+ expect(scanner).to be_a(RE2::Scanner)
413
411
  end
414
412
  end
415
413
  end