Skip to content

Commit c1e6a7f

Browse files
Tests: Added test for empty regexes (#1847)
This adds a new test which checks all regexes to not match the empty string.
1 parent eb28b62 commit c1e6a7f

File tree

2 files changed

+33
-1
lines changed

2 files changed

+33
-1
lines changed

package.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,9 @@
88
"test:aliases": "mocha tests/aliases-test.js",
99
"test:languages": "mocha tests/run.js",
1010
"test:plugins": "mocha tests/plugins/**/*.js",
11+
"test:regex": "mocha tests/regex-tests.js",
1112
"test:runner": "mocha tests/testrunner-tests.js",
12-
"test": "npm run test:runner && npm run test:languages && npm run test:plugins && npm run test:aliases"
13+
"test": "npm run test:runner && npm run test:languages && npm run test:plugins && npm run test:aliases && npm run test:regex"
1314
},
1415
"repository": {
1516
"type": "git",

tests/regex-tests.js

+31
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
"use strict";
2+
3+
const { assert } = require("chai");
4+
const PrismLoader = require('./helper/prism-loader');
5+
const { languages } = require('../components');
6+
7+
for (const lang in languages) {
8+
if (lang === 'meta') {
9+
continue;
10+
}
11+
12+
describe(`Testing regular expressions of '${lang}'`, function () {
13+
14+
const Prism = PrismLoader.createInstance(lang);
15+
16+
it('- should not match the empty string', function () {
17+
let lastToken = '<unknown>';
18+
19+
Prism.languages.DFS(Prism.languages, function (name, value) {
20+
if (typeof this === 'object' && !Array.isArray(this) && name !== 'pattern') {
21+
lastToken = name;
22+
}
23+
24+
if (Prism.util.type(value) === 'RegExp') {
25+
assert.notMatch('', value, `Token '${lastToken}': ${value} should not match the empty string.`);
26+
}
27+
});
28+
29+
});
30+
});
31+
}

0 commit comments

Comments
 (0)