re2 2.24.0-aarch64-linux-gnu → 2.25.0-aarch64-linux-gnu

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/re2_spec.rb CHANGED
@@ -1,34 +1,34 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  RSpec.describe RE2 do
4
- describe ".Replace" do
4
+ describe ".replace" do
5
5
  it "only replaces the first occurrence of the pattern" do
6
- expect(RE2.Replace("woo", "o", "a")).to eq("wao")
6
+ expect(RE2.replace("woo", "o", "a")).to eq("wao")
7
7
  end
8
8
 
9
9
  it "supports inputs with null bytes" do
10
- expect(RE2.Replace("w\0oo", "o", "a")).to eq("w\0ao")
10
+ expect(RE2.replace("w\0oo", "o", "a")).to eq("w\0ao")
11
11
  end
12
12
 
13
13
  it "supports patterns with null bytes" do
14
- expect(RE2.Replace("w\0oo", "\0", "o")).to eq("wooo")
14
+ expect(RE2.replace("w\0oo", "\0", "o")).to eq("wooo")
15
15
  end
16
16
 
17
17
  it "supports replacements with null bytes" do
18
- expect(RE2.Replace("woo", "o", "\0")).to eq("w\0o")
18
+ expect(RE2.replace("woo", "o", "\0")).to eq("w\0o")
19
19
  end
20
20
 
21
21
  it "performs replacement based on regular expressions" do
22
- expect(RE2.Replace("woo", "o+", "e")).to eq("we")
22
+ expect(RE2.replace("woo", "o+", "e")).to eq("we")
23
23
  end
24
24
 
25
25
  it "supports flags in patterns" do
26
- expect(RE2.Replace("Good morning", "(?i)gOOD MORNING", "hi")).to eq("hi")
26
+ expect(RE2.replace("Good morning", "(?i)gOOD MORNING", "hi")).to eq("hi")
27
27
  end
28
28
 
29
29
  it "does not perform replacements in-place", :aggregate_failures do
30
30
  name = "Robert"
31
- replacement = RE2.Replace(name, "R", "Cr")
31
+ replacement = RE2.replace(name, "R", "Cr")
32
32
 
33
33
  expect(name).to eq("Robert")
34
34
  expect(replacement).to eq("Crobert")
@@ -37,88 +37,94 @@ RSpec.describe RE2 do
37
37
  it "supports passing an RE2::Regexp as the pattern" do
38
38
  re = RE2::Regexp.new('wo{2}')
39
39
 
40
- expect(RE2.Replace("woo", re, "miaow")).to eq("miaow")
40
+ expect(RE2.replace("woo", re, "miaow")).to eq("miaow")
41
41
  end
42
42
 
43
43
  it "respects any passed RE2::Regexp's flags" do
44
44
  re = RE2::Regexp.new('gOOD MORNING', case_sensitive: false)
45
45
 
46
- expect(RE2.Replace("Good morning", re, "hi")).to eq("hi")
46
+ expect(RE2.replace("Good morning", re, "hi")).to eq("hi")
47
47
  end
48
48
 
49
49
  it "supports passing something that can be coerced to a String as input" do
50
- expect(RE2.Replace(StringLike.new("woo"), "oo", "ah")).to eq("wah")
50
+ expect(RE2.replace(StringLike.new("woo"), "oo", "ah")).to eq("wah")
51
51
  end
52
52
 
53
53
  it "supports passing something that can be coerced to a String as a pattern" do
54
- expect(RE2.Replace("woo", StringLike.new("oo"), "ah")).to eq("wah")
54
+ expect(RE2.replace("woo", StringLike.new("oo"), "ah")).to eq("wah")
55
55
  end
56
56
 
57
57
  it "supports passing something that can be coerced to a String as a replacement" do
58
- expect(RE2.Replace("woo", "oo", StringLike.new("ah"))).to eq("wah")
58
+ expect(RE2.replace("woo", "oo", StringLike.new("ah"))).to eq("wah")
59
59
  end
60
60
 
61
61
  it "returns UTF-8 strings if the pattern is UTF-8" do
62
62
  original = "Foo".encode("ISO-8859-1")
63
- replacement = RE2.Replace(original, "oo", "ah")
63
+ replacement = RE2.replace(original, "oo", "ah")
64
64
 
65
65
  expect(replacement.encoding).to eq(Encoding::UTF_8)
66
66
  end
67
67
 
68
68
  it "returns ISO-8859-1 strings if the pattern is not UTF-8" do
69
69
  original = "Foo"
70
- replacement = RE2.Replace(original, RE2("oo", utf8: false), "ah")
70
+ replacement = RE2.replace(original, RE2("oo", utf8: false), "ah")
71
71
 
72
72
  expect(replacement.encoding).to eq(Encoding::ISO_8859_1)
73
73
  end
74
74
 
75
75
  it "returns UTF-8 strings when given a String pattern" do
76
- replacement = RE2.Replace("Foo", "oo".encode("ISO-8859-1"), "ah")
76
+ replacement = RE2.replace("Foo", "oo".encode("ISO-8859-1"), "ah")
77
77
 
78
78
  expect(replacement.encoding).to eq(Encoding::UTF_8)
79
79
  end
80
80
 
81
81
  it "raises a Type Error for input that can't be converted to String" do
82
- expect { RE2.Replace(0, "oo", "ah") }.to raise_error(TypeError)
82
+ expect { RE2.replace(0, "oo", "ah") }.to raise_error(TypeError)
83
83
  end
84
84
 
85
85
  it "raises a Type Error for a non-RE2::Regexp pattern that can't be converted to String" do
86
- expect { RE2.Replace("woo", 0, "ah") }.to raise_error(TypeError)
86
+ expect { RE2.replace("woo", 0, "ah") }.to raise_error(TypeError)
87
87
  end
88
88
 
89
89
  it "raises a Type Error for a replacement that can't be converted to String" do
90
- expect { RE2.Replace("woo", "oo", 0) }.to raise_error(TypeError)
90
+ expect { RE2.replace("woo", "oo", 0) }.to raise_error(TypeError)
91
91
  end
92
92
  end
93
93
 
94
- describe ".GlobalReplace" do
94
+ describe ".Replace" do
95
+ it "is an alias for .replace" do
96
+ expect(RE2.Replace("woo", "o", "a")).to eq("wao")
97
+ end
98
+ end
99
+
100
+ describe ".global_replace" do
95
101
  it "replaces every occurrence of a pattern" do
96
- expect(RE2.GlobalReplace("woo", "o", "a")).to eq("waa")
102
+ expect(RE2.global_replace("woo", "o", "a")).to eq("waa")
97
103
  end
98
104
 
99
105
  it "supports inputs with null bytes" do
100
- expect(RE2.GlobalReplace("w\0oo", "o", "a")).to eq("w\0aa")
106
+ expect(RE2.global_replace("w\0oo", "o", "a")).to eq("w\0aa")
101
107
  end
102
108
 
103
109
  it "supports patterns with null bytes" do
104
- expect(RE2.GlobalReplace("w\0\0oo", "\0", "a")).to eq("waaoo")
110
+ expect(RE2.global_replace("w\0\0oo", "\0", "a")).to eq("waaoo")
105
111
  end
106
112
 
107
113
  it "supports replacements with null bytes" do
108
- expect(RE2.GlobalReplace("woo", "o", "\0")).to eq("w\0\0")
114
+ expect(RE2.global_replace("woo", "o", "\0")).to eq("w\0\0")
109
115
  end
110
116
 
111
117
  it "performs replacement based on regular expressions" do
112
- expect(RE2.GlobalReplace("woohoo", "o+", "e")).to eq("wehe")
118
+ expect(RE2.global_replace("woohoo", "o+", "e")).to eq("wehe")
113
119
  end
114
120
 
115
121
  it "supports flags in patterns" do
116
- expect(RE2.GlobalReplace("Robert", "(?i)r", "w")).to eq("wobewt")
122
+ expect(RE2.global_replace("Robert", "(?i)r", "w")).to eq("wobewt")
117
123
  end
118
124
 
119
125
  it "does not perform replacement in-place", :aggregate_failures do
120
126
  name = "Robert"
121
- replacement = RE2.GlobalReplace(name, "(?i)R", "w")
127
+ replacement = RE2.global_replace(name, "(?i)R", "w")
122
128
 
123
129
  expect(name).to eq("Robert")
124
130
  expect(replacement).to eq("wobewt")
@@ -127,75 +133,171 @@ RSpec.describe RE2 do
127
133
  it "supports passing an RE2::Regexp as the pattern" do
128
134
  re = RE2::Regexp.new('wo{2,}')
129
135
 
130
- expect(RE2.GlobalReplace("woowooo", re, "miaow")).to eq("miaowmiaow")
136
+ expect(RE2.global_replace("woowooo", re, "miaow")).to eq("miaowmiaow")
131
137
  end
132
138
 
133
139
  it "respects any passed RE2::Regexp's flags" do
134
140
  re = RE2::Regexp.new('gOOD MORNING', case_sensitive: false)
135
141
 
136
- expect(RE2.GlobalReplace("Good morning Good morning", re, "hi")).to eq("hi hi")
142
+ expect(RE2.global_replace("Good morning Good morning", re, "hi")).to eq("hi hi")
137
143
  end
138
144
 
139
145
  it "supports passing something that can be coerced to a String as input" do
140
- expect(RE2.GlobalReplace(StringLike.new("woo"), "o", "a")).to eq("waa")
146
+ expect(RE2.global_replace(StringLike.new("woo"), "o", "a")).to eq("waa")
141
147
  end
142
148
 
143
149
  it "supports passing something that can be coerced to a String as a pattern" do
144
- expect(RE2.GlobalReplace("woo", StringLike.new("o"), "a")).to eq("waa")
150
+ expect(RE2.global_replace("woo", StringLike.new("o"), "a")).to eq("waa")
145
151
  end
146
152
 
147
153
  it "supports passing something that can be coerced to a String as a replacement" do
148
- expect(RE2.GlobalReplace("woo", "o", StringLike.new("a"))).to eq("waa")
154
+ expect(RE2.global_replace("woo", "o", StringLike.new("a"))).to eq("waa")
149
155
  end
150
156
 
151
157
  it "returns UTF-8 strings if the pattern is UTF-8" do
152
158
  original = "Foo".encode("ISO-8859-1")
153
- replacement = RE2.GlobalReplace(original, "oo", "ah")
159
+ replacement = RE2.global_replace(original, "oo", "ah")
154
160
 
155
161
  expect(replacement.encoding).to eq(Encoding::UTF_8)
156
162
  end
157
163
 
158
164
  it "returns ISO-8859-1 strings if the pattern is not UTF-8" do
159
165
  original = "Foo"
160
- replacement = RE2.GlobalReplace(original, RE2("oo", utf8: false), "ah")
166
+ replacement = RE2.global_replace(original, RE2("oo", utf8: false), "ah")
161
167
 
162
168
  expect(replacement.encoding).to eq(Encoding::ISO_8859_1)
163
169
  end
164
170
 
165
171
  it "returns UTF-8 strings when given a String pattern" do
166
- replacement = RE2.GlobalReplace("Foo", "oo".encode("ISO-8859-1"), "ah")
172
+ replacement = RE2.global_replace("Foo", "oo".encode("ISO-8859-1"), "ah")
167
173
 
168
174
  expect(replacement.encoding).to eq(Encoding::UTF_8)
169
175
  end
170
176
 
171
177
  it "raises a Type Error for input that can't be converted to String" do
172
- expect { RE2.GlobalReplace(0, "o", "a") }.to raise_error(TypeError)
178
+ expect { RE2.global_replace(0, "o", "a") }.to raise_error(TypeError)
173
179
  end
174
180
 
175
181
  it "raises a Type Error for a non-RE2::Regexp pattern that can't be converted to String" do
176
- expect { RE2.GlobalReplace("woo", 0, "a") }.to raise_error(TypeError)
182
+ expect { RE2.global_replace("woo", 0, "a") }.to raise_error(TypeError)
177
183
  end
178
184
 
179
185
  it "raises a Type Error for a replacement that can't be converted to String" do
180
- expect { RE2.GlobalReplace("woo", "o", 0) }.to raise_error(TypeError)
186
+ expect { RE2.global_replace("woo", "o", 0) }.to raise_error(TypeError)
181
187
  end
182
188
  end
183
189
 
184
- describe "#QuoteMeta" do
190
+ describe ".GlobalReplace" do
191
+ it "is an alias for .global_replace" do
192
+ expect(RE2.GlobalReplace("woo", "o", "a")).to eq("waa")
193
+ end
194
+ end
195
+
196
+ describe ".extract" do
197
+ it "extracts a rewrite of the first match" do
198
+ expect(RE2.extract("alice@example.com", '(\w+)@(\w+)', '\2-\1')).to eq("example-alice")
199
+ end
200
+
201
+ it "returns nil if there is no match" do
202
+ expect(RE2.extract("no match", '(\d+)', '\1')).to be_nil
203
+ end
204
+
205
+ it "supports passing an RE2::Regexp as the pattern" do
206
+ re = RE2::Regexp.new('(\w+)@(\w+)')
207
+
208
+ expect(RE2.extract("alice@example.com", re, '\2-\1')).to eq("example-alice")
209
+ end
210
+
211
+ it "respects any passed RE2::Regexp's flags" do
212
+ re = RE2::Regexp.new('(hello)', case_sensitive: false)
213
+
214
+ expect(RE2.extract("Hello", re, '\1')).to eq("Hello")
215
+ end
216
+
217
+ it "returns UTF-8 strings if the pattern is UTF-8" do
218
+ re = RE2::Regexp.new('(foo)')
219
+ result = RE2.extract("foo", re, '\1')
220
+
221
+ expect(result.encoding.name).to eq("UTF-8")
222
+ end
223
+
224
+ it "returns ISO-8859-1 strings if the pattern is not UTF-8" do
225
+ re = RE2::Regexp.new('(foo)', utf8: false)
226
+ result = RE2.extract("foo", re, '\1')
227
+
228
+ expect(result.encoding.name).to eq("ISO-8859-1")
229
+ end
230
+
231
+ it "returns UTF-8 strings when given a String pattern" do
232
+ result = RE2.extract("foo", '(foo)', '\1')
233
+
234
+ expect(result.encoding.name).to eq("UTF-8")
235
+ end
236
+
237
+ it "supports inputs with null bytes" do
238
+ expect(RE2.extract("ab\0cd", '(a.*d)', '\1')).to eq("ab\0cd")
239
+ end
240
+
241
+ it "supports patterns with null bytes" do
242
+ expect(RE2.extract("ab\0cd", "(b\0c)", '\1')).to eq("b\0c")
243
+ end
244
+
245
+ it "supports rewrites with null bytes" do
246
+ expect(RE2.extract("abcd", '(bc)', "x\0\\1")).to eq("x\0bc")
247
+ end
248
+
249
+ it "supports passing something that can be coerced to a String as input" do
250
+ expect(RE2.extract(StringLike.new("bob123"), '(\d+)', '\1')).to eq("123")
251
+ end
252
+
253
+ it "supports passing something that can be coerced to a String as a pattern" do
254
+ expect(RE2.extract("bob123", StringLike.new('(\d+)'), '\1')).to eq("123")
255
+ end
256
+
257
+ it "supports passing something that can be coerced to a String as a rewrite" do
258
+ expect(RE2.extract("bob123", '(\d+)', StringLike.new('\1'))).to eq("123")
259
+ end
260
+
261
+ it "raises a Type Error for input that can't be converted to String" do
262
+ expect { RE2.extract(0, '(\d+)', '\1') }.to raise_error(TypeError)
263
+ end
264
+
265
+ it "raises a Type Error for a non-RE2::Regexp pattern that can't be converted to String" do
266
+ expect { RE2.extract("woo", 0, '\1') }.to raise_error(TypeError)
267
+ end
268
+
269
+ it "raises a Type Error for a rewrite that can't be converted to String" do
270
+ expect { RE2.extract("woo", '(\w+)', 0) }.to raise_error(TypeError)
271
+ end
272
+ end
273
+
274
+ describe "#escape" do
185
275
  it "escapes a string so it can be used as a regular expression" do
186
- expect(RE2.QuoteMeta("1.5-2.0?")).to eq('1\.5\-2\.0\?')
276
+ expect(RE2.escape("1.5-2.0?")).to eq('1\.5\-2\.0\?')
187
277
  end
188
278
 
189
279
  it "raises a Type Error for input that can't be converted to String" do
190
- expect { RE2.QuoteMeta(0) }.to raise_error(TypeError)
280
+ expect { RE2.escape(0) }.to raise_error(TypeError)
191
281
  end
192
282
 
193
283
  it "supports passing something that can be coerced to a String as input" do
194
- expect(RE2.QuoteMeta(StringLike.new("1.5"))).to eq('1\.5')
284
+ expect(RE2.escape(StringLike.new("1.5"))).to eq('1\.5')
195
285
  end
196
286
 
197
287
  it "supports strings containing null bytes" do
198
- expect(RE2.QuoteMeta("abc\0def")).to eq('abc\x00def')
288
+ expect(RE2.escape("abc\0def")).to eq('abc\x00def')
289
+ end
290
+ end
291
+
292
+ describe ".quote" do
293
+ it "is an alias for .escape" do
294
+ expect(RE2.quote("1.5-2.0?")).to eq('1\.5\-2\.0\?')
295
+ end
296
+ end
297
+
298
+ describe ".QuoteMeta" do
299
+ it "is an alias for .escape" do
300
+ expect(RE2.QuoteMeta("1.5-2.0?")).to eq('1\.5\-2\.0\?')
199
301
  end
200
302
  end
201
303
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: re2
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.24.0
4
+ version: 2.25.0
5
5
  platform: aarch64-linux-gnu
6
6
  authors:
7
7
  - Paul Mucur