gherkin 2.2.5-x86-mswin32

Sign up to get free protection for your applications and to get access to all the features.
Files changed (132) hide show
  1. data/.gitattributes +2 -0
  2. data/.gitignore +11 -0
  3. data/.mailmap +2 -0
  4. data/.rspec +1 -0
  5. data/.rvmrc +1 -0
  6. data/Gemfile +5 -0
  7. data/History.txt +306 -0
  8. data/LICENSE +20 -0
  9. data/README.rdoc +59 -0
  10. data/Rakefile +16 -0
  11. data/VERSION +1 -0
  12. data/bin/gherkin +5 -0
  13. data/build_native_gems.sh +8 -0
  14. data/cucumber.yml +3 -0
  15. data/features/escaped_pipes.feature +8 -0
  16. data/features/feature_parser.feature +237 -0
  17. data/features/json_formatter.feature +278 -0
  18. data/features/json_parser.feature +318 -0
  19. data/features/native_lexer.feature +19 -0
  20. data/features/parser_with_native_lexer.feature +205 -0
  21. data/features/pretty_formatter.feature +15 -0
  22. data/features/step_definitions/eyeball_steps.rb +3 -0
  23. data/features/step_definitions/gherkin_steps.rb +29 -0
  24. data/features/step_definitions/json_formatter_steps.rb +28 -0
  25. data/features/step_definitions/json_parser_steps.rb +20 -0
  26. data/features/step_definitions/pretty_formatter_steps.rb +82 -0
  27. data/features/steps_parser.feature +46 -0
  28. data/features/support/env.rb +38 -0
  29. data/gherkin.gemspec +59 -0
  30. data/ikvm/.gitignore +3 -0
  31. data/java/.gitignore +2 -0
  32. data/java/src/main/java/gherkin/lexer/i18n/.gitignore +1 -0
  33. data/java/src/main/resources/gherkin/.gitignore +1 -0
  34. data/lib/.gitignore +4 -0
  35. data/lib/gherkin.rb +2 -0
  36. data/lib/gherkin/c_lexer.rb +17 -0
  37. data/lib/gherkin/cli/main.rb +33 -0
  38. data/lib/gherkin/formatter/argument.rb +28 -0
  39. data/lib/gherkin/formatter/colors.rb +119 -0
  40. data/lib/gherkin/formatter/escaping.rb +15 -0
  41. data/lib/gherkin/formatter/filter_formatter.rb +136 -0
  42. data/lib/gherkin/formatter/json_formatter.rb +72 -0
  43. data/lib/gherkin/formatter/line_filter.rb +26 -0
  44. data/lib/gherkin/formatter/model.rb +231 -0
  45. data/lib/gherkin/formatter/monochrome_format.rb +9 -0
  46. data/lib/gherkin/formatter/pretty_formatter.rb +174 -0
  47. data/lib/gherkin/formatter/regexp_filter.rb +21 -0
  48. data/lib/gherkin/formatter/tag_count_formatter.rb +47 -0
  49. data/lib/gherkin/formatter/tag_filter.rb +19 -0
  50. data/lib/gherkin/i18n.rb +180 -0
  51. data/lib/gherkin/i18n.yml +601 -0
  52. data/lib/gherkin/json_parser.rb +88 -0
  53. data/lib/gherkin/lexer/i18n_lexer.rb +47 -0
  54. data/lib/gherkin/listener/event.rb +45 -0
  55. data/lib/gherkin/listener/formatter_listener.rb +113 -0
  56. data/lib/gherkin/native.rb +7 -0
  57. data/lib/gherkin/native/ikvm.rb +55 -0
  58. data/lib/gherkin/native/java.rb +55 -0
  59. data/lib/gherkin/native/null.rb +9 -0
  60. data/lib/gherkin/parser/meta.txt +5 -0
  61. data/lib/gherkin/parser/parser.rb +164 -0
  62. data/lib/gherkin/parser/root.txt +11 -0
  63. data/lib/gherkin/parser/steps.txt +4 -0
  64. data/lib/gherkin/rb_lexer.rb +8 -0
  65. data/lib/gherkin/rb_lexer/.gitignore +1 -0
  66. data/lib/gherkin/rb_lexer/README.rdoc +8 -0
  67. data/lib/gherkin/rubify.rb +24 -0
  68. data/lib/gherkin/tag_expression.rb +62 -0
  69. data/lib/gherkin/tools.rb +8 -0
  70. data/lib/gherkin/tools/files.rb +34 -0
  71. data/lib/gherkin/tools/reformat.rb +20 -0
  72. data/lib/gherkin/tools/stats.rb +20 -0
  73. data/lib/gherkin/tools/stats_listener.rb +60 -0
  74. data/lib/gherkin/version.rb +3 -0
  75. data/ragel/i18n/.gitignore +1 -0
  76. data/ragel/lexer.c.rl.erb +459 -0
  77. data/ragel/lexer.java.rl.erb +224 -0
  78. data/ragel/lexer.rb.rl.erb +179 -0
  79. data/ragel/lexer_common.rl.erb +50 -0
  80. data/spec/gherkin/c_lexer_spec.rb +21 -0
  81. data/spec/gherkin/fixtures/1.feature +8 -0
  82. data/spec/gherkin/fixtures/comments_in_table.feature +9 -0
  83. data/spec/gherkin/fixtures/complex.feature +45 -0
  84. data/spec/gherkin/fixtures/complex.json +143 -0
  85. data/spec/gherkin/fixtures/complex_for_filtering.feature +60 -0
  86. data/spec/gherkin/fixtures/complex_with_tags.feature +61 -0
  87. data/spec/gherkin/fixtures/dos_line_endings.feature +45 -0
  88. data/spec/gherkin/fixtures/hantu_pisang.feature +35 -0
  89. data/spec/gherkin/fixtures/i18n_fr.feature +14 -0
  90. data/spec/gherkin/fixtures/i18n_no.feature +7 -0
  91. data/spec/gherkin/fixtures/i18n_zh-CN.feature +9 -0
  92. data/spec/gherkin/fixtures/scenario_outline_with_tags.feature +13 -0
  93. data/spec/gherkin/fixtures/scenario_without_steps.feature +5 -0
  94. data/spec/gherkin/fixtures/simple_with_comments.feature +7 -0
  95. data/spec/gherkin/fixtures/simple_with_tags.feature +11 -0
  96. data/spec/gherkin/fixtures/with_bom.feature +3 -0
  97. data/spec/gherkin/formatter/argument_spec.rb +28 -0
  98. data/spec/gherkin/formatter/colors_spec.rb +18 -0
  99. data/spec/gherkin/formatter/filter_formatter_spec.rb +165 -0
  100. data/spec/gherkin/formatter/model_spec.rb +15 -0
  101. data/spec/gherkin/formatter/pretty_formatter_spec.rb +140 -0
  102. data/spec/gherkin/formatter/spaces.feature +9 -0
  103. data/spec/gherkin/formatter/tabs.feature +9 -0
  104. data/spec/gherkin/formatter/tag_count_formatter_spec.rb +30 -0
  105. data/spec/gherkin/i18n_spec.rb +149 -0
  106. data/spec/gherkin/java_lexer_spec.rb +20 -0
  107. data/spec/gherkin/json.rb +5 -0
  108. data/spec/gherkin/json_parser_spec.rb +67 -0
  109. data/spec/gherkin/lexer/i18n_lexer_spec.rb +43 -0
  110. data/spec/gherkin/output_stream_string_io.rb +24 -0
  111. data/spec/gherkin/parser/parser_spec.rb +16 -0
  112. data/spec/gherkin/rb_lexer_spec.rb +19 -0
  113. data/spec/gherkin/sexp_recorder.rb +56 -0
  114. data/spec/gherkin/shared/lexer_group.rb +592 -0
  115. data/spec/gherkin/shared/py_string_group.rb +153 -0
  116. data/spec/gherkin/shared/row_group.rb +120 -0
  117. data/spec/gherkin/shared/tags_group.rb +54 -0
  118. data/spec/gherkin/tag_expression_spec.rb +137 -0
  119. data/spec/spec_helper.rb +68 -0
  120. data/tasks/bench.rake +184 -0
  121. data/tasks/bench/feature_builder.rb +49 -0
  122. data/tasks/bench/generated/.gitignore +1 -0
  123. data/tasks/bench/null_listener.rb +4 -0
  124. data/tasks/compile.rake +102 -0
  125. data/tasks/cucumber.rake +18 -0
  126. data/tasks/gems.rake +42 -0
  127. data/tasks/ikvm.rake +54 -0
  128. data/tasks/ragel_task.rb +70 -0
  129. data/tasks/rdoc.rake +9 -0
  130. data/tasks/release.rake +30 -0
  131. data/tasks/rspec.rake +8 -0
  132. metadata +447 -0
@@ -0,0 +1,15 @@
1
+ module Gherkin
2
+ module Formatter
3
+ module Escaping
4
+ # Escapes a pipes and backslashes:
5
+ #
6
+ # * | becomes \|
7
+ # * \ becomes \\
8
+ #
9
+ # This is used in the pretty formatter.
10
+ def escape_cell(s)
11
+ s.gsub(/\|/, "\\|").gsub(/\\(?!\|)/, "\\\\\\\\")
12
+ end
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,136 @@
1
+ require 'gherkin/tag_expression'
2
+ require 'gherkin/formatter/regexp_filter'
3
+ require 'gherkin/formatter/line_filter'
4
+ require 'gherkin/formatter/tag_filter'
5
+ require 'gherkin/formatter/model'
6
+ require 'gherkin/native'
7
+
8
+ module Gherkin
9
+ module Formatter
10
+ class FilterFormatter
11
+ native_impl('gherkin')
12
+
13
+ def initialize(formatter, filters)
14
+ @formatter = formatter
15
+ @filter = detect_filter(filters)
16
+
17
+ @feature_tags = []
18
+ @feature_element_tags = []
19
+ @examples_tags = []
20
+
21
+ @feature_events = []
22
+ @background_events = []
23
+ @feature_element_events = []
24
+ @examples_events = []
25
+ end
26
+
27
+ def uri(uri)
28
+ @formatter.uri(uri)
29
+ end
30
+
31
+ def feature(feature)
32
+ @feature_tags = feature.tags
33
+ @feature_name = feature.name
34
+ @feature_events = [feature]
35
+ end
36
+
37
+ def background(background)
38
+ @feature_element_name = background.name
39
+ @feature_element_range = background.line_range
40
+ @background_events = [background]
41
+ end
42
+
43
+ def scenario(scenario)
44
+ replay!
45
+ @feature_element_tags = scenario.tags
46
+ @feature_element_name = scenario.name
47
+ @feature_element_range = scenario.line_range
48
+ @feature_element_events = [scenario]
49
+ end
50
+
51
+ def scenario_outline(scenario_outline)
52
+ replay!
53
+ @feature_element_tags = scenario_outline.tags
54
+ @feature_element_name = scenario_outline.name
55
+ @feature_element_range = scenario_outline.line_range
56
+ @feature_element_events = [scenario_outline]
57
+ end
58
+
59
+ def examples(examples)
60
+ replay!
61
+ @examples_tags = examples.tags
62
+ @examples_name = examples.name
63
+
64
+ table_body_range = examples.rows[1].line..examples.rows[-1].line
65
+ @examples_range = examples.line_range.first..table_body_range.last
66
+ if(@filter.eval([], [], [table_body_range]))
67
+ examples.rows = @filter.filter_table_body_rows(examples.rows)
68
+ end
69
+ @examples_events = [examples]
70
+ end
71
+
72
+ def step(step)
73
+ if @feature_element_events.any?
74
+ @feature_element_events << step
75
+ else
76
+ @background_events << step
77
+ end
78
+
79
+ @feature_element_range = @feature_element_range.first..step.line_range.last
80
+ end
81
+
82
+ def eof
83
+ replay!
84
+ @formatter.eof
85
+ end
86
+
87
+ private
88
+
89
+ def detect_filter(filters)
90
+ raise "Inconsistent filters: #{filters.inspect}" if filters.map{|filter| filter.class}.uniq.length > 1
91
+ case(filters[0])
92
+ when Fixnum
93
+ LineFilter.new(filters)
94
+ when Regexp
95
+ RegexpFilter.new(filters)
96
+ when String
97
+ TagFilter.new(filters)
98
+ end
99
+ end
100
+
101
+ def replay!
102
+ feature_element_ok = @filter.eval(
103
+ (@feature_tags + @feature_element_tags),
104
+ [@feature_name, @feature_element_name].compact,
105
+ [@feature_element_range].compact
106
+ )
107
+ examples_ok = @filter.eval(
108
+ (@feature_tags + @feature_element_tags + @examples_tags),
109
+ [@feature_name, @feature_element_name, @examples_name].compact,
110
+ [@feature_element_range, @examples_range].compact
111
+ )
112
+
113
+ if feature_element_ok || examples_ok
114
+ replay_events!(@feature_events)
115
+ replay_events!(@background_events)
116
+ replay_events!(@feature_element_events)
117
+
118
+ if examples_ok
119
+ replay_events!(@examples_events)
120
+ end
121
+ end
122
+
123
+ @examples_events.clear
124
+ @examples_tags.clear
125
+ @examples_name = nil
126
+ end
127
+
128
+ def replay_events!(events)
129
+ events.each do |event|
130
+ event.replay(@formatter)
131
+ end
132
+ events.clear
133
+ end
134
+ end
135
+ end
136
+ end
@@ -0,0 +1,72 @@
1
+ require 'json'
2
+ require 'gherkin/formatter/model'
3
+ require 'gherkin/native'
4
+
5
+ module Gherkin
6
+ module Formatter
7
+ class JSONFormatter
8
+ native_impl('gherkin')
9
+
10
+ attr_reader :gherkin_object
11
+
12
+ # Creates a new instance that writes the resulting JSON to +io+.
13
+ # If +io+ is nil, the JSON will not be written, but instead a Ruby
14
+ # object can be retrieved with #gherkin_object
15
+ def initialize(io)
16
+ @io = io
17
+ end
18
+
19
+ def uri(uri)
20
+ # We're ignoring the uri - we don't want it as part of the JSON
21
+ # (The pretty formatter uses it just for visual niceness - comments)
22
+ end
23
+
24
+ def feature(feature)
25
+ @gherkin_object = feature.to_hash
26
+ end
27
+
28
+ def background(background)
29
+ feature_elements << background.to_hash
30
+ end
31
+
32
+ def scenario(scenario)
33
+ feature_elements << scenario.to_hash
34
+ end
35
+
36
+ def scenario_outline(scenario_outline)
37
+ feature_elements << scenario_outline.to_hash
38
+ end
39
+
40
+ def examples(examples)
41
+ all_examples << examples.to_hash
42
+ end
43
+
44
+ def step(step)
45
+ steps << step.to_hash
46
+ end
47
+
48
+ def eof
49
+ @io.write(@gherkin_object.to_json) if @io
50
+ end
51
+
52
+ private
53
+
54
+ def feature_elements
55
+ @gherkin_object['elements'] ||= []
56
+ end
57
+
58
+ def feature_element
59
+ feature_elements[-1]
60
+ end
61
+
62
+ def all_examples
63
+ feature_element['examples'] ||= []
64
+ end
65
+
66
+ def steps
67
+ feature_element['steps'] ||= []
68
+ end
69
+ end
70
+ end
71
+ end
72
+
@@ -0,0 +1,26 @@
1
+ module Gherkin
2
+ module Formatter
3
+ class LineFilter
4
+ def initialize(lines)
5
+ @lines = lines
6
+ end
7
+
8
+ def eval(tags, names, ranges)
9
+ ranges.detect do |range|
10
+ @lines.detect do |line|
11
+ range.include?(line)
12
+ end
13
+ end
14
+ end
15
+
16
+ def filter_table_body_rows(rows)
17
+ body = rows.to_a[1..-1].select do |row|
18
+ @lines.detect do |line|
19
+ row.line == line
20
+ end
21
+ end
22
+ [rows[0]] + body
23
+ end
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,231 @@
1
+ require 'gherkin/native'
2
+
3
+ module Gherkin
4
+ module Formatter
5
+ module Model
6
+ class Hashable
7
+ def to_hash
8
+ instance_variables.inject({}) do |hash, ivar|
9
+ value = instance_variable_get(ivar)
10
+ value = value.to_hash if value.respond_to?(:to_hash)
11
+ if Array === value
12
+ value = value.map do |e|
13
+ e.respond_to?(:to_hash) ? e.to_hash : e
14
+ end
15
+ end
16
+ hash[ivar[1..-1]] = value unless [[], nil].index(value)
17
+ hash
18
+ end
19
+ end
20
+ end
21
+
22
+ class BasicStatement < Hashable
23
+ attr_reader :comments, :keyword, :name, :line
24
+
25
+ def initialize(comments, keyword, name, line)
26
+ @comments, @keyword, @name, @line = comments, keyword, name, line
27
+ end
28
+
29
+ def line_range
30
+ first = @comments.any? ? @comments[0].line : first_non_comment_line
31
+ first..line
32
+ end
33
+
34
+ def first_non_comment_line
35
+ @line
36
+ end
37
+ end
38
+
39
+ class DescribedStatement < BasicStatement
40
+ attr_reader :description
41
+
42
+ def initialize(comments, keyword, name, description, line)
43
+ super(comments, keyword, name, line)
44
+ @description = description
45
+ end
46
+ end
47
+
48
+ class TagStatement < DescribedStatement
49
+ attr_reader :tags
50
+
51
+ def initialize(comments, tags, keyword, name, description, line)
52
+ super(comments, keyword, name, description, line)
53
+ @tags = tags
54
+ end
55
+
56
+ def first_non_comment_line
57
+ @tags.any? ? @tags[0].line : @line
58
+ end
59
+ end
60
+
61
+ class Feature < TagStatement
62
+ native_impl('gherkin')
63
+
64
+ def initialize(comments, tags, keyword, name, description, line)
65
+ super(comments, tags, keyword, name, description, line)
66
+ end
67
+
68
+ def replay(formatter)
69
+ formatter.feature(self)
70
+ end
71
+ end
72
+
73
+ class Background < DescribedStatement
74
+ native_impl('gherkin')
75
+
76
+ def initialize(comments, keyword, name, description, line)
77
+ super(comments, keyword, name, description, line)
78
+ @type = "background"
79
+ end
80
+
81
+ def replay(formatter)
82
+ formatter.background(self)
83
+ end
84
+ end
85
+
86
+ class Scenario < TagStatement
87
+ native_impl('gherkin')
88
+
89
+ def initialize(comments, tags, keyword, name, description, line)
90
+ super(comments, tags, keyword, name, description, line)
91
+ @type = "scenario"
92
+ end
93
+
94
+ def replay(formatter)
95
+ formatter.scenario(self)
96
+ end
97
+ end
98
+
99
+ class ScenarioOutline < TagStatement
100
+ native_impl('gherkin')
101
+
102
+ def initialize(comments, tags, keyword, name, description, line)
103
+ super(comments, tags, keyword, name, description, line)
104
+ @type = "scenario_outline"
105
+ end
106
+
107
+ def replay(formatter)
108
+ formatter.scenario_outline(self)
109
+ end
110
+ end
111
+
112
+ class Examples < TagStatement
113
+ native_impl('gherkin')
114
+
115
+ attr_accessor :rows
116
+
117
+ def initialize(comments, tags, keyword, name, description, line, rows=nil)
118
+ super(comments, tags, keyword, name, description, line)
119
+ @rows = rows
120
+ end
121
+
122
+ def replay(formatter)
123
+ formatter.examples(self)
124
+ end
125
+ end
126
+
127
+ class Step < BasicStatement
128
+ native_impl('gherkin')
129
+
130
+ attr_accessor :multiline_arg, :result
131
+
132
+ def initialize(comments, keyword, name, line, multiline_arg=nil, result=nil)
133
+ super(comments, keyword, name, line)
134
+ @multiline_arg = multiline_arg
135
+ @result = result
136
+ end
137
+
138
+ def line_range
139
+ range = super
140
+ case multiline_arg
141
+ when Array
142
+ range = range.first..multiline_arg[-1].line
143
+ when Model::PyString
144
+ range = range.first..multiline_arg.line_range.last
145
+ end
146
+ range
147
+ end
148
+
149
+ def replay(formatter)
150
+ formatter.step(self)
151
+ end
152
+
153
+ def to_hash
154
+ hash = super
155
+ if Array === @multiline_arg
156
+ hash['multiline_arg'] = {
157
+ 'type' => 'table',
158
+ 'value' => hash['multiline_arg']
159
+ }
160
+ elsif PyString === @multiline_arg
161
+ hash['multiline_arg']['type'] = 'py_string'
162
+ end
163
+ hash
164
+ end
165
+ end
166
+
167
+ class Comment < Hashable
168
+ native_impl('gherkin')
169
+
170
+ attr_reader :value, :line
171
+
172
+ def initialize(value, line)
173
+ @value, @line = value, line
174
+ end
175
+ end
176
+
177
+ class Tag < Hashable
178
+ native_impl('gherkin')
179
+
180
+ attr_reader :name, :line
181
+
182
+ def initialize(name, line)
183
+ @name, @line = name, line
184
+ end
185
+
186
+ def eql?(tag)
187
+ @name.eql?(tag.name)
188
+ end
189
+
190
+ def hash
191
+ @name.hash
192
+ end
193
+ end
194
+
195
+ class PyString < Hashable
196
+ native_impl('gherkin')
197
+
198
+ attr_reader :value, :line
199
+
200
+ def initialize(value, line)
201
+ @value, @line = value, line
202
+ end
203
+
204
+ def line_range
205
+ line_count = value.split(/\r?\n/).length
206
+ line..(line+line_count+1)
207
+ end
208
+ end
209
+
210
+ class Row < Hashable
211
+ native_impl('gherkin')
212
+
213
+ attr_reader :comments, :cells, :line
214
+
215
+ def initialize(comments, cells, line)
216
+ @comments, @cells, @line = comments, cells, line
217
+ end
218
+ end
219
+
220
+ class Result
221
+ native_impl('gherkin')
222
+
223
+ attr_reader :status, :error_message, :arguments, :stepdef_location
224
+
225
+ def initialize(status, error_message, arguments, stepdef_location)
226
+ @status, @error_message, @arguments, @stepdef_location = status, error_message, arguments, stepdef_location
227
+ end
228
+ end
229
+ end
230
+ end
231
+ end