UNPKG

typespec-bdd

Version:

BDD framework for TypeScript.

82 lines 3.6 kB
(function (factory) { if (typeof module === "object" && typeof module.exports === "object") { var v = factory(require, exports); if (v !== undefined) module.exports = v; } else if (typeof define === "function" && define.amd) { define(["require", "exports"], factory); } })(function (require, exports) { "use strict"; Object.defineProperty(exports, "__esModule", { value: true }); var KeywordType; (function (KeywordType) { KeywordType[KeywordType["Unknown"] = 0] = "Unknown"; KeywordType[KeywordType["Feature"] = 1] = "Feature"; KeywordType[KeywordType["Scenario"] = 2] = "Scenario"; KeywordType[KeywordType["Outline"] = 3] = "Outline"; KeywordType[KeywordType["Examples"] = 4] = "Examples"; KeywordType[KeywordType["Tag"] = 5] = "Tag"; KeywordType[KeywordType["Table"] = 6] = "Table"; KeywordType[KeywordType["TokenStart"] = 7] = "TokenStart"; KeywordType[KeywordType["TokenEnd"] = 8] = "TokenEnd"; KeywordType[KeywordType["Given"] = 9] = "Given"; KeywordType[KeywordType["When"] = 10] = "When"; KeywordType[KeywordType["Then"] = 11] = "Then"; KeywordType[KeywordType["And"] = 12] = "And"; })(KeywordType = exports.KeywordType || (exports.KeywordType = {})); class Keywords { constructor() { this.Feature = 'Feature:'; this.Scenario = 'Scenario:'; this.Outline = 'Scenario Outline:'; this.Examples = 'Examples:'; this.Tag = '@'; this.Table = '|'; this.TokenStart = '<'; this.TokenEnd = '>'; this.Given = 'Given '; this.When = 'When '; this.Then = 'Then '; this.And = 'And '; this.KeywordMap = {}; this.KeywordTypeMap = {}; this.addMap(this.Feature, KeywordType.Feature); this.addMap(this.Scenario, KeywordType.Scenario); this.addMap(this.Outline, KeywordType.Outline); this.addMap(this.Examples, KeywordType.Examples); this.addMap(this.Tag, KeywordType.Tag); this.addMap(this.Table, KeywordType.Table); this.addMap(this.TokenStart, KeywordType.TokenStart); this.addMap(this.TokenEnd, KeywordType.TokenEnd); this.addMap(this.Given, KeywordType.Given); this.addMap(this.When, KeywordType.When); this.addMap(this.Then, KeywordType.Then); this.addMap(this.And, KeywordType.And); } is(text, keywordType) { const keyword = this.KeywordTypeMap[keywordType]; return (text.length >= keyword.length && text.substring(0, keyword.length) === keyword); } trimKeyword(text, keywordType) { const keyword = this.KeywordTypeMap[keywordType]; return text.substring(keyword.length).trim(); } getToken(text) { return exports.Keyword.TokenStart + text + exports.Keyword.TokenEnd; } getTags(text) { return text.split(exports.Keyword.Tag); } getTableRow(text) { return text.split(exports.Keyword.Table); } addMap(keyword, keywordType) { this.KeywordMap[keyword] = keywordType; this.KeywordTypeMap[keywordType] = keyword; } } exports.Keywords = Keywords; exports.Keyword = new Keywords(); }); //# sourceMappingURL=Keyword.js.map