New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Tests: Exhaustive pattern tests #2688
Merged
RunDevelopment
merged 3 commits into
PrismJS:master
from
RunDevelopment:exhaustive-pattern-tests
May 1, 2021
Merged
Tests: Exhaustive pattern tests #2688
RunDevelopment
merged 3 commits into
PrismJS:master
from
RunDevelopment:exhaustive-pattern-tests
May 1, 2021
Conversation
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
|
I will merge this. It really doesn't matter that the tests take longer now. |
This was referenced Jun 28, 2021
Closed
Closed
This was referenced Jul 12, 2021
Open
This was referenced Jul 19, 2021
This was referenced Jul 26, 2021
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
This improves the static pattern test to check every regex.
Method
This is achieved by running all test files for a given language and overwriting the
Prism.tokenizefunction itself. Thetokenizefunction will be replaced with a function that runs all checks on the grammar given to the function and then uses the originaltokenizefunction. Assuming that our test files cover (nearly) all aspects of our languages, this approach will analyze all regexes used in grammar.This runtime approach is necessary because some languages (e.g. PHP and Latte) use markup templating (MT) which changes the grammar with one that might not be reachable from
Prism.languages.However, even this isn't enough. MT also requires a regex to detect the embedded language (example). This pattern isn't passed to
Prism.tokenize.To analyze these regexes for super-linear runtime, the prototype of the
RegExptype itself is changed to replace theexecandtestmethods with methods that run the analysis for every regex that is used throughout the tests.Problem
The only problem with this approach is that it is slow.
To statically analyze all regexes, I need about 2s, and to run all test files, I need about another 2s on my machine. However, the exhaustive pattern test takes 9s on my machine.
This is because of the
RegExpprototype magic that forces us to take the slow path. Without the prototype magic, the whole thing only takes 5s on my machine.