re2 2.0.0-aarch64-linux
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.rspec +2 -0
- data/Gemfile +5 -0
- data/LICENSE.txt +28 -0
- data/README.md +263 -0
- data/Rakefile +132 -0
- data/dependencies.yml +9 -0
- data/ext/re2/extconf.rb +438 -0
- data/ext/re2/re2.cc +1889 -0
- data/ext/re2/recipes.rb +43 -0
- data/lib/2.6/re2.so +0 -0
- data/lib/2.7/re2.so +0 -0
- data/lib/3.0/re2.so +0 -0
- data/lib/3.1/re2.so +0 -0
- data/lib/3.2/re2.so +0 -0
- data/lib/re2/scanner.rb +15 -0
- data/lib/re2/string.rb +85 -0
- data/lib/re2/version.rb +5 -0
- data/lib/re2.rb +14 -0
- data/re2.gemspec +43 -0
- data/spec/kernel_spec.rb +13 -0
- data/spec/re2/match_data_spec.rb +302 -0
- data/spec/re2/regexp_spec.rb +456 -0
- data/spec/re2/scanner_spec.rb +204 -0
- data/spec/re2/set_spec.rb +168 -0
- data/spec/re2/string_spec.rb +56 -0
- data/spec/re2_spec.rb +75 -0
- data/spec/spec_helper.rb +19 -0
- metadata +123 -0
@@ -0,0 +1,168 @@
|
|
1
|
+
RSpec.describe RE2::Set do
|
2
|
+
describe "#initialize" do
|
3
|
+
it "returns an instance given no args" do
|
4
|
+
set = RE2::Set.new
|
5
|
+
|
6
|
+
expect(set).to be_a(RE2::Set)
|
7
|
+
end
|
8
|
+
|
9
|
+
it "returns an instance given only an anchor of :unanchored" do
|
10
|
+
set = RE2::Set.new(:unanchored)
|
11
|
+
|
12
|
+
expect(set).to be_a(RE2::Set)
|
13
|
+
end
|
14
|
+
|
15
|
+
it "returns an instance given only an anchor of :anchor_start" do
|
16
|
+
set = RE2::Set.new(:anchor_start)
|
17
|
+
|
18
|
+
expect(set).to be_a(RE2::Set)
|
19
|
+
end
|
20
|
+
|
21
|
+
it "returns an instance given only an anchor of :anchor_both" do
|
22
|
+
set = RE2::Set.new(:anchor_both)
|
23
|
+
|
24
|
+
expect(set).to be_a(RE2::Set)
|
25
|
+
end
|
26
|
+
|
27
|
+
it "returns an instance given an anchor and options" do
|
28
|
+
set = RE2::Set.new(:unanchored, :case_sensitive => false)
|
29
|
+
|
30
|
+
expect(set).to be_a(RE2::Set)
|
31
|
+
end
|
32
|
+
|
33
|
+
it "raises an error if given an inappropriate type" do
|
34
|
+
expect { RE2::Set.new(0) }.to raise_error(TypeError)
|
35
|
+
end
|
36
|
+
|
37
|
+
it "raises an error if given an invalid anchor" do
|
38
|
+
expect { RE2::Set.new(:not_a_valid_anchor) }.to raise_error(
|
39
|
+
ArgumentError,
|
40
|
+
"anchor should be one of: :unanchored, :anchor_start, :anchor_both"
|
41
|
+
)
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
describe "#add" do
|
46
|
+
it "allows multiple patterns to be added", :aggregate_failures do
|
47
|
+
set = RE2::Set.new
|
48
|
+
|
49
|
+
expect(set.add("abc")).to eq(0)
|
50
|
+
expect(set.add("def")).to eq(1)
|
51
|
+
expect(set.add("ghi")).to eq(2)
|
52
|
+
end
|
53
|
+
|
54
|
+
it "rejects invalid patterns when added" do
|
55
|
+
set = RE2::Set.new(:unanchored, :log_errors => false)
|
56
|
+
|
57
|
+
expect { set.add("???") }.to raise_error(ArgumentError, /str rejected by RE2::Set->Add()/)
|
58
|
+
end
|
59
|
+
|
60
|
+
it "raises an error if called after #compile" do
|
61
|
+
set = RE2::Set.new(:unanchored, :log_errors => false)
|
62
|
+
set.add("abc")
|
63
|
+
set.compile
|
64
|
+
|
65
|
+
silence_stderr do
|
66
|
+
expect { set.add("def") }.to raise_error(ArgumentError)
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
70
|
+
it "raises an error if given a non-string pattern" do
|
71
|
+
set = RE2::Set.new(:unanchored, :log_errors => false)
|
72
|
+
|
73
|
+
expect { set.add(0) }.to raise_error(TypeError)
|
74
|
+
end
|
75
|
+
end
|
76
|
+
|
77
|
+
describe "#compile" do
|
78
|
+
it "compiles the set without error" do
|
79
|
+
set = RE2::Set.new
|
80
|
+
set.add("abc")
|
81
|
+
set.add("def")
|
82
|
+
set.add("ghi")
|
83
|
+
|
84
|
+
expect(set.compile).to be_truthy
|
85
|
+
end
|
86
|
+
end
|
87
|
+
|
88
|
+
describe "#match" do
|
89
|
+
it "matches against multiple patterns" do
|
90
|
+
set = RE2::Set.new
|
91
|
+
set.add("abc")
|
92
|
+
set.add("def")
|
93
|
+
set.add("ghi")
|
94
|
+
set.compile
|
95
|
+
|
96
|
+
expect(set.match("abcdefghi", :exception => false)).to eq([0, 1, 2])
|
97
|
+
end
|
98
|
+
|
99
|
+
it "raises an error if called before #compile by default" do
|
100
|
+
skip "Underlying RE2::Set::Match does not output error information" unless RE2::Set.match_raises_errors?
|
101
|
+
|
102
|
+
set = RE2::Set.new(:unanchored, :log_errors => false)
|
103
|
+
|
104
|
+
silence_stderr do
|
105
|
+
expect { set.match("") }.to raise_error(RE2::Set::MatchError)
|
106
|
+
end
|
107
|
+
end
|
108
|
+
|
109
|
+
it "raises an error if called before #compile when :exception is true" do
|
110
|
+
skip "Underlying RE2::Set::Match does not output error information" unless RE2::Set.match_raises_errors?
|
111
|
+
|
112
|
+
set = RE2::Set.new(:unanchored, :log_errors => false)
|
113
|
+
|
114
|
+
silence_stderr do
|
115
|
+
expect { set.match("", :exception => true) }.to raise_error(RE2::Set::MatchError)
|
116
|
+
end
|
117
|
+
end
|
118
|
+
|
119
|
+
it "returns an empty array if called before #compile when :exception is false" do
|
120
|
+
set = RE2::Set.new(:unanchored, :log_errors => false)
|
121
|
+
|
122
|
+
silence_stderr do
|
123
|
+
expect(set.match("", :exception => false)).to be_empty
|
124
|
+
end
|
125
|
+
end
|
126
|
+
|
127
|
+
it "raises an error if :exception is true and re2 does not support it" do
|
128
|
+
skip "Underlying RE2::Set::Match outputs error information" if RE2::Set.match_raises_errors?
|
129
|
+
|
130
|
+
set = RE2::Set.new(:unanchored, :log_errors => false)
|
131
|
+
|
132
|
+
silence_stderr do
|
133
|
+
expect { set.match("", :exception => true) }.to raise_error(RE2::Set::UnsupportedError)
|
134
|
+
end
|
135
|
+
end
|
136
|
+
|
137
|
+
it "raises an error if given non-hash options" do
|
138
|
+
set = RE2::Set.new
|
139
|
+
|
140
|
+
expect { set.match("", 0) }.to raise_error(TypeError)
|
141
|
+
end
|
142
|
+
end
|
143
|
+
|
144
|
+
def silence_stderr
|
145
|
+
original_stream = STDERR
|
146
|
+
|
147
|
+
if File.const_defined?(:NULL)
|
148
|
+
STDERR.reopen(File::NULL)
|
149
|
+
else
|
150
|
+
platform = RUBY_PLATFORM == 'java' ? RbConfig::CONFIG['host_os'] : RUBY_PLATFORM
|
151
|
+
|
152
|
+
case platform
|
153
|
+
when /mswin|mingw/i
|
154
|
+
STDERR.reopen('NUL')
|
155
|
+
when /amiga/i
|
156
|
+
STDERR.reopen('NIL')
|
157
|
+
when /openvms/i
|
158
|
+
STDERR.reopen('NL:')
|
159
|
+
else
|
160
|
+
STDERR.reopen('/dev/null')
|
161
|
+
end
|
162
|
+
end
|
163
|
+
|
164
|
+
yield
|
165
|
+
ensure
|
166
|
+
STDERR.reopen(original_stream)
|
167
|
+
end
|
168
|
+
end
|
@@ -0,0 +1,56 @@
|
|
1
|
+
require "re2/string"
|
2
|
+
|
3
|
+
class String
|
4
|
+
include RE2::String
|
5
|
+
end
|
6
|
+
|
7
|
+
RSpec.describe RE2::String do
|
8
|
+
describe "#re2_sub" do
|
9
|
+
it "delegates to RE2.Replace to perform replacement" do
|
10
|
+
expect("My name is Robert Paulson".re2_sub('Robert', 'Crobert')).to eq("My name is Crobert Paulson")
|
11
|
+
end
|
12
|
+
|
13
|
+
it "doesn't perform an in-place replacement" do
|
14
|
+
string = "My name is Robert Paulson"
|
15
|
+
expect(string.re2_sub('Robert', 'Crobert')).to_not equal(string)
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
describe "#re2_gsub" do
|
20
|
+
it "delegates to RE2.GlobalReplace to perform replacement" do
|
21
|
+
expect("My name is Robert Paulson".re2_gsub('a', 'e')).to eq("My neme is Robert Peulson")
|
22
|
+
end
|
23
|
+
|
24
|
+
it "doesn't perform an in-place replacement" do
|
25
|
+
string = "My name is Robert Paulson"
|
26
|
+
expect(string.re2_gsub('a', 'e')).to_not equal(string)
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
describe "#re2_match" do
|
31
|
+
it "delegates to RE2::Regexp#match to perform matches" do
|
32
|
+
md = "My name is Robert Paulson".re2_match('My name is (\S+) (\S+)')
|
33
|
+
expect(md).to be_a(RE2::MatchData)
|
34
|
+
expect(md[0]).to eq("My name is Robert Paulson")
|
35
|
+
expect(md[1]).to eq("Robert")
|
36
|
+
expect(md[2]).to eq("Paulson")
|
37
|
+
end
|
38
|
+
|
39
|
+
it "supports limiting the number of matches" do
|
40
|
+
md = "My name is Robert Paulson".re2_match('My name is (\S+) (\S+)', 0)
|
41
|
+
expect(md).to eq(true)
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
describe "#re2_escape" do
|
46
|
+
it "escapes the string for use in regular expressions" do
|
47
|
+
expect("1.5-2.0?".re2_escape).to eq('1\.5\-2\.0\?')
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
describe "#re2_quote" do
|
52
|
+
it "escapes the string for use in regular expressions" do
|
53
|
+
expect("1.5-2.0?".re2_quote).to eq('1\.5\-2\.0\?')
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
data/spec/re2_spec.rb
ADDED
@@ -0,0 +1,75 @@
|
|
1
|
+
RSpec.describe RE2 do
|
2
|
+
describe "#Replace" do
|
3
|
+
it "only replaces the first occurrence of the pattern" do
|
4
|
+
expect(RE2.Replace("woo", "o", "a")).to eq("wao")
|
5
|
+
end
|
6
|
+
|
7
|
+
it "performs replacement based on regular expressions" do
|
8
|
+
expect(RE2.Replace("woo", "o+", "e")).to eq("we")
|
9
|
+
end
|
10
|
+
|
11
|
+
it "supports flags in patterns" do
|
12
|
+
expect(RE2.Replace("Good morning", "(?i)gOOD MORNING", "hi")).to eq("hi")
|
13
|
+
end
|
14
|
+
|
15
|
+
it "does not perform replacements in-place" do
|
16
|
+
name = "Robert"
|
17
|
+
replacement = RE2.Replace(name, "R", "Cr")
|
18
|
+
expect(name).to_not equal(replacement)
|
19
|
+
end
|
20
|
+
|
21
|
+
it "supports passing an RE2::Regexp as the pattern" do
|
22
|
+
re = RE2::Regexp.new('wo{2}')
|
23
|
+
expect(RE2.Replace("woo", re, "miaow")).to eq("miaow")
|
24
|
+
end
|
25
|
+
|
26
|
+
it "respects any passed RE2::Regexp's flags" do
|
27
|
+
re = RE2::Regexp.new('gOOD MORNING', :case_sensitive => false)
|
28
|
+
expect(RE2.Replace("Good morning", re, "hi")).to eq("hi")
|
29
|
+
end
|
30
|
+
|
31
|
+
if String.method_defined?(:encoding)
|
32
|
+
it "preserves the original string's encoding" do
|
33
|
+
original = "Foo"
|
34
|
+
replacement = RE2.Replace(original, "oo", "ah")
|
35
|
+
expect(original.encoding).to eq(replacement.encoding)
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
describe "#GlobalReplace" do
|
41
|
+
it "replaces every occurrence of a pattern" do
|
42
|
+
expect(RE2.GlobalReplace("woo", "o", "a")).to eq("waa")
|
43
|
+
end
|
44
|
+
|
45
|
+
it "performs replacement based on regular expressions" do
|
46
|
+
expect(RE2.GlobalReplace("woohoo", "o+", "e")).to eq("wehe")
|
47
|
+
end
|
48
|
+
|
49
|
+
it "supports flags in patterns" do
|
50
|
+
expect(RE2.GlobalReplace("Robert", "(?i)r", "w")).to eq("wobewt")
|
51
|
+
end
|
52
|
+
|
53
|
+
it "does not perform replacement in-place" do
|
54
|
+
name = "Robert"
|
55
|
+
replacement = RE2.GlobalReplace(name, "(?i)R", "w")
|
56
|
+
expect(name).to_not equal(replacement)
|
57
|
+
end
|
58
|
+
|
59
|
+
it "supports passing an RE2::Regexp as the pattern" do
|
60
|
+
re = RE2::Regexp.new('wo{2,}')
|
61
|
+
expect(RE2.GlobalReplace("woowooo", re, "miaow")).to eq("miaowmiaow")
|
62
|
+
end
|
63
|
+
|
64
|
+
it "respects any passed RE2::Regexp's flags" do
|
65
|
+
re = RE2::Regexp.new('gOOD MORNING', :case_sensitive => false)
|
66
|
+
expect(RE2.GlobalReplace("Good morning Good morning", re, "hi")).to eq("hi hi")
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
70
|
+
describe "#QuoteMeta" do
|
71
|
+
it "escapes a string so it can be used as a regular expression" do
|
72
|
+
expect(RE2.QuoteMeta("1.5-2.0?")).to eq('1\.5\-2\.0\?')
|
73
|
+
end
|
74
|
+
end
|
75
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
require "re2"
|
2
|
+
|
3
|
+
RSpec.configure do |config|
|
4
|
+
config.expect_with :rspec do |expectations|
|
5
|
+
expectations.include_chain_clauses_in_custom_matcher_descriptions = true
|
6
|
+
end
|
7
|
+
|
8
|
+
config.mock_with :rspec do |mocks|
|
9
|
+
mocks.verify_partial_doubles = true
|
10
|
+
end
|
11
|
+
|
12
|
+
config.filter_run :focus
|
13
|
+
config.run_all_when_everything_filtered = true
|
14
|
+
config.disable_monkey_patching!
|
15
|
+
config.warnings = true
|
16
|
+
config.default_formatter = 'doc' if config.files_to_run.one?
|
17
|
+
config.order = :random
|
18
|
+
Kernel.srand config.seed
|
19
|
+
end
|
metadata
ADDED
@@ -0,0 +1,123 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: re2
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 2.0.0
|
5
|
+
platform: aarch64-linux
|
6
|
+
authors:
|
7
|
+
- Paul Mucur
|
8
|
+
- Stan Hu
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2023-09-13 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.1
|
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.1
|
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.3.0
|
35
|
+
type: :development
|
36
|
+
prerelease: false
|
37
|
+
version_requirements: !ruby/object:Gem::Requirement
|
38
|
+
requirements:
|
39
|
+
- - "~>"
|
40
|
+
- !ruby/object:Gem::Version
|
41
|
+
version: 1.3.0
|
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, "an efficient, principled regular expression library".
|
57
|
+
email:
|
58
|
+
executables: []
|
59
|
+
extensions: []
|
60
|
+
extra_rdoc_files: []
|
61
|
+
files:
|
62
|
+
- ".rspec"
|
63
|
+
- Gemfile
|
64
|
+
- LICENSE.txt
|
65
|
+
- README.md
|
66
|
+
- Rakefile
|
67
|
+
- dependencies.yml
|
68
|
+
- ext/re2/extconf.rb
|
69
|
+
- ext/re2/re2.cc
|
70
|
+
- ext/re2/recipes.rb
|
71
|
+
- lib/2.6/re2.so
|
72
|
+
- lib/2.7/re2.so
|
73
|
+
- lib/3.0/re2.so
|
74
|
+
- lib/3.1/re2.so
|
75
|
+
- lib/3.2/re2.so
|
76
|
+
- lib/re2.rb
|
77
|
+
- lib/re2/scanner.rb
|
78
|
+
- lib/re2/string.rb
|
79
|
+
- lib/re2/version.rb
|
80
|
+
- re2.gemspec
|
81
|
+
- spec/kernel_spec.rb
|
82
|
+
- spec/re2/match_data_spec.rb
|
83
|
+
- spec/re2/regexp_spec.rb
|
84
|
+
- spec/re2/scanner_spec.rb
|
85
|
+
- spec/re2/set_spec.rb
|
86
|
+
- spec/re2/string_spec.rb
|
87
|
+
- spec/re2_spec.rb
|
88
|
+
- spec/spec_helper.rb
|
89
|
+
homepage: https://github.com/mudge/re2
|
90
|
+
licenses:
|
91
|
+
- BSD-3-Clause
|
92
|
+
metadata: {}
|
93
|
+
post_install_message:
|
94
|
+
rdoc_options: []
|
95
|
+
require_paths:
|
96
|
+
- lib
|
97
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
98
|
+
requirements:
|
99
|
+
- - ">="
|
100
|
+
- !ruby/object:Gem::Version
|
101
|
+
version: '2.6'
|
102
|
+
- - "<"
|
103
|
+
- !ruby/object:Gem::Version
|
104
|
+
version: 3.3.dev
|
105
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
106
|
+
requirements:
|
107
|
+
- - ">="
|
108
|
+
- !ruby/object:Gem::Version
|
109
|
+
version: '0'
|
110
|
+
requirements: []
|
111
|
+
rubygems_version: 3.3.26
|
112
|
+
signing_key:
|
113
|
+
specification_version: 4
|
114
|
+
summary: Ruby bindings to re2.
|
115
|
+
test_files:
|
116
|
+
- spec/spec_helper.rb
|
117
|
+
- spec/re2_spec.rb
|
118
|
+
- spec/kernel_spec.rb
|
119
|
+
- spec/re2/regexp_spec.rb
|
120
|
+
- spec/re2/match_data_spec.rb
|
121
|
+
- spec/re2/string_spec.rb
|
122
|
+
- spec/re2/set_spec.rb
|
123
|
+
- spec/re2/scanner_spec.rb
|