cucumber-expressions 5.0.18 → 6.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/cucumber-expressions.gemspec +1 -1
- data/lib/cucumber/cucumber_expressions/cucumber_expression.rb +19 -2
- data/lib/cucumber/cucumber_expressions/parameter_type.rb +1 -1
- data/spec/cucumber/cucumber_expressions/cucumber_expression_spec.rb +12 -0
- data/spec/cucumber/cucumber_expressions/regular_expression_spec.rb +7 -0
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a4e80f6b342fd980a7e30ed217e54f83d5ee4da8198e93487470daff410e4959
|
4
|
+
data.tar.gz: 9cb0efc96dfc3f26257ac35998bdce354470543ccafdb604e227645fb6f5dd75
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 844a25bb968e193a071b4bdfef1a79cc9bd3da3f5211c75adeef363b74ba3e34f7b6cbe578c06fbaf7e6d8f118eae33be2acdca0af5ecd70c8c77c42aac78252
|
7
|
+
data.tar.gz: e9359ff92fccbc88eb457bec080607397d723d6c488ee4ce87053b360e43268d8a5b3bd4523c3415e76ac8c1b79965db9aff7d4ae6ddb486f3acf02e08e32c7c
|
@@ -1,7 +1,7 @@
|
|
1
1
|
# -*- encoding: utf-8 -*-
|
2
2
|
Gem::Specification.new do |s|
|
3
3
|
s.name = 'cucumber-expressions'
|
4
|
-
s.version = '
|
4
|
+
s.version = '6.0.0'
|
5
5
|
s.authors = ["Aslak Hellesøy"]
|
6
6
|
s.description = 'Cucumber Expressions - a simpler alternative to Regular Expressions'
|
7
7
|
s.summary = "cucumber-expressions-#{s.version}"
|
@@ -11,6 +11,8 @@ module Cucumber
|
|
11
11
|
OPTIONAL_REGEXP = /(\\\\)?\(([^)]+)\)/
|
12
12
|
ALTERNATIVE_NON_WHITESPACE_TEXT_REGEXP = /([^\s^\/]+)((\/[^\s^\/]+)+)/
|
13
13
|
DOUBLE_ESCAPE = '\\\\'
|
14
|
+
PARAMETER_TYPES_CANNOT_BE_ALTERNATIVE = 'Parameter types cannot be alternative: '
|
15
|
+
PARAMETER_TYPES_CANNOT_BE_OPTIONAL = 'Parameter types cannot be optional: '
|
14
16
|
|
15
17
|
attr_reader :source
|
16
18
|
|
@@ -48,8 +50,10 @@ module Cucumber
|
|
48
50
|
def process_optional(expression)
|
49
51
|
# Create non-capturing, optional capture groups from parenthesis
|
50
52
|
expression.gsub(OPTIONAL_REGEXP) do
|
53
|
+
g2 = $2
|
54
|
+
check_no_parameter_type(g2, PARAMETER_TYPES_CANNOT_BE_OPTIONAL)
|
51
55
|
# look for double-escaped parentheses
|
52
|
-
$1 == DOUBLE_ESCAPE ? "\\(#{
|
56
|
+
$1 == DOUBLE_ESCAPE ? "\\(#{g2}\\)" : "(?:#{g2})?"
|
53
57
|
end
|
54
58
|
end
|
55
59
|
|
@@ -58,7 +62,14 @@ module Cucumber
|
|
58
62
|
# replace \/ with /
|
59
63
|
# replace / with |
|
60
64
|
replacement = $&.tr('/', '|').gsub(/\\\|/, '/')
|
61
|
-
|
65
|
+
if replacement.include?('|')
|
66
|
+
replacement.split(/\|/).each do |part|
|
67
|
+
check_no_parameter_type(part, PARAMETER_TYPES_CANNOT_BE_ALTERNATIVE)
|
68
|
+
end
|
69
|
+
"(?:#{replacement})"
|
70
|
+
else
|
71
|
+
replacement
|
72
|
+
end
|
62
73
|
end
|
63
74
|
end
|
64
75
|
|
@@ -83,6 +94,12 @@ module Cucumber
|
|
83
94
|
capture_groups = regexps.map { |group| "(?:#{group})" }
|
84
95
|
"(#{capture_groups.join('|')})"
|
85
96
|
end
|
97
|
+
|
98
|
+
def check_no_parameter_type(s, message)
|
99
|
+
if PARAMETER_REGEXP =~ s
|
100
|
+
raise CucumberExpressionError.new("#{message}#{source}")
|
101
|
+
end
|
102
|
+
end
|
86
103
|
end
|
87
104
|
end
|
88
105
|
end
|
@@ -80,6 +80,18 @@ module Cucumber
|
|
80
80
|
expect {match("{unknown}", "something")}.to raise_error('Undefined parameter type {unknown}')
|
81
81
|
end
|
82
82
|
|
83
|
+
it "does not allow optional parameter types" do
|
84
|
+
expect {match("({int})", "3")}.to raise_error('Parameter types cannot be optional: ({int})')
|
85
|
+
end
|
86
|
+
|
87
|
+
it "does not allow text/parameter type alternation" do
|
88
|
+
expect {match("x/{int}", "3")}.to raise_error('Parameter types cannot be alternative: x/{int}')
|
89
|
+
end
|
90
|
+
|
91
|
+
it "does not allow parameter type/text alternation" do
|
92
|
+
expect {match("{int}/x", "3")}.to raise_error('Parameter types cannot be alternative: {int}/x')
|
93
|
+
end
|
94
|
+
|
83
95
|
it "exposes source" do
|
84
96
|
expr = "I have {int} cuke(s)"
|
85
97
|
expect(CucumberExpression.new(expr, ParameterTypeRegistry.new).source).to eq(expr)
|
@@ -55,6 +55,13 @@ module Cucumber
|
|
55
55
|
).to eq(["I", "can", 1, "slide"])
|
56
56
|
end
|
57
57
|
|
58
|
+
it "matches capture group nested in optional one" do
|
59
|
+
regexp = /^a (pre-commercial transaction |pre buyer fee model )?purchase(?: for \$(\d+))?$/
|
60
|
+
expect( match(regexp, 'a purchase') ).to eq([nil, nil])
|
61
|
+
expect( match(regexp, 'a purchase for $33') ).to eq([nil, 33])
|
62
|
+
expect( match(regexp, 'a pre buyer fee model purchase') ).to eq(['pre buyer fee model ', nil])
|
63
|
+
end
|
64
|
+
|
58
65
|
it "works with escaped parenthesis" do
|
59
66
|
expect( match(/Across the line\(s\)/, 'Across the line(s)') ).to eq([])
|
60
67
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: cucumber-expressions
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 6.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Aslak Hellesøy
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-05-
|
11
|
+
date: 2018-05-30 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -134,7 +134,7 @@ rubyforge_project:
|
|
134
134
|
rubygems_version: 2.7.6
|
135
135
|
signing_key:
|
136
136
|
specification_version: 4
|
137
|
-
summary: cucumber-expressions-
|
137
|
+
summary: cucumber-expressions-6.0.0
|
138
138
|
test_files:
|
139
139
|
- spec/capture_warnings.rb
|
140
140
|
- spec/coverage.rb
|