twing
Version:
First-class Twig engine for Node.js
37 lines (36 loc) • 1.01 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.getTest = void 0;
/**
* Gets a test by name.
*
* @param {string} name The test name
* @returns {TwingTest} A MyTest instance or null if the test does not exist
*/
const getTest = (tests, name) => {
const result = tests.get(name);
if (result) {
return result;
}
for (let [pattern, test] of tests) {
let count = 0;
pattern = pattern.replace(/\*/g, function () {
count++;
return '(.*?)';
});
if (count) {
const regExp = new RegExp('^' + pattern + '$', 'g');
const match = regExp.exec(name);
const matches = [];
if (match) {
for (let i = 1; i <= count; i++) {
matches.push(match[i]);
}
test.nativeArguments = matches;
return test;
}
}
}
return null;
};
exports.getTest = getTest;