gherkin 1.0.2-java

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.
Files changed (89) hide show
  1. data/.gitignore +7 -0
  2. data/.mailmap +2 -0
  3. data/History.txt +9 -0
  4. data/LICENSE +20 -0
  5. data/README.rdoc +38 -0
  6. data/Rakefile +48 -0
  7. data/VERSION.yml +4 -0
  8. data/bin/gherkin +5 -0
  9. data/cucumber.yml +3 -0
  10. data/features/feature_parser.feature +206 -0
  11. data/features/native_lexer.feature +19 -0
  12. data/features/parser_with_native_lexer.feature +205 -0
  13. data/features/pretty_printer.feature +14 -0
  14. data/features/step_definitions/gherkin_steps.rb +34 -0
  15. data/features/step_definitions/pretty_printer_steps.rb +56 -0
  16. data/features/steps_parser.feature +46 -0
  17. data/features/support/env.rb +33 -0
  18. data/gherkin.gemspec +155 -0
  19. data/java/.gitignore +2 -0
  20. data/java/Gherkin.iml +24 -0
  21. data/java/build.xml +13 -0
  22. data/java/src/gherkin/FixJava.java +34 -0
  23. data/java/src/gherkin/Lexer.java +5 -0
  24. data/java/src/gherkin/LexingError.java +7 -0
  25. data/java/src/gherkin/Listener.java +27 -0
  26. data/java/src/gherkin/ParseError.java +22 -0
  27. data/java/src/gherkin/Parser.java +185 -0
  28. data/java/src/gherkin/lexer/.gitignore +1 -0
  29. data/java/src/gherkin/parser/StateMachineReader.java +62 -0
  30. data/lib/.gitignore +4 -0
  31. data/lib/gherkin.rb +2 -0
  32. data/lib/gherkin/c_lexer.rb +10 -0
  33. data/lib/gherkin/cli/main.rb +34 -0
  34. data/lib/gherkin/core_ext/array.rb +5 -0
  35. data/lib/gherkin/i18n.rb +87 -0
  36. data/lib/gherkin/i18n.yml +535 -0
  37. data/lib/gherkin/i18n_lexer.rb +29 -0
  38. data/lib/gherkin/java_lexer.rb +10 -0
  39. data/lib/gherkin/lexer.rb +44 -0
  40. data/lib/gherkin/parser.rb +19 -0
  41. data/lib/gherkin/parser/meta.txt +4 -0
  42. data/lib/gherkin/parser/root.txt +9 -0
  43. data/lib/gherkin/parser/steps.txt +3 -0
  44. data/lib/gherkin/rb_lexer.rb +10 -0
  45. data/lib/gherkin/rb_lexer/.gitignore +1 -0
  46. data/lib/gherkin/rb_lexer/README.rdoc +8 -0
  47. data/lib/gherkin/rb_parser.rb +117 -0
  48. data/lib/gherkin/tools.rb +8 -0
  49. data/lib/gherkin/tools/files.rb +30 -0
  50. data/lib/gherkin/tools/pretty_listener.rb +84 -0
  51. data/lib/gherkin/tools/reformat.rb +19 -0
  52. data/lib/gherkin/tools/stats.rb +21 -0
  53. data/lib/gherkin/tools/stats_listener.rb +50 -0
  54. data/nativegems.sh +5 -0
  55. data/ragel/i18n/.gitignore +1 -0
  56. data/ragel/lexer.c.rl.erb +403 -0
  57. data/ragel/lexer.java.rl.erb +200 -0
  58. data/ragel/lexer.rb.rl.erb +171 -0
  59. data/ragel/lexer_common.rl.erb +46 -0
  60. data/spec/gherkin/c_lexer_spec.rb +21 -0
  61. data/spec/gherkin/fixtures/1.feature +8 -0
  62. data/spec/gherkin/fixtures/complex.feature +43 -0
  63. data/spec/gherkin/fixtures/i18n_fr.feature +13 -0
  64. data/spec/gherkin/fixtures/i18n_no.feature +6 -0
  65. data/spec/gherkin/fixtures/i18n_zh-CN.feature +8 -0
  66. data/spec/gherkin/fixtures/simple.feature +3 -0
  67. data/spec/gherkin/fixtures/simple_with_comments.feature +7 -0
  68. data/spec/gherkin/fixtures/simple_with_tags.feature +11 -0
  69. data/spec/gherkin/i18n_lexer_spec.rb +22 -0
  70. data/spec/gherkin/i18n_spec.rb +57 -0
  71. data/spec/gherkin/java_lexer_spec.rb +20 -0
  72. data/spec/gherkin/parser_spec.rb +28 -0
  73. data/spec/gherkin/rb_lexer_spec.rb +18 -0
  74. data/spec/gherkin/sexp_recorder.rb +29 -0
  75. data/spec/gherkin/shared/lexer_spec.rb +433 -0
  76. data/spec/gherkin/shared/py_string_spec.rb +124 -0
  77. data/spec/gherkin/shared/table_spec.rb +97 -0
  78. data/spec/gherkin/shared/tags_spec.rb +50 -0
  79. data/spec/spec_helper.rb +53 -0
  80. data/tasks/bench.rake +186 -0
  81. data/tasks/bench/feature_builder.rb +49 -0
  82. data/tasks/bench/generated/.gitignore +1 -0
  83. data/tasks/bench/null_listener.rb +4 -0
  84. data/tasks/compile.rake +70 -0
  85. data/tasks/cucumber.rake +20 -0
  86. data/tasks/ragel_task.rb +70 -0
  87. data/tasks/rdoc.rake +12 -0
  88. data/tasks/rspec.rake +15 -0
  89. metadata +196 -0
@@ -0,0 +1,171 @@
1
+ require 'gherkin/core_ext/array'
2
+
3
+ module Gherkin
4
+ module RbLexer
5
+ class <%= @i18n.sanitized_key.capitalize %> #:nodoc:
6
+ %%{
7
+ machine lexer;
8
+
9
+ action begin_content {
10
+ @content_start = p
11
+ @current_line = @line_number
12
+ }
13
+
14
+ action start_pystring {
15
+ @current_line = @line_number
16
+ @start_col = p - @last_newline
17
+ }
18
+
19
+ action begin_pystring_content {
20
+ @content_start = p
21
+ }
22
+
23
+ action store_pystring_content {
24
+ con = unindent(@start_col, data[@content_start...@next_keyword_start-1].utf8_pack("c*").sub(/(\r?\n)?( )*\Z/, ''))
25
+ @listener.py_string(con, @current_line)
26
+ }
27
+
28
+ action store_feature_content {
29
+ store_keyword_content(:feature, data, p, eof) { |con| multiline_strip(con) }
30
+ p = @next_keyword_start - 1 if @next_keyword_start
31
+ @next_keyword_start = nil
32
+ }
33
+
34
+ action store_background_content {
35
+ store_keyword_content(:background, data, p, eof) { |con| multiline_strip(con) }
36
+ p = @next_keyword_start - 1 if @next_keyword_start
37
+ @next_keyword_start = nil
38
+ }
39
+
40
+ action store_scenario_content {
41
+ store_keyword_content(:scenario, data, p, eof) { |con| multiline_strip(con) }
42
+ p = @next_keyword_start - 1 if @next_keyword_start
43
+ @next_keyword_start = nil
44
+ }
45
+
46
+ action store_scenario_outline_content {
47
+ store_keyword_content(:scenario_outline, data, p, eof) { |con| multiline_strip(con) }
48
+ p = @next_keyword_start - 1 if @next_keyword_start
49
+ @next_keyword_start = nil
50
+ }
51
+
52
+ action store_examples_content {
53
+ store_keyword_content(:examples, data, p, eof) { |con| multiline_strip(con) }
54
+ p = @next_keyword_start - 1 if @next_keyword_start
55
+ @next_keyword_start = nil
56
+ }
57
+
58
+ action store_step_content {
59
+ con = data[@content_start...p].utf8_pack("c*").strip
60
+ @listener.step(@keyword, con, @current_line)
61
+ }
62
+
63
+ action store_comment_content {
64
+ con = data[@content_start...p].utf8_pack("c*").strip
65
+ @listener.comment(con, @line_number)
66
+ @keyword_start = nil
67
+ }
68
+
69
+ action store_tag_content {
70
+ con = data[@content_start...p].utf8_pack("c*").strip
71
+ @listener.tag(con, @current_line)
72
+ @keyword_start = nil
73
+ }
74
+
75
+ action inc_line_number {
76
+ @line_number += 1
77
+ }
78
+
79
+ action last_newline {
80
+ @last_newline = p + 1
81
+ }
82
+
83
+ action start_keyword {
84
+ @keyword_start ||= p
85
+ }
86
+
87
+ action end_keyword {
88
+ @keyword = data[@keyword_start...p].utf8_pack("c*").sub(/:$/,'').strip
89
+ @keyword_start = nil
90
+ }
91
+
92
+ action next_keyword_start {
93
+ @next_keyword_start = p
94
+ }
95
+
96
+ action start_table {
97
+ p = p - 1
98
+ @rows = []
99
+ @current_line = @line_number
100
+ }
101
+
102
+ action start_row {
103
+ current_row = []
104
+ }
105
+
106
+ action begin_cell_content {
107
+ @content_start = p
108
+ }
109
+
110
+ action store_cell_content {
111
+ con = data[@content_start...p].utf8_pack("c*").strip
112
+ current_row << con
113
+ }
114
+
115
+ action store_row {
116
+ @rows << current_row
117
+ }
118
+
119
+ action store_table {
120
+ if @rows.size != 0
121
+ @listener.table(@rows, @current_line)
122
+ end
123
+ }
124
+
125
+ action end_feature {
126
+ if cs < lexer_first_final
127
+ content = current_line_content(data, p)
128
+ raise Lexer::LexingError.new("Lexing error on line %d: '%s'." % [@line_number, content])
129
+ end
130
+ }
131
+
132
+ include lexer_common "lexer_common.<%= @i18n.sanitized_key %>.rl";
133
+ }%%
134
+
135
+ def initialize(listener)
136
+ @listener = listener
137
+ %% write data;
138
+ end
139
+
140
+ def scan(data)
141
+ data = (data + "\n%_FEATURE_END_%").unpack("c*") # Explicit EOF simplifies things considerably
142
+ eof = pe = data.length
143
+
144
+ @line_number = 1
145
+ @last_newline = 0
146
+
147
+ %% write init;
148
+ %% write exec;
149
+ end
150
+
151
+ def multiline_strip(text)
152
+ text.split("\n").map{|s| s.strip}.join("\n").strip
153
+ end
154
+
155
+ def unindent(startcol, text)
156
+ text.gsub(/^ {0,#{startcol}}/, "")
157
+ end
158
+
159
+ def store_keyword_content(event, data, p, eof)
160
+ end_point = (!@next_keyword_start or (p == eof)) ? p : @next_keyword_start
161
+ con = yield data[@content_start...end_point].utf8_pack("c*")
162
+ @listener.send(event, @keyword, con, @current_line)
163
+ end
164
+
165
+ def current_line_content(data, p)
166
+ rest = data[@last_newline..-1]
167
+ rest[0..rest.index(10)||-1].utf8_pack("c*").strip
168
+ end
169
+ end
170
+ end
171
+ end
@@ -0,0 +1,46 @@
1
+ %%{
2
+ machine lexer_common;
3
+
4
+ # Language specific
5
+ I18N_Feature = (<%= ragel_list(@i18n.feature_keywords) %> ':') >start_keyword %end_keyword;
6
+ I18N_Background = (<%= ragel_list(@i18n.background_keywords) %> ':') >start_keyword %end_keyword;
7
+ I18N_ScenarioOutline = (<%= ragel_list(@i18n.scenario_outline_keywords) %> ':') >start_keyword %end_keyword;
8
+ I18N_Scenario = (<%= ragel_list(@i18n.scenario_keywords) %> ':') >start_keyword %end_keyword;
9
+ I18N_Step = <%= ragel_list(@i18n.step_keywords) %> >start_keyword %end_keyword;
10
+ I18N_Examples = (<%= ragel_list(@i18n.examples_keywords) %> ':') >start_keyword %end_keyword;
11
+
12
+ EOF = '%_FEATURE_END_%'; # Explicit EOF added before scanning begins
13
+ EOL = ('\r'? '\n') @inc_line_number @last_newline;
14
+
15
+ FeatureHeadingEnd = EOL+ space* (I18N_Background | I18N_Scenario | I18N_ScenarioOutline | '@' | '#' | EOF) >next_keyword_start;
16
+ ScenarioHeadingEnd = EOL+ space* ( I18N_Scenario | I18N_ScenarioOutline | I18N_Step | '@' | '#' | EOF ) >next_keyword_start;
17
+ BackgroundHeadingEnd = EOL+ space* ( I18N_Scenario | I18N_ScenarioOutline | I18N_Step | '@' | '#'| EOF ) >next_keyword_start;
18
+ ScenarioOutlineHeadingEnd = EOL+ space* ( I18N_Scenario | I18N_Step | '@' | '#' | EOF ) >next_keyword_start;
19
+ ExamplesHeadingEnd = EOL+ space* '|' >next_keyword_start;
20
+
21
+ FeatureHeading = space* I18N_Feature %begin_content ^FeatureHeadingEnd* :>> FeatureHeadingEnd @store_feature_content;
22
+ BackgroundHeading = space* I18N_Background %begin_content ^BackgroundHeadingEnd* :>> BackgroundHeadingEnd @store_background_content;
23
+ ScenarioHeading = space* I18N_Scenario %begin_content ^ScenarioHeadingEnd* :>> ScenarioHeadingEnd @store_scenario_content;
24
+ ScenarioOutlineHeading = space* I18N_ScenarioOutline %begin_content ^ScenarioOutlineHeadingEnd* :>> ScenarioOutlineHeadingEnd @store_scenario_outline_content;
25
+ ExamplesHeading = space* I18N_Examples %begin_content ^ExamplesHeadingEnd* :>> ExamplesHeadingEnd @store_examples_content;
26
+
27
+ Step = space* I18N_Step %begin_content ^EOL+ %store_step_content EOL+;
28
+ Comment = space* '#' >begin_content ^EOL* %store_comment_content EOL+;
29
+
30
+ Tag = ( '@' [^@\r\n\t ]+ >begin_content ) %store_tag_content;
31
+ Tags = space* (Tag space*)+ EOL+;
32
+
33
+ StartTable = space* '|' >start_table;
34
+ EndTable = EOL space* ^('|') >next_keyword_start;
35
+ Cell = '|' (any - '|')* >begin_cell_content %store_cell_content;
36
+ Row = space* Cell* >start_row '|' :>> (space* EOL+ space*) %store_row;
37
+ Table = StartTable :>> Row+ %store_table <: EndTable?;
38
+
39
+ StartPyString = '"""' >start_pystring space* :>> EOL;
40
+ EndPyString = (space* '"""') >next_keyword_start;
41
+ PyString = space* StartPyString %begin_pystring_content (^EOL | EOL)* :>> EndPyString %store_pystring_content space* EOL+;
42
+
43
+ Tokens = (space | EOL)* (Tags | Comment | FeatureHeading | BackgroundHeading | ScenarioHeading | ScenarioOutlineHeading | ExamplesHeading | Step | Table | PyString)* (space | EOL)* EOF;
44
+
45
+ main := Tokens %end_feature @!end_feature;
46
+ }%%
@@ -0,0 +1,21 @@
1
+ #encoding: utf-8
2
+ unless defined?(JRUBY_VERSION)
3
+ require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
4
+ require 'gherkin/c_lexer'
5
+
6
+ module Gherkin
7
+ module Lexer
8
+ describe "C Lexer" do
9
+ before do
10
+ @listener = Gherkin::SexpRecorder.new
11
+ @lexer = Gherkin::CLexer['en'].new(@listener)
12
+ end
13
+
14
+ it_should_behave_like "a Gherkin lexer"
15
+ it_should_behave_like "a Gherkin lexer lexing tags"
16
+ it_should_behave_like "a Gherkin lexer lexing py_strings"
17
+ it_should_behave_like "a Gherkin lexer lexing tables"
18
+ end
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,8 @@
1
+ Feature: Logging in
2
+ So that I can be myself
3
+ # Comment
4
+ Scenario: Anonymous user can get a login form.
5
+ Scenery here
6
+
7
+ @tag
8
+ Scenario: Another one
@@ -0,0 +1,43 @@
1
+ #Comment on line 1
2
+ #Comment on line 2
3
+ @tag1 @tag2
4
+ Feature: Feature Text
5
+ In order to test multiline forms
6
+ As a ragel writer
7
+ I need to check for complex combinations
8
+
9
+ #Comment on line 9
10
+
11
+ #Comment on line 11
12
+
13
+ Background:
14
+ Given this is a background step
15
+ And this is another one
16
+
17
+ @tag3 @tag4
18
+ Scenario: Reading a Scenario
19
+ Given there is a step
20
+ But not another step
21
+
22
+ @tag3
23
+ Scenario: Reading a second scenario
24
+ #Comment on line 24
25
+ Given a third step with a table
26
+ |a|b|
27
+ |c|d|
28
+ |e|f|
29
+ And I am still testing things
30
+ |g|h|
31
+ |e|r|
32
+ |k|i|
33
+ |n||
34
+ And I am done testing these tables
35
+ #Comment on line 29
36
+ Then I am happy
37
+
38
+ Scenario: Hammerzeit
39
+ Given All work and no play
40
+ """
41
+ Makes Homer something something
42
+ """
43
+ Then crazy
@@ -0,0 +1,13 @@
1
+ Fonctionnalité: Addition
2
+ Plan du scénario: Addition de produits dérivés
3
+ Soit une calculatrice
4
+ Etant donné qu'on tape <a>
5
+ Et qu'on tape <b>
6
+ Lorsqu'on tape additionner
7
+ Alors le résultat doit être <somme>
8
+
9
+ Exemples:
10
+ | a | b | somme |
11
+ | 2 | 2 | 4 |
12
+ | 2 | 3 | 5 |
13
+
@@ -0,0 +1,6 @@
1
+ Egenskap: i18n support
2
+
3
+ Scenario: Parsing many languages
4
+ Gitt Gherkin supports many languages
5
+ Når Norwegian keywords are parsed
6
+ Så they should be recognized
@@ -0,0 +1,8 @@
1
+ 功能:加法
2
+
3
+ 场景: 两个数相加
4
+ 假如我已经在计算器里输入6
5
+ 而且我已经在计算器里输入7
6
+ 当我按相加按钮
7
+ 那么我应该在屏幕上看到的结果是13
8
+
@@ -0,0 +1,3 @@
1
+ Feature: Feature Text
2
+ Scenario: Reading a Scenario
3
+ Given there is a step
@@ -0,0 +1,7 @@
1
+ # Here is a comment
2
+ Feature: Feature Text
3
+ # Here is another # comment
4
+ Scenario: Reading a Scenario
5
+ # Here is a third comment
6
+ Given there is a step
7
+ # Here is a fourth comment
@@ -0,0 +1,11 @@
1
+ # FC
2
+ @ft
3
+ Feature: hi
4
+
5
+ @st1 @st2
6
+ Scenario: First
7
+ Given Pepper
8
+
9
+ @st3
10
+ @st4 @ST5 @#^%&ST6**!
11
+ Scenario: Second
@@ -0,0 +1,22 @@
1
+ #encoding: utf-8
2
+ require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
3
+
4
+ module Gherkin
5
+ describe I18nLexer do
6
+ before do
7
+ @lexer = I18nLexer.new(SexpRecorder.new)
8
+ end
9
+
10
+ it "should store the i18n language of the last scanned feature" do
11
+ @lexer.scan("# language: fr\n")
12
+ @lexer.language.key.should == "fr"
13
+ @lexer.scan("# language: no\n")
14
+ @lexer.language.key.should == "no"
15
+ end
16
+
17
+ it "should use English i18n by default" do
18
+ @lexer.scan("Feature: foo\n")
19
+ @lexer.language.key.should == "en"
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,57 @@
1
+ #encoding: utf-8
2
+ require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
3
+
4
+ module Gherkin
5
+ module Lexer
6
+ describe "i18n parsing" do
7
+ before do
8
+ @listener = Gherkin::SexpRecorder.new
9
+ end
10
+
11
+ def scan_file(lexer, file)
12
+ lexer.scan(File.new(File.dirname(__FILE__) + "/fixtures/" + file).read)
13
+ end
14
+
15
+ it "should recognize keywords in the language of the lexer" do
16
+ lexer = Gherkin::Lexer['no'].new(@listener)
17
+ scan_file(lexer, "i18n_no.feature")
18
+ @listener.to_sexp.should == [
19
+ [:feature, "Egenskap", "i18n support", 1],
20
+ [:scenario, "Scenario", "Parsing many languages", 3],
21
+ [:step, "Gitt", "Gherkin supports many languages", 4],
22
+ [:step, "Når", "Norwegian keywords are parsed", 5],
23
+ [:step, "Så", "they should be recognized", 6]
24
+ ]
25
+ end
26
+
27
+ it "should parse languages without a space after keywords" do
28
+ lexer = Gherkin::Lexer['zh-CN'].new(@listener)
29
+ scan_file(lexer, "i18n_zh-CN.feature")
30
+ @listener.to_sexp.should == [
31
+ [:feature, "功能", "加法", 1],
32
+ [:scenario, "场景", "两个数相加", 3],
33
+ [:step, "假如", "我已经在计算器里输入6", 4],
34
+ [:step, "而且", "我已经在计算器里输入7", 5],
35
+ [:step, "当", "我按相加按钮", 6],
36
+ [:step, "那么", "我应该在屏幕上看到的结果是13", 7]
37
+ ]
38
+ end
39
+
40
+ it "should parse languages with spaces after some keywords but not others" do
41
+ lexer = Gherkin::Lexer['fr'].new(@listener)
42
+ scan_file(lexer, "i18n_fr.feature")
43
+ @listener.to_sexp.should == [
44
+ [:feature, "Fonctionnalité", "Addition", 1],
45
+ [:scenario_outline, "Plan du scénario", "Addition de produits dérivés", 2],
46
+ [:step, "Soit", "une calculatrice", 3],
47
+ [:step, "Etant donné", "qu'on tape <a>", 4],
48
+ [:step, "Et", "qu'on tape <b>", 5],
49
+ [:step, "Lorsqu'", "on tape additionner", 6],
50
+ [:step, "Alors", "le résultat doit être <somme>", 7],
51
+ [:examples, "Exemples", "", 9],
52
+ [:table, [["a","b","somme"],["2","2","4"],["2","3","5"]], 10]
53
+ ]
54
+ end
55
+ end
56
+ end
57
+ end
@@ -0,0 +1,20 @@
1
+ #encoding: utf-8
2
+ if defined?(JRUBY_VERSION)
3
+ require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
4
+
5
+ module Gherkin
6
+ module JavaLexer
7
+ describe "Java Lexer" do
8
+ before do
9
+ @listener = Gherkin::SexpRecorder.new
10
+ @lexer = Gherkin::Lexer.java['en'].new(@listener)
11
+ end
12
+
13
+ it_should_behave_like "a Gherkin lexer"
14
+ it_should_behave_like "a Gherkin lexer lexing tags"
15
+ it_should_behave_like "a Gherkin lexer lexing py_strings"
16
+ it_should_behave_like "a Gherkin lexer lexing tables"
17
+ end
18
+ end
19
+ end
20
+ end