to_regexp 0.2.0 → 0.2.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,15 @@
1
+ ---
2
+ !binary "U0hBMQ==":
3
+ metadata.gz: !binary |-
4
+ ODk4NmY5MWJhN2E3ZGNjNDg4ZTU1ZGM3NzFmYjBhODQzZmQ1MjkzOA==
5
+ data.tar.gz: !binary |-
6
+ ZmU5MTg2MGFjMWY4MjljMGYxMWVhZjkwN2RjNjc5ZDU0M2QwNjU5Mg==
7
+ !binary "U0hBNTEy":
8
+ metadata.gz: !binary |-
9
+ YTU0OGZiMmMyNjdjNjk1YjI2ZDRjYmRlMDNhYjA5MWQ0OGI0MDdjMDNlMWI5
10
+ MTBmMDgwNzFlY2U5ZDEzYmZlYWZjMjZiNjgwYTg2ODRjNzg2ODgzMjAwZWJj
11
+ NjlmNDIzODAzYTdiMjBlYmUwMGUyYmRkMDU4NGJkOTAzMWY0ZmM=
12
+ data.tar.gz: !binary |-
13
+ MzkwZGEyYTFlMzJkYjkzOTRkNDc5MjAzMzVlMmMyODRkODU3MDMzNjFmYTkx
14
+ YWVhNmM3MDAzY2ZhNTljYzFhNzE2ZWI1NWIzNTkzZjY5ODhkOTlhNmYzN2M4
15
+ Mjc5OWY2YTRkYjk2ZDY1YzNiM2ZjMTBiNDE3NTNjOWFhMmI0Yzg=
data/CHANGELOG CHANGED
@@ -1,3 +1,9 @@
1
+ 0.2.1 / 2013-05-21
2
+
3
+ * Bug fixes
4
+
5
+ * Make sure (for example) '/foo/imn'.to_regexp(detect: true) is detected as a case-insensitive, multiline, no-encoding regexp
6
+
1
7
  0.2.0 / 2013-02-13
2
8
 
3
9
  * Breaking changes
data/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013 Seamus Abshere
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -7,6 +7,13 @@ module ToRegexp
7
7
  end
8
8
 
9
9
  module String
10
+ class << self
11
+ def literal?(str)
12
+ REGEXP_DELIMITERS.none? { |s, e| str.start_with?(s) and str =~ /#{e}#{INLINE_OPTIONS}\z/ }
13
+ end
14
+ end
15
+
16
+ INLINE_OPTIONS = /[imxnesu]*/
10
17
  REGEXP_DELIMITERS = {
11
18
  '%r{' => '}',
12
19
  '/' => '/',
@@ -39,11 +46,11 @@ module ToRegexp
39
46
 
40
47
  return if options[:detect] and str == ''
41
48
 
42
- if options[:literal] or (options[:detect] and REGEXP_DELIMITERS.none? { |k, v| str.start_with?(k) and str.end_with?(v) })
49
+ if options[:literal] or (options[:detect] and ToRegexp::String.literal?(str))
43
50
  content = ::Regexp.escape str
44
- elsif delim_set = REGEXP_DELIMITERS.detect { |k, v| str.start_with?(k) }
45
- delim_start, delim_end = delim_set.map { |delim| ::Regexp.escape delim }
46
- /\A#{delim_start}(.*)#{delim_end}([^#{delim_end}]*)\z/u =~ str
51
+ elsif delim_set = REGEXP_DELIMITERS.detect { |k, _| str.start_with?(k) }
52
+ delim_start, delim_end = delim_set
53
+ /\A#{delim_start}(.*)#{delim_end}(#{INLINE_OPTIONS})\z/u =~ str
47
54
  content = $1
48
55
  inline_options = $2
49
56
  return unless content.is_a?(::String)
@@ -1,3 +1,3 @@
1
1
  module ToRegexp
2
- VERSION = "0.2.0"
2
+ VERSION = '0.2.1'
3
3
  end
@@ -35,7 +35,7 @@ class TestToRegexp < Test::Unit::TestCase
35
35
  end
36
36
 
37
37
  def test_005_multiline_and_ignore_case
38
- assert_equal 'bar', '/foo.*(bar)/mi'.to_regexp.match("foo\n\nbar").captures[0]
38
+ assert_equal 'bar', '/FOO.*(BAR)/mi'.to_regexp.match("foo\n\nbar").captures[0]
39
39
  end
40
40
 
41
41
  def test_006_cant_fix_garbled_input
@@ -116,6 +116,7 @@ class TestToRegexp < Test::Unit::TestCase
116
116
  def test_015_union
117
117
  assert_equal /penzance/, Regexp.union('penzance')
118
118
  assert_equal /skiing|sledding/, Regexp.union('skiing', 'sledding')
119
+ assert_equal /skiing|sledding/, Regexp.union(['skiing', 'sledding'])
119
120
  assert_equal /(?-mix:dogs)|(?i-mx:cats)/, Regexp.union(/dogs/, /cats/i)
120
121
  assert_equal /(?-mix:dogs)|(?i-mx:cats)/, Regexp.union('/dogs/', /cats/i)
121
122
  assert_equal /(?-mix:dogs)|(?i-mx:cats)/, Regexp.union(/dogs/, '/cats/i')
@@ -129,5 +130,62 @@ class TestToRegexp < Test::Unit::TestCase
129
130
  assert_equal %r{foo\\b}, 'foo\b'.to_regexp(detect: true)
130
131
  assert_equal %r{foo\b}, '/foo\b/'.to_regexp(detect: true)
131
132
  assert_equal %r{foo\\b/}, 'foo\b/'.to_regexp(detect: true)
133
+ assert_equal %r{foo\b}i, '/foo\b/i'.to_regexp(detect: true)
134
+ assert_equal %r{foo\\b/i}, 'foo\b/i'.to_regexp(detect: true)
135
+ assert_equal /FOO.*(BAR)/mi, '/FOO.*(BAR)/mi'.to_regexp(detect: true)
132
136
  end
137
+
138
+ # https://github.com/ruby/ruby/blob/trunk/test/ruby/test_regexp.rb#L474 "test_union2"
139
+ def test_mri_union2
140
+ assert_equal(/(?!)/, Regexp.union)
141
+ assert_equal(/foo/, Regexp.union(/foo/))
142
+ assert_equal(/foo/, Regexp.union([/foo/]))
143
+ assert_equal(/\t/, Regexp.union("\t"))
144
+ assert_equal(/(?-mix:\u3042)|(?-mix:\u3042)/, Regexp.union(/\u3042/, /\u3042/))
145
+ assert_equal("\u3041", "\u3041"[Regexp.union(/\u3042/, "\u3041")])
146
+ end
147
+
148
+ # https://github.com/ruby/ruby/blob/trunk/test/ruby/test_regexp.rb#L464 "test_try_convert"
149
+ def test_mri_try_convert
150
+ assert_equal(/re/, Regexp.try_convert(/re/))
151
+ assert_nil(Regexp.try_convert("re"))
152
+
153
+ o = Object.new
154
+ assert_nil(Regexp.try_convert(o))
155
+ def o.to_regexp() /foo/ end
156
+ assert_equal(/foo/, Regexp.try_convert(o))
157
+ end
158
+
159
+ # https://github.com/jruby/jruby/blob/master/spec/ruby/core/regexp/try_convert_spec.rb#L5
160
+ def test_jruby_returns_argument_if_given_regexp
161
+ assert_equal /foo/s, Regexp.try_convert(/foo/s)
162
+ end
163
+
164
+ # https://github.com/jruby/jruby/blob/master/spec/ruby/core/regexp/try_convert_spec.rb#L9
165
+ def test_jruby_returns_nil_if_given_arg_cant_be_converted
166
+ ['', 'glark', [], Object.new, :pat].each do |arg|
167
+ assert_equal nil, Regexp.try_convert(arg)
168
+ end
169
+ end
170
+
171
+ # https://github.com/jruby/jruby/blob/master/test/externals/ruby1.9/uri/test_common.rb#L32
172
+ def test_jruby_uri_common_regexp
173
+ assert_instance_of Regexp, URI.regexp
174
+ assert_instance_of Regexp, URI.regexp(['http'])
175
+ assert_equal URI.regexp, URI.regexp
176
+ assert_equal 'http://', 'x http:// x'.slice(URI.regexp)
177
+ assert_equal 'http://', 'x http:// x'.slice(URI.regexp(['http']))
178
+ assert_equal 'http://', 'x http:// x ftp://'.slice(URI.regexp(['http']))
179
+ assert_equal nil, 'http://'.slice(URI.regexp([]))
180
+ assert_equal nil, ''.slice(URI.regexp)
181
+ assert_equal nil, 'xxxx'.slice(URI.regexp)
182
+ assert_equal nil, ':'.slice(URI.regexp)
183
+ assert_equal 'From:', 'From:'.slice(URI.regexp)
184
+ end
185
+
186
+ # https://github.com/jruby/jruby/blob/master/spec/ruby/core/regexp/union_spec.rb#L14
187
+ def test_jruby_quotes_string_arguments
188
+ assert_equal /n|\./, Regexp.union("n", ".")
189
+ end
190
+
133
191
  end
metadata CHANGED
@@ -1,20 +1,18 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: to_regexp
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
5
- prerelease:
4
+ version: 0.2.1
6
5
  platform: ruby
7
6
  authors:
8
7
  - Seamus Abshere
9
8
  autorequire:
10
9
  bindir: bin
11
10
  cert_chain: []
12
- date: 2013-02-13 00:00:00.000000000 Z
11
+ date: 2013-05-21 00:00:00.000000000 Z
13
12
  dependencies:
14
13
  - !ruby/object:Gem::Dependency
15
14
  name: ensure-encoding
16
15
  requirement: !ruby/object:Gem::Requirement
17
- none: false
18
16
  requirements:
19
17
  - - ! '>='
20
18
  - !ruby/object:Gem::Version
@@ -22,7 +20,6 @@ dependencies:
22
20
  type: :development
23
21
  prerelease: false
24
22
  version_requirements: !ruby/object:Gem::Requirement
25
- none: false
26
23
  requirements:
27
24
  - - ! '>='
28
25
  - !ruby/object:Gem::Version
@@ -30,7 +27,6 @@ dependencies:
30
27
  - !ruby/object:Gem::Dependency
31
28
  name: yard
32
29
  requirement: !ruby/object:Gem::Requirement
33
- none: false
34
30
  requirements:
35
31
  - - ! '>='
36
32
  - !ruby/object:Gem::Version
@@ -38,7 +34,6 @@ dependencies:
38
34
  type: :development
39
35
  prerelease: false
40
36
  version_requirements: !ruby/object:Gem::Requirement
41
- none: false
42
37
  requirements:
43
38
  - - ! '>='
44
39
  - !ruby/object:Gem::Version
@@ -55,6 +50,7 @@ files:
55
50
  - CHANGELOG
56
51
  - Gemfile
57
52
  - History.txt
53
+ - LICENSE
58
54
  - README.rdoc
59
55
  - Rakefile
60
56
  - lib/to_regexp.rb
@@ -64,27 +60,26 @@ files:
64
60
  - to_regexp.gemspec
65
61
  homepage: https://github.com/seamusabshere/to_regexp
66
62
  licenses: []
63
+ metadata: {}
67
64
  post_install_message:
68
65
  rdoc_options: []
69
66
  require_paths:
70
67
  - lib
71
68
  required_ruby_version: !ruby/object:Gem::Requirement
72
- none: false
73
69
  requirements:
74
70
  - - ! '>='
75
71
  - !ruby/object:Gem::Version
76
72
  version: '0'
77
73
  required_rubygems_version: !ruby/object:Gem::Requirement
78
- none: false
79
74
  requirements:
80
75
  - - ! '>='
81
76
  - !ruby/object:Gem::Version
82
77
  version: '0'
83
78
  requirements: []
84
79
  rubyforge_project: to_regexp
85
- rubygems_version: 1.8.25
80
+ rubygems_version: 2.0.3
86
81
  signing_key:
87
- specification_version: 3
82
+ specification_version: 4
88
83
  summary: Provides String#to_regexp
89
84
  test_files:
90
85
  - test/helper.rb