gherkin-ast
Version:
JS model for Gherkin feature files
64 lines • 4.86 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.Scenario = void 0;
const common_1 = require("../common");
const element_1 = require("./element");
const step_1 = require("./step");
const tag_1 = require("./tag");
const debug_1 = require("../debug");
const debug = (0, debug_1.getDebugger)("Scenario");
/**
* Model for Scenario
*/
class Scenario extends element_1.Element {
static parse(obj, comments) {
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k;
debug("parse(obj: %o, comments: %d)", obj, (_a = comments === null || comments === void 0 ? void 0 : comments.comments) === null || _a === void 0 ? void 0 : _a.length);
if (!obj || !obj.scenario || ((_c = (_b = obj.scenario) === null || _b === void 0 ? void 0 : _b.examples) === null || _c === void 0 ? void 0 : _c.length)) {
throw new TypeError("The given object is not a Scenario!");
}
const { description, keyword, name, steps, tags, location } = obj.scenario;
const scenario = new Scenario(keyword, name, description);
scenario.precedingComment = comments === null || comments === void 0 ? void 0 : comments.parseComment(location, (_d = tags === null || tags === void 0 ? void 0 : tags[tags.length - 1]) === null || _d === void 0 ? void 0 : _d.location);
scenario.tagComment = comments === null || comments === void 0 ? void 0 : comments.parseTagComment(tags);
scenario.steps = step_1.Step.parseAll(steps, comments);
scenario.tags = tag_1.Tag.parseAll(tags, comments);
scenario.descriptionComment = comments === null || comments === void 0 ? void 0 : comments.parseCommentBetween(location, (_e = steps === null || steps === void 0 ? void 0 : steps[0]) === null || _e === void 0 ? void 0 : _e.location);
debug("parse(this: {keyword: '%s', name: '%s', description: '%s', " +
"steps: %d, tags: %d, precedingComment: '%s', tagComment: '%s', " +
"descriptionComment: '%s'})", scenario.keyword, scenario.name, scenario.description, (_f = scenario.steps) === null || _f === void 0 ? void 0 : _f.length, (_g = scenario.tags) === null || _g === void 0 ? void 0 : _g.length, (_h = scenario.precedingComment) === null || _h === void 0 ? void 0 : _h.text, (_j = scenario.tagComment) === null || _j === void 0 ? void 0 : _j.text, (_k = scenario.descriptionComment) === null || _k === void 0 ? void 0 : _k.text);
return scenario;
}
constructor(keyword, name, description) {
var _a, _b, _c, _d, _e;
super(keyword, name, description);
debug("constructor(keyword: '%s', name: '%s', description: '%s')", keyword, name, description);
this.tags = [];
this.precedingComment = null;
this.tagComment = null;
debug("constructor(this: {keyword: '%s', name: '%s', description: '%s', " +
"steps: %d, tags: %d, precedingComment: '%s', tagComment: '%s', " +
"descriptionComment: '%s'})", this.keyword, this.name, this.description, (_a = this.steps) === null || _a === void 0 ? void 0 : _a.length, (_b = this.tags) === null || _b === void 0 ? void 0 : _b.length, (_c = this.precedingComment) === null || _c === void 0 ? void 0 : _c.text, (_d = this.tagComment) === null || _d === void 0 ? void 0 : _d.text, (_e = this.descriptionComment) === null || _e === void 0 ? void 0 : _e.text);
}
replace(key, value) {
debug("replace(key: '%s', value: '%s')", key, value);
super.replace(key, value);
(0, common_1.replaceArray)(this.tags, key, value);
this.tagComment && this.tagComment.replace(key, value);
}
clone() {
var _a, _b, _c, _d, _e;
debug("clone(this: {keyword: '%s', name: '%s', description: '%s', " +
"steps: %d, tags: %d, precedingComment: '%s', tagComment: '%s', " +
"descriptionComment: '%s'})", this.keyword, this.name, this.description, (_a = this.steps) === null || _a === void 0 ? void 0 : _a.length, (_b = this.tags) === null || _b === void 0 ? void 0 : _b.length, (_c = this.precedingComment) === null || _c === void 0 ? void 0 : _c.text, (_d = this.tagComment) === null || _d === void 0 ? void 0 : _d.text, (_e = this.descriptionComment) === null || _e === void 0 ? void 0 : _e.text);
const scenario = new Scenario(this.keyword, this.name, this.description);
scenario.steps = (0, common_1.cloneArray)(this.steps);
scenario.tags = (0, common_1.cloneArray)(this.tags);
scenario.precedingComment = this.precedingComment ? this.precedingComment.clone() : null;
scenario.tagComment = this.tagComment ? this.tagComment.clone() : null;
scenario.descriptionComment = this.descriptionComment ? this.descriptionComment.clone() : null;
return scenario;
}
}
exports.Scenario = Scenario;
//# sourceMappingURL=scenario.js.map