step_master 0.0.5 → 0.0.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/lib/step_master.rb +1 -1
- data/lib/step_master/matcher.rb +41 -11
- data/spec/step_helper/matcher_spec.rb +9 -1
- metadata +2 -2
data/lib/step_master.rb
CHANGED
data/lib/step_master/matcher.rb
CHANGED
@@ -23,7 +23,7 @@ module StepMaster
|
|
23
23
|
STEP_REGEX = /^\s*(Given|Then|When)\s*\(?\s*\/\^?(.*)\/(\w*)\s*\)?\s*(?:do|\{)\s*(\|[^\|]+\|)?/.freeze
|
24
24
|
ARG_NAMES_REGEX = /\|(.*)\|/
|
25
25
|
ARG_TEXT_REGEX = /\(.*?[^\\]\)[\?\+\*]?/
|
26
|
-
NON_CAPTURE_REGEX =
|
26
|
+
NON_CAPTURE_REGEX = /^\(\?\:/
|
27
27
|
CHUNK_REGEX = /\S+|\s\??/
|
28
28
|
|
29
29
|
attr_reader :match_table
|
@@ -52,25 +52,21 @@ module StepMaster
|
|
52
52
|
args = $4
|
53
53
|
|
54
54
|
arg_names = (args =~ ARG_NAMES_REGEX) ? $1.split(/\s*,\s*/) : []
|
55
|
-
arg_regexs = regex
|
55
|
+
arg_regexs = extract_captures(regex)
|
56
56
|
|
57
57
|
arg_objects = arg_regexs.collect do |x|
|
58
58
|
is_non_capture = (x =~ NON_CAPTURE_REGEX) != nil
|
59
59
|
StepVariable.new(x, regex_options, (is_non_capture) ? nil : arg_names.shift)
|
60
60
|
end
|
61
61
|
|
62
|
-
|
63
|
-
|
64
|
-
regex.split(Regexp.union(arg_regexs.collect { |x|
|
65
|
-
Regexp.new(Regexp.escape(x))
|
66
|
-
})).collect { |x|
|
62
|
+
if arg_regexs.length > 0
|
63
|
+
regex.split(Regexp.union(arg_regexs.collect { |x| Regexp.new(Regexp.escape(x)) })).collect { |x|
|
67
64
|
x.scan(CHUNK_REGEX).collect { |i| StepItem.new(i, regex_options) }
|
68
|
-
}.zip(arg_objects).flatten.compact.unshift(StepItem.new(" ", regex_options)).unshift(StepItem.new(step_type, regex_options))
|
65
|
+
}.+(Array.new(5)).zip(arg_objects).flatten.compact.unshift(StepItem.new(" ", regex_options)).unshift(StepItem.new(step_type, regex_options))
|
69
66
|
else
|
70
67
|
regex.scan(CHUNK_REGEX).unshift(" ").unshift(step_type).collect { |i| StepItem.new(i, regex_options) }
|
71
|
-
end
|
72
|
-
|
73
|
-
elements.inject(@match_table) { |parent, i| parent[i] ||= Possible.new }.terminal!(value, options)
|
68
|
+
end.inject(@match_table) { |parent, i| parent[i] ||= Possible.new }.terminal!(value, options)
|
69
|
+
|
74
70
|
end
|
75
71
|
|
76
72
|
# Returns all possible outcomes of a string.
|
@@ -136,5 +132,39 @@ private
|
|
136
132
|
end
|
137
133
|
collection
|
138
134
|
end
|
135
|
+
|
136
|
+
def extract_captures(t)
|
137
|
+
captures = []
|
138
|
+
index = 0
|
139
|
+
while true do
|
140
|
+
break unless index = t.index(/\(/, index)
|
141
|
+
index += 1
|
142
|
+
next if t[index-2,1] == "\\"
|
143
|
+
|
144
|
+
close, depth = index - 1, 1
|
145
|
+
|
146
|
+
begin
|
147
|
+
next_close = t.index(/[^\\]\)/, close)
|
148
|
+
next_open = t.index(/[^\\]\(/, close)
|
149
|
+
|
150
|
+
raise "Unmatched" unless next_close
|
151
|
+
|
152
|
+
if !next_open.nil? and next_open < next_close
|
153
|
+
close = next_open + 1
|
154
|
+
depth += 1
|
155
|
+
else
|
156
|
+
close = next_close + 1
|
157
|
+
depth -= 1
|
158
|
+
end
|
159
|
+
|
160
|
+
end while depth > 0
|
161
|
+
|
162
|
+
close += $&.length if t[close + 1..-1] =~ /^[\+\*\?]/
|
163
|
+
captures << t[index -1..close]
|
164
|
+
|
165
|
+
index = close
|
166
|
+
end
|
167
|
+
captures
|
168
|
+
end
|
139
169
|
end
|
140
170
|
end
|
@@ -118,7 +118,15 @@ module StepMaster
|
|
118
118
|
it "should correctly match" do
|
119
119
|
@matcher.is_match?("Given this").should be_true
|
120
120
|
end
|
121
|
-
end
|
121
|
+
end
|
122
|
+
|
123
|
+
describe "with a weird self-repeating step" do
|
124
|
+
it "should correctly match" do
|
125
|
+
@matcher << %q[Given /^I have a scheduled encounter ((?:\d+\s(?:weeks?|days?|minutes?|hours?|seconds|)(?:,\s?|\s?and\s?| ))+)(from now|ago)$/ do |time, from_now_or_ago| ]
|
126
|
+
@matcher.is_match?("Given I have a scheduled encounter 3 weeks from now").should be_true
|
127
|
+
end
|
128
|
+
|
129
|
+
end
|
122
130
|
end
|
123
131
|
|
124
132
|
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: step_master
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.6
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jim Holmes
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2009-10-
|
12
|
+
date: 2009-10-29 00:00:00 -04:00
|
13
13
|
default_executable:
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|