re2 2.0.0.beta1-x64-mingw32
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 +13 -0
- data/LICENSE.txt +28 -0
- data/README.md +239 -0
- data/Rakefile +155 -0
- data/dependencies.yml +9 -0
- data/ext/re2/extconf.rb +384 -0
- data/ext/re2/re2.cc +1889 -0
- data/ext/re2/recipes.rb +43 -0
- data/lib/2.7/re2.so +0 -0
- data/lib/3.0/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 +119 -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,119 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: re2
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 2.0.0.beta1
|
5
|
+
platform: x64-mingw32
|
6
|
+
authors:
|
7
|
+
- Paul Mucur
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2023-09-07 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: rake-compiler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 1.2.1
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 1.2.1
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake-compiler-dock
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: 1.3.0
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: 1.3.0
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rspec
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '3.2'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '3.2'
|
55
|
+
description: Ruby bindings to re2, "an efficient, principled regular expression library".
|
56
|
+
email:
|
57
|
+
executables: []
|
58
|
+
extensions: []
|
59
|
+
extra_rdoc_files: []
|
60
|
+
files:
|
61
|
+
- ".rspec"
|
62
|
+
- Gemfile
|
63
|
+
- LICENSE.txt
|
64
|
+
- README.md
|
65
|
+
- Rakefile
|
66
|
+
- dependencies.yml
|
67
|
+
- ext/re2/extconf.rb
|
68
|
+
- ext/re2/re2.cc
|
69
|
+
- ext/re2/recipes.rb
|
70
|
+
- lib/2.7/re2.so
|
71
|
+
- lib/3.0/re2.so
|
72
|
+
- lib/re2.rb
|
73
|
+
- lib/re2/scanner.rb
|
74
|
+
- lib/re2/string.rb
|
75
|
+
- lib/re2/version.rb
|
76
|
+
- re2.gemspec
|
77
|
+
- spec/kernel_spec.rb
|
78
|
+
- spec/re2/match_data_spec.rb
|
79
|
+
- spec/re2/regexp_spec.rb
|
80
|
+
- spec/re2/scanner_spec.rb
|
81
|
+
- spec/re2/set_spec.rb
|
82
|
+
- spec/re2/string_spec.rb
|
83
|
+
- spec/re2_spec.rb
|
84
|
+
- spec/spec_helper.rb
|
85
|
+
homepage: https://github.com/mudge/re2
|
86
|
+
licenses:
|
87
|
+
- BSD-3-Clause
|
88
|
+
metadata: {}
|
89
|
+
post_install_message:
|
90
|
+
rdoc_options: []
|
91
|
+
require_paths:
|
92
|
+
- lib
|
93
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
94
|
+
requirements:
|
95
|
+
- - ">="
|
96
|
+
- !ruby/object:Gem::Version
|
97
|
+
version: '2.7'
|
98
|
+
- - "<"
|
99
|
+
- !ruby/object:Gem::Version
|
100
|
+
version: 3.1.dev
|
101
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
102
|
+
requirements:
|
103
|
+
- - ">"
|
104
|
+
- !ruby/object:Gem::Version
|
105
|
+
version: 1.3.1
|
106
|
+
requirements: []
|
107
|
+
rubygems_version: 3.3.26
|
108
|
+
signing_key:
|
109
|
+
specification_version: 4
|
110
|
+
summary: Ruby bindings to re2.
|
111
|
+
test_files:
|
112
|
+
- spec/spec_helper.rb
|
113
|
+
- spec/re2_spec.rb
|
114
|
+
- spec/kernel_spec.rb
|
115
|
+
- spec/re2/regexp_spec.rb
|
116
|
+
- spec/re2/match_data_spec.rb
|
117
|
+
- spec/re2/string_spec.rb
|
118
|
+
- spec/re2/set_spec.rb
|
119
|
+
- spec/re2/scanner_spec.rb
|