cucumber-gherkin 29.0.0 → 30.0.1
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.
- checksums.yaml +4 -4
- data/bin/gherkin +12 -10
- data/bin/gherkin-ruby +2 -0
- data/lib/gherkin/ast_builder.rb +27 -19
- data/lib/gherkin/ast_node.rb +2 -0
- data/lib/gherkin/dialect.rb +4 -1
- data/lib/gherkin/errors.rb +5 -3
- data/lib/gherkin/gherkin_line.rb +7 -6
- data/lib/gherkin/parser.rb +532 -532
- data/lib/gherkin/pickles/compiler.rb +21 -14
- data/lib/gherkin/query.rb +6 -0
- data/lib/gherkin/stream/parser_message_stream.rb +16 -13
- data/lib/gherkin/token.rb +2 -0
- data/lib/gherkin/token_formatter_builder.rb +17 -11
- data/lib/gherkin/token_matcher.rb +20 -19
- data/lib/gherkin/token_scanner.rb +8 -5
- data/lib/gherkin.rb +11 -11
- metadata +6 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c8e28c956d49e3459e25aa1dc8aedf72dfbfa31d904426676f1c38126f5954a1
|
4
|
+
data.tar.gz: 4f9821c2a63ed6d29c19270081b04389c3c53e6440af042e7e748c7066fad584
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3f517b44e24aa884a2c213a782b931a09f45e1642da6a74b36536f83e5b2863f3b2a45256174fc1886ecd3fbe491ead2f308782ec4b2f431fe86b4a29ba827c8
|
7
|
+
data.tar.gz: 378cd806e477186a82ab8a884e927eb4318bf0d03afa50df71f73f02f8f4b2dac0477141ed665002914e26d182ff5aae0c608c404f32b2ab833978eb0142908a
|
data/bin/gherkin
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
|
+
# frozen_string_literal: true
|
2
3
|
|
3
|
-
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__),
|
4
|
+
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '../lib'))
|
4
5
|
|
5
6
|
require 'optparse'
|
6
7
|
require 'json'
|
@@ -29,18 +30,19 @@ OptionParser.new do |opts|
|
|
29
30
|
end
|
30
31
|
end.parse!
|
31
32
|
|
32
|
-
def process_messages(messages,
|
33
|
+
def process_messages(messages, _options)
|
33
34
|
messages.each do |message|
|
34
|
-
|
35
|
-
|
35
|
+
$stdout.write(message.to_json)
|
36
|
+
$stdout.write("\n")
|
36
37
|
end
|
37
38
|
end
|
38
39
|
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
40
|
+
messages =
|
41
|
+
if ARGV.empty?
|
42
|
+
# Read from $stdin
|
43
|
+
Cucumber::Messages::Helpers::NdjsonToMessageEnumerator.new($stdin)
|
44
|
+
else
|
45
|
+
Gherkin.from_paths(ARGV, options)
|
46
|
+
end
|
45
47
|
|
46
48
|
process_messages(messages, options)
|
data/bin/gherkin-ruby
CHANGED
data/lib/gherkin/ast_builder.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'cucumber/messages'
|
2
4
|
require_relative 'ast_node'
|
3
5
|
|
@@ -17,17 +19,19 @@ module Gherkin
|
|
17
19
|
@stack.push AstNode.new(rule_type)
|
18
20
|
end
|
19
21
|
|
20
|
-
def end_rule(
|
22
|
+
def end_rule(_rule_type)
|
21
23
|
node = @stack.pop
|
22
24
|
current_node.add(node.rule_type, transform_node(node))
|
23
25
|
end
|
24
26
|
|
25
27
|
def build(token)
|
26
28
|
if token.matched_type == :Comment
|
27
|
-
@comments.push(
|
28
|
-
|
29
|
-
|
30
|
-
|
29
|
+
@comments.push(
|
30
|
+
Cucumber::Messages::Comment.new(
|
31
|
+
location: get_location(token, 0),
|
32
|
+
text: token.matched_text
|
33
|
+
)
|
34
|
+
)
|
31
35
|
else
|
32
36
|
current_node.add(token.matched_type, token)
|
33
37
|
end
|
@@ -56,11 +60,13 @@ module Gherkin
|
|
56
60
|
|
57
61
|
tags_node.get_tokens(:TagLine).each do |token|
|
58
62
|
token.matched_items.each do |tag_item|
|
59
|
-
tags.push(
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
63
|
+
tags.push(
|
64
|
+
Cucumber::Messages::Tag.new(
|
65
|
+
location: get_location(token, tag_item.column),
|
66
|
+
name: tag_item.text,
|
67
|
+
id: @id_generator.new_id
|
68
|
+
)
|
69
|
+
)
|
64
70
|
end
|
65
71
|
end
|
66
72
|
|
@@ -75,17 +81,15 @@ module Gherkin
|
|
75
81
|
cells: get_cells(token)
|
76
82
|
)
|
77
83
|
end
|
78
|
-
ensure_cell_count(rows)
|
79
|
-
rows
|
84
|
+
rows.tap { ensure_cell_count(rows) }
|
80
85
|
end
|
81
86
|
|
82
87
|
def ensure_cell_count(rows)
|
83
88
|
return if rows.empty?
|
89
|
+
|
84
90
|
cell_count = rows[0].cells.length
|
85
91
|
rows.each do |row|
|
86
|
-
if row.cells.length != cell_count
|
87
|
-
raise AstBuilderException.new("inconsistent cell count within the table", row.location.to_h)
|
88
|
-
end
|
92
|
+
raise AstBuilderException.new('inconsistent cell count within the table', row.location.to_h) if row.cells.length != cell_count
|
89
93
|
end
|
90
94
|
end
|
91
95
|
|
@@ -113,7 +117,7 @@ module Gherkin
|
|
113
117
|
data_table = node.get_single(:DataTable)
|
114
118
|
doc_string = node.get_single(:DocString)
|
115
119
|
|
116
|
-
|
120
|
+
Cucumber::Messages::Step.new(
|
117
121
|
location: get_location(step_line, 0),
|
118
122
|
keyword: step_line.matched_keyword,
|
119
123
|
keyword_type: step_line.matched_keyword_type,
|
@@ -196,14 +200,16 @@ module Gherkin
|
|
196
200
|
line_tokens = node.get_tokens(:Other)
|
197
201
|
# Trim trailing empty lines
|
198
202
|
last_non_empty = line_tokens.rindex { |token| !token.line.trimmed_line_text.empty? }
|
199
|
-
|
200
|
-
|
203
|
+
line_tokens[0..last_non_empty].map { |token| token.matched_text }.join("\n")
|
204
|
+
|
201
205
|
when :Feature
|
202
206
|
header = node.get_single(:FeatureHeader)
|
203
207
|
return unless header
|
208
|
+
|
204
209
|
tags = get_tags(header)
|
205
210
|
feature_line = header.get_token(:FeatureLine)
|
206
211
|
return unless feature_line
|
212
|
+
|
207
213
|
children = []
|
208
214
|
background = node.get_single(:Background)
|
209
215
|
children.push(Cucumber::Messages::FeatureChild.new(background: background)) if background
|
@@ -228,8 +234,10 @@ module Gherkin
|
|
228
234
|
when :Rule
|
229
235
|
header = node.get_single(:RuleHeader)
|
230
236
|
return unless header
|
237
|
+
|
231
238
|
rule_line = header.get_token(:RuleLine)
|
232
239
|
return unless rule_line
|
240
|
+
|
233
241
|
tags = get_tags(header)
|
234
242
|
children = []
|
235
243
|
background = node.get_single(:Background)
|
@@ -255,7 +263,7 @@ module Gherkin
|
|
255
263
|
feature: feature
|
256
264
|
)
|
257
265
|
else
|
258
|
-
|
266
|
+
node
|
259
267
|
end
|
260
268
|
end
|
261
269
|
end
|
data/lib/gherkin/ast_node.rb
CHANGED
data/lib/gherkin/dialect.rb
CHANGED
@@ -1,14 +1,17 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'cucumber/messages'
|
2
4
|
require 'json'
|
3
5
|
|
4
6
|
module Gherkin
|
5
|
-
DIALECT_FILE_PATH = File.expand_path(
|
7
|
+
DIALECT_FILE_PATH = File.expand_path('gherkin-languages.json', File.dirname(__FILE__))
|
6
8
|
DIALECTS = JSON.parse File.open(DIALECT_FILE_PATH, 'r:UTF-8').read
|
7
9
|
|
8
10
|
class Dialect
|
9
11
|
def self.for(name)
|
10
12
|
spec = DIALECTS[name]
|
11
13
|
return nil unless spec
|
14
|
+
|
12
15
|
new(spec)
|
13
16
|
end
|
14
17
|
|
data/lib/gherkin/errors.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module Gherkin
|
2
4
|
class ParserError < StandardError; end
|
3
5
|
class AstNodeNotLocatedException < StandardError; end
|
@@ -30,16 +32,16 @@ module Gherkin
|
|
30
32
|
end
|
31
33
|
|
32
34
|
class UnexpectedTokenException < ParserException
|
33
|
-
def initialize(received_token, expected_token_types,
|
35
|
+
def initialize(received_token, expected_token_types, _state_comment)
|
34
36
|
message = "expected: #{expected_token_types.join(", ")}, got '#{received_token.token_value.strip}'"
|
35
37
|
column = received_token.location[:column]
|
36
|
-
location =
|
38
|
+
location = (column.nil? || column.zero?) ? { line: received_token.location[:line], column: received_token.line.indent + 1 } : received_token.location
|
37
39
|
super(message, location)
|
38
40
|
end
|
39
41
|
end
|
40
42
|
|
41
43
|
class UnexpectedEOFException < ParserException
|
42
|
-
def initialize(received_token, expected_token_types,
|
44
|
+
def initialize(received_token, expected_token_types, _state_comment)
|
43
45
|
message = "unexpected end of file, expected: #{expected_token_types.join(", ")}"
|
44
46
|
super(message, received_token.location)
|
45
47
|
end
|
data/lib/gherkin/gherkin_line.rb
CHANGED
@@ -1,6 +1,9 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module Gherkin
|
2
4
|
class GherkinLine
|
3
5
|
attr_reader :indent, :trimmed_line_text
|
6
|
+
|
4
7
|
def initialize(line_text, line_number)
|
5
8
|
@line_text = line_text
|
6
9
|
@line_number = line_number
|
@@ -13,7 +16,7 @@ module Gherkin
|
|
13
16
|
end
|
14
17
|
|
15
18
|
def start_with_title_keyword?(keyword)
|
16
|
-
start_with?(keyword+':') # The C# impl is more complicated. Find out why.
|
19
|
+
start_with?(keyword + ':') # The C# impl is more complicated. Find out why.
|
17
20
|
end
|
18
21
|
|
19
22
|
def get_rest_trimmed(length)
|
@@ -87,11 +90,9 @@ module Gherkin
|
|
87
90
|
items = uncommented_line.split('@')
|
88
91
|
|
89
92
|
tags = []
|
90
|
-
items.each
|
93
|
+
items.each do |untrimmed|
|
91
94
|
item = untrimmed.strip
|
92
|
-
if item.length == 0
|
93
|
-
next
|
94
|
-
end
|
95
|
+
next if item.length == 0
|
95
96
|
|
96
97
|
unless item =~ /^\S+$/
|
97
98
|
location = { line: @line_number, column: column }
|
@@ -100,7 +101,7 @@ module Gherkin
|
|
100
101
|
|
101
102
|
tags << Span.new(column, '@' + item)
|
102
103
|
column += untrimmed.length + 1
|
103
|
-
|
104
|
+
end
|
104
105
|
tags
|
105
106
|
end
|
106
107
|
|