-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* add embedded language to `package.json` * add embedded language to TMLanguage * improve grammar loader the grammar loader should be able to load the embedded grammar scope at least at a minimum level * disable verbose mode in fact it is sufficient to show only the names of the tests, no more details are needed for the moment * basic tests for JS injection rules
- Loading branch information
1 parent
4d2703e
commit 14ce25f
Showing
5 changed files
with
97 additions
and
20 deletions.
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
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
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,39 @@ | ||
/** | ||
* @file Tests for JS injection rules | ||
*/ | ||
|
||
import { AdblockTokenizer, getAdblockTokenizer } from '../common/get-adblock-tokenizer'; | ||
import { expectTokens } from '../common/token-expectation'; | ||
|
||
let tokenize: AdblockTokenizer; | ||
|
||
// Before running any tests, we should load the grammar and get the tokenizer | ||
beforeAll(async () => { | ||
tokenize = await getAdblockTokenizer(); | ||
}); | ||
|
||
describe('JS injection rules', () => { | ||
test('should tokenize valid JS injections', () => { | ||
expectTokens( | ||
tokenize, | ||
'#%#window.hello = 1', | ||
[ | ||
{ fragment: '#%#', scopes: ['text.adblock', 'keyword.control.adblock'] }, | ||
{ fragment: 'window.hello = 1', scopes: ['text.adblock', 'source.js'] }, | ||
], | ||
); | ||
}); | ||
|
||
test('should detect invalid cases', () => { | ||
// Unclosed scriptlet call. Since it's not closed, it's not matches as a scriptlet call, | ||
// but #%# is "stronger" than scriptlet injection, and we shouldn't tokenize it as a JS comment | ||
expectTokens( | ||
tokenize, | ||
'#%#//scriptlet(\'a\',', | ||
[ | ||
{ fragment: '#%#', scopes: ['text.adblock', 'keyword.control.adblock'] }, | ||
{ fragment: '//scriptlet(\'a\',', scopes: ['text.adblock', 'invalid.illegal'] }, | ||
], | ||
); | ||
}); | ||
}); |