diff --git a/features/with_bom.feature b/features/with_bom.feature new file mode 100644 index 000000000..a10f06c13 --- /dev/null +++ b/features/with_bom.feature @@ -0,0 +1,53 @@ +Feature: User logs into the system + In order to be able to use eraNET components + As a user + I want to log in to the system + + + Scenario: Unlogged user sees welcome page with login + Given I have not logged or have logged out before + When I visit initial page + Then Default app should be loaded + And I should see login request + And I should not see any username + + + Scenario: Minimal user sees welcome page with its username and logout + Given I have logged as guest named "Guest" + When I visit initial page + Then Default app should be loaded + And I should see logout request + And I should see "Guest" as username + + + Scenario: Unlogged user logs in + Given I have not logged or have logged out before + And I have visited initial page + And I have seen login request + When I ask to log in + Then I should be taken to login page + + + Scenario: Logged user logs out + Given I have logged as guest named "Guest" + And I have visited initial page + And I have seen logout request + When I ask to log out + Then I should be taken to logout page + + + Scenario: Disconnected user sees welcome page and reconnect option + Given I have had a broken connection with api site + When I visit initial page + Then Default app should be loaded + And I should see reconnect request + And I should not see any username + + + Scenario: User sees 'connecting' while connecting + Given I have had lagging api site + When I visit initial page + Then I should see connecting message + And I should not see any username + + diff --git a/lib/cucumber/gherkin_lexer.js b/lib/cucumber/gherkin_lexer.js new file mode 100644 index 000000000..122881ca2 --- /dev/null +++ b/lib/cucumber/gherkin_lexer.js @@ -0,0 +1,19 @@ +var gherkin = require('gherkin'); + +/** + * Small wrapper around Gherkin that strips BOM and loads the correct lexer based + * on the language header. + */ +module.exports = function GherkinLexer(content, gherkinListener) { + // Strip BOM + content = content.replace(/^\ufeff/g, ''); + + var languageMatch = /^\s*#\s*language:\s*([a-zA-Z-]+)\s*$/m.exec(content); + var language = languageMatch == null ? 'en' : languageMatch[1].toLowerCase(); + var Lexer = gherkin.Lexer(language); + var lexer = new Lexer(gherkinListener); + + this.scan = function() { + lexer.scan(content); + } +}; diff --git a/lib/cucumber/parser.js b/lib/cucumber/parser.js index 08b93aa08..b44e56856 100644 --- a/lib/cucumber/parser.js +++ b/lib/cucumber/parser.js @@ -1,5 +1,5 @@ var Parser = function(featureSources, astFilter) { - var Gherkin = require('gherkin'); + var GherkinLexer = require('./gherkin_lexer'); var Cucumber = require('../cucumber'); var features = Cucumber.Ast.Features(); @@ -8,22 +8,12 @@ var Parser = function(featureSources, astFilter) { var self = { parse: function parse() { - var lexers = {}; - var lexer = function (lang) { - if (!(lang in lexers)) { - lexers[lang] = new (Gherkin.Lexer(lang))(self.getEventHandlers()); - } - - return lexers[lang]; - }; - for (i in featureSources) { var currentSourceUri = featureSources[i][Parser.FEATURE_NAME_SOURCE_PAIR_URI_INDEX]; var featureSource = featureSources[i][Parser.FEATURE_NAME_SOURCE_PAIR_SOURCE_INDEX]; self.setCurrentSourceUri(currentSourceUri); - var languageMatch = /^\s*#\s*language:\s*([a-z_]*)/.exec(featureSource.toString()); - var language = languageMatch == null ? 'en' : languageMatch[1]; - lexer(language).scan(featureSource); + var lexer = new GherkinLexer(featureSource.toString(), self.getEventHandlers()); + lexer.scan(); } return features; }, diff --git a/spec/cucumber/parser_spec.js b/spec/cucumber/parser_spec.js index e5fa88a45..872ffdb11 100644 --- a/spec/cucumber/parser_spec.js +++ b/spec/cucumber/parser_spec.js @@ -78,16 +78,6 @@ describe("Cucumber.Parser", function () { expect(parser.setCurrentSourceUri).toHaveBeenCalledWith(featureSources[1][0]); }); - it("asks the English lexer to scan the first feature source", function () { - parser.parse(); - expect(gherkinENLexer.scan).toHaveBeenCalledWith(featureSources[0][1]); - }); - - it("asks the French lexer to scan the second feature source", function () { - parser.parse(); - expect(gherkinFRLexer.scan).toHaveBeenCalledWith(featureSources[1][1]); - }); - it("returns the features root element", function () { expect(parser.parse()).toBe(features); });