re2 2.15.0.rc1-x86_64-linux-gnu

Sign up to get free protection for your applications and to get access to all the features.
data/spec/re2_spec.rb ADDED
@@ -0,0 +1,201 @@
1
+ # frozen_string_literal: true
2
+
3
+ RSpec.describe RE2 do
4
+ describe ".Replace" do
5
+ it "only replaces the first occurrence of the pattern" do
6
+ expect(RE2.Replace("woo", "o", "a")).to eq("wao")
7
+ end
8
+
9
+ it "supports inputs with null bytes" do
10
+ expect(RE2.Replace("w\0oo", "o", "a")).to eq("w\0ao")
11
+ end
12
+
13
+ it "supports patterns with null bytes" do
14
+ expect(RE2.Replace("w\0oo", "\0", "o")).to eq("wooo")
15
+ end
16
+
17
+ it "supports replacements with null bytes" do
18
+ expect(RE2.Replace("woo", "o", "\0")).to eq("w\0o")
19
+ end
20
+
21
+ it "performs replacement based on regular expressions" do
22
+ expect(RE2.Replace("woo", "o+", "e")).to eq("we")
23
+ end
24
+
25
+ it "supports flags in patterns" do
26
+ expect(RE2.Replace("Good morning", "(?i)gOOD MORNING", "hi")).to eq("hi")
27
+ end
28
+
29
+ it "does not perform replacements in-place", :aggregate_failures do
30
+ name = "Robert"
31
+ replacement = RE2.Replace(name, "R", "Cr")
32
+
33
+ expect(name).to eq("Robert")
34
+ expect(replacement).to eq("Crobert")
35
+ end
36
+
37
+ it "supports passing an RE2::Regexp as the pattern" do
38
+ re = RE2::Regexp.new('wo{2}')
39
+
40
+ expect(RE2.Replace("woo", re, "miaow")).to eq("miaow")
41
+ end
42
+
43
+ it "respects any passed RE2::Regexp's flags" do
44
+ re = RE2::Regexp.new('gOOD MORNING', case_sensitive: false)
45
+
46
+ expect(RE2.Replace("Good morning", re, "hi")).to eq("hi")
47
+ end
48
+
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")
51
+ end
52
+
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")
55
+ end
56
+
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")
59
+ end
60
+
61
+ it "returns UTF-8 strings if the pattern is UTF-8" do
62
+ original = "Foo".encode("ISO-8859-1")
63
+ replacement = RE2.Replace(original, "oo", "ah")
64
+
65
+ expect(replacement.encoding).to eq(Encoding::UTF_8)
66
+ end
67
+
68
+ it "returns ISO-8859-1 strings if the pattern is not UTF-8" do
69
+ original = "Foo"
70
+ replacement = RE2.Replace(original, RE2("oo", utf8: false), "ah")
71
+
72
+ expect(replacement.encoding).to eq(Encoding::ISO_8859_1)
73
+ end
74
+
75
+ it "returns UTF-8 strings when given a String pattern" do
76
+ replacement = RE2.Replace("Foo", "oo".encode("ISO-8859-1"), "ah")
77
+
78
+ expect(replacement.encoding).to eq(Encoding::UTF_8)
79
+ end
80
+
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)
83
+ end
84
+
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)
87
+ end
88
+
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)
91
+ end
92
+ end
93
+
94
+ describe ".GlobalReplace" do
95
+ it "replaces every occurrence of a pattern" do
96
+ expect(RE2.GlobalReplace("woo", "o", "a")).to eq("waa")
97
+ end
98
+
99
+ it "supports inputs with null bytes" do
100
+ expect(RE2.GlobalReplace("w\0oo", "o", "a")).to eq("w\0aa")
101
+ end
102
+
103
+ it "supports patterns with null bytes" do
104
+ expect(RE2.GlobalReplace("w\0\0oo", "\0", "a")).to eq("waaoo")
105
+ end
106
+
107
+ it "supports replacements with null bytes" do
108
+ expect(RE2.GlobalReplace("woo", "o", "\0")).to eq("w\0\0")
109
+ end
110
+
111
+ it "performs replacement based on regular expressions" do
112
+ expect(RE2.GlobalReplace("woohoo", "o+", "e")).to eq("wehe")
113
+ end
114
+
115
+ it "supports flags in patterns" do
116
+ expect(RE2.GlobalReplace("Robert", "(?i)r", "w")).to eq("wobewt")
117
+ end
118
+
119
+ it "does not perform replacement in-place", :aggregate_failures do
120
+ name = "Robert"
121
+ replacement = RE2.GlobalReplace(name, "(?i)R", "w")
122
+
123
+ expect(name).to eq("Robert")
124
+ expect(replacement).to eq("wobewt")
125
+ end
126
+
127
+ it "supports passing an RE2::Regexp as the pattern" do
128
+ re = RE2::Regexp.new('wo{2,}')
129
+
130
+ expect(RE2.GlobalReplace("woowooo", re, "miaow")).to eq("miaowmiaow")
131
+ end
132
+
133
+ it "respects any passed RE2::Regexp's flags" do
134
+ re = RE2::Regexp.new('gOOD MORNING', case_sensitive: false)
135
+
136
+ expect(RE2.GlobalReplace("Good morning Good morning", re, "hi")).to eq("hi hi")
137
+ end
138
+
139
+ 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")
141
+ end
142
+
143
+ 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")
145
+ end
146
+
147
+ 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")
149
+ end
150
+
151
+ it "returns UTF-8 strings if the pattern is UTF-8" do
152
+ original = "Foo".encode("ISO-8859-1")
153
+ replacement = RE2.GlobalReplace(original, "oo", "ah")
154
+
155
+ expect(replacement.encoding).to eq(Encoding::UTF_8)
156
+ end
157
+
158
+ it "returns ISO-8859-1 strings if the pattern is not UTF-8" do
159
+ original = "Foo"
160
+ replacement = RE2.GlobalReplace(original, RE2("oo", utf8: false), "ah")
161
+
162
+ expect(replacement.encoding).to eq(Encoding::ISO_8859_1)
163
+ end
164
+
165
+ it "returns UTF-8 strings when given a String pattern" do
166
+ replacement = RE2.GlobalReplace("Foo", "oo".encode("ISO-8859-1"), "ah")
167
+
168
+ expect(replacement.encoding).to eq(Encoding::UTF_8)
169
+ end
170
+
171
+ 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)
173
+ end
174
+
175
+ 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)
177
+ end
178
+
179
+ 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)
181
+ end
182
+ end
183
+
184
+ describe "#QuoteMeta" do
185
+ 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\?')
187
+ end
188
+
189
+ it "raises a Type Error for input that can't be converted to String" do
190
+ expect { RE2.QuoteMeta(0) }.to raise_error(TypeError)
191
+ end
192
+
193
+ 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')
195
+ end
196
+
197
+ it "supports strings containing null bytes" do
198
+ expect(RE2.QuoteMeta("abc\0def")).to eq('abc\x00def')
199
+ end
200
+ end
201
+ end
@@ -0,0 +1,31 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "re2"
4
+
5
+ # To test passing objects that can be coerced to a String.
6
+ class StringLike
7
+ attr_reader :str
8
+ alias_method :to_str, :str
9
+
10
+ def initialize(str)
11
+ @str = str
12
+ end
13
+ end
14
+
15
+ RSpec.configure do |config|
16
+ config.expect_with :rspec do |expectations|
17
+ expectations.include_chain_clauses_in_custom_matcher_descriptions = true
18
+ end
19
+
20
+ config.mock_with :rspec do |mocks|
21
+ mocks.verify_partial_doubles = true
22
+ end
23
+
24
+ config.filter_run :focus
25
+ config.run_all_when_everything_filtered = true
26
+ config.disable_monkey_patching!
27
+ config.warnings = true
28
+ config.default_formatter = 'doc' if config.files_to_run.one?
29
+ config.order = :random
30
+ Kernel.srand config.seed
31
+ end
metadata ADDED
@@ -0,0 +1,129 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: re2
3
+ version: !ruby/object:Gem::Version
4
+ version: 2.15.0.rc1
5
+ platform: x86_64-linux-gnu
6
+ authors:
7
+ - Paul Mucur
8
+ - Stan Hu
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2024-12-16 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: rake-compiler
16
+ requirement: !ruby/object:Gem::Requirement
17
+ requirements:
18
+ - - "~>"
19
+ - !ruby/object:Gem::Version
20
+ version: 1.2.7
21
+ type: :development
22
+ prerelease: false
23
+ version_requirements: !ruby/object:Gem::Requirement
24
+ requirements:
25
+ - - "~>"
26
+ - !ruby/object:Gem::Version
27
+ version: 1.2.7
28
+ - !ruby/object:Gem::Dependency
29
+ name: rake-compiler-dock
30
+ requirement: !ruby/object:Gem::Requirement
31
+ requirements:
32
+ - - "~>"
33
+ - !ruby/object:Gem::Version
34
+ version: 1.7.0.rc1
35
+ type: :development
36
+ prerelease: false
37
+ version_requirements: !ruby/object:Gem::Requirement
38
+ requirements:
39
+ - - "~>"
40
+ - !ruby/object:Gem::Version
41
+ version: 1.7.0.rc1
42
+ - !ruby/object:Gem::Dependency
43
+ name: rspec
44
+ requirement: !ruby/object:Gem::Requirement
45
+ requirements:
46
+ - - "~>"
47
+ - !ruby/object:Gem::Version
48
+ version: '3.2'
49
+ type: :development
50
+ prerelease: false
51
+ version_requirements: !ruby/object:Gem::Requirement
52
+ requirements:
53
+ - - "~>"
54
+ - !ruby/object:Gem::Version
55
+ version: '3.2'
56
+ description: Ruby bindings to RE2, "a fast, safe, thread-friendly alternative to backtracking
57
+ regular expression engines like those used in PCRE, Perl, and Python".
58
+ email:
59
+ executables: []
60
+ extensions: []
61
+ extra_rdoc_files: []
62
+ files:
63
+ - ".rspec"
64
+ - Gemfile
65
+ - LICENSE-DEPENDENCIES.txt
66
+ - LICENSE.txt
67
+ - README.md
68
+ - Rakefile
69
+ - dependencies.yml
70
+ - ext/re2/extconf.rb
71
+ - ext/re2/re2.cc
72
+ - ext/re2/recipes.rb
73
+ - lib/3.1/re2.so
74
+ - lib/3.2/re2.so
75
+ - lib/3.3/re2.so
76
+ - lib/3.4/re2.so
77
+ - lib/re2.rb
78
+ - lib/re2/regexp.rb
79
+ - lib/re2/scanner.rb
80
+ - lib/re2/string.rb
81
+ - lib/re2/version.rb
82
+ - re2.gemspec
83
+ - spec/kernel_spec.rb
84
+ - spec/re2/match_data_spec.rb
85
+ - spec/re2/regexp_spec.rb
86
+ - spec/re2/scanner_spec.rb
87
+ - spec/re2/set_spec.rb
88
+ - spec/re2/string_spec.rb
89
+ - spec/re2_spec.rb
90
+ - spec/spec_helper.rb
91
+ homepage: https://github.com/mudge/re2
92
+ licenses:
93
+ - BSD-3-Clause
94
+ metadata: {}
95
+ post_install_message:
96
+ rdoc_options: []
97
+ require_paths:
98
+ - lib
99
+ required_ruby_version: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ version: '3.1'
104
+ - - "<"
105
+ - !ruby/object:Gem::Version
106
+ version: 3.5.dev
107
+ required_rubygems_version: !ruby/object:Gem::Requirement
108
+ requirements:
109
+ - - ">"
110
+ - !ruby/object:Gem::Version
111
+ version: 1.3.1
112
+ - - ">="
113
+ - !ruby/object:Gem::Version
114
+ version: 3.3.22
115
+ requirements: []
116
+ rubygems_version: 3.3.26
117
+ signing_key:
118
+ specification_version: 4
119
+ summary: Ruby bindings to RE2.
120
+ test_files:
121
+ - ".rspec"
122
+ - spec/spec_helper.rb
123
+ - spec/re2_spec.rb
124
+ - spec/kernel_spec.rb
125
+ - spec/re2/regexp_spec.rb
126
+ - spec/re2/match_data_spec.rb
127
+ - spec/re2/string_spec.rb
128
+ - spec/re2/set_spec.rb
129
+ - spec/re2/scanner_spec.rb