gherkin-ast
Version:
JS model for Gherkin feature files
54 lines • 2.13 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.Element = exports.REPEAT_STEP_KEYWORDS = void 0;
const common_1 = require("../common");
const uniqueObject_1 = require("./uniqueObject");
const debug_1 = require("../debug");
const debug = (0, debug_1.getDebugger)("Element");
exports.REPEAT_STEP_KEYWORDS = ["And", "But", "*"];
/**
* Model for Element
*/
class Element extends uniqueObject_1.UniqueObject {
constructor(keyword, name, description) {
super();
debug("constructor(keyword: '%s', name: '%s', description: '%s')", keyword, name, description);
this.keyword = (0, common_1.normalizeString)(keyword);
this.name = (0, common_1.normalizeString)(name);
this.description = (0, common_1.normalizeString)(description);
this.steps = [];
this.precedingComment = null;
this.descriptionComment = null;
}
clone() {
debug("clone()");
throw new Error("Not implemented");
}
replace(key, value) {
debug("replace(key: '%s', value: '%s')", key, value);
this.name = (0, common_1.replaceAll)(this.name, key, value);
this.description = (0, common_1.replaceAll)(this.description, key, value);
(0, common_1.replaceArray)(this.steps, key, value);
this.precedingComment && this.precedingComment.replace(key, value);
this.descriptionComment && this.descriptionComment.replace(key, value);
}
useNormalStepKeywords() {
debug("useNormalStepKeywords()");
this.steps.forEach((step, i) => {
if (i && exports.REPEAT_STEP_KEYWORDS.indexOf(step.keyword) > -1) {
step.keyword = this.steps[i - 1].keyword;
}
});
}
useReadableStepKeywords() {
debug("useReadableStepKeywords()");
this.useNormalStepKeywords();
for (let i = this.steps.length - 1; i > 0; --i) {
if (this.steps[i].keyword === this.steps[i - 1].keyword) {
this.steps[i].keyword = "And";
}
}
}
}
exports.Element = Element;
//# sourceMappingURL=element.js.map