Permalink
Browse files

Store URI on AST elements

  • Loading branch information...
jbpros committed Jun 19, 2012
1 parent 3057098 commit 35c4d25c7d9745e3c9471b27655030b230846f5c
@@ -1,4 +1,4 @@
-var Background = function(keyword, name, description, line) {
+var Background = function(keyword, name, description, uri, line) {
var Cucumber = require('../../cucumber');
var steps = Cucumber.Type.Collection();
@@ -16,6 +16,10 @@ var Background = function(keyword, name, description, line) {
return description;
},
+ getUri: function getUri() {
+ return uri;
+ },
+
getLine: function getLine() {
return line;
},
@@ -1,4 +1,4 @@
-var Row = function(cells, line) {
+var Row = function(cells, uri, line) {
var Cucumber = require('../../../cucumber');
self = {
@@ -1,4 +1,4 @@
-var DocString = function(contentType, contents, line) {
+var DocString = function(contentType, contents, uri, line) {
var self = {
getContents: function getContents() {
return contents;
@@ -8,6 +8,10 @@ var DocString = function(contentType, contents, line) {
return contentType;
},
+ getUri: function getUri() {
+ return uri;
+ },
+
getLine: function getLine() {
return line;
}
@@ -1,4 +1,4 @@
-var Feature = function(keyword, name, description, line) {
+var Feature = function(keyword, name, description, uri, line) {
var Cucumber = require('../../cucumber');
var background;
@@ -18,6 +18,10 @@ var Feature = function(keyword, name, description, line) {
return description;
},
+ getUri: function getUri() {
+ return uri;
+ },
+
getLine: function getLine() {
return line;
},
@@ -1,4 +1,4 @@
-var Scenario = function(keyword, name, description, line) {
+var Scenario = function(keyword, name, description, uri, line) {
var Cucumber = require('../../cucumber');
var background;
@@ -22,6 +22,10 @@ var Scenario = function(keyword, name, description, line) {
return description;
},
+ getUri: function getUri() {
+ return uri;
+ },
+
getLine: function getLine() {
return line;
},
View
@@ -1,4 +1,4 @@
-var Step = function(keyword, name, line) {
+var Step = function(keyword, name, uri, line) {
var Cucumber = require('../../cucumber');
var docString, dataTable, previousStep;
@@ -15,6 +15,10 @@ var Step = function(keyword, name, line) {
return name;
},
+ getUri: function getUri() {
+ return uri;
+ },
+
getLine: function getLine() {
return line;
},
View
@@ -1,11 +1,19 @@
-var Tag = function(name, line) {
+var Tag = function(name, uri, line) {
var Cucumber = require('../../cucumber');
var self = {
getName: function getName() {
return name;
+ },
+
+ getUri: function getUri() {
+ return uri;
+ },
+
+ getLine: function getLine() {
+ return line;
}
};
return self;
};
-module.exports = Tag;
+module.exports = Tag;
View
@@ -4,18 +4,29 @@ var Parser = function(featureSources, astFilter) {
var features = Cucumber.Ast.Features();
var astAssembler = Cucumber.Ast.Assembler(features, astFilter);
+ var currentSourceUri;
var self = {
parse: function parse() {
var Lexer = Gherkin.Lexer('en');
var lexer = new Lexer(self.getEventHandlers());
for (i in featureSources) {
- var featureSource = featureSources[i][Parser.FEATURE_NAME_SOURCE_PAIR_SOURCE_INDEX];
+ 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);
lexer.scan(featureSource);
}
return features;
},
+ setCurrentSourceUri: function setCurrentSourceUri(uri) {
+ currentSourceUri = uri;
+ },
+
+ getCurrentSourceUri: function getCurrentSourceUri() {
+ return currentSourceUri;
+ },
+
getEventHandlers: function getEventHandlers() {
return {
background: self.handleBackground,
@@ -30,46 +41,54 @@ var Parser = function(featureSources, astFilter) {
};
},
- handleTag: function handleTag(tag, line) {
- var tag = Cucumber.Ast.Tag(tag, line);
- astAssembler.insertTag(tag);
- },
-
handleBackground: function handleBackground(keyword, name, description, line) {
- var background = Cucumber.Ast.Background(keyword, name, description, line);
+ var uri = self.getCurrentSourceUri();
+ var background = Cucumber.Ast.Background(keyword, name, description, uri, line);
astAssembler.insertBackground(background);
},
handleComment: function handleComment() {},
handleDocString: function handleDocString(contentType, string, line) {
- var docString = Cucumber.Ast.DocString(contentType, string, line);
+ var uri = self.getCurrentSourceUri();
+ var docString = Cucumber.Ast.DocString(contentType, string, uri, line);
astAssembler.insertDocString(docString);
},
handleEof: function handleEof() {},
handleFeature: function handleFeature(keyword, name, description, line) {
- var feature = Cucumber.Ast.Feature(keyword, name, description, line);
+ var uri = self.getCurrentSourceUri();
+ var feature = Cucumber.Ast.Feature(keyword, name, description, uri, line);
astAssembler.insertFeature(feature);
},
handleDataTableRow: function handleDataTableRow(cells, line) {
- var dataTableRow = Cucumber.Ast.DataTable.Row(cells, line);
+ var uri = self.getCurrentSourceUri();
+ var dataTableRow = Cucumber.Ast.DataTable.Row(cells, uri, line);
astAssembler.insertDataTableRow(dataTableRow);
},
handleScenario: function handleScenario(keyword, name, description, line) {
- var scenario = Cucumber.Ast.Scenario(keyword, name, description, line);
+ var uri = self.getCurrentSourceUri();
+ var scenario = Cucumber.Ast.Scenario(keyword, name, description, uri, line);
astAssembler.insertScenario(scenario);
},
handleStep: function handleStep(keyword, name, line) {
- var step = Cucumber.Ast.Step(keyword, name, line);
+ var uri = self.getCurrentSourceUri();
+ var step = Cucumber.Ast.Step(keyword, name, uri, line);
astAssembler.insertStep(step);
+ },
+
+ handleTag: function handleTag(tag, line) {
+ var uri = self.getCurrentSourceUri();
+ var tag = Cucumber.Ast.Tag(tag, uri, line);
+ astAssembler.insertTag(tag);
}
};
return self;
};
+Parser.FEATURE_NAME_SOURCE_PAIR_URI_INDEX = 0;
Parser.FEATURE_NAME_SOURCE_PAIR_SOURCE_INDEX = 1;
module.exports = Parser;
@@ -3,19 +3,20 @@ require('../../support/spec_helper');
describe("Cucumber.Ast.Background", function() {
var Cucumber = requireLib('cucumber');
var steps;
- var background, keyword, name, description, line, lastStep;
+ var background, keyword, name, description, uri, line, lastStep;
beforeEach(function() {
keyword = createSpy("background keyword");
name = createSpy("background name");
description = createSpy("background description");
+ uri = createSpy("uri");
line = createSpy("starting background line number");
lastStep = createSpy("Last step");
steps = createSpy("Step collection");
spyOnStub(steps, 'add');
spyOnStub(steps, 'getLast').andReturn(lastStep);
spyOn(Cucumber.Type, 'Collection').andReturn(steps);
- background = Cucumber.Ast.Background(keyword, name, description, line);
+ background = Cucumber.Ast.Background(keyword, name, description, uri, line);
});
describe("constructor", function() {
@@ -42,6 +43,12 @@ describe("Cucumber.Ast.Background", function() {
});
});
+ describe("getUri()", function() {
+ it("returns the URI on which the background starts", function() {
+ expect(background.getUri()).toBe(uri);
+ });
+ });
+
describe("getLine()", function() {
it("returns the line on which the background starts", function() {
expect(background.getLine()).toBe(line);
@@ -3,12 +3,13 @@ require('../../../support/spec_helper');
describe("Cucumber.Ast.Feature", function() {
var Cucumber = requireLib('cucumber');
- var row, cells, line;
+ var row, cells, uri, line;
beforeEach(function() {
cells = createSpy("cells");
+ uri = createSpy("uri");
line = createSpy("line");
- row = Cucumber.Ast.DataTable.Row(cells);
+ row = Cucumber.Ast.DataTable.Row(cells, uri, line);
});
describe("raw()", function() {
@@ -2,13 +2,14 @@ require('../../support/spec_helper');
describe("Cucumber.Ast.DocString", function() {
var Cucumber = requireLib('cucumber');
- var docString, contents, line;
+ var docString, contents, uri, line;
beforeEach(function() {
contentType = createSpy("content type");
- contents = createSpy("DocString contents");
- line = createSpy("DocString line number");
- docString = Cucumber.Ast.DocString(contentType, contents, line);
+ contents = createSpy("contents");
+ uri = createSpy("uri");
+ line = createSpy("line number");
+ docString = Cucumber.Ast.DocString(contentType, contents, uri, line);
});
describe("getContents()", function() {
@@ -23,6 +24,12 @@ describe("Cucumber.Ast.DocString", function() {
});
});
+ describe("getUri()", function() {
+ it("returns the URI on which the background starts", function() {
+ expect(docString.getUri()).toBe(uri);
+ });
+ });
+
describe("getLine()", function() {
it("returns the line on which the DocString starts", function() {
expect(docString.getLine()).toBe(line);
@@ -3,7 +3,7 @@ require('../../support/spec_helper');
describe("Cucumber.Ast.Feature", function() {
var Cucumber = requireLib('cucumber');
var scenarioCollection, lastScenario;
- var feature, keyword, name, line;
+ var feature, keyword, name, uri, line;
beforeEach(function() {
lastScenario = createSpy("Last scenario");
@@ -12,11 +12,12 @@ describe("Cucumber.Ast.Feature", function() {
spyOnStub(scenarioCollection, 'getLast').andReturn(lastScenario);
spyOnStub(scenarioCollection, 'forEach');
spyOn(Cucumber.Type, 'Collection').andReturn(scenarioCollection);
- keyword = createSpy("Feature keyword");
- name = createSpy("Feature name");
- description = createSpy("Feature description");
- line = createSpy("Feature line number");
- feature = Cucumber.Ast.Feature(keyword, name, description, line);
+ keyword = createSpy("keyword");
+ name = createSpy("name");
+ description = createSpy("description");
+ uri = createSpy("uri");
+ line = createSpy("line number");
+ feature = Cucumber.Ast.Feature(keyword, name, description, uri, line);
});
describe("constructor", function() {
@@ -43,6 +44,12 @@ describe("Cucumber.Ast.Feature", function() {
});
});
+ describe("getUri()", function() {
+ it("returns the URI on which the background starts", function() {
+ expect(feature.getUri()).toBe(uri);
+ });
+ });
+
describe("getLine()", function() {
it("returns the line number on which the feature starts", function() {
expect(feature.getLine()).toBe(line);
@@ -3,19 +3,20 @@ require('../../support/spec_helper');
describe("Cucumber.Ast.Scenario", function() {
var Cucumber = requireLib('cucumber');
var steps;
- var scenario, keyword, name, description, line, lastStep;
+ var scenario, keyword, name, description, uri, line, lastStep;
beforeEach(function() {
keyword = createSpy("scenario keyword");
name = createSpy("scenario name");
description = createSpy("scenario description");
+ uri = createSpy("uri");
line = createSpy("starting scenario line number");
lastStep = createSpy("last step");
steps = createSpy("step collection");
spyOnStub(steps, 'add');
spyOnStub(steps, 'getLast').andReturn(lastStep);
spyOn(Cucumber.Type, 'Collection').andReturn(steps);
- scenario = Cucumber.Ast.Scenario(keyword, name, description, line);
+ scenario = Cucumber.Ast.Scenario(keyword, name, description, uri, line);
});
describe("constructor", function() {
@@ -42,6 +43,12 @@ describe("Cucumber.Ast.Scenario", function() {
});
});
+ describe("getUri()", function() {
+ it("returns the URI on which the background starts", function() {
+ expect(scenario.getUri()).toBe(uri);
+ });
+ });
+
describe("getLine()", function() {
it("returns the line on which the scenario starts", function() {
expect(scenario.getLine()).toBe(line);
Oops, something went wrong.

0 comments on commit 35c4d25

Please sign in to comment.