Skip to content

Commit

Permalink
Tests: Added test for empty regexes (#1847)
Browse files Browse the repository at this point in the history
This adds a new test which checks all regexes to not match the empty string.
  • Loading branch information
RunDevelopment committed Apr 22, 2019
1 parent eb28b62 commit c1e6a7f
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 1 deletion.
3 changes: 2 additions & 1 deletion package.json
Expand Up @@ -8,8 +8,9 @@
"test:aliases": "mocha tests/aliases-test.js",
"test:languages": "mocha tests/run.js",
"test:plugins": "mocha tests/plugins/**/*.js",
"test:regex": "mocha tests/regex-tests.js",
"test:runner": "mocha tests/testrunner-tests.js",
"test": "npm run test:runner && npm run test:languages && npm run test:plugins && npm run test:aliases"
"test": "npm run test:runner && npm run test:languages && npm run test:plugins && npm run test:aliases && npm run test:regex"
},
"repository": {
"type": "git",
Expand Down
31 changes: 31 additions & 0 deletions tests/regex-tests.js
@@ -0,0 +1,31 @@
"use strict";

const { assert } = require("chai");
const PrismLoader = require('./helper/prism-loader');
const { languages } = require('../components');

for (const lang in languages) {
if (lang === 'meta') {
continue;
}

describe(`Testing regular expressions of '${lang}'`, function () {

const Prism = PrismLoader.createInstance(lang);

it('- should not match the empty string', function () {
let lastToken = '<unknown>';

Prism.languages.DFS(Prism.languages, function (name, value) {
if (typeof this === 'object' && !Array.isArray(this) && name !== 'pattern') {
lastToken = name;
}

if (Prism.util.type(value) === 'RegExp') {
assert.notMatch('', value, `Token '${lastToken}': ${value} should not match the empty string.`);
}
});

});
});
}

0 comments on commit c1e6a7f

Please sign in to comment.