regexp-examples 1.4.4 → 1.5.0

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: c1b039b345ad1978b9d96b4d87d2e709326f9a45
4
- data.tar.gz: fc3578734d1c91a01030d864ab240252600df089
2
+ SHA256:
3
+ metadata.gz: 905cc28db8e824ca4bdfed6a6b3e304af0fa76de572a7fd673c4e64074f758a0
4
+ data.tar.gz: 42bcbba65b38998244b26d7a1a5c20f8212094ab204860381442d56d56760989
5
5
  SHA512:
6
- metadata.gz: 1eb398e9341eb8fc06a97a1b3a27c8b0d5efafd6b049f76f454efb13516fa29b1047f51b0646e14ff2888ee16fbed738dac53d1042bd8ccb180064e5c3ce702d
7
- data.tar.gz: cc01ceb7567b6e77f37a369dc99e429ccd3389a72393711554a959dcc6cc6d72292ffb7e0906768898b593d1dceac9a0a0f557552ca34dc9c259cb679fe7b1ca
6
+ metadata.gz: fa88b19665fbf46251d7226369d1b27b35e19a61deb354df5d3fef3cab0a09a86c3214767f52410a39a384953c8e488ae1c51d67fe382351d76b2eaae0f09bdb
7
+ data.tar.gz: 34572d245792daa0cbe168e110592ba76174c6b986099db2a7f1591c2d9b0bb095f8869bf4b9cdfe1afab19648a0cd2354eff322e6b45179b2bdd21bea56dd9d
data/.gitignore CHANGED
@@ -14,3 +14,5 @@
14
14
  mkmf.log
15
15
  tags
16
16
  /coverage/
17
+
18
+ /spec/examples.txt
data/.rspec CHANGED
@@ -1,2 +1,2 @@
1
1
  --color
2
- --require spec_helper
2
+ --require gem_helper
@@ -0,0 +1 @@
1
+ 2.6.3
@@ -1,12 +1,9 @@
1
1
  language: ruby
2
2
  rvm:
3
- - 2.0.0
4
- - 2.1.10
5
- - 2.2.10
6
- - 2.3.8
7
3
  - 2.4.5
8
- - 2.5.3
9
- - 2.6.0
4
+ - 2.5.5
5
+ - 2.6.2 # Uses unicode 12.0.0
6
+ - 2.6.3 # Uses unicode 12.1.0
10
7
  - ruby-head
11
8
  matrix:
12
9
  allow_failures:
data/README.md CHANGED
@@ -52,21 +52,18 @@ Obviously, you will get different (random) results if you try these yourself!
52
52
  ```
53
53
 
54
54
  ## Supported ruby versions
55
- * MRI 2.0.x
56
- * MRI 2.1.x
57
- * MRI 2.2.x
58
- * MRI 2.3.x
59
- * MRI 2.4.x
60
- * MRI 2.5.x
61
- * MRI 2.6.x
62
-
63
- MRI 1.9.3 are not supported. This is primarily because MRI 2.0.0 introduced a new
64
- regexp engine (`Oniguruma` was replaced by `Onigmo`). Whilst *most* of this gem could
65
- be made to work with MRI 1.9.x (or even 1.8.x), I feel the changes are too significant
66
- to implement backwards compatability (especially since [long-term support for MRI
67
- 1.9.3 has now ended](https://www.ruby-lang.org/en/news/2014/01/10/ruby-1-9-3-will-end-on-2015/)).
68
-
69
- For example, named properties (e.g. `/\p{Alpha}/`) are illegal syntax on MRI 1.9.3.
55
+ MRI 2.4.0 (oldest non-[EOL](https://www.ruby-lang.org/en/news/2019/03/31/support-of-ruby-2-3-has-ended/) version) --> 2.6.3 (latest stable version)
56
+
57
+ MRI 2.0.0 --> 2.3.x were supported until version `1.5.0` of this library. Support was dropped primarily
58
+ because of the need to use `RbConfig::CONFIG['UNICODE_VERSION']`, which was added to ruby version `2.4.0`.
59
+
60
+ MRI versions ≤ 1.9.3 were never supported by this library. This is primarily because MRI 2.0.0 introduced a new
61
+ regexp engine (`Oniguruma` was replaced by `Onigmo` -- For example, named properties like `/\p{Alpha}/`
62
+ are illegal syntax on MRI 1.9.3.). Whilst *most* of this gem could be made to work with MRI 1.9.x
63
+ (or even 1.8.x), I considered the changes too significant to implement backwards compatability
64
+ (especially since [long-term support for MRI 1.9.3 has long
65
+ ended](https://www.ruby-lang.org/en/news/2014/01/10/ruby-1-9-3-will-end-on-2015/)).
66
+
70
67
 
71
68
  Other implementations, such as JRuby, could probably work fine -
72
69
  but I haven't fully tried/tested it. Pull requests are welcome.
@@ -29,5 +29,4 @@ module CoreExtensions
29
29
  end
30
30
  end
31
31
 
32
- # Regexp#include is private for ruby 2.0 and below
33
- Regexp.send(:include, CoreExtensions::Regexp::Examples)
32
+ Regexp.include(CoreExtensions::Regexp::Examples)
@@ -3,7 +3,7 @@ module RegexpExamples
3
3
  # In a nutshell, this works by doing the following:
4
4
  # * Given a regex that contains a capute group and backreference, e.g. `/(a|b) \1/`
5
5
  # * After generating examples, the backreference is tored as a placeholder:
6
- # `["a __1__", "b __1__"]`
6
+ # `["a __BACKREF-PLACEHOLDER-1__", "b __BACKREF-PLACEHOLDER-1__"]`
7
7
  # * This class is used to fill in each placeholder accordingly:
8
8
  # `["a a", "b b"]`
9
9
  # * Also, beware of octal groups and cases where the backref invalidates the example!!
@@ -15,7 +15,7 @@ module RegexpExamples
15
15
 
16
16
  def substitute_backreferences(full_examples)
17
17
  full_examples.map do |full_example|
18
- # For instance, one "full example" from /(a|(b)) \2/: "a __2__"
18
+ # For instance, one "full example" from /(a|(b)) \2/: "a __BACKREF-PLACEHOLDER-2__"
19
19
  # should be rejected because the backref (\2) does not exist
20
20
  catch(:backref_not_found) do
21
21
  substitute_backrefs_one_at_a_time(full_example)
@@ -1,4 +1,6 @@
1
1
  require_relative 'parser_helpers/charset_negation_helper'
2
+ require_relative 'parser_helpers/parse_group_helper'
3
+ require_relative 'parser_helpers/parse_after_backslash_group_helper'
2
4
 
3
5
  module RegexpExamples
4
6
  # A "sub-parser", for char groups in a regular expression
@@ -13,6 +15,8 @@ module RegexpExamples
13
15
  # [[^:alpha:]&&[\n]a-c] - all of the above!!!! (should match "\n")
14
16
  class ChargroupParser
15
17
  include CharsetNegationHelper
18
+ include ParseGroupHelper
19
+ include ParseAfterBackslashGroupHelper
16
20
 
17
21
  attr_reader :regexp_string, :current_position
18
22
  alias length current_position
@@ -37,7 +41,6 @@ module RegexpExamples
37
41
  parse_after_ampersand
38
42
  else
39
43
  @charset.concat parse_checking_backlash
40
- @current_position += 1
41
44
  end
42
45
  end
43
46
 
@@ -79,15 +82,23 @@ module RegexpExamples
79
82
  @current_position += 1
80
83
  parse_after_backslash
81
84
  else
82
- [next_char]
85
+ r = [next_char]
86
+ @current_position += 1
87
+ r
83
88
  end
84
89
  end
85
90
 
86
91
  def parse_after_backslash
87
92
  if next_char == 'b'
93
+ @current_position += 1
88
94
  ["\b"]
95
+ elsif rest_of_string =~ /\Au(\h{4}|\{\h{1,4}\})/
96
+ @current_position += 1
97
+ parse_backslash_unicode_sequence(Regexp.last_match(1)).result.map(&:to_s)
89
98
  else
90
- CharSets::BackslashCharMap.fetch(next_char, [next_char])
99
+ char = CharSets::BackslashCharMap.fetch(next_char, [next_char])
100
+ @current_position += 1
101
+ char
91
102
  end
92
103
  end
93
104
 
@@ -117,13 +128,18 @@ module RegexpExamples
117
128
  end
118
129
 
119
130
  def parse_after_hyphen
120
- if regexp_string[@current_position + 1] == ']' # e.g. /[abc-]/ -- not a range!
131
+ r = if regexp_string[@current_position + 1] == ']' # e.g. /[abc-]/ -- not a range!
132
+ @current_position += 1
121
133
  @charset << '-'
134
+ elsif rest_of_string =~ /\A-\\u(\h{4}|\{\h{1,4}\})/
135
+ @current_position += 3
136
+ char = parse_backslash_unicode_sequence(Regexp.last_match(1)).result.first.to_s
137
+ @charset.concat((@charset.last..char).to_a)
122
138
  else
123
139
  @current_position += 1
124
140
  @charset.concat((@charset.last..parse_checking_backlash.first).to_a)
125
141
  end
126
- @current_position += 1
142
+ r
127
143
  end
128
144
 
129
145
  def rest_of_string
@@ -181,10 +181,10 @@ module RegexpExamples
181
181
  # We substitute backreferences with PLACEHOLDERS. These are then, later,
182
182
  # replaced by the appropriate value. (See BackReferenceReplacer)
183
183
  # The simplest example is /(a) \1/ - So, we temporarily treat the "result"
184
- # of /\1/ as being "__1__". It later gets updated.
184
+ # of /\1/ as being "__BACKREF-PLACEHOLDER-1__". It later gets updated.
185
185
  class BackReferenceGroup
186
186
  include RandomResultBySample
187
- PLACEHOLDER_FORMAT = '__%s__'.freeze
187
+ PLACEHOLDER_FORMAT = '__BACKREF-PLACEHOLDER-%s__'.freeze
188
188
  attr_reader :id
189
189
  def initialize(id)
190
190
  @id = id
@@ -11,8 +11,7 @@ module RegexpExamples
11
11
  # These values were generated by: scripts/unicode_lister.rb
12
12
  # Note: Only the first 128 results are listed, for performance.
13
13
  # Also, some groups seem to have no matches (weird!)
14
- # (Don't care about ruby micro version number)
15
- STORE_FILENAME = "unicode_ranges_#{RUBY_VERSION[0..2]}.pstore".freeze
14
+ STORE_FILENAME = "unicode_ranges_#{RbConfig::CONFIG['UNICODE_VERSION']}.pstore".freeze
16
15
 
17
16
  attr_reader :range_store
18
17
 
@@ -30,10 +29,12 @@ module RegexpExamples
30
29
 
31
30
  private
32
31
 
32
+ # The method is written like this to future-proof it a little,
33
+ # i.e. the gem won't completely break for a new ruby version release
33
34
  def unicode_ranges_file
34
35
  db_path = File.join(__dir__, '../../db')
35
36
  Dir["#{db_path}/*.pstore"].sort.select do |file|
36
- file <= "#{db_path}/unicode_ranges_#{RUBY_VERSION[0..2]}.pstore"
37
+ file <= "#{db_path}/#{STORE_FILENAME}"
37
38
  end.last
38
39
  end
39
40
 
@@ -1,4 +1,4 @@
1
1
  # Gem version
2
2
  module RegexpExamples
3
- VERSION = '1.4.4'.freeze
3
+ VERSION = '1.5.0'.freeze
4
4
  end
@@ -13,10 +13,10 @@ Gem::Specification.new do |s|
13
13
  s.executables = s.files.grep(/^bin\//) { |f| File.basename(f) }
14
14
  s.test_files = s.files.grep(/^(test|spec|features)\//)
15
15
  s.require_paths = ['lib']
16
- s.homepage =
17
- 'http://rubygems.org/gems/regexp-examples'
18
- s.add_development_dependency 'bundler', '~> 1.7'
19
- s.add_development_dependency 'rake', '~> 10.0'
16
+ s.homepage = 'http://rubygems.org/gems/regexp-examples'
17
+ s.add_development_dependency 'bundler', '> 1.7'
18
+ s.add_development_dependency 'rake', '~> 12.0'
19
+ s.add_development_dependency 'pry', '~> 0.12.0'
20
20
  s.license = 'MIT'
21
- s.required_ruby_version = '>= 2.0.0'
21
+ s.required_ruby_version = '>= 2.4.0'
22
22
  end
@@ -0,0 +1,19 @@
1
+ require 'spec_helper'
2
+
3
+ require 'coveralls'
4
+ Coveralls.wear!
5
+
6
+ require './lib/regexp-examples.rb'
7
+ require 'helpers'
8
+ require 'pry'
9
+
10
+ # Several of these tests (intentionally) use "weird" regex patterns,
11
+ # that spam annoying warnings when running.
12
+ # E.g. warning: invalid back reference: /\k/
13
+ # and warning: character class has ']' without escape: /[]]/
14
+ # This config disables those warnings.
15
+ $VERBOSE = nil
16
+
17
+ RSpec.configure do |config|
18
+ config.include Helpers
19
+ end
@@ -72,6 +72,7 @@ RSpec.describe Regexp, '#examples' do
72
72
  /[abc]/,
73
73
  /[a-c]/,
74
74
  /[abc-e]/,
75
+ /[\u4e00-\u9fa5]/,
75
76
  /[^a-zA-Z]/,
76
77
  /[\w]/,
77
78
  /[]]/,
@@ -1,28 +1,30 @@
1
- require 'coveralls'
2
- Coveralls.wear!
3
-
4
- require './lib/regexp-examples.rb'
5
- require 'helpers'
6
- require 'pry'
7
-
8
- # Several of these tests (intentionally) use "weird" regex patterns,
9
- # that spam annoying warnings when running.
10
- # E.g. warning: invalid back reference: /\k/
11
- # and warning: character class has ']' without escape: /[]]/
12
- # This config disables those warnings.
13
- $VERBOSE = nil
14
-
1
+ # This file was generated by the `rspec --init` command. Conventionally, all
2
+ # specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
3
+ # The generated `.rspec` file contains `--require spec_helper` which will cause
4
+ # this file to always be loaded, without a need to explicitly require it in any
5
+ # files.
6
+ #
7
+ # Given that it is always loaded, you are encouraged to keep this file as
8
+ # light-weight as possible. Requiring heavyweight dependencies from this file
9
+ # will add to the boot time of your test suite on EVERY test run, even for an
10
+ # individual file that may not need all of that loaded. Instead, consider making
11
+ # a separate helper file that requires the additional dependencies and performs
12
+ # the additional setup, and require it from the spec files that actually need
13
+ # it.
14
+ #
15
+ # See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
15
16
  RSpec.configure do |config|
16
- config.include Helpers
17
-
17
+ # rspec-expectations config goes here. You can use an alternate
18
+ # assertion/expectation library such as wrong or the stdlib/minitest
19
+ # assertions if you prefer.
18
20
  config.expect_with :rspec do |expectations|
19
21
  # This option will default to `true` in RSpec 4. It makes the `description`
20
22
  # and `failure_message` of custom matchers include text for helper methods
21
23
  # defined using `chain`, e.g.:
22
- # be_bigger_than(2).and_smaller_than(4).description
23
- # # => "be bigger than 2 and smaller than 4"
24
+ # be_bigger_than(2).and_smaller_than(4).description
25
+ # # => "be bigger than 2 and smaller than 4"
24
26
  # ...rather than:
25
- # # => "be bigger than 2"
27
+ # # => "be bigger than 2"
26
28
  expectations.include_chain_clauses_in_custom_matcher_descriptions = true
27
29
  end
28
30
 
@@ -35,10 +37,60 @@ RSpec.configure do |config|
35
37
  mocks.verify_partial_doubles = true
36
38
  end
37
39
 
40
+ # This option will default to `:apply_to_host_groups` in RSpec 4 (and will
41
+ # have no way to turn it off -- the option exists only for backwards
42
+ # compatibility in RSpec 3). It causes shared context metadata to be
43
+ # inherited by the metadata hash of host groups and examples, rather than
44
+ # triggering implicit auto-inclusion in groups with matching metadata.
45
+ config.shared_context_metadata_behavior = :apply_to_host_groups
46
+
47
+ # This allows you to limit a spec run to individual examples or groups
48
+ # you care about by tagging them with `:focus` metadata. When nothing
49
+ # is tagged with `:focus`, all examples get run. RSpec also provides
50
+ # aliases for `it`, `describe`, and `context` that include `:focus`
51
+ # metadata: `fit`, `fdescribe` and `fcontext`, respectively.
52
+ config.filter_run_when_matching :focus
53
+
54
+ # Allows RSpec to persist some state between runs in order to support
55
+ # the `--only-failures` and `--next-failure` CLI options. We recommend
56
+ # you configure your source control system to ignore this file.
57
+ config.example_status_persistence_file_path = "spec/examples.txt"
58
+
59
+ # Limits the available syntax to the non-monkey patched syntax that is
60
+ # recommended. For more details, see:
61
+ # - http://rspec.info/blog/2012/06/rspecs-new-expectation-syntax/
62
+ # - http://www.teaisaweso.me/blog/2013/05/27/rspecs-new-message-expectation-syntax/
63
+ # - http://rspec.info/blog/2014/05/notable-changes-in-rspec-3/#zero-monkey-patching-mode
38
64
  config.disable_monkey_patching!
39
65
 
66
+ # This setting enables warnings. It's recommended, but in some cases may
67
+ # be too noisy due to issues in dependencies.
68
+ config.warnings = true
69
+
70
+ # Many RSpec users commonly either run the entire suite or an individual
71
+ # file, and it's useful to allow more verbose output when running an
72
+ # individual spec file.
73
+ if config.files_to_run.one?
74
+ # Use the documentation formatter for detailed output,
75
+ # unless a formatter has already been configured
76
+ # (e.g. via a command-line flag).
77
+ config.default_formatter = "doc"
78
+ end
79
+
40
80
  # Print the 10 slowest examples and example groups at the
41
81
  # end of the spec run, to help surface which specs are running
42
82
  # particularly slow.
43
- # config.profile_examples = 10
83
+ config.profile_examples = 10
84
+
85
+ # Run specs in random order to surface order dependencies. If you find an
86
+ # order dependency and want to debug it, you can fix the order by providing
87
+ # the seed, which is printed after each run.
88
+ # --seed 1234
89
+ config.order = :random
90
+
91
+ # Seed global randomization in this process using the `--seed` CLI option.
92
+ # Setting this allows you to use `--seed` to deterministically reproduce
93
+ # test failures related to randomization by passing the same `--seed` value
94
+ # as the one that triggered the failure.
95
+ Kernel.srand config.seed
44
96
  end
metadata CHANGED
@@ -1,27 +1,27 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: regexp-examples
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.4.4
4
+ version: 1.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tom Lord
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-12-27 00:00:00.000000000 Z
11
+ date: 2019-07-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - "~>"
17
+ - - ">"
18
18
  - !ruby/object:Gem::Version
19
19
  version: '1.7'
20
20
  type: :development
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - "~>"
24
+ - - ">"
25
25
  - !ruby/object:Gem::Version
26
26
  version: '1.7'
27
27
  - !ruby/object:Gem::Dependency
@@ -30,14 +30,28 @@ dependencies:
30
30
  requirements:
31
31
  - - "~>"
32
32
  - !ruby/object:Gem::Version
33
- version: '10.0'
33
+ version: '12.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '12.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: pry
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: 0.12.0
34
48
  type: :development
35
49
  prerelease: false
36
50
  version_requirements: !ruby/object:Gem::Requirement
37
51
  requirements:
38
52
  - - "~>"
39
53
  - !ruby/object:Gem::Version
40
- version: '10.0'
54
+ version: 0.12.0
41
55
  description: Regexp#examples returns a list of "all" strings that are matched by the
42
56
  regex. Regexp#random_example returns one, random string that matches.
43
57
  email: lord.thom@gmail.com
@@ -48,17 +62,17 @@ files:
48
62
  - ".gitignore"
49
63
  - ".rspec"
50
64
  - ".rubocop.yml"
65
+ - ".ruby-version"
51
66
  - ".travis.yml"
52
67
  - Gemfile
53
68
  - LICENSE.txt
54
69
  - README.md
55
70
  - Rakefile
56
- - db/unicode_ranges_2.0.pstore
57
- - db/unicode_ranges_2.2.pstore
58
- - db/unicode_ranges_2.3.pstore
59
- - db/unicode_ranges_2.4.pstore
60
- - db/unicode_ranges_2.5.pstore
61
- - db/unicode_ranges_2.6.pstore
71
+ - db/unicode_ranges_10.0.0.pstore
72
+ - db/unicode_ranges_11.0.0.pstore
73
+ - db/unicode_ranges_12.0.0.pstore
74
+ - db/unicode_ranges_12.1.0.pstore
75
+ - db/unicode_ranges_9.0.0.pstore
62
76
  - lib/core_extensions/regexp/examples.rb
63
77
  - lib/regexp-examples.rb
64
78
  - lib/regexp-examples/backreferences.rb
@@ -80,6 +94,7 @@ files:
80
94
  - regexp-examples.gemspec
81
95
  - scripts/unicode_lister.rb
82
96
  - spec/config_spec.rb
97
+ - spec/gem_helper.rb
83
98
  - spec/helpers.rb
84
99
  - spec/regexp-examples_spec.rb
85
100
  - spec/regexp-examples_spec_2.4.1.rb
@@ -97,20 +112,20 @@ required_ruby_version: !ruby/object:Gem::Requirement
97
112
  requirements:
98
113
  - - ">="
99
114
  - !ruby/object:Gem::Version
100
- version: 2.0.0
115
+ version: 2.4.0
101
116
  required_rubygems_version: !ruby/object:Gem::Requirement
102
117
  requirements:
103
118
  - - ">="
104
119
  - !ruby/object:Gem::Version
105
120
  version: '0'
106
121
  requirements: []
107
- rubyforge_project:
108
- rubygems_version: 2.6.14.1
122
+ rubygems_version: 3.0.3
109
123
  signing_key:
110
124
  specification_version: 4
111
125
  summary: Extends the Regexp class with '#examples' and '#random_example'
112
126
  test_files:
113
127
  - spec/config_spec.rb
128
+ - spec/gem_helper.rb
114
129
  - spec/helpers.rb
115
130
  - spec/regexp-examples_spec.rb
116
131
  - spec/regexp-examples_spec_2.4.1.rb
Binary file
Binary file