Skip to content

Commit 732a673

Browse files
committed
support advanced value for !#safari_cb_affinity. AG-35318
AdguardTeam/FiltersCompiler#226 Squashed commit of the following: commit ee1ed4c Author: Slava Leleka <v.leleka@adguard.com> Date: Thu Aug 22 21:17:58 2024 +0300 support advanced for safari_cb_affinity
1 parent de26a52 commit 732a673

File tree

5 files changed

+99
-5
lines changed

5 files changed

+99
-5
lines changed

CHANGELOG.md

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,15 @@ All notable changes to this project will be documented in this file.
44

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

7+
## 1.1.11 - 2024-08-23
8+
9+
### Added
10+
11+
- Support of `advanced` value for `!#safari_cb_affinity` directive: [FiltersCompiler#226]
12+
13+
[FiltersCompiler#226]: https://github.com/AdguardTeam/FiltersCompiler/issues/226
14+
15+
716
## 1.1.10 - 2024-04-26
817

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

175184
### Changed
176185

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"name": "adblock",
33
"displayName": "Adblock/AdGuard/uBlock filters grammar",
44
"description": "VS code extension that adds support for ad blocking rules syntax.",
5-
"version": "1.1.10",
5+
"version": "1.1.11",
66
"publisher": "adguard",
77
"icon": "icons/aglint_128x128.png",
88
"main": "./client/out/extension",

syntaxes/adblock.yaml-tmlanguage

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ repository:
124124
"2":
125125
patterns:
126126
- name: constant.language.contentblocker.name
127-
match: "(all|general|privacy|social|security|other|custom)"
127+
match: "(all|general|privacy|social|security|other|custom|advanced)"
128128
- name: keyword.control.characters
129129
match: "(\\(|\\)|,)"
130130
- name: invalid.illegal

test/grammar/comments/preprocessor.test.ts

Lines changed: 86 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,5 +140,90 @@ describe('Preprocessor directive comments', () => {
140140
});
141141
});
142142

143-
// TODO: add tests for !#include, !#safari_cb_affinity and for unknown preprocessor directives
143+
describe('!#safari_cb_affinity', () => {
144+
test.each([
145+
{
146+
actual: '!#safari_cb_affinity(general)',
147+
expected: [
148+
{ fragment: '!#safari_cb_affinity', scopes: [BASE_SCOPE, 'keyword.preprocessor.directive'] },
149+
{ fragment: '(', scopes: [BASE_SCOPE, 'keyword.control.characters'] },
150+
{ fragment: 'general', scopes: [BASE_SCOPE, 'constant.language.contentblocker.name'] },
151+
{ fragment: ')', scopes: [BASE_SCOPE, 'keyword.control.characters'] },
152+
],
153+
},
154+
{
155+
actual: '!#safari_cb_affinity(general,privacy)',
156+
expected: [
157+
{ fragment: '!#safari_cb_affinity', scopes: [BASE_SCOPE, 'keyword.preprocessor.directive'] },
158+
{ fragment: '(', scopes: [BASE_SCOPE, 'keyword.control.characters'] },
159+
{ fragment: 'general', scopes: [BASE_SCOPE, 'constant.language.contentblocker.name'] },
160+
{ fragment: ',', scopes: [BASE_SCOPE, 'keyword.control.characters'] },
161+
{ fragment: 'privacy', scopes: [BASE_SCOPE, 'constant.language.contentblocker.name'] },
162+
{ fragment: ')', scopes: [BASE_SCOPE, 'keyword.control.characters'] },
163+
],
164+
},
165+
{
166+
actual: '!#safari_cb_affinity(all)',
167+
expected: [
168+
{ fragment: '!#safari_cb_affinity', scopes: [BASE_SCOPE, 'keyword.preprocessor.directive'] },
169+
{ fragment: '(', scopes: [BASE_SCOPE, 'keyword.control.characters'] },
170+
{ fragment: 'all', scopes: [BASE_SCOPE, 'constant.language.contentblocker.name'] },
171+
{ fragment: ')', scopes: [BASE_SCOPE, 'keyword.control.characters'] },
172+
],
173+
},
174+
{
175+
actual: '!#safari_cb_affinity(advanced)',
176+
expected: [
177+
{ fragment: '!#safari_cb_affinity', scopes: [BASE_SCOPE, 'keyword.preprocessor.directive'] },
178+
{ fragment: '(', scopes: [BASE_SCOPE, 'keyword.control.characters'] },
179+
{ fragment: 'advanced', scopes: [BASE_SCOPE, 'constant.language.contentblocker.name'] },
180+
{ fragment: ')', scopes: [BASE_SCOPE, 'keyword.control.characters'] },
181+
],
182+
},
183+
{
184+
actual: '!#safari_cb_affinity(privacy,advanced)',
185+
expected: [
186+
{ fragment: '!#safari_cb_affinity', scopes: [BASE_SCOPE, 'keyword.preprocessor.directive'] },
187+
{ fragment: '(', scopes: [BASE_SCOPE, 'keyword.control.characters'] },
188+
{ fragment: 'privacy', scopes: [BASE_SCOPE, 'constant.language.contentblocker.name'] },
189+
{ fragment: ',', scopes: [BASE_SCOPE, 'keyword.control.characters'] },
190+
{ fragment: 'advanced', scopes: [BASE_SCOPE, 'constant.language.contentblocker.name'] },
191+
{ fragment: ')', scopes: [BASE_SCOPE, 'keyword.control.characters'] },
192+
],
193+
},
194+
])("valid: '$actual'", ({ actual, expected }) => {
195+
expectTokens(tokenize, actual, expected);
196+
});
197+
198+
test.each([
199+
{
200+
actual: '!#safari_cb_affinity all',
201+
expected: [
202+
{ fragment: '!#safari_cb_affinity', scopes: [BASE_SCOPE, 'keyword.preprocessor.directive'] },
203+
{ fragment: ' all', scopes: [BASE_SCOPE, 'invalid.illegal'] },
204+
],
205+
},
206+
{
207+
actual: '!#safari_cb_affinity (all)',
208+
expected: [
209+
{ fragment: '!#safari_cb_affinity', scopes: [BASE_SCOPE, 'keyword.preprocessor.directive'] },
210+
{ fragment: ' (all)', scopes: [BASE_SCOPE, 'invalid.illegal'] },
211+
],
212+
},
213+
{
214+
actual: '!#safari_cb_affinity(social, other)',
215+
expected: [
216+
{ fragment: '!#safari_cb_affinity', scopes: [BASE_SCOPE, 'keyword.preprocessor.directive'] },
217+
{ fragment: '(', scopes: [BASE_SCOPE, 'keyword.control.characters'] },
218+
{ fragment: 'social', scopes: [BASE_SCOPE, 'constant.language.contentblocker.name'] },
219+
{ fragment: ',', scopes: [BASE_SCOPE, 'keyword.control.characters'] },
220+
{ fragment: ' other)', scopes: [BASE_SCOPE, 'invalid.illegal'] },
221+
],
222+
},
223+
])("invalid case '$actual'", ({ actual, expected }) => {
224+
expectTokens(tokenize, actual, expected);
225+
});
226+
});
227+
228+
// TODO: add tests for !#include and for other unknown preprocessor directives
144229
});

test/grammar/common/token-expectation.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ export function expectTokens(tokenize: AdblockTokenizer, source: string, expecte
3737
const mergedFragments = expectedTokens.map((token) => token.fragment).join('');
3838

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

4343
// Tokenize the source

0 commit comments

Comments
 (0)