gherkin 2.2.5-x86-mswin32
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitattributes +2 -0
- data/.gitignore +11 -0
- data/.mailmap +2 -0
- data/.rspec +1 -0
- data/.rvmrc +1 -0
- data/Gemfile +5 -0
- data/History.txt +306 -0
- data/LICENSE +20 -0
- data/README.rdoc +59 -0
- data/Rakefile +16 -0
- data/VERSION +1 -0
- data/bin/gherkin +5 -0
- data/build_native_gems.sh +8 -0
- data/cucumber.yml +3 -0
- data/features/escaped_pipes.feature +8 -0
- data/features/feature_parser.feature +237 -0
- data/features/json_formatter.feature +278 -0
- data/features/json_parser.feature +318 -0
- data/features/native_lexer.feature +19 -0
- data/features/parser_with_native_lexer.feature +205 -0
- data/features/pretty_formatter.feature +15 -0
- data/features/step_definitions/eyeball_steps.rb +3 -0
- data/features/step_definitions/gherkin_steps.rb +29 -0
- data/features/step_definitions/json_formatter_steps.rb +28 -0
- data/features/step_definitions/json_parser_steps.rb +20 -0
- data/features/step_definitions/pretty_formatter_steps.rb +82 -0
- data/features/steps_parser.feature +46 -0
- data/features/support/env.rb +38 -0
- data/gherkin.gemspec +59 -0
- data/ikvm/.gitignore +3 -0
- data/java/.gitignore +2 -0
- data/java/src/main/java/gherkin/lexer/i18n/.gitignore +1 -0
- data/java/src/main/resources/gherkin/.gitignore +1 -0
- data/lib/.gitignore +4 -0
- data/lib/gherkin.rb +2 -0
- data/lib/gherkin/c_lexer.rb +17 -0
- data/lib/gherkin/cli/main.rb +33 -0
- data/lib/gherkin/formatter/argument.rb +28 -0
- data/lib/gherkin/formatter/colors.rb +119 -0
- data/lib/gherkin/formatter/escaping.rb +15 -0
- data/lib/gherkin/formatter/filter_formatter.rb +136 -0
- data/lib/gherkin/formatter/json_formatter.rb +72 -0
- data/lib/gherkin/formatter/line_filter.rb +26 -0
- data/lib/gherkin/formatter/model.rb +231 -0
- data/lib/gherkin/formatter/monochrome_format.rb +9 -0
- data/lib/gherkin/formatter/pretty_formatter.rb +174 -0
- data/lib/gherkin/formatter/regexp_filter.rb +21 -0
- data/lib/gherkin/formatter/tag_count_formatter.rb +47 -0
- data/lib/gherkin/formatter/tag_filter.rb +19 -0
- data/lib/gherkin/i18n.rb +180 -0
- data/lib/gherkin/i18n.yml +601 -0
- data/lib/gherkin/json_parser.rb +88 -0
- data/lib/gherkin/lexer/i18n_lexer.rb +47 -0
- data/lib/gherkin/listener/event.rb +45 -0
- data/lib/gherkin/listener/formatter_listener.rb +113 -0
- data/lib/gherkin/native.rb +7 -0
- data/lib/gherkin/native/ikvm.rb +55 -0
- data/lib/gherkin/native/java.rb +55 -0
- data/lib/gherkin/native/null.rb +9 -0
- data/lib/gherkin/parser/meta.txt +5 -0
- data/lib/gherkin/parser/parser.rb +164 -0
- data/lib/gherkin/parser/root.txt +11 -0
- data/lib/gherkin/parser/steps.txt +4 -0
- data/lib/gherkin/rb_lexer.rb +8 -0
- data/lib/gherkin/rb_lexer/.gitignore +1 -0
- data/lib/gherkin/rb_lexer/README.rdoc +8 -0
- data/lib/gherkin/rubify.rb +24 -0
- data/lib/gherkin/tag_expression.rb +62 -0
- data/lib/gherkin/tools.rb +8 -0
- data/lib/gherkin/tools/files.rb +34 -0
- data/lib/gherkin/tools/reformat.rb +20 -0
- data/lib/gherkin/tools/stats.rb +20 -0
- data/lib/gherkin/tools/stats_listener.rb +60 -0
- data/lib/gherkin/version.rb +3 -0
- data/ragel/i18n/.gitignore +1 -0
- data/ragel/lexer.c.rl.erb +459 -0
- data/ragel/lexer.java.rl.erb +224 -0
- data/ragel/lexer.rb.rl.erb +179 -0
- data/ragel/lexer_common.rl.erb +50 -0
- data/spec/gherkin/c_lexer_spec.rb +21 -0
- data/spec/gherkin/fixtures/1.feature +8 -0
- data/spec/gherkin/fixtures/comments_in_table.feature +9 -0
- data/spec/gherkin/fixtures/complex.feature +45 -0
- data/spec/gherkin/fixtures/complex.json +143 -0
- data/spec/gherkin/fixtures/complex_for_filtering.feature +60 -0
- data/spec/gherkin/fixtures/complex_with_tags.feature +61 -0
- data/spec/gherkin/fixtures/dos_line_endings.feature +45 -0
- data/spec/gherkin/fixtures/hantu_pisang.feature +35 -0
- data/spec/gherkin/fixtures/i18n_fr.feature +14 -0
- data/spec/gherkin/fixtures/i18n_no.feature +7 -0
- data/spec/gherkin/fixtures/i18n_zh-CN.feature +9 -0
- data/spec/gherkin/fixtures/scenario_outline_with_tags.feature +13 -0
- data/spec/gherkin/fixtures/scenario_without_steps.feature +5 -0
- data/spec/gherkin/fixtures/simple_with_comments.feature +7 -0
- data/spec/gherkin/fixtures/simple_with_tags.feature +11 -0
- data/spec/gherkin/fixtures/with_bom.feature +3 -0
- data/spec/gherkin/formatter/argument_spec.rb +28 -0
- data/spec/gherkin/formatter/colors_spec.rb +18 -0
- data/spec/gherkin/formatter/filter_formatter_spec.rb +165 -0
- data/spec/gherkin/formatter/model_spec.rb +15 -0
- data/spec/gherkin/formatter/pretty_formatter_spec.rb +140 -0
- data/spec/gherkin/formatter/spaces.feature +9 -0
- data/spec/gherkin/formatter/tabs.feature +9 -0
- data/spec/gherkin/formatter/tag_count_formatter_spec.rb +30 -0
- data/spec/gherkin/i18n_spec.rb +149 -0
- data/spec/gherkin/java_lexer_spec.rb +20 -0
- data/spec/gherkin/json.rb +5 -0
- data/spec/gherkin/json_parser_spec.rb +67 -0
- data/spec/gherkin/lexer/i18n_lexer_spec.rb +43 -0
- data/spec/gherkin/output_stream_string_io.rb +24 -0
- data/spec/gherkin/parser/parser_spec.rb +16 -0
- data/spec/gherkin/rb_lexer_spec.rb +19 -0
- data/spec/gherkin/sexp_recorder.rb +56 -0
- data/spec/gherkin/shared/lexer_group.rb +592 -0
- data/spec/gherkin/shared/py_string_group.rb +153 -0
- data/spec/gherkin/shared/row_group.rb +120 -0
- data/spec/gherkin/shared/tags_group.rb +54 -0
- data/spec/gherkin/tag_expression_spec.rb +137 -0
- data/spec/spec_helper.rb +68 -0
- data/tasks/bench.rake +184 -0
- data/tasks/bench/feature_builder.rb +49 -0
- data/tasks/bench/generated/.gitignore +1 -0
- data/tasks/bench/null_listener.rb +4 -0
- data/tasks/compile.rake +102 -0
- data/tasks/cucumber.rake +18 -0
- data/tasks/gems.rake +42 -0
- data/tasks/ikvm.rake +54 -0
- data/tasks/ragel_task.rb +70 -0
- data/tasks/rdoc.rake +9 -0
- data/tasks/release.rake +30 -0
- data/tasks/rspec.rake +8 -0
- metadata +447 -0
@@ -0,0 +1,30 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
require 'spec_helper'
|
3
|
+
require 'gherkin/parser/parser'
|
4
|
+
require 'gherkin/formatter/tag_count_formatter'
|
5
|
+
|
6
|
+
module Gherkin
|
7
|
+
module Formatter
|
8
|
+
describe TagCountFormatter do
|
9
|
+
it "should count tags" do
|
10
|
+
tag_counts = {}
|
11
|
+
dummy = Gherkin::SexpRecorder.new
|
12
|
+
formatter = Gherkin::Formatter::TagCountFormatter.new(dummy, tag_counts)
|
13
|
+
parser = Gherkin::Parser::Parser.new(formatter)
|
14
|
+
|
15
|
+
f = File.new(File.dirname(__FILE__) + "/../fixtures/complex_with_tags.feature").read
|
16
|
+
parser.parse(f, 'f.feature', 0)
|
17
|
+
|
18
|
+
tag_counts.should == {
|
19
|
+
"@hamster" => ["f.feature:58"],
|
20
|
+
"@tag1" => ["f.feature:18","f.feature:23","f.feature:39","f.feature:52","f.feature:58"],
|
21
|
+
"@tag2" => ["f.feature:18","f.feature:23","f.feature:39","f.feature:52","f.feature:58"],
|
22
|
+
"@tag3" => ["f.feature:18", "f.feature:23"],
|
23
|
+
"@tag4" => ["f.feature:18"],
|
24
|
+
"@neat" => ["f.feature:52"],
|
25
|
+
"@more" => ["f.feature:52", "f.feature:58"]
|
26
|
+
}
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
@@ -0,0 +1,149 @@
|
|
1
|
+
#encoding: utf-8
|
2
|
+
require 'spec_helper'
|
3
|
+
|
4
|
+
module Gherkin
|
5
|
+
module Lexer
|
6
|
+
describe I18n 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::I18nLexer.new(@listener, false)
|
17
|
+
scan_file(lexer, "i18n_no.feature")
|
18
|
+
@listener.to_sexp.should == [
|
19
|
+
[:comment, "#language:no", 1],
|
20
|
+
[:feature, "Egenskap", "i18n support", "", 2],
|
21
|
+
[:scenario, "Scenario", "Parsing many languages", "", 4],
|
22
|
+
[:step, "Gitt ", "Gherkin supports many languages", 5],
|
23
|
+
[:step, "Når ", "Norwegian keywords are parsed", 6],
|
24
|
+
[:step, "Så ", "they should be recognized", 7],
|
25
|
+
[:eof]
|
26
|
+
]
|
27
|
+
end
|
28
|
+
|
29
|
+
it "should parse languages without a space after keywords" do
|
30
|
+
lexer = Gherkin::Lexer::I18nLexer.new(@listener, false)
|
31
|
+
scan_file(lexer, "i18n_zh-CN.feature")
|
32
|
+
@listener.to_sexp.should == [
|
33
|
+
[:comment, "#language:zh-CN", 1],
|
34
|
+
[:feature, "功能", "加法", "", 2],
|
35
|
+
[:scenario, "场景", "两个数相加", "", 4],
|
36
|
+
[:step, "假如", "我已经在计算器里输入6", 5],
|
37
|
+
[:step, "而且", "我已经在计算器里输入7", 6],
|
38
|
+
[:step, "当", "我按相加按钮", 7],
|
39
|
+
[:step, "那么", "我应该在屏幕上看到的结果是13", 8],
|
40
|
+
[:eof]
|
41
|
+
]
|
42
|
+
end
|
43
|
+
|
44
|
+
it "should parse languages with spaces after some keywords but not others" do
|
45
|
+
lexer = Gherkin::Lexer::I18nLexer.new(@listener, false)
|
46
|
+
scan_file(lexer, "i18n_fr.feature")
|
47
|
+
@listener.to_sexp.should == [
|
48
|
+
[:comment, "#language:fr", 1],
|
49
|
+
[:feature, "Fonctionnalité", "Addition", "", 2],
|
50
|
+
[:scenario_outline, "Plan du scénario", "Addition de produits dérivés", "", 3],
|
51
|
+
[:step, "Soit ", "une calculatrice", 4],
|
52
|
+
[:step, "Etant donné ", "qu'on tape <a>", 5],
|
53
|
+
[:step, "Et ", "qu'on tape <b>", 6],
|
54
|
+
[:step, "Lorsqu'", "on tape additionner", 7],
|
55
|
+
[:step, "Alors ", "le résultat doit être <somme>", 8],
|
56
|
+
[:examples, "Exemples", "", "", 10],
|
57
|
+
[:row, %w{a b somme}, 11],
|
58
|
+
[:row, %w{2 2 4}, 12],
|
59
|
+
[:row, %w{2 3 5}, 13],
|
60
|
+
[:eof]
|
61
|
+
]
|
62
|
+
end
|
63
|
+
|
64
|
+
describe 'keywords' do
|
65
|
+
it "should have code keywords without space, comma or apostrophe" do
|
66
|
+
['Akkor', 'Etantdonné', 'Lorsque', '假設'].each do |code_keyword|
|
67
|
+
Gherkin::I18n.code_keywords.should include(code_keyword)
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
71
|
+
it "should report keyword regexp" do
|
72
|
+
Gherkin::I18n.keyword_regexp(:step).should =~ /\|Quando \|Quand \|Quan \|Pryd \|Pokud \|/
|
73
|
+
end
|
74
|
+
|
75
|
+
unless defined?(JRUBY_VERSION)
|
76
|
+
it "should print available languages" do
|
77
|
+
("\n" + Gherkin::I18n.language_table).should == %{
|
78
|
+
| ar | Arabic | العربية |
|
79
|
+
| bg | Bulgarian | български |
|
80
|
+
| ca | Catalan | català |
|
81
|
+
| cs | Czech | Česky |
|
82
|
+
| cy-GB | Welsh | Cymraeg |
|
83
|
+
| da | Danish | dansk |
|
84
|
+
| de | German | Deutsch |
|
85
|
+
| en | English | English |
|
86
|
+
| en-Scouse | Scouse | Scouse |
|
87
|
+
| en-au | Australian | Australian |
|
88
|
+
| en-lol | LOLCAT | LOLCAT |
|
89
|
+
| en-pirate | Pirate | Pirate |
|
90
|
+
| en-tx | Texan | Texan |
|
91
|
+
| eo | Esperanto | Esperanto |
|
92
|
+
| es | Spanish | español |
|
93
|
+
| et | Estonian | eesti keel |
|
94
|
+
| fi | Finnish | suomi |
|
95
|
+
| fr | French | français |
|
96
|
+
| he | Hebrew | עברית |
|
97
|
+
| hr | Croatian | hrvatski |
|
98
|
+
| hu | Hungarian | magyar |
|
99
|
+
| id | Indonesian | Bahasa Indonesia |
|
100
|
+
| it | Italian | italiano |
|
101
|
+
| ja | Japanese | 日本語 |
|
102
|
+
| ko | Korean | 한국어 |
|
103
|
+
| lt | Lithuanian | lietuvių kalba |
|
104
|
+
| lu | Luxemburgish | Lëtzebuergesch |
|
105
|
+
| lv | Latvian | latviešu |
|
106
|
+
| nl | Dutch | Nederlands |
|
107
|
+
| no | Norwegian | norsk |
|
108
|
+
| pl | Polish | polski |
|
109
|
+
| pt | Portuguese | português |
|
110
|
+
| ro | Romanian | română |
|
111
|
+
| ro-RO | Romanian (diacritical) | română (diacritical) |
|
112
|
+
| ru | Russian | русский |
|
113
|
+
| sk | Slovak | Slovensky |
|
114
|
+
| sr-Cyrl | Serbian | Српски |
|
115
|
+
| sr-Latn | Serbian (Latin) | Srpski (Latinica) |
|
116
|
+
| sv | Swedish | Svenska |
|
117
|
+
| tr | Turkish | Türkçe |
|
118
|
+
| uk | Ukrainian | Українська |
|
119
|
+
| uz | Uzbek | Узбекча |
|
120
|
+
| vi | Vietnamese | Tiếng Việt |
|
121
|
+
| zh-CN | Chinese simplified | 简体中文 |
|
122
|
+
| zh-TW | Chinese traditional | 繁體中文 |
|
123
|
+
}
|
124
|
+
end
|
125
|
+
end
|
126
|
+
|
127
|
+
it "should print keywords for a given language" do
|
128
|
+
("\n" + Gherkin::I18n.get('fr').keyword_table).should == %{
|
129
|
+
| feature | "Fonctionnalité" |
|
130
|
+
| background | "Contexte" |
|
131
|
+
| scenario | "Scénario" |
|
132
|
+
| scenario_outline | "Plan du scénario", "Plan du Scénario" |
|
133
|
+
| examples | "Exemples" |
|
134
|
+
| given | "* ", "Soit ", "Etant donné " |
|
135
|
+
| when | "* ", "Quand ", "Lorsque ", "Lorsqu'" |
|
136
|
+
| then | "* ", "Alors " |
|
137
|
+
| and | "* ", "Et " |
|
138
|
+
| but | "* ", "Mais " |
|
139
|
+
| given (code) | "Soit", "Etantdonné" |
|
140
|
+
| when (code) | "Quand", "Lorsque", "Lorsqu" |
|
141
|
+
| then (code) | "Alors" |
|
142
|
+
| and (code) | "Et" |
|
143
|
+
| but (code) | "Mais" |
|
144
|
+
}
|
145
|
+
end
|
146
|
+
end
|
147
|
+
end
|
148
|
+
end
|
149
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
#encoding: utf-8
|
2
|
+
if defined?(JRUBY_VERSION)
|
3
|
+
require 'spec_helper'
|
4
|
+
|
5
|
+
module Gherkin
|
6
|
+
module JavaLexer
|
7
|
+
describe "Java Lexer" do
|
8
|
+
before do
|
9
|
+
@listener = Gherkin::SexpRecorder.new
|
10
|
+
@lexer = Java::GherkinLexer::I18nLexer.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 rows"
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,67 @@
|
|
1
|
+
#encoding: utf-8
|
2
|
+
require 'ap'
|
3
|
+
require 'spec_helper'
|
4
|
+
require 'gherkin/json_parser'
|
5
|
+
require 'gherkin/formatter/json_formatter'
|
6
|
+
|
7
|
+
module Gherkin
|
8
|
+
describe JSONParser do
|
9
|
+
|
10
|
+
def check_json(json)
|
11
|
+
io = StringIO.new
|
12
|
+
f = Formatter::JSONFormatter.new(io)
|
13
|
+
p = JSONParser.new(f)
|
14
|
+
p.parse(json, 'unknown.json', 0)
|
15
|
+
expected = JSON.parse(json)
|
16
|
+
actual = JSON.parse(io.string)
|
17
|
+
|
18
|
+
actual.should == expected
|
19
|
+
end
|
20
|
+
|
21
|
+
it "should parse a barely empty feature" do
|
22
|
+
check_json(%{{
|
23
|
+
"keyword": "Feature",
|
24
|
+
"name": "One",
|
25
|
+
"description": "",
|
26
|
+
"line" : 3
|
27
|
+
}})
|
28
|
+
end
|
29
|
+
|
30
|
+
it "should parse feature with tags and one scenario" do
|
31
|
+
check_json(%{{
|
32
|
+
"tags": [
|
33
|
+
{
|
34
|
+
"name": "@foo",
|
35
|
+
"line": 22
|
36
|
+
}
|
37
|
+
],
|
38
|
+
"keyword": "Feature",
|
39
|
+
"name": "One",
|
40
|
+
"description": "",
|
41
|
+
"line": 3,
|
42
|
+
"elements": [
|
43
|
+
{
|
44
|
+
"type": "scenario",
|
45
|
+
"steps": [
|
46
|
+
{
|
47
|
+
"name": "Hello",
|
48
|
+
"multiline_arg": {
|
49
|
+
"type": "table",
|
50
|
+
"value": [
|
51
|
+
{
|
52
|
+
"cells": ["foo", "bar"]
|
53
|
+
}
|
54
|
+
]
|
55
|
+
}
|
56
|
+
}
|
57
|
+
]
|
58
|
+
}
|
59
|
+
]
|
60
|
+
}})
|
61
|
+
end
|
62
|
+
|
63
|
+
it "shoud parse a complex feature" do
|
64
|
+
check_json(fixture("complex.json"))
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
@@ -0,0 +1,43 @@
|
|
1
|
+
#encoding: utf-8
|
2
|
+
require 'spec_helper'
|
3
|
+
|
4
|
+
module Gherkin
|
5
|
+
module Lexer
|
6
|
+
describe I18nLexer do
|
7
|
+
before do
|
8
|
+
@lexer = Gherkin::Lexer::I18nLexer.new(Gherkin::SexpRecorder.new, false)
|
9
|
+
end
|
10
|
+
|
11
|
+
it "should store the i18n language of the last scanned feature" do
|
12
|
+
@lexer.scan("# language: fr\n")
|
13
|
+
@lexer.i18n_language.iso_code.should == "fr"
|
14
|
+
@lexer.scan("# language: no\n")
|
15
|
+
@lexer.i18n_language.iso_code.should == "no"
|
16
|
+
end
|
17
|
+
|
18
|
+
it "should detect language when there are spaces and CRLF" do
|
19
|
+
@lexer.scan("# language: da \r\n")
|
20
|
+
@lexer.i18n_language.iso_code.should == "da"
|
21
|
+
end
|
22
|
+
|
23
|
+
it "should detect language when the language comment is not the first line" do
|
24
|
+
@lexer.scan("# hello\n# language: no\n")
|
25
|
+
@lexer.i18n_language.iso_code.should == "no"
|
26
|
+
end
|
27
|
+
|
28
|
+
it "should detect language when the language is on the third line, and there are empty lines above" do
|
29
|
+
@lexer.scan("# hello\n\n# language: no\n")
|
30
|
+
@lexer.i18n_language.iso_code.should == "no"
|
31
|
+
end
|
32
|
+
|
33
|
+
it "should use English i18n by default" do
|
34
|
+
@lexer.scan("Feature: foo\n")
|
35
|
+
@lexer.i18n_language.iso_code.should == "en"
|
36
|
+
end
|
37
|
+
|
38
|
+
it "should === its ruby class, even when the impl is Java" do
|
39
|
+
Gherkin::Lexer::I18nLexer.should === Gherkin::Lexer::I18nLexer.new(Gherkin::SexpRecorder.new, true)
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
if defined?(JRUBY_VERSION)
|
2
|
+
class OutputStreamStringIO < Java.java.io.ByteArrayOutputStream
|
3
|
+
def write(what)
|
4
|
+
if String === what
|
5
|
+
super(Java.java.lang.String.new(what).getBytes("UTF-8"))
|
6
|
+
else
|
7
|
+
super(what)
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
11
|
+
def string
|
12
|
+
toString("UTF-8")
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
require 'stringio'
|
17
|
+
class StringIO
|
18
|
+
class << self
|
19
|
+
def new
|
20
|
+
OutputStreamStringIO.new
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
module Gherkin
|
4
|
+
module Parser
|
5
|
+
describe Parser do
|
6
|
+
unless defined?(JRUBY_VERSION)
|
7
|
+
it "should raise when feature doesn't parse" do
|
8
|
+
p = Parser.new(mock('formatter').as_null_object)
|
9
|
+
lambda do
|
10
|
+
p.parse("Feature: f\nFeature: f", __FILE__, __LINE__-1)
|
11
|
+
end.should raise_error(/Parse error at/)
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
#encoding: utf-8
|
2
|
+
require 'spec_helper'
|
3
|
+
require 'gherkin/rb_lexer/en'
|
4
|
+
|
5
|
+
module Gherkin
|
6
|
+
module Lexer
|
7
|
+
describe "Ruby Lexer" do
|
8
|
+
before do
|
9
|
+
@listener = Gherkin::SexpRecorder.new
|
10
|
+
@lexer = Gherkin::RbLexer::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 rows"
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,56 @@
|
|
1
|
+
require 'gherkin/rubify'
|
2
|
+
require 'gherkin/formatter/model'
|
3
|
+
|
4
|
+
module Gherkin
|
5
|
+
class SexpRecorder
|
6
|
+
include Rubify
|
7
|
+
|
8
|
+
def initialize
|
9
|
+
@sexps = []
|
10
|
+
end
|
11
|
+
|
12
|
+
def method_missing(event, *args)
|
13
|
+
event = :scenario_outline if event == :scenarioOutline # Special Java Lexer handling
|
14
|
+
event = :py_string if event == :pyString # Special Java Lexer handling
|
15
|
+
event = :syntax_error if event == :syntaxError # Special Java Lexer handling
|
16
|
+
args = rubify(args)
|
17
|
+
args = sexpify(args)
|
18
|
+
@sexps << [event] + args
|
19
|
+
end
|
20
|
+
|
21
|
+
def to_sexp
|
22
|
+
@sexps
|
23
|
+
end
|
24
|
+
|
25
|
+
# Useful in IRB
|
26
|
+
def reset!
|
27
|
+
@sexps = []
|
28
|
+
end
|
29
|
+
|
30
|
+
def errors
|
31
|
+
@sexps.select { |sexp| sexp[0] == :syntax_error }
|
32
|
+
end
|
33
|
+
|
34
|
+
def line(number)
|
35
|
+
@sexps.find { |sexp| sexp.last == number }
|
36
|
+
end
|
37
|
+
|
38
|
+
def sexpify(o)
|
39
|
+
if (defined?(JRUBY_VERSION) && Java.java.util.Collection === o) || Array === o
|
40
|
+
o.map{|e| sexpify(e)}
|
41
|
+
elsif(Formatter::Model::Row === o)
|
42
|
+
{
|
43
|
+
"cells" => sexpify(o.cells),
|
44
|
+
"comments" => sexpify(o.comments),
|
45
|
+
"line" => o.line,
|
46
|
+
}
|
47
|
+
elsif(Formatter::Model::Comment === o)
|
48
|
+
o.value
|
49
|
+
elsif(Formatter::Model::Tag === o)
|
50
|
+
o.name
|
51
|
+
else
|
52
|
+
o
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|