-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Tests: Added test for empty regexes (#1847)
This adds a new test which checks all regexes to not match the empty string.
- Loading branch information
1 parent
eb28b62
commit c1e6a7f
Showing
2 changed files
with
33 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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.`); | ||
} | ||
}); | ||
|
||
}); | ||
}); | ||
} |