re2 0.0.3 → 0.0.4

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.
Files changed (4) hide show
  1. data/README.md +12 -11
  2. data/ext/re2/re2.cc +343 -400
  3. data/test/re2_test.rb +68 -110
  4. metadata +4 -4
@@ -10,19 +10,15 @@ require "test/unit"
10
10
 
11
11
  class RE2Test < Test::Unit::TestCase
12
12
  def test_interface
13
- assert_respond_to RE2, :FullMatch
14
- assert_respond_to RE2, :FullMatchN
15
- assert_respond_to RE2, :PartialMatch
16
- assert_respond_to RE2, :PartialMatchN
17
13
  assert_respond_to RE2, :Replace
18
14
  assert_respond_to RE2, :GlobalReplace
19
15
  assert_respond_to RE2, :QuoteMeta
20
- assert_respond_to RE2, :escape
21
- assert_respond_to RE2, :quote
22
- assert_respond_to RE2, :new
23
- assert_respond_to RE2, :compile
16
+ assert_respond_to RE2::Regexp, :escape
17
+ assert_respond_to RE2::Regexp, :quote
18
+ assert_respond_to RE2::Regexp, :new
19
+ assert_respond_to RE2::Regexp, :compile
24
20
 
25
- r = RE2.new('woo')
21
+ r = RE2::Regexp.new('woo')
26
22
  assert_respond_to r, :ok?
27
23
  assert_respond_to r, :options
28
24
  assert_respond_to r, :error
@@ -56,82 +52,16 @@ class RE2Test < Test::Unit::TestCase
56
52
 
57
53
  def test_global_re2
58
54
  r = RE2('w(o)(o)')
59
- assert_kind_of RE2, r
55
+ assert_kind_of RE2::Regexp, r
60
56
  assert_respond_to r, :ok?
61
57
  end
62
58
 
63
59
  def test_re2_compile
64
- r = RE2.compile('w(o)(o)')
65
- assert_kind_of RE2, r
60
+ r = RE2::Regexp.compile('w(o)(o)')
61
+ assert_kind_of RE2::Regexp, r
66
62
  assert_respond_to r, :ok?
67
63
  end
68
64
 
69
- def test_full_match
70
- assert RE2::FullMatch("woo", "woo")
71
- assert RE2::FullMatch("woo", "wo+")
72
- assert RE2::FullMatch("woo", "woo?")
73
- assert RE2::FullMatch("woo", "wo{2}")
74
- assert !RE2::FullMatch("woo", "wowzer")
75
- end
76
-
77
- def test_full_match_with_compiled_pattern
78
- r = RE2.new("woo")
79
- assert RE2::FullMatch("woo", r)
80
- assert !RE2::FullMatch("wowzer", r)
81
-
82
- assert RE2::FullMatch("woo", RE2("woo"))
83
- assert RE2::FullMatch("woo", RE2("wo+"))
84
- assert RE2::FullMatch("woo", RE2("woo?"))
85
- assert RE2::FullMatch("woo", RE2("wo{2}"))
86
- assert !RE2::FullMatch("woo", RE2("wowzer"))
87
- end
88
-
89
- def test_full_match_n
90
- assert_equal ["oo"], RE2::FullMatchN("woo", "w(oo)")
91
- assert_equal ["12"], RE2::FullMatchN("woo12w", 'woo(\d{2})w')
92
- assert_equal [nil, "1", "234"], RE2::FullMatchN("w1234", 'w(a?)(\d)(\d+)')
93
- assert_nil RE2::FullMatchN("bob", 'w(\d+)')
94
- end
95
-
96
- def test_full_match_n_with_compiled_pattern
97
- assert_equal ["oo"], RE2::FullMatchN("woo", RE2.new("w(oo)"))
98
- assert_equal ["12"], RE2::FullMatchN("woo12w", RE2.new('woo(\d{2})w'))
99
- assert_equal [nil, "1", "234"], RE2::FullMatchN("w1234", RE2.new('w(a?)(\d)(\d+)'))
100
- assert_nil RE2::FullMatchN("bob", RE2.new('w(\d+)'))
101
- end
102
-
103
- def test_partial_match
104
- assert RE2::PartialMatch("woo", "oo")
105
- assert RE2::PartialMatch("woo", "oo?")
106
- assert RE2::PartialMatch("woo", "o{2}")
107
- assert !RE2::PartialMatch("woo", "ha")
108
- end
109
-
110
- def test_partial_match_with_compiled_pattern
111
- r = RE2.new("woo")
112
- assert RE2::PartialMatch("woo", r)
113
- assert !RE2::PartialMatch("wowzer", r)
114
-
115
- assert RE2::PartialMatch("woo", RE2("oo"))
116
- assert RE2::PartialMatch("woo", RE2("oo?"))
117
- assert RE2::PartialMatch("woo", RE2("o{2}"))
118
- assert !RE2::PartialMatch("woo", RE2("ha"))
119
- end
120
-
121
- def test_partial_match_n
122
- assert_equal ["oo"], RE2::PartialMatchN("awooa", "w(oo)")
123
- assert_equal ["12"], RE2::PartialMatchN("awoo12wa", 'woo(\d{2})w')
124
- assert_equal [nil, "1", "234"], RE2::PartialMatchN("aw1234a", 'w(a?)(\d)(\d+)')
125
- assert_nil RE2::PartialMatchN("bob", 'w(\d+)')
126
- end
127
-
128
- def test_partial_match_n_with_compiled_pattern
129
- assert_equal ["oo"], RE2::PartialMatchN("awooa", RE2.new("w(oo)"))
130
- assert_equal ["12"], RE2::PartialMatchN("awoo12wa", RE2.new('woo(\d{2})w'))
131
- assert_equal [nil, "1", "234"], RE2::PartialMatchN("aw1234a", RE2.new('w(a?)(\d)(\d+)'))
132
- assert_nil RE2::PartialMatchN("bob", RE2.new('w(\d+)'))
133
- end
134
-
135
65
  def test_replace
136
66
  assert_equal "wao", RE2::Replace("woo", "o", "a")
137
67
  assert_equal "hoo", RE2::Replace("woo", "w", "h")
@@ -159,50 +89,78 @@ class RE2Test < Test::Unit::TestCase
159
89
  end
160
90
 
161
91
  def test_compiling
162
- r = RE2.new("woo")
92
+ r = RE2::Regexp.new("woo")
163
93
  assert r.ok?
164
- assert_equal "/woo/", r.inspect
94
+ assert_equal "#<RE2::Regexp /woo/>", r.inspect
165
95
  assert_equal "woo", r.to_s
166
96
  end
167
97
 
168
98
  def test_number_of_capturing_groups
169
- assert_equal 3, RE2.new('(a)(b)(c)').number_of_capturing_groups
170
- assert_equal 0, RE2.new('abc').number_of_capturing_groups
171
- assert_equal 2, RE2.new('a((b)c)').number_of_capturing_groups
99
+ assert_equal 3, RE2('(a)(b)(c)').number_of_capturing_groups
100
+ assert_equal 0, RE2('abc').number_of_capturing_groups
101
+ assert_equal 2, RE2('a((b)c)').number_of_capturing_groups
172
102
  end
173
103
 
174
104
  def test_matching_all_subpatterns
175
- assert_equal ["woo", "o", "o"], RE2.new('w(o)(o)').match('woo')
176
- assert_equal ["ab", nil, "a", "b"], RE2.new('(\d?)(a)(b)').match('ab')
105
+ assert_equal ["woo", "o", "o"], RE2('w(o)(o)').match('woo').to_a
106
+ assert_equal ["ab", nil, "a", "b"], RE2('(\d?)(a)(b)').match('ab').to_a
107
+ end
108
+
109
+ def test_matchdata
110
+ r = RE2('(\d+)')
111
+ text = "bob 123"
112
+ m = r.match(text)
113
+ assert_kind_of RE2::MatchData, m
114
+ assert_respond_to m, :string
115
+ assert_respond_to m, :size
116
+ assert_respond_to m, :length
117
+ assert_respond_to m, :regexp
118
+ assert_respond_to m, :to_a
119
+ assert_respond_to m, :[]
120
+ assert_equal r, m.regexp
121
+ assert_equal text, m.string
122
+ assert m.string.frozen?
123
+ assert_not_equal m.string.object_id, text.object_id
124
+ assert_equal '#<RE2::MatchData "123" 1:"123">', m.inspect
125
+ assert_equal "123", m.to_s
126
+ assert_equal "123", m[0]
127
+ assert_equal "123", m[1]
128
+ assert_equal ["123"], m[0, 1]
129
+ assert_equal ["123", "123"], m[0, 2]
130
+ assert_equal ["123"], m[0...1]
131
+ assert_equal ["123", "123"], m[0..1]
132
+ m1, m2 = *r.match(text)
133
+ assert_equal "123", m1
134
+ assert_equal "123", m2
177
135
  end
178
136
 
179
137
  def test_matching_no_subpatterns
180
- assert RE2.new('woo').match('woo', 0)
181
- assert !RE2.new('bob').match('woo', 0)
182
- assert RE2.new('woo').match?('woo')
183
- assert !RE2.new('bob').match?('woo')
184
- assert RE2.new('woo') =~ 'woo'
185
- assert !(RE2.new('bob') =~ 'woo')
186
- assert !(RE2.new('woo') !~ 'woo')
187
- assert RE2.new('bob') !~ 'woo'
188
- assert RE2.new('woo') === 'woo'
189
- assert !(RE2.new('bob') === 'woo')
138
+ assert RE2('woo').match('woo', 0)
139
+ assert !RE2('bob').match('woo', 0)
140
+ assert RE2('woo').match?('woo')
141
+ assert !RE2('bob').match?('woo')
142
+ assert RE2('woo') =~ 'woo'
143
+ assert !(RE2('bob') =~ 'woo')
144
+ assert !(RE2('woo') !~ 'woo')
145
+ assert RE2('bob') !~ 'woo'
146
+ assert RE2('woo') === 'woo'
147
+ assert !(RE2('bob') === 'woo')
190
148
  end
191
149
 
192
150
  def test_matching_some_sub_patterns
193
- assert_equal ["woo", "o"], RE2.new('w(o)(o)').match('woo', 1)
194
- assert_equal ["woo", "o", "o"], RE2.new('w(o)(o)').match('woo', 2)
195
- assert_equal ["woo", "o", "o", nil], RE2.new('w(o)(o)').match('woo', 3)
196
- assert_equal ["w", nil], RE2.new('w(o)?(o)?').match('w', 1)
197
- assert_equal ["w", nil, nil], RE2.new('w(o)?(o)?').match('w', 2)
198
- assert_equal ["w", nil, nil, nil], RE2.new('w(o)?(o)?').match('w', 3)
151
+ assert_equal ["woo", "o"], RE2('w(o)(o)').match('woo', 1).to_a
152
+ assert_equal ["woo", "o", "o"], RE2('w(o)(o)').match('woo', 2).to_a
153
+ assert_equal ["woo", "o", "o", nil], RE2('w(o)(o)').match('woo', 3).to_a
154
+ assert_equal ["w", nil], RE2('w(o)?(o)?').match('w', 1).to_a
155
+ assert_equal ["w", nil, nil], RE2('w(o)?(o)?').match('w', 2).to_a
156
+ assert_equal ["w", nil, nil, nil], RE2('w(o)?(o)?').match('w', 3).to_a
199
157
  end
200
158
 
201
159
  def test_compiling_with_options
202
- r = RE2.new("woo", :case_sensitive => false)
160
+ r = RE2("woo", :case_sensitive => false)
203
161
  assert r.ok?
204
- assert RE2::FullMatch("woo", r)
205
- assert RE2::FullMatch("WOO", r)
162
+ assert r =~ "woo"
163
+ assert r =~ "WOO"
206
164
  assert !r.options[:case_sensitive]
207
165
  assert r.case_insensitive?
208
166
  assert r.casefold?
@@ -212,7 +170,7 @@ class RE2Test < Test::Unit::TestCase
212
170
  end
213
171
 
214
172
  def test_replace_with_re2
215
- r = RE2.new("wo{2}")
173
+ r = RE2("wo{2}")
216
174
  assert_equal "miaow", RE2::Replace("woo", r, "miaow")
217
175
 
218
176
  assert_equal "wao", RE2::Replace("woo", RE2("o"), "a")
@@ -223,7 +181,7 @@ class RE2Test < Test::Unit::TestCase
223
181
  end
224
182
 
225
183
  def test_global_replace_with_re2
226
- r = RE2.new("o")
184
+ r = RE2("o")
227
185
  assert_equal "wii", RE2::GlobalReplace("woo", r, "i")
228
186
 
229
187
  assert_equal "waa", RE2::GlobalReplace("woo", RE2("o"), "a")
@@ -233,18 +191,18 @@ class RE2Test < Test::Unit::TestCase
233
191
 
234
192
  def test_quote_meta
235
193
  assert_equal "1\\.5\\-2\\.0\\?", RE2::QuoteMeta("1.5-2.0?")
236
- assert_equal "1\\.5\\-2\\.0\\?", RE2.escape("1.5-2.0?")
237
- assert_equal "1\\.5\\-2\\.0\\?", RE2.quote("1.5-2.0?")
194
+ assert_equal "1\\.5\\-2\\.0\\?", RE2::Regexp.escape("1.5-2.0?")
195
+ assert_equal "1\\.5\\-2\\.0\\?", RE2::Regexp.quote("1.5-2.0?")
238
196
  end
239
197
 
240
198
  def test_re2_error
241
- r = RE2.new("woo")
199
+ r = RE2("woo")
242
200
  assert_equal "", r.error
243
201
  assert_equal "", r.error_arg
244
202
  end
245
203
 
246
204
  def test_re2_error_with_error
247
- r = RE2.new("wo(o", :log_errors => false)
205
+ r = RE2("wo(o", :log_errors => false)
248
206
  assert !r.ok?
249
207
  assert_equal "missing ): wo(o", r.error
250
208
  assert_equal "wo(o", r.error_arg
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: re2
3
3
  version: !ruby/object:Gem::Version
4
- hash: 25
4
+ hash: 23
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
8
  - 0
9
- - 3
10
- version: 0.0.3
9
+ - 4
10
+ version: 0.0.4
11
11
  platform: ruby
12
12
  authors:
13
13
  - Paul Mucur
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2010-07-29 00:00:00 +01:00
18
+ date: 2010-08-02 00:00:00 +01:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency