cucumber-expressions 5.0.4 → 5.0.5
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 +3 -2
- data/lib/cucumber/cucumber_expressions/parameter_type.rb +21 -5
- data/lib/cucumber/cucumber_expressions/parameter_type_matcher.rb +1 -1
- data/spec/cucumber/cucumber_expressions/cucumber_expression_generator_spec.rb +22 -0
- data/spec/cucumber/cucumber_expressions/parameter_type_spec.rb +15 -0
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 10a2279494e6d21d2ae58e07cf6ae1ea9e39649d
|
4
|
+
data.tar.gz: 7efbabfceb72c3efb98e72bab08cc32d9d50752d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a964b7806d22e66902aac68a3c135ac02abe4269b747a6b9e7496d38cf8747095cbc2c086a7f64700ab5082f28388478ab1d9fd97d4f61e65c5b5eac3a8bae4b
|
7
|
+
data.tar.gz: c6b73917402c7b55f1615e7e0878d2001c3d2224954f1f53cf34ef28098055263bc04eca7b8e546e43e4267f6d1009066c6ca3ae57441f4ff7a25a0805705ad8
|
@@ -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 = '5.0.
|
4
|
+
s.version = '5.0.5'
|
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}"
|
@@ -5,6 +5,8 @@ require 'cucumber/cucumber_expressions/errors'
|
|
5
5
|
module Cucumber
|
6
6
|
module CucumberExpressions
|
7
7
|
class CucumberExpression
|
8
|
+
# Does not include (){} characters because they have special meaning
|
9
|
+
ESCAPE_REGEXP = /([\\^\[$.|?*+\]])/
|
8
10
|
PARAMETER_REGEXP = /{([^}]+)}/
|
9
11
|
OPTIONAL_REGEXP = /\(([^)]+)\)/
|
10
12
|
ALTERNATIVE_NON_WHITESPACE_TEXT_REGEXP = /([^\s^\/]+)((\/[^\s^\/]+)+)/
|
@@ -17,8 +19,7 @@ module Cucumber
|
|
17
19
|
regexp = '^'
|
18
20
|
match_offset = 0
|
19
21
|
|
20
|
-
|
21
|
-
expression = expression.gsub(/([\\\^\[$.|?*+\]])/, '\\\\\1')
|
22
|
+
expression = expression.gsub(ESCAPE_REGEXP, '\\\\\1')
|
22
23
|
|
23
24
|
# Create non-capturing, optional capture groups from parenthesis
|
24
25
|
expression = expression.gsub(OPTIONAL_REGEXP, '(?:\1)?')
|
@@ -38,7 +38,7 @@ module Cucumber
|
|
38
38
|
if @transformer.arity == 1
|
39
39
|
non_nil_group_values = group_values.compact
|
40
40
|
raise CucumberExpressionError.new(
|
41
|
-
"Single transformer unexpectedly matched 2 values - \"#{non_nil_group_values[0]}\" and \"
|
41
|
+
"Single transformer unexpectedly matched 2 values - \"#{non_nil_group_values[0]}\" and \"#{non_nil_group_values[1]}\""
|
42
42
|
) if non_nil_group_values.length >= 2
|
43
43
|
args = [non_nil_group_values[0]]
|
44
44
|
else
|
@@ -49,15 +49,31 @@ module Cucumber
|
|
49
49
|
|
50
50
|
def <=>(other)
|
51
51
|
return -1 if prefer_for_regexp_match? && !other.prefer_for_regexp_match?
|
52
|
-
return 1
|
52
|
+
return 1 if other.prefer_for_regexp_match? && !prefer_for_regexp_match?
|
53
53
|
name <=> other.name
|
54
54
|
end
|
55
55
|
|
56
56
|
private
|
57
57
|
|
58
|
-
def string_array(
|
59
|
-
array =
|
60
|
-
array.map {
|
58
|
+
def string_array(regexps)
|
59
|
+
array = regexps.is_a?(Array) ? regexps : [regexps]
|
60
|
+
array.map {|regexp| regexp.is_a?(String) ? regexp : regexp_source(regexp)}
|
61
|
+
end
|
62
|
+
|
63
|
+
def regexp_source(regexp)
|
64
|
+
[
|
65
|
+
'EXTENDED',
|
66
|
+
'FIXEDENCODING',
|
67
|
+
'IGNORECASE',
|
68
|
+
'MULTILINE',
|
69
|
+
'NOENCODING'
|
70
|
+
].each do |option_name|
|
71
|
+
option = Regexp.const_get(option_name)
|
72
|
+
if regexp.options & option != 0
|
73
|
+
raise CucumberExpressionError.new("ParameterType Regexps can't use option Regexp::#{option_name}")
|
74
|
+
end
|
75
|
+
end
|
76
|
+
regexp.source
|
61
77
|
end
|
62
78
|
end
|
63
79
|
end
|
@@ -79,6 +79,28 @@ module Cucumber
|
|
79
79
|
expect(types).to eq([Integer, Float])
|
80
80
|
end
|
81
81
|
|
82
|
+
it "ignores parameter types with optional capture groups" do
|
83
|
+
@parameter_type_registry.define_parameter_type(ParameterType.new(
|
84
|
+
'optional-flight',
|
85
|
+
/(1st flight)?/,
|
86
|
+
String,
|
87
|
+
lambda {|s| s},
|
88
|
+
true,
|
89
|
+
false
|
90
|
+
))
|
91
|
+
@parameter_type_registry.define_parameter_type(ParameterType.new(
|
92
|
+
'optional-hotel',
|
93
|
+
/(1st hotel)?/,
|
94
|
+
String,
|
95
|
+
lambda {|s| s},
|
96
|
+
true,
|
97
|
+
false
|
98
|
+
))
|
99
|
+
|
100
|
+
expression = @generator.generate_expressions("I reach Stage4: 1st flight-1st hotl")[0]
|
101
|
+
expect(expression.source).to eq("I reach Stage{int}: {int}st flight{int}st hotl")
|
102
|
+
end
|
103
|
+
|
82
104
|
def assert_expression(expected_expression, expected_argument_names, text)
|
83
105
|
generated_expression = @generator.generate_expression(text)
|
84
106
|
expect(generated_expression.parameter_names).to eq(expected_argument_names)
|
@@ -0,0 +1,15 @@
|
|
1
|
+
require 'cucumber/cucumber_expressions/parameter_type'
|
2
|
+
|
3
|
+
module Cucumber
|
4
|
+
module CucumberExpressions
|
5
|
+
describe ParameterType do
|
6
|
+
it 'does not allow ignore flag on regexp' do
|
7
|
+
expect do
|
8
|
+
ParameterType.new("case-insensitive", /[a-z]+/i, String, lambda {|s| s}, true, true)
|
9
|
+
end.to raise_error(
|
10
|
+
CucumberExpressionError,
|
11
|
+
"ParameterType Regexps can't use option Regexp::IGNORECASE")
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: cucumber-expressions
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 5.0.
|
4
|
+
version: 5.0.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Aslak Hellesøy
|
@@ -104,6 +104,7 @@ files:
|
|
104
104
|
- spec/cucumber/cucumber_expressions/custom_parameter_type_spec.rb
|
105
105
|
- spec/cucumber/cucumber_expressions/expression_examples_spec.rb
|
106
106
|
- spec/cucumber/cucumber_expressions/parameter_type_registry_spec.rb
|
107
|
+
- spec/cucumber/cucumber_expressions/parameter_type_spec.rb
|
107
108
|
- spec/cucumber/cucumber_expressions/regular_expression_spec.rb
|
108
109
|
- spec/cucumber/cucumber_expressions/tree_regexp_spec.rb
|
109
110
|
homepage: https://github.com/cucumber/cucumber-expressions-ruby#readme
|
@@ -130,7 +131,7 @@ rubyforge_project:
|
|
130
131
|
rubygems_version: 2.6.8
|
131
132
|
signing_key:
|
132
133
|
specification_version: 4
|
133
|
-
summary: cucumber-expressions-5.0.
|
134
|
+
summary: cucumber-expressions-5.0.5
|
134
135
|
test_files:
|
135
136
|
- spec/capture_warnings.rb
|
136
137
|
- spec/coverage.rb
|
@@ -141,5 +142,6 @@ test_files:
|
|
141
142
|
- spec/cucumber/cucumber_expressions/custom_parameter_type_spec.rb
|
142
143
|
- spec/cucumber/cucumber_expressions/expression_examples_spec.rb
|
143
144
|
- spec/cucumber/cucumber_expressions/parameter_type_registry_spec.rb
|
145
|
+
- spec/cucumber/cucumber_expressions/parameter_type_spec.rb
|
144
146
|
- spec/cucumber/cucumber_expressions/regular_expression_spec.rb
|
145
147
|
- spec/cucumber/cucumber_expressions/tree_regexp_spec.rb
|