regexp-examples 0.5.3 → 0.5.4

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 9a3253848cbd5e95b1b662848d999c23863fcbbf
4
- data.tar.gz: b18197c5e6c64813fef50dbb35d1f8d73a9ca703
3
+ metadata.gz: 749811525558a012bc616a34cc04f017270d04e8
4
+ data.tar.gz: 31de4f7cbd8f7aed68d2c4efd370cfdc85f9bd0f
5
5
  SHA512:
6
- metadata.gz: 2d83e121338b0a2a70d4c9615f33571d782bb026c9fb231b72ae517f0b7a9b78e957874452358566514fac71c082c6d57bd57745f65777d60b1cccc67188e790
7
- data.tar.gz: 0ec1e6b521e9a5cf8e6a66ab0674d365829ef4096ece2ff5fb0501126e0f77d05b65b8d5d417f8ddcc03d741f51eb0c73ead5cd6fe0c1cdca72d684482faa232
6
+ metadata.gz: fbc3bf4111f29daec1c550dbdf03fc97fcb3fde5069a7a0259547d5df0e47972e3a112473f2a1a9c95788ec8a39c885b71a19d1b22717d15e674b71864d55020
7
+ data.tar.gz: 6082e8ed18458b1eca2c47b18cc3e3484a8cb93c1111215f3565578dada06fc2deb388fb3813cae24343c6e2d1c41cdc377359d87876bc14e8dc53ffa30b700d
data/README.md CHANGED
@@ -42,6 +42,7 @@ For more detail on this, see [configuration options](#configuration-options).
42
42
  * Control characters, e.g. `/\ca/`, `/\cZ/`, `/\C-9/`
43
43
  * Escape sequences, e.g. `/\x42/`, `/\x5word/`, `/#{"\x80".force_encoding("ASCII-8BIT")}/`
44
44
  * Unicode characters, e.g. `/\u0123/`, `/\uabcd/`, `/\u{789}/`
45
+ * Octal characters, e.g. `/\10/`, `/\177/`
45
46
  * **Arbitrarily complex combinations of all the above!**
46
47
 
47
48
  * Regexp options can also be used:
@@ -58,8 +59,6 @@ For more detail on this, see [configuration options](#configuration-options).
58
59
 
59
60
  * Conditional capture groups, such as `/(group1) (?(1)yes|no)`
60
61
 
61
- * The patterns: `/\10/` ... `/\77/` should match the octal representation of their character code, if there is no nth grouped subexpression. For example, `/\10/.examples` should return `["\x08"]`. Funnily enough, I did not think of this when writing my regexp parser.
62
-
63
62
  Using any of the following will raise a RegexpExamples::UnsupportedSyntax exception (until such time as they are implemented!):
64
63
 
65
64
  * POSIX bracket expressions, e.g. `/[[:alnum:]]/`, `/[[:space:]]/`
@@ -19,9 +19,16 @@ module RegexpExamples
19
19
  def find_backref_for(full_example, group_id)
20
20
  full_example.all_subgroups.detect do |subgroup|
21
21
  subgroup.group_id == group_id
22
- end || raise(RegexpExamples::BackrefNotFound)
23
- # TODO: Regex like /\10/ should match the octal representation of their character code,
24
- # if there is no nth grouped subexpression. For example, `/\10/.examples` should return `["\x08"]`
22
+ end || octal_char_for(group_id)
23
+ end
24
+
25
+ def octal_char_for(octal_chars)
26
+ # For octal characters in the range \10 - \177
27
+ if octal_chars =~ /\A[01]?[0-7]{1,2}\z/ && octal_chars.to_i >= 10
28
+ Integer(octal_chars, 8).chr
29
+ else
30
+ raise(RegexpExamples::BackrefNotFound)
31
+ end
25
32
  end
26
33
 
27
34
  end
@@ -77,7 +77,7 @@ module RegexpExamples
77
77
  def parse_after_backslash_group
78
78
  @current_position += 1
79
79
  case
80
- when rest_of_string =~ /\A(\d+)/
80
+ when rest_of_string =~ /\A(\d{1,3})/
81
81
  @current_position += ($1.length - 1) # In case of 10+ backrefs!
82
82
  group = parse_backreference_group($1)
83
83
  when rest_of_string =~ /\Ak<([^>]+)>/ # Named capture group
@@ -1,3 +1,3 @@
1
1
  module RegexpExamples
2
- VERSION = '0.5.3'
2
+ VERSION = '0.5.4'
3
3
  end
@@ -128,6 +128,13 @@ RSpec.describe Regexp, "#examples" do
128
128
  )
129
129
  end
130
130
 
131
+ context "for escaped octal characters" do
132
+ examples_exist_and_match(
133
+ /\10\20\30\40\50/,
134
+ /\177123/ # Should work for numbers up to 177
135
+ )
136
+ end
137
+
131
138
  context "for complex patterns" do
132
139
  # Longer combinations of the above
133
140
  examples_exist_and_match(
@@ -242,6 +249,13 @@ RSpec.describe Regexp, "#examples" do
242
249
  it { expect(/a{1}?/.examples).to eq ["", "a"] }
243
250
  end
244
251
 
252
+ context "backreferences and escaped octal combined" do
253
+ it do
254
+ expect(/(a)(b)(c)(d)(e)(f)(g)(h)(i)(j)? \10\9\8\7\6\5\4\3\2\1/.examples)
255
+ .to eq ["abcdefghi \x08ihgfedcba", "abcdefghij jihgfedcba"]
256
+ end
257
+ end
258
+
245
259
  context "max_repeater_variance config option" do
246
260
  it do
247
261
  expect(/a+/.examples(max_repeater_variance: 5))
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: regexp-examples
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.3
4
+ version: 0.5.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tom Lord
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-02-10 00:00:00.000000000 Z
11
+ date: 2015-02-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -86,7 +86,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
86
86
  version: '0'
87
87
  requirements: []
88
88
  rubyforge_project:
89
- rubygems_version: 2.2.2
89
+ rubygems_version: 2.4.5
90
90
  signing_key:
91
91
  specification_version: 4
92
92
  summary: Extends the Regexp class with '#examples'