16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
|
# File 'lib/cucumber/cucumber_expressions/cucumber_expression_generator.rb', line 16
def generate_expressions(text)
parameter_type_combinations = []
parameter_type_matchers = create_parameter_type_matchers(text)
expression_template = ""
pos = 0
loop do
matching_parameter_type_matchers = []
parameter_type_matchers.each do |parameter_type_matcher|
advanced_parameter_type_matcher = parameter_type_matcher.advance_to(pos)
if advanced_parameter_type_matcher.find
matching_parameter_type_matchers.push(advanced_parameter_type_matcher)
end
end
if matching_parameter_type_matchers.any?
matching_parameter_type_matchers = matching_parameter_type_matchers.sort
best_parameter_type_matcher = matching_parameter_type_matchers[0]
best_parameter_type_matchers = matching_parameter_type_matchers.select do |m|
(m <=> best_parameter_type_matcher).zero?
end
parameter_types = []
best_parameter_type_matchers.each do |parameter_type_matcher|
unless parameter_types.include?(parameter_type_matcher.parameter_type)
parameter_types.push(parameter_type_matcher.parameter_type)
end
end
parameter_types.sort!
parameter_type_combinations.push(parameter_types)
expression_template += escape(text.slice(pos...best_parameter_type_matcher.start))
expression_template += "{%s}"
pos = best_parameter_type_matcher.start + best_parameter_type_matcher.group.length
else
break
end
if pos >= text.length
break
end
end
expression_template += escape(text.slice(pos..-1))
CombinatorialGeneratedExpressionFactory.new(
expression_template,
parameter_type_combinations
).generate_expressions
end
|