Skip to content

Commit

Permalink
support advanced for safari_cb_affinity
Browse files Browse the repository at this point in the history
  • Loading branch information
slavaleleka committed Aug 22, 2024
1 parent de26a52 commit ee1ed4c
Show file tree
Hide file tree
Showing 5 changed files with 99 additions and 5 deletions.
11 changes: 10 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,15 @@ All notable changes to this project will be documented in this file.

The format is based on [Keep a Changelog][keepachangelog], and this project adheres to [Semantic Versioning][semver].

## 1.1.11 - 2024-08-23

### Added

- Support of `advanced` value for `!#safari_cb_affinity` directive: [FiltersCompiler#226]

[FiltersCompiler#226]: https://github.com/AdguardTeam/FiltersCompiler/issues/226


## 1.1.10 - 2024-04-26

### Changed
Expand Down Expand Up @@ -170,7 +179,7 @@ The format is based on [Keep a Changelog][keepachangelog], and this project adhe
- Support for `$stealth`: [#39]
- Support for multiple DNS filtering modifiers: `$client`, `$ctag`, `$dnsrewrite`, `$dnstype`:
[#38]
- Support for `safari_cb_affinity` hint: [#43]
- Support for `!#safari_cb_affinity` directive: [#43]

### Changed

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "adblock",
"displayName": "Adblock/AdGuard/uBlock filters grammar",
"description": "VS code extension that adds support for ad blocking rules syntax.",
"version": "1.1.10",
"version": "1.1.11",
"publisher": "adguard",
"icon": "icons/aglint_128x128.png",
"main": "./client/out/extension",
Expand Down
2 changes: 1 addition & 1 deletion syntaxes/adblock.yaml-tmlanguage
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ repository:
"2":
patterns:
- name: constant.language.contentblocker.name
match: "(all|general|privacy|social|security|other|custom)"
match: "(all|general|privacy|social|security|other|custom|advanced)"
- name: keyword.control.characters
match: "(\\(|\\)|,)"
- name: invalid.illegal
Expand Down
87 changes: 86 additions & 1 deletion test/grammar/comments/preprocessor.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -140,5 +140,90 @@ describe('Preprocessor directive comments', () => {
});
});

// TODO: add tests for !#include, !#safari_cb_affinity and for unknown preprocessor directives
describe('!#safari_cb_affinity', () => {
test.each([
{
actual: '!#safari_cb_affinity(general)',
expected: [
{ fragment: '!#safari_cb_affinity', scopes: [BASE_SCOPE, 'keyword.preprocessor.directive'] },
{ fragment: '(', scopes: [BASE_SCOPE, 'keyword.control.characters'] },
{ fragment: 'general', scopes: [BASE_SCOPE, 'constant.language.contentblocker.name'] },
{ fragment: ')', scopes: [BASE_SCOPE, 'keyword.control.characters'] },
],
},
{
actual: '!#safari_cb_affinity(general,privacy)',
expected: [
{ fragment: '!#safari_cb_affinity', scopes: [BASE_SCOPE, 'keyword.preprocessor.directive'] },
{ fragment: '(', scopes: [BASE_SCOPE, 'keyword.control.characters'] },
{ fragment: 'general', scopes: [BASE_SCOPE, 'constant.language.contentblocker.name'] },
{ fragment: ',', scopes: [BASE_SCOPE, 'keyword.control.characters'] },
{ fragment: 'privacy', scopes: [BASE_SCOPE, 'constant.language.contentblocker.name'] },
{ fragment: ')', scopes: [BASE_SCOPE, 'keyword.control.characters'] },
],
},
{
actual: '!#safari_cb_affinity(all)',
expected: [
{ fragment: '!#safari_cb_affinity', scopes: [BASE_SCOPE, 'keyword.preprocessor.directive'] },
{ fragment: '(', scopes: [BASE_SCOPE, 'keyword.control.characters'] },
{ fragment: 'all', scopes: [BASE_SCOPE, 'constant.language.contentblocker.name'] },
{ fragment: ')', scopes: [BASE_SCOPE, 'keyword.control.characters'] },
],
},
{
actual: '!#safari_cb_affinity(advanced)',
expected: [
{ fragment: '!#safari_cb_affinity', scopes: [BASE_SCOPE, 'keyword.preprocessor.directive'] },
{ fragment: '(', scopes: [BASE_SCOPE, 'keyword.control.characters'] },
{ fragment: 'advanced', scopes: [BASE_SCOPE, 'constant.language.contentblocker.name'] },
{ fragment: ')', scopes: [BASE_SCOPE, 'keyword.control.characters'] },
],
},
{
actual: '!#safari_cb_affinity(privacy,advanced)',
expected: [
{ fragment: '!#safari_cb_affinity', scopes: [BASE_SCOPE, 'keyword.preprocessor.directive'] },
{ fragment: '(', scopes: [BASE_SCOPE, 'keyword.control.characters'] },
{ fragment: 'privacy', scopes: [BASE_SCOPE, 'constant.language.contentblocker.name'] },
{ fragment: ',', scopes: [BASE_SCOPE, 'keyword.control.characters'] },
{ fragment: 'advanced', scopes: [BASE_SCOPE, 'constant.language.contentblocker.name'] },
{ fragment: ')', scopes: [BASE_SCOPE, 'keyword.control.characters'] },
],
},
])("valid: '$actual'", ({ actual, expected }) => {
expectTokens(tokenize, actual, expected);
});

test.each([
{
actual: '!#safari_cb_affinity all',
expected: [
{ fragment: '!#safari_cb_affinity', scopes: [BASE_SCOPE, 'keyword.preprocessor.directive'] },
{ fragment: ' all', scopes: [BASE_SCOPE, 'invalid.illegal'] },
],
},
{
actual: '!#safari_cb_affinity (all)',
expected: [
{ fragment: '!#safari_cb_affinity', scopes: [BASE_SCOPE, 'keyword.preprocessor.directive'] },
{ fragment: ' (all)', scopes: [BASE_SCOPE, 'invalid.illegal'] },
],
},
{
actual: '!#safari_cb_affinity(social, other)',
expected: [
{ fragment: '!#safari_cb_affinity', scopes: [BASE_SCOPE, 'keyword.preprocessor.directive'] },
{ fragment: '(', scopes: [BASE_SCOPE, 'keyword.control.characters'] },
{ fragment: 'social', scopes: [BASE_SCOPE, 'constant.language.contentblocker.name'] },
{ fragment: ',', scopes: [BASE_SCOPE, 'keyword.control.characters'] },
{ fragment: ' other)', scopes: [BASE_SCOPE, 'invalid.illegal'] },
],
},
])("invalid case '$actual'", ({ actual, expected }) => {
expectTokens(tokenize, actual, expected);
});
});

// TODO: add tests for !#include and for other unknown preprocessor directives
});
2 changes: 1 addition & 1 deletion test/grammar/common/token-expectation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ export function expectTokens(tokenize: AdblockTokenizer, source: string, expecte
const mergedFragments = expectedTokens.map((token) => token.fragment).join('');

if (mergedFragments !== source) {
throw new Error('The merged fragments don\'t match the source, so the expectation is invalid');
throw new Error('The merged fragments do not match the source, so the expectation is invalid');
}

// Tokenize the source
Expand Down

0 comments on commit ee1ed4c

Please sign in to comment.