diff --git a/package.json b/package.json index 6eb6937af9..1a3fcb6637 100755 --- a/package.json +++ b/package.json @@ -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", diff --git a/tests/regex-tests.js b/tests/regex-tests.js new file mode 100644 index 0000000000..0b30ad82e6 --- /dev/null +++ b/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 = ''; + + 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.`); + } + }); + + }); + }); +}