gherkin3 3.1.1 → 3.1.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: a81f75966e784b53f08bc889ca623b5cec3ead69
4
- data.tar.gz: f309592aed98e2edf99898075097e3fab25b0fac
3
+ metadata.gz: b01f87ff376d17629e22eea00b781a1927f49fa8
4
+ data.tar.gz: c30f9c6938ff0b8da9efcab944f7bf6ce98376ae
5
5
  SHA512:
6
- metadata.gz: 47b1295ebe8c60d5e936e7c672dca0ccebb22c34d61740dbe7bd774f298a9321843b244ea4e202d719931ab99e91d13f5a7924b4272541a48da983cf2bb1ab5b
7
- data.tar.gz: ce03ffe0eb6dab329deb7941720c63ae52917202cf7b828bd091310fe69627a3353f3c710e37427ca1f9f732fb4aa7c9e7ce2f7f215cd914e66efa31cd846038
6
+ metadata.gz: 1af62f02da64aab37a8a3f9b7692f6ffe5a55638f60c22f1ac6cf885de43a473fdb17c99efbf4eb473b22a0aaa370bb6520d099461ee967ad6d7fba730bdfb44
7
+ data.tar.gz: 754a0d3728fbe8fb56bb65c91c391a3501aefaa52caf35fd2f0352e536aa52031ef3c59443465d385bc7d3167f6336785c116271f5d795e1fdeaddf4baf6a94c
data/README.md CHANGED
@@ -1,3 +1,13 @@
1
1
  [![Build Status](https://secure.travis-ci.org/cucumber/gherkin-ruby.png)](http://travis-ci.org/cucumber/gherkin-ruby)
2
2
 
3
3
  Gherkin parser/compiler for Ruby. Please see [Gherkin3](https://github.com/cucumber/gherkin3) for details.
4
+
5
+ ## Developers
6
+
7
+ Some files are generated from the `gherkin-ruby.razor` file. Please run the
8
+ following command to generate the ruby files.
9
+
10
+ ~~~bash
11
+ cd <project_root>/ruby
12
+ make
13
+ ~~~
@@ -1,7 +1,6 @@
1
1
  #!/usr/bin/env ruby
2
2
  $LOAD_PATH.unshift(File.join(File.dirname(__FILE__),"../lib"))
3
3
  require 'gherkin3/parser'
4
- require 'gherkin3/token_scanner'
5
4
  require 'json'
6
5
 
7
6
  parser = Gherkin3::Parser.new
@@ -9,9 +8,10 @@ parser.stop_at_first_error = false
9
8
  files = ARGV.any? ? ARGV : (STDIN.tty? ? [] : [STDIN])
10
9
  start_time = Time.now
11
10
  files.each do |file|
12
- scanner = Gherkin3::TokenScanner.new(file)
13
11
  begin
14
- puts JSON.generate(parser.parse(scanner))
12
+ File.open(file) do |io|
13
+ puts JSON.generate(parser.parse(io))
14
+ end
15
15
  rescue Gherkin3::ParserError => e
16
16
  STDERR.puts e.message
17
17
  exit 1
@@ -1,12 +1,12 @@
1
1
  #!/usr/bin/env ruby
2
2
  $LOAD_PATH.unshift(File.join(File.dirname(__FILE__),"../lib"))
3
3
  require 'gherkin3/parser'
4
- require 'gherkin3/token_scanner'
5
4
  require 'gherkin3/token_formatter_builder'
6
5
 
7
6
  parser = Gherkin3::Parser.new(Gherkin3::TokenFormatterBuilder.new)
8
7
  files = ARGV + (STDIN.tty? ? [] : [STDIN])
9
8
  files.each do |file|
10
- scanner = Gherkin3::TokenScanner.new(file)
11
- print parser.parse(scanner)
9
+ File.open(file) do |io|
10
+ print parser.parse(io)
11
+ end
12
12
  end
@@ -28,6 +28,7 @@
28
28
  # This file is generated. Do not edit! Edit gherkin-ruby.razor instead.
29
29
  require_relative 'ast_builder'
30
30
  require_relative 'token_matcher'
31
+ require_relative 'token_scanner'
31
32
  require_relative 'errors'
32
33
 
33
34
  module Gherkin3
@@ -58,6 +59,8 @@ module Gherkin3
58
59
  end
59
60
 
60
61
  def parse(token_scanner, token_matcher=TokenMatcher.new)
62
+ token_scanner = token_scanner.is_a?(TokenScanner) ? token_scanner : TokenScanner.new(token_scanner)
63
+
61
64
  @@ast_builder.reset
62
65
  token_matcher.reset
63
66
  context = ParserContext.new(
@@ -175,7 +178,7 @@ module Gherkin3
175
178
  loop do
176
179
  token = read_token(context)
177
180
  token.detach
178
- queue.unshift(token)
181
+ queue.push(token)
179
182
 
180
183
  if (false @foreach(var tokenType in lookAheadHint.ExpectedTokens) {<text>|| @MatchToken(tokenType)</text>})
181
184
  match = true
@@ -1,7 +1,7 @@
1
1
  # encoding: utf-8
2
2
  Gem::Specification.new do |s|
3
3
  s.name = 'gherkin3'
4
- s.version = '3.1.1'
4
+ s.version = '3.1.2'
5
5
  s.authors = ["Gáspár Nagy", "Aslak Hellesøy", "Steve Tooke"]
6
6
  s.description = 'Gherkin parser'
7
7
  s.summary = "gherkin-#{s.version}"
@@ -1,6 +1,7 @@
1
1
  # This file is generated. Do not edit! Edit gherkin-ruby.razor instead.
2
2
  require_relative 'ast_builder'
3
3
  require_relative 'token_matcher'
4
+ require_relative 'token_scanner'
4
5
  require_relative 'errors'
5
6
 
6
7
  module Gherkin3
@@ -64,6 +65,8 @@ module Gherkin3
64
65
  end
65
66
 
66
67
  def parse(token_scanner, token_matcher=TokenMatcher.new)
68
+ token_scanner = token_scanner.is_a?(TokenScanner) ? token_scanner : TokenScanner.new(token_scanner)
69
+
67
70
  @ast_builder.reset
68
71
  token_matcher.reset
69
72
  context = ParserContext.new(
@@ -1868,7 +1871,7 @@ module Gherkin3
1868
1871
  loop do
1869
1872
  token = read_token(context)
1870
1873
  token.detach
1871
- queue.unshift(token)
1874
+ queue.push(token)
1872
1875
 
1873
1876
  if (false || match_ExamplesLine(context, token))
1874
1877
  match = true
@@ -6,12 +6,13 @@ module Gherkin3
6
6
  LANGUAGE_PATTERN = /^\s*#\s*language\s*:\s*([a-zA-Z\-_]+)\s*$/
7
7
 
8
8
  def initialize(dialect_name = 'en')
9
+ @default_dialect_name = dialect_name
9
10
  change_dialect(dialect_name, nil)
10
11
  reset
11
12
  end
12
13
 
13
14
  def reset
14
- change_dialect('en', nil) unless @dialect_name == 'en'
15
+ change_dialect(@default_dialect_name, nil) unless @dialect_name == @default_dialect_name
15
16
  @active_doc_string_separator = nil
16
17
  @indent_to_remove = 0
17
18
  end
@@ -1,19 +1,26 @@
1
+ require 'stringio'
1
2
  require_relative 'token'
2
3
  require_relative 'gherkin_line'
3
4
 
4
5
  module Gherkin3
6
+ # The scanner reads a gherkin doc (typically read from a .feature file) and
7
+ # creates a token for line. The tokens are passed to the parser, which outputs
8
+ # an AST (Abstract Syntax Tree).
9
+ #
10
+ # If the scanner sees a # language header, it will reconfigure itself dynamically
11
+ # to look for Gherkin keywords for the associated language. The keywords are defined
12
+ # in gherkin-languages.json.
5
13
  class TokenScanner
6
-
7
- def initialize(source_or_path_or_io)
14
+ def initialize(source_or_io)
8
15
  @line_number = 0
9
- if String === source_or_path_or_io
10
- if File.file?(source_or_path_or_io)
11
- @io = File.open(source_or_path_or_io, 'r:BOM|UTF-8')
12
- else
13
- @io = StringIO.new(source_or_path_or_io)
14
- end
16
+
17
+ case(source_or_io)
18
+ when String
19
+ @io = StringIO.new(source_or_io)
20
+ when StringIO, IO
21
+ @io = source_or_io
15
22
  else
16
- @io = source_or_path_or_io
23
+ fail ArgumentError, "Please a pass String, StringIO or IO. I got a #{source_or_io.class}"
17
24
  end
18
25
  end
19
26
 
@@ -23,6 +23,37 @@ module Gherkin3
23
23
  })
24
24
  end
25
25
 
26
+ it "parses string feature" do
27
+ parser = Parser.new
28
+ ast = parser.parse("Feature: test")
29
+ expect(ast).to eq({
30
+ type: :Feature,
31
+ tags: [],
32
+ location: {line: 1, column: 1},
33
+ language: "en",
34
+ keyword: "Feature",
35
+ name: "test",
36
+ scenarioDefinitions: [],
37
+ comments: []
38
+ })
39
+ end
40
+
41
+ it "parses io feature" do
42
+ parser = Parser.new
43
+ ast = parser.parse(StringIO.new("Feature: test"))
44
+
45
+ expect(ast).to eq({
46
+ type: :Feature,
47
+ tags: [],
48
+ location: {line: 1, column: 1},
49
+ language: "en",
50
+ keyword: "Feature",
51
+ name: "test",
52
+ scenarioDefinitions: [],
53
+ comments: []
54
+ })
55
+ end
56
+
26
57
  it "can parse multiple features" do
27
58
  parser = Parser.new
28
59
  ast1 = parser.parse(TokenScanner.new("Feature: test"))
@@ -95,5 +126,22 @@ module Gherkin3
95
126
  comments: []
96
127
  })
97
128
  end
129
+
130
+ it "can change the default language" do
131
+ parser = Parser.new
132
+ matcher = TokenMatcher.new("no")
133
+ scanner = TokenScanner.new("Egenskap: i18n support")
134
+ ast = parser.parse(scanner, matcher)
135
+ expect(ast).to eq({
136
+ type: :Feature,
137
+ tags: [],
138
+ location: {line: 1, column: 1},
139
+ language: "no",
140
+ keyword: "Egenskap",
141
+ name: "i18n support",
142
+ scenarioDefinitions: [],
143
+ comments: []
144
+ })
145
+ end
98
146
  end
99
147
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: gherkin3
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.1.1
4
+ version: 3.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Gáspár Nagy
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2015-09-03 00:00:00.000000000 Z
13
+ date: 2015-10-03 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: bundler
@@ -123,7 +123,7 @@ rubyforge_project:
123
123
  rubygems_version: 2.4.5
124
124
  signing_key:
125
125
  specification_version: 4
126
- summary: gherkin-3.1.1
126
+ summary: gherkin-3.1.2
127
127
  test_files:
128
128
  - spec/capture_warnings.rb
129
129
  - spec/coverage.rb