diff --git a/features/json_formatter.feature b/features/json_formatter.feature index e48097f0..e7f04295 100644 --- a/features/json_formatter.feature +++ b/features/json_formatter.feature @@ -282,6 +282,8 @@ Feature: JSON formatter but this means we need to respect whitespace at the start and end of lines in the description. + Pay close attention to the whitespace in this example. + Given the following text is parsed: """ Feature: Foo @@ -289,6 +291,22 @@ Feature: JSON formatter another line some pre-formatted stuff + + Background: name + test + + Scenario: name + test + + Scenario Outline: name + test + + Given + + Examples: name + test + | foo | + | table | """ Then the outputted JSON should be: """ @@ -296,7 +314,59 @@ Feature: JSON formatter "keyword": "Feature", "name": "Foo", "description": "one line \nanother line \n\n some pre-formatted stuff", - "line": 1 + "line": 1, + "elements": [ + { + "description": " test ", + "keyword": "Background", + "line": 7, + "name": "name", + "type": "background" + }, + { + "description": " test ", + "keyword": "Scenario", + "line": 10, + "name": "name", + "type": "scenario" + }, + { + "description": " test ", + "examples": [ + { + "description": " test ", + "keyword": "Examples", + "line": 18, + "name": "name", + "rows": [ + { + "cells": [ + "foo" + ], + "line": 20 + }, + { + "cells": [ + "table" + ], + "line": 21 + } + ] + } + ], + "keyword": "Scenario Outline", + "line": 13, + "name": "name", + "steps": [ + { + "keyword": "Given ", + "line": 16, + "name": "" + } + ], + "type": "scenario_outline" + } + ] } """ diff --git a/ragel/lexer.rb.rl.erb b/ragel/lexer.rb.rl.erb index c88f4b40..70cb9327 100644 --- a/ragel/lexer.rb.rl.erb +++ b/ragel/lexer.rb.rl.erb @@ -34,25 +34,25 @@ module Gherkin } action store_background_content { - store_keyword_content(:background, data, p, eof) { |con| multiline_strip(con) } + store_keyword_content(:background, data, p, eof) { |con| unindent(@start_col + 2, con) } p = @next_keyword_start - 1 if @next_keyword_start @next_keyword_start = nil } action store_scenario_content { - store_keyword_content(:scenario, data, p, eof) { |con| multiline_strip(con) } + store_keyword_content(:scenario, data, p, eof) { |con| unindent(@start_col + 2, con) } p = @next_keyword_start - 1 if @next_keyword_start @next_keyword_start = nil } action store_scenario_outline_content { - store_keyword_content(:scenario_outline, data, p, eof) { |con| multiline_strip(con) } + store_keyword_content(:scenario_outline, data, p, eof) { |con| unindent(@start_col + 2, con) } p = @next_keyword_start - 1 if @next_keyword_start @next_keyword_start = nil } action store_examples_content { - store_keyword_content(:examples, data, p, eof) { |con| multiline_strip(con) } + store_keyword_content(:examples, data, p, eof) { |con| unindent(@start_col + 2, con) } p = @next_keyword_start - 1 if @next_keyword_start @next_keyword_start = nil } @@ -147,13 +147,6 @@ module Gherkin CRLF = "\r\n" LF = "\n" - def multiline_strip(text) - crlf_count = text.scan(CRLF_RE).size - lf_count = text.scan(LF_RE).size - eol = crlf_count > lf_count ? CRLF : LF - text.split(/\r?\n/).map{|s| s.strip}.join(eol).strip - end - def unindent(startcol, text) text.gsub(/^[\t ]{0,#{startcol}}/, "") end