cucumber-expressions 4.0.3 → 4.0.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rsync +1 -0
- data/.travis.yml +9 -4
- data/cucumber-expressions.gemspec +1 -1
- data/lib/cucumber/cucumber_expressions/cucumber_expression_generator.rb +5 -2
- data/lib/cucumber/cucumber_expressions/group_builder.rb +6 -0
- data/lib/cucumber/cucumber_expressions/regular_expression.rb +14 -25
- data/lib/cucumber/cucumber_expressions/tree_regexp.rb +6 -2
- data/spec/cucumber/cucumber_expressions/cucumber_expression_generator_spec.rb +6 -0
- data/spec/cucumber/cucumber_expressions/custom_parameter_type_spec.rb +6 -6
- data/spec/cucumber/cucumber_expressions/regular_expression_spec.rb +4 -0
- data/spec/cucumber/cucumber_expressions/tree_regexp_spec.rb +6 -1
- 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: 585a2bd12be1402edbd044df4eba75a3facc8ae7
|
4
|
+
data.tar.gz: e2f73a0945067fc0f36aee14c2fd2c8a0a1953cf
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 107cee1adc2c92cf7fde7b709dc01ae34b316e34ce604adc19232d75ed66d5abfb28be5cf29c96d6e633d34bf38c5650a8626d314a4db0c6064e481622e28923
|
7
|
+
data.tar.gz: caebefb4d97b8abe78c6565a643bb35c6f96175b5169394b46d03b9cfab339512d7167d6df1a0ea4071033a2139a77e88586139ed0868df45ff4275bb768c215
|
data/.rsync
CHANGED
data/.travis.yml
CHANGED
@@ -1,10 +1,15 @@
|
|
1
|
+
# Please update /.travis/ruby/.travis.yml in the cucumber/cucumber monorepo
|
2
|
+
# and sync:
|
3
|
+
#
|
4
|
+
# source scripts/functions.sh && rsync_files
|
5
|
+
#
|
1
6
|
language: ruby
|
2
7
|
|
3
8
|
rvm:
|
4
|
-
- 2.4.
|
5
|
-
- 2.3.
|
6
|
-
- 2.2.
|
7
|
-
- jruby-9.1.
|
9
|
+
- 2.4.2
|
10
|
+
- 2.3.5
|
11
|
+
- 2.2.8
|
12
|
+
- jruby-9.1.13.0
|
8
13
|
|
9
14
|
notifications:
|
10
15
|
webhooks:
|
@@ -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.0.
|
4
|
+
s.version = '4.0.4'
|
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}"
|
@@ -51,7 +51,7 @@ module Cucumber
|
|
51
51
|
|
52
52
|
parameter_type_combinations.push(parameter_types)
|
53
53
|
|
54
|
-
expression_template += text.slice(pos...best_parameter_type_matcher.start)
|
54
|
+
expression_template += escape_for_sprintf(text.slice(pos...best_parameter_type_matcher.start))
|
55
55
|
expression_template += "{%s}"
|
56
56
|
|
57
57
|
pos = best_parameter_type_matcher.start + best_parameter_type_matcher.group.length
|
@@ -64,7 +64,7 @@ module Cucumber
|
|
64
64
|
end
|
65
65
|
end
|
66
66
|
|
67
|
-
expression_template += text.slice(pos..-1)
|
67
|
+
expression_template += escape_for_sprintf(text.slice(pos..-1))
|
68
68
|
|
69
69
|
CombinatorialGeneratedExpressionFactory.new(
|
70
70
|
expression_template,
|
@@ -94,6 +94,9 @@ module Cucumber
|
|
94
94
|
result
|
95
95
|
end
|
96
96
|
|
97
|
+
def escape_for_sprintf(s)
|
98
|
+
s.gsub(/%/, '%%')
|
99
|
+
end
|
97
100
|
end
|
98
101
|
end
|
99
102
|
end
|
@@ -3,6 +3,8 @@ require 'cucumber/cucumber_expressions/group'
|
|
3
3
|
module Cucumber
|
4
4
|
module CucumberExpressions
|
5
5
|
class GroupBuilder
|
6
|
+
attr_accessor :source
|
7
|
+
|
6
8
|
def initialize
|
7
9
|
@group_builders = []
|
8
10
|
@capturing = true
|
@@ -31,6 +33,10 @@ module Cucumber
|
|
31
33
|
group_builder.add(child)
|
32
34
|
end
|
33
35
|
end
|
36
|
+
|
37
|
+
def children
|
38
|
+
@group_builders
|
39
|
+
end
|
34
40
|
end
|
35
41
|
end
|
36
42
|
end
|
@@ -5,7 +5,6 @@ require 'cucumber/cucumber_expressions/tree_regexp'
|
|
5
5
|
module Cucumber
|
6
6
|
module CucumberExpressions
|
7
7
|
class RegularExpression
|
8
|
-
CAPTURE_GROUP_PATTERN = /\((?!\?:)([^(]+)\)/
|
9
8
|
|
10
9
|
def initialize(expression_regexp, parameter_type_registry)
|
11
10
|
@expression_regexp = expression_regexp
|
@@ -14,30 +13,20 @@ module Cucumber
|
|
14
13
|
end
|
15
14
|
|
16
15
|
def match(text)
|
17
|
-
parameter_types =
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
parameter_type_regexp,
|
32
|
-
parameter_type_regexp,
|
33
|
-
String,
|
34
|
-
lambda {|s| s},
|
35
|
-
false,
|
36
|
-
false
|
37
|
-
)
|
38
|
-
end
|
39
|
-
|
40
|
-
parameter_types.push(parameter_type)
|
16
|
+
parameter_types = @tree_regexp.group_builder.children.map do |group_builder|
|
17
|
+
parameter_type_regexp = group_builder.source
|
18
|
+
@parameter_type_registry.lookup_by_regexp(
|
19
|
+
parameter_type_regexp,
|
20
|
+
@expression_regexp,
|
21
|
+
text
|
22
|
+
) || ParameterType.new(
|
23
|
+
parameter_type_regexp,
|
24
|
+
parameter_type_regexp,
|
25
|
+
String,
|
26
|
+
lambda {|s| s},
|
27
|
+
false,
|
28
|
+
false
|
29
|
+
)
|
41
30
|
end
|
42
31
|
|
43
32
|
Argument.build(@tree_regexp, text, parameter_types)
|
@@ -3,21 +3,25 @@ require 'cucumber/cucumber_expressions/group_builder'
|
|
3
3
|
module Cucumber
|
4
4
|
module CucumberExpressions
|
5
5
|
class TreeRegexp
|
6
|
-
attr_reader :regexp
|
6
|
+
attr_reader :regexp, :group_builder
|
7
7
|
|
8
8
|
def initialize(regexp)
|
9
9
|
@regexp = regexp.is_a?(Regexp) ? regexp : Regexp.new(regexp)
|
10
10
|
|
11
11
|
stack = [GroupBuilder.new]
|
12
|
+
group_start_stack = []
|
12
13
|
last = nil
|
13
14
|
non_capturing_maybe = false
|
14
|
-
@regexp.source.split('').
|
15
|
+
@regexp.source.split('').each_with_index do |c, n|
|
15
16
|
if c == '(' && last != '\\'
|
16
17
|
stack.push(GroupBuilder.new)
|
18
|
+
group_start_stack.push(n+1)
|
17
19
|
non_capturing_maybe = false
|
18
20
|
elsif c == ')' && last != '\\'
|
19
21
|
gb = stack.pop
|
22
|
+
group_start = group_start_stack.pop
|
20
23
|
if gb.capturing?
|
24
|
+
gb.source = @regexp.source[group_start...n]
|
21
25
|
stack.last.add(gb)
|
22
26
|
else
|
23
27
|
gb.move_children_to(stack.last)
|
@@ -40,6 +40,12 @@ module Cucumber
|
|
40
40
|
'I like "bangers" and \'mash\'')
|
41
41
|
end
|
42
42
|
|
43
|
+
it "generates expression for strings with % sign" do
|
44
|
+
assert_expression(
|
45
|
+
"I am {int}% foobar", ["int"],
|
46
|
+
'I am 20% foobar')
|
47
|
+
end
|
48
|
+
|
43
49
|
it "generates expression for just int" do
|
44
50
|
assert_expression(
|
45
51
|
"{int}", ["int"],
|
@@ -48,12 +48,12 @@ module Cucumber
|
|
48
48
|
parameter_registry = ParameterTypeRegistry.new
|
49
49
|
### [add-color-parameter-type]
|
50
50
|
parameter_registry.define_parameter_type(ParameterType.new(
|
51
|
-
'color',
|
52
|
-
/red|blue|yellow/,
|
53
|
-
Color,
|
54
|
-
lambda {|s| Color.new(s)},
|
55
|
-
true,
|
56
|
-
false
|
51
|
+
'color', # name
|
52
|
+
/red|blue|yellow/, # regexp
|
53
|
+
Color, # type
|
54
|
+
lambda {|s| Color.new(s)}, # transform
|
55
|
+
true, # use_for_snippets
|
56
|
+
false # prefer_for_regexp_match
|
57
57
|
))
|
58
58
|
### [add-color-parameter-type]
|
59
59
|
@parameter_type_registry = parameter_registry
|
@@ -47,6 +47,10 @@ module Cucumber
|
|
47
47
|
).to eq(["I", "can", 1, "slide"])
|
48
48
|
end
|
49
49
|
|
50
|
+
it "works with escaped parenthesis" do
|
51
|
+
expect( match(/Across the line\(s\)/, 'Across the line(s)') ).to eq([])
|
52
|
+
end
|
53
|
+
|
50
54
|
it "exposes source and regexp" do
|
51
55
|
regexp = /I have (\d+) cukes? in my (\+) now/
|
52
56
|
expression = RegularExpression.new(regexp, ParameterTypeRegistry.new)
|
@@ -3,6 +3,11 @@ require 'cucumber/cucumber_expressions/tree_regexp'
|
|
3
3
|
module Cucumber
|
4
4
|
module CucumberExpressions
|
5
5
|
describe TreeRegexp do
|
6
|
+
it 'exposes group source' do
|
7
|
+
tr = TreeRegexp.new(/(a(?:b)?)(c)/)
|
8
|
+
expect(tr.group_builder.children.map{|gb| gb.source}).to eq(['a(?:b)?', 'c'])
|
9
|
+
end
|
10
|
+
|
6
11
|
it 'builds tree' do
|
7
12
|
tr = TreeRegexp.new(/(a(?:b)?)(c)/)
|
8
13
|
group = tr.match('ac')
|
@@ -57,4 +62,4 @@ module Cucumber
|
|
57
62
|
end
|
58
63
|
end
|
59
64
|
end
|
60
|
-
end
|
65
|
+
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.0.
|
4
|
+
version: 4.0.4
|
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: 2017-
|
11
|
+
date: 2017-10-05 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -130,7 +130,7 @@ rubyforge_project:
|
|
130
130
|
rubygems_version: 2.6.8
|
131
131
|
signing_key:
|
132
132
|
specification_version: 4
|
133
|
-
summary: cucumber-expressions-4.0.
|
133
|
+
summary: cucumber-expressions-4.0.4
|
134
134
|
test_files:
|
135
135
|
- spec/capture_warnings.rb
|
136
136
|
- spec/coverage.rb
|