regexp-examples 0.5.3 → 0.5.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.
- checksums.yaml +4 -4
- data/README.md +1 -2
- data/lib/regexp-examples/backreferences.rb +10 -3
- data/lib/regexp-examples/parser.rb +1 -1
- data/lib/regexp-examples/version.rb +1 -1
- data/spec/regexp-examples_spec.rb +14 -0
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 749811525558a012bc616a34cc04f017270d04e8
|
4
|
+
data.tar.gz: 31de4f7cbd8f7aed68d2c4efd370cfdc85f9bd0f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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 ||
|
23
|
-
|
24
|
-
|
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
|
@@ -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.
|
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-
|
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.
|
89
|
+
rubygems_version: 2.4.5
|
90
90
|
signing_key:
|
91
91
|
specification_version: 4
|
92
92
|
summary: Extends the Regexp class with '#examples'
|