bryanl-gherkin 2.11.1.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.
- data/.gitattributes +2 -0
- data/.mailmap +2 -0
- data/.rbenv-gemsets +1 -0
- data/.rspec +1 -0
- data/.rvmrc +1 -0
- data/.travis.yml +16 -0
- data/.yardopts +5 -0
- data/Gemfile +5 -0
- data/History.md +788 -0
- data/LICENSE +20 -0
- data/README.md +272 -0
- data/Rakefile +26 -0
- data/build_native_gems.sh +7 -0
- data/cucumber.yml +4 -0
- data/examples/parse_and_output_json.rb +19 -0
- data/features/.cucumber/stepdefs.json +244 -0
- data/features/escaped_pipes.feature +8 -0
- data/features/feature_parser.feature +237 -0
- data/features/json_formatter.feature +498 -0
- data/features/json_parser.feature +331 -0
- data/features/native_lexer.feature +19 -0
- data/features/parser_with_native_lexer.feature +205 -0
- data/features/pretty_formatter.feature +16 -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 +30 -0
- data/features/step_definitions/json_parser_steps.rb +20 -0
- data/features/step_definitions/pretty_formatter_steps.rb +85 -0
- data/features/steps_parser.feature +46 -0
- data/features/support/env.rb +42 -0
- data/gherkin.gemspec +77 -0
- data/install_mingw_os_x.sh +7 -0
- data/js/.npmignore +1 -0
- data/js/lib/gherkin/lexer/.npmignore +0 -0
- data/lib/gherkin.rb +2 -0
- data/lib/gherkin/c_lexer.rb +17 -0
- data/lib/gherkin/formatter/ansi_escapes.rb +97 -0
- data/lib/gherkin/formatter/argument.rb +16 -0
- data/lib/gherkin/formatter/escaping.rb +15 -0
- data/lib/gherkin/formatter/filter_formatter.rb +146 -0
- data/lib/gherkin/formatter/hashable.rb +19 -0
- data/lib/gherkin/formatter/json_formatter.rb +122 -0
- data/lib/gherkin/formatter/line_filter.rb +26 -0
- data/lib/gherkin/formatter/model.rb +281 -0
- data/lib/gherkin/formatter/pretty_formatter.rb +244 -0
- data/lib/gherkin/formatter/regexp_filter.rb +21 -0
- data/lib/gherkin/formatter/step_printer.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 +613 -0
- data/lib/gherkin/js_lexer.rb +20 -0
- data/lib/gherkin/json_parser.rb +177 -0
- data/lib/gherkin/lexer/i18n_lexer.rb +46 -0
- data/lib/gherkin/listener/event.rb +45 -0
- data/lib/gherkin/listener/formatter_listener.rb +143 -0
- data/lib/gherkin/native.rb +7 -0
- data/lib/gherkin/native/java.rb +72 -0
- data/lib/gherkin/native/null.rb +5 -0
- data/lib/gherkin/native/therubyracer.rb +39 -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/README.rdoc +8 -0
- data/lib/gherkin/rb_lexer/ar.rb +1165 -0
- data/lib/gherkin/rb_lexer/bg.rb +1377 -0
- data/lib/gherkin/rb_lexer/bm.rb +1081 -0
- data/lib/gherkin/rb_lexer/ca.rb +1305 -0
- data/lib/gherkin/rb_lexer/cs.rb +1157 -0
- data/lib/gherkin/rb_lexer/cy_gb.rb +1027 -0
- data/lib/gherkin/rb_lexer/da.rb +1043 -0
- data/lib/gherkin/rb_lexer/de.rb +1151 -0
- data/lib/gherkin/rb_lexer/en.rb +1151 -0
- data/lib/gherkin/rb_lexer/en_au.rb +971 -0
- data/lib/gherkin/rb_lexer/en_lol.rb +929 -0
- data/lib/gherkin/rb_lexer/en_pirate.rb +1205 -0
- data/lib/gherkin/rb_lexer/en_scouse.rb +1357 -0
- data/lib/gherkin/rb_lexer/en_tx.rb +1011 -0
- data/lib/gherkin/rb_lexer/eo.rb +990 -0
- data/lib/gherkin/rb_lexer/es.rb +1135 -0
- data/lib/gherkin/rb_lexer/et.rb +985 -0
- data/lib/gherkin/rb_lexer/fi.rb +964 -0
- data/lib/gherkin/rb_lexer/fr.rb +1223 -0
- data/lib/gherkin/rb_lexer/he.rb +1113 -0
- data/lib/gherkin/rb_lexer/hr.rb +1061 -0
- data/lib/gherkin/rb_lexer/hu.rb +1113 -0
- data/lib/gherkin/rb_lexer/id.rb +958 -0
- data/lib/gherkin/rb_lexer/is.rb +1115 -0
- data/lib/gherkin/rb_lexer/it.rb +1081 -0
- data/lib/gherkin/rb_lexer/ja.rb +1413 -0
- data/lib/gherkin/rb_lexer/ko.rb +1097 -0
- data/lib/gherkin/rb_lexer/lt.rb +1040 -0
- data/lib/gherkin/rb_lexer/lu.rb +1127 -0
- data/lib/gherkin/rb_lexer/lv.rb +1161 -0
- data/lib/gherkin/rb_lexer/nl.rb +1110 -0
- data/lib/gherkin/rb_lexer/no.rb +1055 -0
- data/lib/gherkin/rb_lexer/pl.rb +1452 -0
- data/lib/gherkin/rb_lexer/pt.rb +1425 -0
- data/lib/gherkin/rb_lexer/ro.rb +1159 -0
- data/lib/gherkin/rb_lexer/ru.rb +1749 -0
- data/lib/gherkin/rb_lexer/sk.rb +1041 -0
- data/lib/gherkin/rb_lexer/sr_cyrl.rb +1798 -0
- data/lib/gherkin/rb_lexer/sr_latn.rb +1289 -0
- data/lib/gherkin/rb_lexer/sv.rb +1065 -0
- data/lib/gherkin/rb_lexer/tr.rb +1087 -0
- data/lib/gherkin/rb_lexer/uk.rb +1641 -0
- data/lib/gherkin/rb_lexer/uz.rb +1371 -0
- data/lib/gherkin/rb_lexer/vi.rb +1193 -0
- data/lib/gherkin/rb_lexer/zh_cn.rb +1053 -0
- data/lib/gherkin/rb_lexer/zh_tw.rb +1047 -0
- data/lib/gherkin/rubify.rb +24 -0
- data/lib/gherkin/tag_expression.rb +62 -0
- data/ragel/lexer.c.rl.erb +454 -0
- data/ragel/lexer.java.rl.erb +219 -0
- data/ragel/lexer.js.rl.erb +227 -0
- data/ragel/lexer.rb.rl.erb +174 -0
- data/ragel/lexer_common.rl.erb +50 -0
- data/spec/gherkin/c_lexer_spec.rb +22 -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 +139 -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/examples_with_only_header.feature +14 -0
- data/spec/gherkin/fixtures/hantu_pisang.feature +35 -0
- data/spec/gherkin/fixtures/i18n_fr.feature +14 -0
- data/spec/gherkin/fixtures/i18n_fr2.feature +8 -0
- data/spec/gherkin/fixtures/i18n_no.feature +7 -0
- data/spec/gherkin/fixtures/i18n_pt1.feature +44 -0
- data/spec/gherkin/fixtures/i18n_pt2.feature +4 -0
- data/spec/gherkin/fixtures/i18n_pt3.feature +4 -0
- data/spec/gherkin/fixtures/i18n_pt4.feature +4 -0
- data/spec/gherkin/fixtures/i18n_zh-CN.feature +9 -0
- data/spec/gherkin/fixtures/issue_145.feature +22 -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/ansi_escapes_spec.rb +32 -0
- data/spec/gherkin/formatter/filter_formatter_spec.rb +204 -0
- data/spec/gherkin/formatter/json_formatter_spec.rb +92 -0
- data/spec/gherkin/formatter/model_spec.rb +28 -0
- data/spec/gherkin/formatter/pretty_formatter_spec.rb +177 -0
- data/spec/gherkin/formatter/spaces.feature +9 -0
- data/spec/gherkin/formatter/step_printer_spec.rb +55 -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 +241 -0
- data/spec/gherkin/java_lexer_spec.rb +20 -0
- data/spec/gherkin/js_lexer_spec.rb +23 -0
- data/spec/gherkin/json_parser_spec.rb +176 -0
- data/spec/gherkin/lexer/i18n_lexer_spec.rb +43 -0
- data/spec/gherkin/output_stream_string_io.rb +20 -0
- data/spec/gherkin/parser/parser_spec.rb +16 -0
- data/spec/gherkin/rb_lexer_spec.rb +20 -0
- data/spec/gherkin/sexp_recorder.rb +59 -0
- data/spec/gherkin/shared/bom_group.rb +20 -0
- data/spec/gherkin/shared/doc_string_group.rb +163 -0
- data/spec/gherkin/shared/lexer_group.rb +591 -0
- data/spec/gherkin/shared/row_group.rb +125 -0
- data/spec/gherkin/shared/tags_group.rb +54 -0
- data/spec/gherkin/tag_expression_spec.rb +142 -0
- data/spec/spec_helper.rb +75 -0
- data/tasks/bench.rake +184 -0
- data/tasks/bench/feature_builder.rb +49 -0
- data/tasks/bench/null_listener.rb +4 -0
- data/tasks/compile.rake +120 -0
- data/tasks/cucumber.rake +22 -0
- data/tasks/gems.rake +31 -0
- data/tasks/ikvm.rake +124 -0
- data/tasks/ragel_task.rb +100 -0
- data/tasks/release.rake +49 -0
- data/tasks/rspec.rake +8 -0
- data/tasks/yard.rake +7 -0
- data/tasks/yard/default/layout/html/bubble_32x32.png +0 -0
- data/tasks/yard/default/layout/html/bubble_48x48.png +0 -0
- data/tasks/yard/default/layout/html/footer.erb +5 -0
- data/tasks/yard/default/layout/html/index.erb +1 -0
- data/tasks/yard/default/layout/html/layout.erb +25 -0
- data/tasks/yard/default/layout/html/logo.erb +1 -0
- data/tasks/yard/default/layout/html/setup.rb +4 -0
- metadata +473 -0
@@ -0,0 +1,92 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'stringio'
|
3
|
+
require 'gherkin/formatter/json_formatter'
|
4
|
+
require 'gherkin/formatter/model'
|
5
|
+
|
6
|
+
module Gherkin
|
7
|
+
module Formatter
|
8
|
+
describe JSONFormatter do
|
9
|
+
it "renders results" do
|
10
|
+
io = StringIO.new
|
11
|
+
f = JSONFormatter.new(io)
|
12
|
+
f.uri("f.feature")
|
13
|
+
f.feature(Model::Feature.new([], [], "Feature", "ff", "", 1, "ff"))
|
14
|
+
f.scenario(Model::Scenario.new([], [], "Scenario", "ss", "", 2, "ff/ss"))
|
15
|
+
|
16
|
+
f.step(Model::Step.new([], "Given ", "g", 3, nil, nil))
|
17
|
+
f.match(Model::Match.new([], "def.rb:33"))
|
18
|
+
f.result(Model::Result.new(:passed, 1, nil))
|
19
|
+
|
20
|
+
f.step(Model::Step.new([], "When ", "w", 4, nil, nil))
|
21
|
+
f.match(Model::Match.new([], "def.rb:44"))
|
22
|
+
f.result(Model::Result.new(:passed, 1, nil))
|
23
|
+
|
24
|
+
f.after(Model::Match.new([], "def.rb:55"), Model::Result.new(:passed, 22, nil))
|
25
|
+
|
26
|
+
f.eof
|
27
|
+
f.done
|
28
|
+
|
29
|
+
expected = %{
|
30
|
+
[
|
31
|
+
{
|
32
|
+
"id": "ff",
|
33
|
+
"uri": "f.feature",
|
34
|
+
"keyword": "Feature",
|
35
|
+
"name": "ff",
|
36
|
+
"line": 1,
|
37
|
+
"description": "",
|
38
|
+
"elements": [
|
39
|
+
{
|
40
|
+
"id": "ff/ss",
|
41
|
+
"keyword": "Scenario",
|
42
|
+
"name": "ss",
|
43
|
+
"line": 2,
|
44
|
+
"description": "",
|
45
|
+
"type": "scenario",
|
46
|
+
"steps": [
|
47
|
+
{
|
48
|
+
"keyword": "Given ",
|
49
|
+
"name": "g",
|
50
|
+
"line": 3,
|
51
|
+
"match": {
|
52
|
+
"location": "def.rb:33"
|
53
|
+
},
|
54
|
+
"result": {
|
55
|
+
"status": "passed",
|
56
|
+
"duration": 1
|
57
|
+
}
|
58
|
+
},
|
59
|
+
{
|
60
|
+
"keyword": "When ",
|
61
|
+
"name": "w",
|
62
|
+
"line": 4,
|
63
|
+
"match": {
|
64
|
+
"location": "def.rb:44"
|
65
|
+
},
|
66
|
+
"result": {
|
67
|
+
"status": "passed",
|
68
|
+
"duration": 1
|
69
|
+
}
|
70
|
+
}
|
71
|
+
],
|
72
|
+
"after": [
|
73
|
+
{
|
74
|
+
"match":{
|
75
|
+
"location":"def.rb:55"
|
76
|
+
},
|
77
|
+
"result":{
|
78
|
+
"status":"passed",
|
79
|
+
"duration": 22
|
80
|
+
}
|
81
|
+
}
|
82
|
+
]
|
83
|
+
}
|
84
|
+
]
|
85
|
+
}
|
86
|
+
]
|
87
|
+
}
|
88
|
+
JSON.parse(expected).should == JSON.parse(io.string)
|
89
|
+
end
|
90
|
+
end
|
91
|
+
end
|
92
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'gherkin/formatter/model'
|
3
|
+
require 'gherkin/formatter/argument'
|
4
|
+
|
5
|
+
module Gherkin
|
6
|
+
module Formatter
|
7
|
+
module Model
|
8
|
+
describe Tag do
|
9
|
+
it "should be equal when name is equal" do
|
10
|
+
tags = [Tag.new('@x', 1), Tag.new('@y', 2), Tag.new('@x', 3)]
|
11
|
+
tags.to_a.uniq.length.should == 2
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
describe Step do
|
16
|
+
it "should provide arguments for outline tokens" do
|
17
|
+
step = Step.new([], 'Given ', "I have <number> cukes in <whose> belly", 10, nil, nil)
|
18
|
+
step.outline_args.map{|arg| [arg.offset, arg.val]}.should == [[7, "<number>"], [25, "<whose>"]]
|
19
|
+
end
|
20
|
+
|
21
|
+
it "should provide no arguments when there are no outline tokens" do
|
22
|
+
step = Step.new([], 'Given ', "I have 33 cukes in my belly", 10, nil, nil)
|
23
|
+
step.outline_args.to_a.should == []
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
@@ -0,0 +1,177 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
require 'spec_helper'
|
3
|
+
require 'gherkin/formatter/pretty_formatter'
|
4
|
+
require 'gherkin/formatter/argument'
|
5
|
+
require 'gherkin/formatter/model'
|
6
|
+
require 'gherkin/listener/formatter_listener'
|
7
|
+
require 'gherkin/parser/parser'
|
8
|
+
require 'stringio'
|
9
|
+
|
10
|
+
module Gherkin
|
11
|
+
module Formatter
|
12
|
+
describe PrettyFormatter do
|
13
|
+
include AnsiEscapes
|
14
|
+
|
15
|
+
def assert_io(s)
|
16
|
+
actual = @io.string
|
17
|
+
actual.gsub!(/\e\[m/, "\e[0m") # JANSI resets without the 0.
|
18
|
+
actual.should == s
|
19
|
+
end
|
20
|
+
|
21
|
+
def assert_pretty(input, expected_output=input)
|
22
|
+
[true, false].each do |force_ruby|
|
23
|
+
io = StringIO.new
|
24
|
+
pf = Gherkin::Formatter::PrettyFormatter.new(io, true, false)
|
25
|
+
parser = Gherkin::Parser::Parser.new(pf, true, "root", force_ruby)
|
26
|
+
parser.parse(input, "test.feature", 0)
|
27
|
+
output = io.string
|
28
|
+
output.should == expected_output
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
before do
|
33
|
+
@io = StringIO.new
|
34
|
+
@f = Gherkin::Formatter::PrettyFormatter.new(@io, false, true)
|
35
|
+
end
|
36
|
+
|
37
|
+
it "should print comments when scenario is longer" do
|
38
|
+
@f.uri("features/foo.feature")
|
39
|
+
@f.feature(Model::Feature.new([], [], "Feature", "Hello", "World", 1, "hello"))
|
40
|
+
|
41
|
+
@f.scenario(Model::Scenario.new([], [], "Scenario", "The scenario", "", 4, "the-scenario"))
|
42
|
+
@f.step(Model::Step.new([], "Given ", "some stuff", 5, nil, nil))
|
43
|
+
@f.step(Model::Step.new([], "When ", "foo", 6, nil, nil))
|
44
|
+
|
45
|
+
@f.match(Model::Match.new([], "features/step_definitions/bar.rb:56"))
|
46
|
+
@f.result(Model::Result.new('passed', 22, nil))
|
47
|
+
|
48
|
+
@f.match(Model::Match.new([], "features/step_definitions/bar.rb:96"))
|
49
|
+
@f.result(Model::Result.new('passed', 33, nil))
|
50
|
+
|
51
|
+
assert_io(%{Feature: Hello
|
52
|
+
World
|
53
|
+
|
54
|
+
Scenario: The scenario #{comments}# features/foo.feature:4#{reset}
|
55
|
+
#{executing}Given #{reset}#{executing}some stuff#{reset} #{comments}# features/step_definitions/bar.rb:56#{reset}
|
56
|
+
#{up(1)} #{passed}Given #{reset}#{passed}some stuff#{reset} #{comments}# features/step_definitions/bar.rb:56#{reset}
|
57
|
+
#{executing}When #{reset}#{executing}foo#{reset} #{comments}# features/step_definitions/bar.rb:96#{reset}
|
58
|
+
#{up(1)} #{passed}When #{reset}#{passed}foo#{reset} #{comments}# features/step_definitions/bar.rb:96#{reset}
|
59
|
+
})
|
60
|
+
end
|
61
|
+
|
62
|
+
it "should print comments when step is longer" do
|
63
|
+
@f.uri("features/foo.feature")
|
64
|
+
@f.feature(Model::Feature.new([], [], "Feature", "Hello", "World", 1, "hello"))
|
65
|
+
step = Model::Step.new([], "Given ", "some stuff that is longer", 5, nil, nil)
|
66
|
+
match = Model::Match.new([], "features/step_definitions/bar.rb:56")
|
67
|
+
result = Model::Result.new('passed', 0, nil)
|
68
|
+
|
69
|
+
@f.scenario(Model::Scenario.new([], [], "Scenario", "The scenario", "", 4, "the-scenario"))
|
70
|
+
@f.step(step)
|
71
|
+
@f.match(match)
|
72
|
+
@f.result(result)
|
73
|
+
|
74
|
+
assert_io(%{Feature: Hello
|
75
|
+
World
|
76
|
+
|
77
|
+
Scenario: The scenario #{comments}# features/foo.feature:4#{reset}
|
78
|
+
#{executing}Given #{reset}#{executing}some stuff that is longer#{reset} #{comments}# features/step_definitions/bar.rb:56#{reset}
|
79
|
+
#{up(1)} #{passed}Given #{reset}#{passed}some stuff that is longer#{reset} #{comments}# features/step_definitions/bar.rb:56#{reset}
|
80
|
+
})
|
81
|
+
end
|
82
|
+
|
83
|
+
it "should highlight arguments for regular steps" do
|
84
|
+
@f.uri("foo.feature")
|
85
|
+
@f.scenario(Model::Scenario.new([], [], "Scenario", "Lots of cukes", "", 3, "lots-of-cukes"))
|
86
|
+
@f.step(Model::Step.new([], "Given ", "I have 999 cukes in my belly", 3, nil, nil))
|
87
|
+
@f.match(Model::Match.new([Gherkin::Formatter::Argument.new(7, '999')], nil))
|
88
|
+
@f.result(Model::Result.new('passed', 6, nil))
|
89
|
+
|
90
|
+
assert_io(
|
91
|
+
"\n" +
|
92
|
+
" Scenario: Lots of cukes \e[90m# foo.feature:3\e[0m\n" +
|
93
|
+
" #{executing}Given #{reset}#{executing}I have #{reset}#{executing_arg}999#{reset}#{executing} cukes in my belly#{reset}\n" +
|
94
|
+
"#{up(1)} #{passed}Given #{reset}#{passed}I have #{reset}#{passed_arg}999#{reset}#{passed} cukes in my belly#{reset}\n"
|
95
|
+
)
|
96
|
+
end
|
97
|
+
|
98
|
+
# See https://github.com/cucumber/gherkin/pull/171
|
99
|
+
it "should highlight arguments when there are optional arguments" do
|
100
|
+
@f.uri("foo.feature")
|
101
|
+
@f.scenario(Model::Scenario.new([], [], "Scenario", "Lots of cukes", "", 3, "lots-of-cukes"))
|
102
|
+
@f.step(Model::Step.new([], "Given ", "I have 999 cukes in my belly", 3, nil, nil))
|
103
|
+
@f.match(Model::Match.new([
|
104
|
+
Gherkin::Formatter::Argument.new(nil, nil), # An optional argument
|
105
|
+
Gherkin::Formatter::Argument.new(7, '999')
|
106
|
+
], nil))
|
107
|
+
@f.result(Model::Result.new('passed', 6, nil))
|
108
|
+
|
109
|
+
assert_io(
|
110
|
+
"\n" +
|
111
|
+
" Scenario: Lots of cukes \e[90m# foo.feature:3\e[0m\n" +
|
112
|
+
" #{executing}Given #{reset}#{executing}I have #{reset}#{executing_arg}999#{reset}#{executing} cukes in my belly#{reset}\n" +
|
113
|
+
"#{up(1)} #{passed}Given #{reset}#{passed}I have #{reset}#{passed_arg}999#{reset}#{passed} cukes in my belly#{reset}\n"
|
114
|
+
)
|
115
|
+
end
|
116
|
+
|
117
|
+
it "should prettify scenario" do
|
118
|
+
assert_pretty(%{Feature: Feature Description
|
119
|
+
Some preamble
|
120
|
+
|
121
|
+
Scenario: Scenario Description
|
122
|
+
description has multiple lines
|
123
|
+
|
124
|
+
Given there is a step
|
125
|
+
"""
|
126
|
+
with
|
127
|
+
pystrings
|
128
|
+
"""
|
129
|
+
And there is another step
|
130
|
+
| æ | \\|o |
|
131
|
+
| \\|a | ø\\\\ |
|
132
|
+
Then we will see steps
|
133
|
+
})
|
134
|
+
end
|
135
|
+
|
136
|
+
|
137
|
+
it "should prettify scenario outline with table" do
|
138
|
+
assert_pretty(%{# A feature comment
|
139
|
+
@foo
|
140
|
+
Feature: Feature Description
|
141
|
+
Some preamble
|
142
|
+
on several
|
143
|
+
lines
|
144
|
+
|
145
|
+
# A Scenario Outline comment
|
146
|
+
@bar
|
147
|
+
Scenario Outline: Scenario Ouline Description
|
148
|
+
Given there is a
|
149
|
+
"""
|
150
|
+
string with <foo>
|
151
|
+
"""
|
152
|
+
And a table with
|
153
|
+
| <bar> |
|
154
|
+
| <baz> |
|
155
|
+
|
156
|
+
@zap @boing
|
157
|
+
Examples: Examples Description
|
158
|
+
| foo | bar | baz |
|
159
|
+
| Banana | I | am hungry |
|
160
|
+
| Beer | You | are thirsty |
|
161
|
+
| Bed | They | are tired |
|
162
|
+
})
|
163
|
+
end
|
164
|
+
|
165
|
+
it "should preserve tabs" do
|
166
|
+
assert_pretty(IO.read(File.dirname(__FILE__) + '/tabs.feature'), IO.read(File.dirname(__FILE__) + '/spaces.feature'))
|
167
|
+
end
|
168
|
+
|
169
|
+
it "should escape backslashes and pipes" do
|
170
|
+
io = StringIO.new
|
171
|
+
f = Gherkin::Formatter::PrettyFormatter.new(io, true, false)
|
172
|
+
f.__send__(:table, [Gherkin::Formatter::Model::DataTableRow.new([], ['|', '\\'], 1)])
|
173
|
+
io.string.should == ' | \\| | \\\\ |' + "\n"
|
174
|
+
end
|
175
|
+
end
|
176
|
+
end
|
177
|
+
end
|
@@ -0,0 +1,55 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
require 'spec_helper'
|
3
|
+
require 'gherkin/formatter/step_printer'
|
4
|
+
require 'gherkin/formatter/argument'
|
5
|
+
require 'stringio'
|
6
|
+
|
7
|
+
module Gherkin
|
8
|
+
module Formatter
|
9
|
+
class ParenthesisFormat
|
10
|
+
def text(text)
|
11
|
+
"(#{text})"
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
class BracketFormat
|
16
|
+
def text(text)
|
17
|
+
"[#{text}]"
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
describe StepPrinter do
|
22
|
+
before do
|
23
|
+
@io = StringIO.new
|
24
|
+
@p = StepPrinter.new
|
25
|
+
@pf = ParenthesisFormat.new
|
26
|
+
@bf = BracketFormat.new
|
27
|
+
end
|
28
|
+
|
29
|
+
it "should replace 0 args" do
|
30
|
+
@p.write_step(@io, @pf, @bf, "I have 10 cukes", [])
|
31
|
+
@io.string.should == "(I have 10 cukes)"
|
32
|
+
end
|
33
|
+
|
34
|
+
it "should replace 1 arg" do
|
35
|
+
@p.write_step(@io, @pf, @bf, "I have 10 cukes", [Argument.new(7, '10')])
|
36
|
+
@io.string.should == "(I have )[10]( cukes)"
|
37
|
+
end
|
38
|
+
|
39
|
+
it "should replace 1 unicode arg" do
|
40
|
+
@p.write_step(@io, @pf, @bf, "I hæve øæ cåkes", [Argument.new(7, 'øæ')])
|
41
|
+
@io.string.should == "(I hæve )[øæ]( cåkes)"
|
42
|
+
end
|
43
|
+
|
44
|
+
it "should replace 2 args" do
|
45
|
+
@p.write_step(@io, @pf, @bf, "I have 10 yellow cukes in my belly", [Argument.new(7, '10'), Argument.new(17, 'cukes')])
|
46
|
+
@io.string.should == "(I have )[10]( yellow )[cukes]( in my belly)"
|
47
|
+
end
|
48
|
+
|
49
|
+
it "should replace 2 unicode args" do
|
50
|
+
@p.write_step(@io, @pf, @bf, "Æslåk likes æøå", [Argument.new(0, 'Æslåk'), Argument.new(12, 'æøå')])
|
51
|
+
@io.string.should == "[Æslåk]( likes )[æøå]"
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
@@ -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,241 @@
|
|
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 recognize keywords that are a little ambiguous" do
|
30
|
+
lexer = Gherkin::Lexer::I18nLexer.new(@listener, false)
|
31
|
+
scan_file(lexer, "i18n_fr2.feature")
|
32
|
+
@listener.to_sexp.should == [
|
33
|
+
[:comment, "#language:fr", 1],
|
34
|
+
[:feature, "Fonctionnalité", "i18n", "", 2],
|
35
|
+
[:scenario, "Scénario", "Le French", "", 4],
|
36
|
+
[:step, "Etant donné ", "qqch", 5],
|
37
|
+
[:step, "Etant donnée ", "qqch", 6],
|
38
|
+
[:step, "Etant donnés ", "qqch", 7],
|
39
|
+
[:step, "Etant données ", "qqch", 8],
|
40
|
+
[:eof]
|
41
|
+
]
|
42
|
+
end
|
43
|
+
|
44
|
+
it "should parse languages without a space after keywords" do
|
45
|
+
lexer = Gherkin::Lexer::I18nLexer.new(@listener, false)
|
46
|
+
scan_file(lexer, "i18n_zh-CN.feature")
|
47
|
+
@listener.to_sexp.should == [
|
48
|
+
[:comment, "#language:zh-CN", 1],
|
49
|
+
[:feature, "功能", "加法", "", 2],
|
50
|
+
[:scenario, "场景", "两个数相加", "", 4],
|
51
|
+
[:step, "假如", "我已经在计算器里输入6", 5],
|
52
|
+
[:step, "而且", "我已经在计算器里输入7", 6],
|
53
|
+
[:step, "当", "我按相加按钮", 7],
|
54
|
+
[:step, "那么", "我应该在屏幕上看到的结果是13", 8],
|
55
|
+
[:eof]
|
56
|
+
]
|
57
|
+
end
|
58
|
+
|
59
|
+
it "should parse languages with spaces after some keywords but not others" do
|
60
|
+
lexer = Gherkin::Lexer::I18nLexer.new(@listener, false)
|
61
|
+
scan_file(lexer, "i18n_fr.feature")
|
62
|
+
@listener.to_sexp.should == [
|
63
|
+
[:comment, "#language:fr", 1],
|
64
|
+
[:feature, "Fonctionnalité", "Addition", "", 2],
|
65
|
+
[:scenario_outline, "Plan du scénario", "Addition de produits dérivés", "", 3],
|
66
|
+
[:step, "Soit ", "une calculatrice", 4],
|
67
|
+
[:step, "Etant donné ", "qu'on tape <a>", 5],
|
68
|
+
[:step, "Et ", "qu'on tape <b>", 6],
|
69
|
+
[:step, "Lorsqu'", "on tape additionner", 7],
|
70
|
+
[:step, "Alors ", "le résultat doit être <somme>", 8],
|
71
|
+
[:examples, "Exemples", "", "", 10],
|
72
|
+
[:row, %w{a b somme}, 11],
|
73
|
+
[:row, %w{2 2 4}, 12],
|
74
|
+
[:row, %w{2 3 5}, 13],
|
75
|
+
[:eof]
|
76
|
+
]
|
77
|
+
end
|
78
|
+
|
79
|
+
it "should recognize keywords in Portuguese (1st variant)" do
|
80
|
+
lexer = Gherkin::Lexer::I18nLexer.new(@listener, false)
|
81
|
+
scan_file(lexer, "i18n_pt1.feature")
|
82
|
+
@listener.to_sexp.should == [
|
83
|
+
[:comment, "# language: pt", 1],
|
84
|
+
[:feature, "Funcionalidade", "Reconhece \"Funcionalidade\"", "", 2],
|
85
|
+
[:background, "Contexto", "Reconhece \"Contexto\"", "", 4],
|
86
|
+
[:scenario, "Cenário", "Reconhece \"Cenário\" com acento", "", 6],
|
87
|
+
[:scenario, "Cenario", "Reconhece \"Cenário\" sem acento", "", 8],
|
88
|
+
[:scenario_outline, "Esquema do Cenário", "Reconhece \"Esquema do Cenário\" com acento", "", 10],
|
89
|
+
[:step, "Dado ", "que <Valor> é um valor e que reconhece \"Dado\";", 11],
|
90
|
+
[:step, "Dada ", "a afirmação de que reconhece \"Dada\";", 12],
|
91
|
+
[:step, "Dados ", "os factos acima e ainda que reconhece \"Dados\";", 13],
|
92
|
+
[:step, "Dadas ", "as afirmações acima e ainda que reconhece \"Dadas\";", 14],
|
93
|
+
[:step, "Quando ", "reconhece \"Quando\";", 15],
|
94
|
+
[:step, "Então ", "também reconhece \"Então\" com acento e", 16],
|
95
|
+
[:step, "Entao ", "também reconhece \"Então\" sem acento;", 17],
|
96
|
+
[:step, "E ", "reconhece \"E\";", 18],
|
97
|
+
[:step, "Mas ", "também reconhece \"Mas\".", 19],
|
98
|
+
[:examples, "Exemplos", "Reconhece \"Exemplos\"", "", 21],
|
99
|
+
[:row, ["Valor"], 22],
|
100
|
+
[:row, ["1"], 23],
|
101
|
+
[:scenario_outline, "Esquema do Cenario", "Reconhece \"Esquema do Cenário\" sem acento", "", 25],
|
102
|
+
[:step, "Dado ", "que <Valor> é um valor;", 26],
|
103
|
+
[:examples, "Cenários", "Reconhece \"Cenários\" com acento", "", 28],
|
104
|
+
[:row, ["Valor"], 29],
|
105
|
+
[:row, ["1"], 30],
|
106
|
+
[:scenario_outline, "Delineação do Cenário", "Reconhece \"Delineação do Cenário\" com acento", "", 32],
|
107
|
+
[:step, "Dado ", "que <Valor> é um valor;", 33],
|
108
|
+
[:examples, "Cenarios", "Reconhece \"Cenários\" sem acento", "", 35],
|
109
|
+
[:row, ["Valor"], 36],
|
110
|
+
[:row, ["1"], 37],
|
111
|
+
[:scenario_outline, "Delineacao do Cenario", "Reconhece \"Delineação do Cenário\" sem acento", "", 39],
|
112
|
+
[:step, "Dado ", "que <Valor> é um valor;", 40],
|
113
|
+
[:examples, "Exemplos", "Reconhece \"Exemplos\"", "", 42],
|
114
|
+
[:row, ["Valor"], 43],
|
115
|
+
[:row, ["1"], 44],
|
116
|
+
[:eof]
|
117
|
+
]
|
118
|
+
end
|
119
|
+
|
120
|
+
it "should recognize keywords in Portuguese (2nd variant)" do
|
121
|
+
lexer = Gherkin::Lexer::I18nLexer.new(@listener, false)
|
122
|
+
scan_file(lexer, "i18n_pt2.feature")
|
123
|
+
@listener.to_sexp.should == [
|
124
|
+
[:comment, "# language: pt", 1],
|
125
|
+
[:feature, "Característica", "Reconhece \"Característica\" com acento", "", 2],
|
126
|
+
[:background, "Cenário de Fundo", "Reconhece \"Cenário de Fundo\" com acento", "", 4],
|
127
|
+
[:eof]
|
128
|
+
]
|
129
|
+
end
|
130
|
+
|
131
|
+
it "should recognize keywords in Portuguese (3rd variant)" do
|
132
|
+
lexer = Gherkin::Lexer::I18nLexer.new(@listener, false)
|
133
|
+
scan_file(lexer, "i18n_pt3.feature")
|
134
|
+
@listener.to_sexp.should == [
|
135
|
+
[:comment, "# language: pt", 1],
|
136
|
+
[:feature, "Caracteristica", "Reconhece \"Característica\" sem acento", "", 2],
|
137
|
+
[:background, "Cenario de Fundo", "Reconhece \"Cenário de Fundo\" sem acento", "", 4],
|
138
|
+
[:eof]
|
139
|
+
]
|
140
|
+
end
|
141
|
+
|
142
|
+
it "should recognize keywords in Portuguese (4th variant)" do
|
143
|
+
lexer = Gherkin::Lexer::I18nLexer.new(@listener, false)
|
144
|
+
scan_file(lexer, "i18n_pt4.feature")
|
145
|
+
@listener.to_sexp.should == [
|
146
|
+
[:comment, "# language: pt", 1],
|
147
|
+
[:feature, "Característica", "Reconhece \"Característica\" com acento", "", 2],
|
148
|
+
[:background, "Fundo", "Reconhece \"Fundo\"", "", 4],
|
149
|
+
[:eof]
|
150
|
+
]
|
151
|
+
end
|
152
|
+
|
153
|
+
describe 'keywords' do
|
154
|
+
it "should have code keywords without space, comma, exclamation or apostrophe" do
|
155
|
+
['Avast', 'Akkor', 'Etantdonné', 'Lorsque', '假設'].each do |code_keyword|
|
156
|
+
Gherkin::I18n.code_keywords.should include(code_keyword)
|
157
|
+
end
|
158
|
+
end
|
159
|
+
|
160
|
+
it "should reject the bullet stars" do
|
161
|
+
Gherkin::I18n.code_keywords.should_not include('*')
|
162
|
+
end
|
163
|
+
|
164
|
+
it "should report keyword regexp" do
|
165
|
+
Gherkin::I18n.keyword_regexp(:step).should =~ /\|Quando \|Quand \|Quan \|Pryd \|Pokud \|/
|
166
|
+
end
|
167
|
+
|
168
|
+
it "should print available languages" do
|
169
|
+
("\n" + Gherkin::I18n.language_table).should == %{
|
170
|
+
| ar | Arabic | العربية |
|
171
|
+
| bg | Bulgarian | български |
|
172
|
+
| bm | Malay | Bahasa Melayu |
|
173
|
+
| ca | Catalan | català |
|
174
|
+
| cs | Czech | Česky |
|
175
|
+
| cy-GB | Welsh | Cymraeg |
|
176
|
+
| da | Danish | dansk |
|
177
|
+
| de | German | Deutsch |
|
178
|
+
| en | English | English |
|
179
|
+
| en-Scouse | Scouse | Scouse |
|
180
|
+
| en-au | Australian | Australian |
|
181
|
+
| en-lol | LOLCAT | LOLCAT |
|
182
|
+
| en-pirate | Pirate | Pirate |
|
183
|
+
| en-tx | Texan | Texan |
|
184
|
+
| eo | Esperanto | Esperanto |
|
185
|
+
| es | Spanish | español |
|
186
|
+
| et | Estonian | eesti keel |
|
187
|
+
| fi | Finnish | suomi |
|
188
|
+
| fr | French | français |
|
189
|
+
| he | Hebrew | עברית |
|
190
|
+
| hr | Croatian | hrvatski |
|
191
|
+
| hu | Hungarian | magyar |
|
192
|
+
| id | Indonesian | Bahasa Indonesia |
|
193
|
+
| is | Icelandic | Íslenska |
|
194
|
+
| it | Italian | italiano |
|
195
|
+
| ja | Japanese | 日本語 |
|
196
|
+
| ko | Korean | 한국어 |
|
197
|
+
| lt | Lithuanian | lietuvių kalba |
|
198
|
+
| lu | Luxemburgish | Lëtzebuergesch |
|
199
|
+
| lv | Latvian | latviešu |
|
200
|
+
| nl | Dutch | Nederlands |
|
201
|
+
| no | Norwegian | norsk |
|
202
|
+
| pl | Polish | polski |
|
203
|
+
| pt | Portuguese | português |
|
204
|
+
| ro | Romanian | română |
|
205
|
+
| ru | Russian | русский |
|
206
|
+
| sk | Slovak | Slovensky |
|
207
|
+
| sr-Cyrl | Serbian | Српски |
|
208
|
+
| sr-Latn | Serbian (Latin) | Srpski (Latinica) |
|
209
|
+
| sv | Swedish | Svenska |
|
210
|
+
| tr | Turkish | Türkçe |
|
211
|
+
| uk | Ukrainian | Українська |
|
212
|
+
| uz | Uzbek | Узбекча |
|
213
|
+
| vi | Vietnamese | Tiếng Việt |
|
214
|
+
| zh-CN | Chinese simplified | 简体中文 |
|
215
|
+
| zh-TW | Chinese traditional | 繁體中文 |
|
216
|
+
}
|
217
|
+
end
|
218
|
+
|
219
|
+
it "should print keywords for a given language" do
|
220
|
+
("\n" + Gherkin::I18n.get('fr').keyword_table).should == %{
|
221
|
+
| feature | "Fonctionnalité" |
|
222
|
+
| background | "Contexte" |
|
223
|
+
| scenario | "Scénario" |
|
224
|
+
| scenario_outline | "Plan du scénario", "Plan du Scénario" |
|
225
|
+
| examples | "Exemples" |
|
226
|
+
| given | "* ", "Soit ", "Etant donné ", "Etant donnée ", "Etant donnés ", "Etant données ", "Étant donné ", "Étant donnée ", "Étant donnés ", "Étant données " |
|
227
|
+
| when | "* ", "Quand ", "Lorsque ", "Lorsqu'" |
|
228
|
+
| then | "* ", "Alors " |
|
229
|
+
| and | "* ", "Et " |
|
230
|
+
| but | "* ", "Mais " |
|
231
|
+
| given (code) | "Soit", "Etantdonné", "Etantdonnée", "Etantdonnés", "Etantdonnées", "Étantdonné", "Étantdonnée", "Étantdonnés", "Étantdonnées" |
|
232
|
+
| when (code) | "Quand", "Lorsque", "Lorsqu" |
|
233
|
+
| then (code) | "Alors" |
|
234
|
+
| and (code) | "Et" |
|
235
|
+
| but (code) | "Mais" |
|
236
|
+
}
|
237
|
+
end
|
238
|
+
end
|
239
|
+
end
|
240
|
+
end
|
241
|
+
end
|