re2 2.27.0-arm-linux-gnu → 2.29.0-arm-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.
@@ -49,6 +49,13 @@ RSpec.describe RE2::Regexp do
49
49
 
50
50
  expect { re.send(:initialize, 'bar') }.to raise_error(FrozenError)
51
51
  end
52
+
53
+ it "cannot be re-initialized while parsing options" do
54
+ re = described_class.allocate
55
+ options = Hash.new { |_, key| re.send(:initialize, 'bar') if key == :utf8 }
56
+
57
+ expect { re.send(:initialize, 'woo', options) }.to raise_error(FrozenError)
58
+ end
52
59
  end
53
60
 
54
61
  describe "#dup" do
@@ -234,24 +241,6 @@ RSpec.describe RE2::Regexp do
234
241
  end
235
242
  end
236
243
 
237
- describe "#to_str" do
238
- it "returns the original pattern" do
239
- string = RE2::Regexp.new('w(o)(o)').to_str
240
-
241
- expect(string).to eq("w(o)(o)")
242
- end
243
-
244
- it "returns the pattern even if invalid" do
245
- string = RE2::Regexp.new('???', log_errors: false).to_str
246
-
247
- expect(string).to eq("???")
248
- end
249
-
250
- it "raises an error when called on an uninitialized object" do
251
- expect { described_class.allocate.to_str }.to raise_error(TypeError, /uninitialized RE2::Regexp/)
252
- end
253
- end
254
-
255
244
  describe "#pattern" do
256
245
  it "returns the original pattern" do
257
246
  pattern = RE2::Regexp.new('w(o)(o)').pattern
@@ -508,6 +497,18 @@ RSpec.describe RE2::Regexp do
508
497
  expect(re.match("My name is Alice Bloggs")).to eq(true)
509
498
  end
510
499
 
500
+ it "returns nil for nil" do
501
+ re = RE2::Regexp.new('.*')
502
+
503
+ expect(re.match(nil)).to be_nil
504
+ end
505
+
506
+ it "matches against symbols" do
507
+ re = RE2::Regexp.new('(\d+)')
508
+
509
+ expect(re.match(:abc123)).to be_a(RE2::MatchData)
510
+ end
511
+
511
512
  it "supports matching against text containing null bytes" do
512
513
  re = RE2::Regexp.new("a\0b")
513
514
 
@@ -529,7 +530,7 @@ RSpec.describe RE2::Regexp do
529
530
  it "raises an exception when given text that cannot be coerced to a string" do
530
531
  re = RE2::Regexp.new('My name is (\w+) (\w+)')
531
532
 
532
- expect { re.match(nil) }.to raise_error(TypeError)
533
+ expect { re.match(0) }.to raise_error(TypeError)
533
534
  end
534
535
 
535
536
  it "returns nil with an invalid pattern" do
@@ -819,6 +820,18 @@ RSpec.describe RE2::Regexp do
819
820
  expect(re.match?("My name is Alice Bloggs")).to eq(false)
820
821
  end
821
822
 
823
+ it "returns false for nil" do
824
+ re = RE2::Regexp.new('.*')
825
+
826
+ expect(re.match?(nil)).to eq(false)
827
+ end
828
+
829
+ it "matches against symbols" do
830
+ re = RE2::Regexp.new('\d+')
831
+
832
+ expect(re.match?(:abc123)).to eq(true)
833
+ end
834
+
822
835
  it "raises an exception if text cannot be coerced to a string" do
823
836
  re = RE2::Regexp.new('My name is (\S+) (\S+)')
824
837
 
@@ -861,6 +874,18 @@ RSpec.describe RE2::Regexp do
861
874
  expect(re.partial_match?("My name is Alice Bloggs")).to eq(false)
862
875
  end
863
876
 
877
+ it "returns false for nil" do
878
+ re = RE2::Regexp.new('.*')
879
+
880
+ expect(re.partial_match?(nil)).to eq(false)
881
+ end
882
+
883
+ it "matches against symbols" do
884
+ re = RE2::Regexp.new('\d+')
885
+
886
+ expect(re.partial_match?(:abc123)).to eq(true)
887
+ end
888
+
864
889
  it "raises an exception if text cannot be coerced to a string" do
865
890
  re = RE2::Regexp.new('My name is (\S+) (\S+)')
866
891
 
@@ -903,6 +928,18 @@ RSpec.describe RE2::Regexp do
903
928
  expect(re =~ "My name is Alice Bloggs").to eq(false)
904
929
  end
905
930
 
931
+ it "returns false for nil" do
932
+ re = RE2::Regexp.new('.*')
933
+
934
+ expect(re =~ nil).to eq(false)
935
+ end
936
+
937
+ it "matches against symbols" do
938
+ re = RE2::Regexp.new('\d+')
939
+
940
+ expect(re =~ :abc123).to eq(true)
941
+ end
942
+
906
943
  it "raises an exception if text cannot be coerced to a string" do
907
944
  re = RE2::Regexp.new('My name is (\S+) (\S+)')
908
945
 
@@ -914,6 +951,52 @@ RSpec.describe RE2::Regexp do
914
951
  end
915
952
  end
916
953
 
954
+ describe "#==" do
955
+ it "returns true for regexps with the same pattern and options" do
956
+ expect(RE2::Regexp.new('a(b)', case_sensitive: false)).to eq(RE2::Regexp.new('a(b)', case_sensitive: false))
957
+ end
958
+
959
+ it "returns false for regexps with different patterns" do
960
+ expect(RE2::Regexp.new('a(b)')).not_to eq(RE2::Regexp.new('a(c)'))
961
+ end
962
+
963
+ it "returns false for regexps with different options" do
964
+ expect(RE2::Regexp.new('a(b)')).not_to eq(RE2::Regexp.new('a(b)', case_sensitive: false))
965
+ end
966
+
967
+ it "returns false for a String with the same pattern" do
968
+ expect(RE2::Regexp.new('a(b)')).not_to eq('a(b)')
969
+ end
970
+
971
+ it "is aliased to eql?" do
972
+ expect(RE2::Regexp.new('a(b)')).to eql(RE2::Regexp.new('a(b)'))
973
+ end
974
+
975
+ it "raises an error when called on an uninitialized object" do
976
+ expect { described_class.allocate == RE2::Regexp.new('a') }.to raise_error(TypeError, /uninitialized RE2::Regexp/)
977
+ end
978
+ end
979
+
980
+ describe "#hash" do
981
+ it "is the same for equal regexps" do
982
+ expect(RE2::Regexp.new('a(b)').hash).to eq(RE2::Regexp.new('a(b)').hash)
983
+ end
984
+
985
+ it "differs for regexps with different options" do
986
+ expect(RE2::Regexp.new('a(b)').hash).not_to eq(RE2::Regexp.new('a(b)', case_sensitive: false).hash)
987
+ end
988
+
989
+ it "allows regexps to be used as Hash keys" do
990
+ hash = { RE2::Regexp.new('a(b)') => :found }
991
+
992
+ expect(hash[RE2::Regexp.new('a(b)')]).to eq(:found)
993
+ end
994
+
995
+ it "allows regexps to be deduplicated" do
996
+ expect([RE2::Regexp.new('a'), RE2::Regexp.new('a')].uniq.size).to eq(1)
997
+ end
998
+ end
999
+
917
1000
  describe "#===" do
918
1001
  it "returns only true or false even if there are capturing groups", :aggregate_failures do
919
1002
  re = RE2::Regexp.new('My name is (\S+) (\S+)')
@@ -928,10 +1011,31 @@ RSpec.describe RE2::Regexp do
928
1011
  expect(re === "My name is Alice Bloggs").to eq(false)
929
1012
  end
930
1013
 
931
- it "raises an exception if text cannot be coerced to a string" do
1014
+ it "matches against symbols" do
1015
+ re = RE2::Regexp.new('\d+')
1016
+
1017
+ expect(re === :abc123).to eq(true)
1018
+ end
1019
+
1020
+ it "returns false if text cannot be coerced to a string" do
932
1021
  re = RE2::Regexp.new('My name is (\S+) (\S+)')
933
1022
 
934
- expect { re === 0 }.to raise_error(TypeError)
1023
+ expect(re === 0).to eq(false)
1024
+ end
1025
+
1026
+ it "returns false for nil" do
1027
+ re = RE2::Regexp.new('.*')
1028
+
1029
+ expect(re === nil).to eq(false)
1030
+ end
1031
+
1032
+ it "can be used in a case statement" do
1033
+ result = case 123
1034
+ when RE2::Regexp.new('\d+') then :matched
1035
+ else :not_matched
1036
+ end
1037
+
1038
+ expect(result).to eq(:not_matched)
935
1039
  end
936
1040
 
937
1041
  it "raises an error when called on an uninitialized object" do
@@ -960,6 +1064,18 @@ RSpec.describe RE2::Regexp do
960
1064
  expect(re.full_match?("My name is Alice Bloggs")).to eq(false)
961
1065
  end
962
1066
 
1067
+ it "returns false for nil" do
1068
+ re = RE2::Regexp.new('.*')
1069
+
1070
+ expect(re.full_match?(nil)).to eq(false)
1071
+ end
1072
+
1073
+ it "matches against symbols" do
1074
+ re = RE2::Regexp.new('\w+')
1075
+
1076
+ expect(re.full_match?(:abc123)).to eq(true)
1077
+ end
1078
+
963
1079
  it "raises an exception if text cannot be coerced to a string" do
964
1080
  re = RE2::Regexp.new('My name is (\S+) (\S+)')
965
1081
 
@@ -1048,6 +1164,13 @@ RSpec.describe RE2::Regexp do
1048
1164
  expect(RE2::Regexp.new('???', log_errors: false).named_capturing_groups).to be_empty
1049
1165
  end
1050
1166
 
1167
+ it "returns names as UTF-8 even if the pattern is Latin-1" do
1168
+ groups = RE2::Regexp.new('(?P<bob>a)', utf8: false).named_capturing_groups
1169
+ key = groups.keys.first
1170
+
1171
+ expect(key.encoding).to eq(Encoding::UTF_8)
1172
+ end
1173
+
1051
1174
  it "raises an error when called on an uninitialized object" do
1052
1175
  expect { described_class.allocate.named_capturing_groups }.to raise_error(TypeError, /uninitialized RE2::Regexp/)
1053
1176
  end
@@ -1071,15 +1194,17 @@ RSpec.describe RE2::Regexp do
1071
1194
  end
1072
1195
 
1073
1196
  it "returns UTF-8 strings if the pattern is UTF-8" do
1074
- names = RE2::Regexp.new('(?P<bob>a)').names
1197
+ re = RE2::Regexp.new('(?P<café>\d+)', log_errors: false)
1198
+ skip "Underlying RE2 does not support non-ASCII capturing group names" unless re.ok?
1075
1199
 
1076
- expect(names.first.encoding).to eq(Encoding::UTF_8)
1200
+ expect(re.names.first.encoding).to eq(Encoding::UTF_8)
1077
1201
  end
1078
1202
 
1079
- it "returns ISO-8859-1 strings if the pattern is not UTF-8" do
1080
- names = RE2::Regexp.new('(?P<bob>a)', utf8: false).names
1203
+ it "returns UTF-8 strings if the pattern is not UTF-8" do
1204
+ re = RE2::Regexp.new('(?P<café>a)'.encode("ISO-8859-1"), utf8: false, log_errors: false)
1205
+ skip "Underlying RE2 does not support non-ASCII capturing group names" unless re.ok?
1081
1206
 
1082
- expect(names.first.encoding).to eq(Encoding::ISO_8859_1)
1207
+ expect(re.names).to contain_exactly("café")
1083
1208
  end
1084
1209
 
1085
1210
  it "raises an error when called on an uninitialized object" do
@@ -1143,6 +1268,18 @@ RSpec.describe RE2::Regexp do
1143
1268
  expect(r.partial_match("foo bar")).to eq(true)
1144
1269
  end
1145
1270
 
1271
+ it "returns nil for nil" do
1272
+ re = RE2::Regexp.new('.*')
1273
+
1274
+ expect(re.partial_match(nil)).to be_nil
1275
+ end
1276
+
1277
+ it "matches against symbols" do
1278
+ re = RE2::Regexp.new('(\d+)')
1279
+
1280
+ expect(re.partial_match(:abc123)).to be_a(RE2::MatchData)
1281
+ end
1282
+
1146
1283
  it "can set the number of submatches to extract", :aggregate_failures do
1147
1284
  r = RE2::Regexp.new('f(o+)(a+)')
1148
1285
  m = r.partial_match("fooaa bar", submatches: 1)
@@ -1203,6 +1340,18 @@ RSpec.describe RE2::Regexp do
1203
1340
  expect(r.full_match("foo")).to eq(true)
1204
1341
  end
1205
1342
 
1343
+ it "returns nil for nil" do
1344
+ re = RE2::Regexp.new('.*')
1345
+
1346
+ expect(re.full_match(nil)).to be_nil
1347
+ end
1348
+
1349
+ it "matches against symbols" do
1350
+ re = RE2::Regexp.new('(\w+)')
1351
+
1352
+ expect(re.full_match(:abc123)).to be_a(RE2::MatchData)
1353
+ end
1354
+
1206
1355
  it "can set the number of submatches to extract", :aggregate_failures do
1207
1356
  r = RE2::Regexp.new('f(o+)(a+)')
1208
1357
  m = r.full_match("fooaa", submatches: 1)
@@ -106,6 +106,15 @@ RSpec.describe RE2::Scanner do
106
106
  end
107
107
  end
108
108
 
109
+ describe "#initialize_copy" do
110
+ it "is a no-op when the source is the same object" do
111
+ scanner = RE2::Regexp.new('(\w+)').scan("foo bar")
112
+ scanner.send(:initialize_copy, scanner)
113
+
114
+ expect(scanner.scan).to eq(["foo"])
115
+ end
116
+ end
117
+
109
118
  describe "#scan" do
110
119
  it "returns the next array of matches", :aggregate_failures do
111
120
  r = RE2::Regexp.new('(\w+)')
data/spec/re2/set_spec.rb CHANGED
@@ -49,6 +49,13 @@ RSpec.describe RE2::Set do
49
49
  "anchor should be one of: :unanchored, :anchor_start, :anchor_both"
50
50
  )
51
51
  end
52
+
53
+ it "cannot be re-initialized before compilation" do
54
+ set = RE2::Set.new
55
+ set.add("abc")
56
+
57
+ expect { set.send(:initialize) }.to raise_error(TypeError, /already initialized RE2::Set/)
58
+ end
52
59
  end
53
60
 
54
61
  describe "#dup" do
@@ -212,6 +219,30 @@ RSpec.describe RE2::Set do
212
219
  end
213
220
  end
214
221
 
222
+ it "raises an error if called after a failed #compile" do
223
+ skip "Underlying RE2::Set::Match does not output error information" unless RE2::Set.match_raises_errors?
224
+
225
+ set = RE2::Set.new(:unanchored, max_mem: 1, log_errors: false)
226
+ set.add("a{1000}b{1000}c{1000}")
227
+
228
+ silence_stderr do
229
+ set.compile
230
+
231
+ expect { set.match("abc") }.to raise_error(RE2::Set::MatchError, "#match must not be called before #compile")
232
+ end
233
+ end
234
+
235
+ it "returns an empty array if called after a failed #compile when :exception is false" do
236
+ set = RE2::Set.new(:unanchored, max_mem: 1, log_errors: false)
237
+ set.add("a{1000}b{1000}c{1000}")
238
+
239
+ silence_stderr do
240
+ set.compile
241
+
242
+ expect(set.match("abc", exception: false)).to be_empty
243
+ end
244
+ end
245
+
215
246
  it "raises an error if :exception is true and RE2 does not support it" do
216
247
  skip "Underlying RE2::Set::Match outputs error information" if RE2::Set.match_raises_errors?
217
248
 
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.27.0
4
+ version: 2.29.0
5
5
  platform: arm-linux-gnu
6
6
  authors:
7
7
  - Paul Mucur
@@ -30,14 +30,14 @@ dependencies:
30
30
  requirements:
31
31
  - - "~>"
32
32
  - !ruby/object:Gem::Version
33
- version: 1.11.0
33
+ version: 1.12.0
34
34
  type: :development
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
38
  - - "~>"
39
39
  - !ruby/object:Gem::Version
40
- version: 1.11.0
40
+ version: 1.12.0
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: rspec
43
43
  requirement: !ruby/object:Gem::Requirement
@@ -74,6 +74,7 @@ files:
74
74
  - lib/3.4/re2.so
75
75
  - lib/4.0/re2.so
76
76
  - lib/re2.rb
77
+ - lib/re2/match_data.rb
77
78
  - lib/re2/regexp.rb
78
79
  - lib/re2/scanner.rb
79
80
  - lib/re2/string.rb
@@ -108,7 +109,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
108
109
  - !ruby/object:Gem::Version
109
110
  version: 3.3.22
110
111
  requirements: []
111
- rubygems_version: 4.0.3
112
+ rubygems_version: 4.0.6
112
113
  specification_version: 4
113
114
  summary: Ruby bindings to RE2.
114
115
  test_files: