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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: e67bd863422fd1397a0e2fb99a9269c9c0938173
4
- data.tar.gz: 6798e6ce638df6ef8cce74010c6f8d210c947127
3
+ metadata.gz: 10a2279494e6d21d2ae58e07cf6ae1ea9e39649d
4
+ data.tar.gz: 7efbabfceb72c3efb98e72bab08cc32d9d50752d
5
5
  SHA512:
6
- metadata.gz: aefbfc1c763e4fa55eca30be560c6446b5ad13c255fc0e5da3acefdc993fa70339d7b318be8b2011b1b39268d806c71c77a0406add436726e6125468aa0c1ced
7
- data.tar.gz: 26b9ee07ef6924a332a759835a65ca749c833ab232d78278f1a3ef5a4f9fa8fb462514663e324db7f0be14c889aa2f0c633b3e92f70049c2826134c7ff6697c3
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'
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
- # Escape Does not include (){} because they have special meaning
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 \"${non_nil_group_values[1]}\""
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 if other.prefer_for_regexp_match? && !prefer_for_regexp_match?
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(regexp)
59
- array = regexp.is_a?(Array) ? regexp : [regexp]
60
- array.map { |r| r.is_a?(String) ? r : r.source }
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
@@ -13,7 +13,7 @@ module Cucumber
13
13
  end
14
14
 
15
15
  def find
16
- !@match.nil?
16
+ !@match.nil? && !group.empty?
17
17
  end
18
18
 
19
19
  def start
@@ -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
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.4
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