@markuplint/types 3.5.1 → 3.6.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,146 @@
1
+ const { Token } = require('../../lib/token/token');
2
+ const { TokenCollection } = require('../../lib/token/token-collection');
3
+
4
+ test('parse', () => {
5
+ expect(new TokenCollection(' a b c ').toJSON()).toStrictEqual([
6
+ {
7
+ offset: 0,
8
+ type: 13,
9
+ value: ' ',
10
+ },
11
+ {
12
+ offset: 1,
13
+ type: 1,
14
+ value: 'a',
15
+ },
16
+ {
17
+ offset: 2,
18
+ type: 13,
19
+ value: ' ',
20
+ },
21
+ {
22
+ offset: 4,
23
+ type: 1,
24
+ value: 'b',
25
+ },
26
+ {
27
+ offset: 5,
28
+ type: 13,
29
+ value: ' ',
30
+ },
31
+ {
32
+ offset: 8,
33
+ type: 1,
34
+ value: 'c',
35
+ },
36
+ {
37
+ offset: 9,
38
+ type: 13,
39
+ value: ' ',
40
+ },
41
+ ]);
42
+ });
43
+
44
+ test('parse comma separator', () => {
45
+ expect(new TokenCollection('a,, ,b,cde', { separator: 'comma' }).toJSON()).toStrictEqual([
46
+ {
47
+ offset: 0,
48
+ type: 1,
49
+ value: 'a',
50
+ },
51
+ {
52
+ offset: 1,
53
+ type: 18,
54
+ value: ',',
55
+ },
56
+ {
57
+ offset: 2,
58
+ type: 18,
59
+ value: ',',
60
+ },
61
+ {
62
+ offset: 3,
63
+ type: 13,
64
+ value: ' ',
65
+ },
66
+ {
67
+ offset: 4,
68
+ type: 18,
69
+ value: ',',
70
+ },
71
+ {
72
+ offset: 5,
73
+ type: 1,
74
+ value: 'b',
75
+ },
76
+ {
77
+ offset: 6,
78
+ type: 18,
79
+ value: ',',
80
+ },
81
+ {
82
+ offset: 7,
83
+ type: 1,
84
+ value: 'cde',
85
+ },
86
+ ]);
87
+ });
88
+
89
+ test('A comma is an ident if the comma is not a separator', () => {
90
+ expect(new TokenCollection('a ,cde , f').toJSON()).toStrictEqual([
91
+ {
92
+ offset: 0,
93
+ type: 1,
94
+ value: 'a',
95
+ },
96
+ {
97
+ offset: 1,
98
+ type: 13,
99
+ value: ' ',
100
+ },
101
+ {
102
+ offset: 2,
103
+ type: 1,
104
+ value: ',cde',
105
+ },
106
+ {
107
+ offset: 6,
108
+ type: 13,
109
+ value: ' ',
110
+ },
111
+ {
112
+ offset: 7,
113
+ type: 1,
114
+ value: ',',
115
+ },
116
+ {
117
+ offset: 8,
118
+ type: 13,
119
+ value: ' ',
120
+ },
121
+ {
122
+ offset: 9,
123
+ type: 1,
124
+ value: 'f',
125
+ },
126
+ ]);
127
+ });
128
+
129
+ test('getConsecutiveToken', () => {
130
+ expect(new TokenCollection('a,b,c', { separator: 'comma' }).getConsecutiveToken(Token.Comma)).toBeFalsy();
131
+ expect(new TokenCollection('a,,b', { separator: 'comma' }).getConsecutiveToken(Token.Comma)).toBeTruthy();
132
+ expect(new TokenCollection('a,,b', { separator: 'comma' }).getConsecutiveToken(Token.Comma)?.offset).toBe(2);
133
+ });
134
+
135
+ test('fromPatterns', () => {
136
+ const patterns = [/\+|-/, /[0-9]{2}/, /:?/, /[0-9]{2}/];
137
+ expect(TokenCollection.fromPatterns('+00:00', patterns).map(t => t.value)).toStrictEqual(['+', '00', ':', '00']);
138
+ expect(TokenCollection.fromPatterns('+0000', patterns).map(t => t.value)).toStrictEqual(['+', '00', '', '00']);
139
+ expect(TokenCollection.fromPatterns('+00/00', patterns).map(t => t.value)).toStrictEqual([
140
+ '+',
141
+ '00',
142
+ '',
143
+ '',
144
+ '/00',
145
+ ]);
146
+ });
@@ -0,0 +1,36 @@
1
+ const { checkSerializedPermissionsPolicy } = require('../../lib/w3c/check-serialized-permissions-policy');
2
+
3
+ const check = checkSerializedPermissionsPolicy();
4
+
5
+ test('checkSerializedPermissionsPolicy', () => {
6
+ expect(check('').reason).toBe('empty-token');
7
+ expect(check(' ').reason).toBe('unexpected-token');
8
+ // expect(check('a').reason).toBe('missing-token');
9
+ expect(check('a').matched).toBe(true); // Current supported
10
+ expect(check('a:').reason).toBe('unexpected-token');
11
+ // expect(check('a ').reason).toBe('missing-token'); // Current supported
12
+ expect(check('a ').matched).toBe(true);
13
+ expect(check('a a').reason).toBe('unexpected-token');
14
+ expect(check('a *').matched).toBe(true);
15
+ expect(check('a *a').reason).toBe('unexpected-token');
16
+ expect(check('a none').reason).toBe('missing-token');
17
+ expect(check("a 'none'").matched).toBe(true);
18
+ expect(check('a https://markuplint.dev').matched).toBe(true);
19
+ expect(check('a https://markuplint.dev/path/to').reason).toBe('extra-token');
20
+ expect(check('a https://マルチバイト.abc.xyz').reason).toBe('must-be-serialized');
21
+ expect(check('a * https://markuplint.dev').matched).toBe(true);
22
+ expect(check("a * https://markuplint.dev 'none'").matched).toBe(true);
23
+ // expect(check("a * https://markuplint.dev 'none';b").reason).toBe('missing-token');
24
+ expect(check("a * https://markuplint.dev 'none';b").matched).toBe(true); // Current supported
25
+ // expect(check("a * https://markuplint.dev 'none';b ").reason).toBe('missing-token');
26
+ expect(check("a * https://markuplint.dev 'none';b ").matched).toBe(true); // Current supported
27
+ expect(check("a * https://markuplint.dev 'none';b *").matched).toBe(true);
28
+ expect(check("a * https://markuplint.dev 'none';b *;c 'none'").matched).toBe(true);
29
+ expect(check("a * https://markuplint.dev 'none'; b *; c 'none'").matched).toBe(true);
30
+ });
31
+
32
+ test('YouTube embed', () => {
33
+ expect(
34
+ check('accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture').matched,
35
+ ).toBe(true);
36
+ });
@@ -0,0 +1,387 @@
1
+ const { checkAutoComplete } = require('../../lib/whatwg/check-autocomplete');
2
+
3
+ const check = checkAutoComplete();
4
+
5
+ test('basic', () => {
6
+ expect(check('on').matched).toBe(true);
7
+ expect(check('on webauthn').matched).toBe(false);
8
+ expect(check('off').matched).toBe(true);
9
+ expect(check('off webauthn').matched).toBe(false);
10
+ expect(check('name').matched).toBe(true);
11
+ expect(check('given-name').matched).toBe(true);
12
+ expect(check('given-name webauthn').matched).toBe(true);
13
+ expect(check('given-name webauthun').matched).toBe(false);
14
+ expect(check('section-').matched).toBe(true);
15
+ expect(check('section-foo').matched).toBe(true);
16
+ expect(check('section-foo webauthn').matched).toBe(true);
17
+ expect(check('section-foo name').matched).toBe(true);
18
+ expect(check('section-foo name webauthn').matched).toBe(true);
19
+ expect(check('section-foo shipping name').matched).toBe(true);
20
+ expect(check('section-foo billing name').matched).toBe(true);
21
+ expect(check('section-foo billing home').matched).toBe(true);
22
+ expect(check('section-foo billing work').matched).toBe(true);
23
+ expect(check('section-foo billing home tel').matched).toBe(true);
24
+ expect(check('section-foo billing work email').matched).toBe(true);
25
+ expect(check('section-foo billing work email webauthn').matched).toBe(true);
26
+ expect(check('shipping name').matched).toBe(true);
27
+ expect(check('billing name').matched).toBe(true);
28
+ expect(check('billing home').matched).toBe(true);
29
+ expect(check('billing work').matched).toBe(true);
30
+ expect(check('billing home tel').matched).toBe(true);
31
+ expect(check('billing work email').matched).toBe(true);
32
+ expect(check('billing work email webauthn').matched).toBe(true);
33
+ expect(check('home tel').matched).toBe(true);
34
+ expect(check('work email').matched).toBe(true);
35
+ expect(check('work email webauthn').matched).toBe(true);
36
+ });
37
+
38
+ test('unexpected-token', () => {
39
+ expect(check('section-foo , name')).toStrictEqual({
40
+ matched: false,
41
+ raw: ',',
42
+ offset: 12,
43
+ length: 1,
44
+ line: 1,
45
+ column: 13,
46
+ reason: 'unexpected-token',
47
+ expects: [
48
+ { type: 'const', value: 'billing' },
49
+ { type: 'const', value: 'shipping' },
50
+ { type: 'common', value: 'autofill field name' },
51
+ ],
52
+ candidate: undefined,
53
+ ref: 'https://html.spec.whatwg.org/multipage/form-control-infrastructure.html#autofill-field',
54
+ });
55
+ });
56
+
57
+ test('unexpected-token', () => {
58
+ expect(check('xxx')).toStrictEqual({
59
+ matched: false,
60
+ raw: 'xxx',
61
+ offset: 0,
62
+ length: 3,
63
+ line: 1,
64
+ column: 1,
65
+ reason: 'unexpected-token',
66
+ expects: [
67
+ { type: 'common', value: 'autofill named group' },
68
+ { type: 'common', value: 'autofill field name' },
69
+ ],
70
+ candidate: undefined,
71
+ ref: 'https://html.spec.whatwg.org/multipage/form-control-infrastructure.html#autofill-field',
72
+ });
73
+ });
74
+
75
+ test('unexpected-token', () => {
76
+ expect(check('section-foo neme')).toStrictEqual({
77
+ matched: false,
78
+ raw: 'neme',
79
+ offset: 12,
80
+ length: 4,
81
+ line: 1,
82
+ column: 13,
83
+ reason: 'unexpected-token',
84
+ expects: [
85
+ { type: 'const', value: 'billing' },
86
+ { type: 'const', value: 'shipping' },
87
+ { type: 'common', value: 'autofill field name' },
88
+ ],
89
+ candidate: 'name',
90
+ ref: 'https://html.spec.whatwg.org/multipage/form-control-infrastructure.html#autofill-field',
91
+ });
92
+ expect(check('section-foo shipping neme')).toStrictEqual({
93
+ matched: false,
94
+ raw: 'neme',
95
+ offset: 21,
96
+ length: 4,
97
+ line: 1,
98
+ column: 22,
99
+ reason: 'unexpected-token',
100
+ expects: [
101
+ { type: 'common', value: 'autofill field name' },
102
+ { type: 'const', value: 'home' },
103
+ { type: 'const', value: 'work' },
104
+ { type: 'const', value: 'mobile' },
105
+ { type: 'const', value: 'fax' },
106
+ { type: 'const', value: 'pager' },
107
+ ],
108
+ candidate: 'name',
109
+ ref: 'https://html.spec.whatwg.org/multipage/form-control-infrastructure.html#autofill-field',
110
+ });
111
+ expect(check('section-foo shipping home name')).toStrictEqual({
112
+ matched: false,
113
+ raw: 'name',
114
+ offset: 26,
115
+ length: 4,
116
+ line: 1,
117
+ column: 27,
118
+ reason: 'unexpected-token',
119
+ expects: [
120
+ { type: 'const', value: 'tel' },
121
+ { type: 'const', value: 'tel-country-code' },
122
+ { type: 'const', value: 'tel-national' },
123
+ { type: 'const', value: 'tel-area-code' },
124
+ { type: 'const', value: 'tel-local' },
125
+ { type: 'const', value: 'tel-local-prefix' },
126
+ { type: 'const', value: 'tel-local-suffix' },
127
+ { type: 'const', value: 'tel-extension' },
128
+ { type: 'const', value: 'email' },
129
+ { type: 'const', value: 'impp' },
130
+ ],
131
+ candidate: undefined,
132
+ ref: 'https://html.spec.whatwg.org/multipage/form-control-infrastructure.html#autofilling-form-controls:-the-autocomplete-attribute:attr-fe-autocomplete-tel',
133
+ });
134
+ expect(check('section-foo shipping home emall')).toStrictEqual({
135
+ matched: false,
136
+ raw: 'emall',
137
+ offset: 26,
138
+ length: 5,
139
+ line: 1,
140
+ column: 27,
141
+ reason: 'unexpected-token',
142
+ expects: [
143
+ { type: 'const', value: 'tel' },
144
+ { type: 'const', value: 'tel-country-code' },
145
+ { type: 'const', value: 'tel-national' },
146
+ { type: 'const', value: 'tel-area-code' },
147
+ { type: 'const', value: 'tel-local' },
148
+ { type: 'const', value: 'tel-local-prefix' },
149
+ { type: 'const', value: 'tel-local-suffix' },
150
+ { type: 'const', value: 'tel-extension' },
151
+ { type: 'const', value: 'email' },
152
+ { type: 'const', value: 'impp' },
153
+ ],
154
+ candidate: 'email',
155
+ ref: 'https://html.spec.whatwg.org/multipage/form-control-infrastructure.html#autofilling-form-controls:-the-autocomplete-attribute:attr-fe-autocomplete-tel',
156
+ });
157
+ });
158
+
159
+ test('duplicated', () => {
160
+ expect(check('name name')).toStrictEqual({
161
+ matched: false,
162
+ raw: 'name',
163
+ offset: 5,
164
+ length: 4,
165
+ line: 1,
166
+ column: 6,
167
+ partName: 'the content of the list',
168
+ reason: 'duplicated',
169
+ expects: [{ type: 'format', value: 'autocomplete' }],
170
+ ref: 'https://html.spec.whatwg.org/multipage/form-control-infrastructure.html#attr-fe-autocomplete',
171
+ });
172
+ expect(check('on on')).toStrictEqual({
173
+ matched: false,
174
+ raw: 'on',
175
+ offset: 3,
176
+ length: 2,
177
+ line: 1,
178
+ column: 4,
179
+ partName: 'the content of the list',
180
+ reason: 'duplicated',
181
+ expects: [{ type: 'format', value: 'autocomplete' }],
182
+ ref: 'https://html.spec.whatwg.org/multipage/form-control-infrastructure.html#attr-fe-autocomplete',
183
+ });
184
+ });
185
+
186
+ test('extra-token', () => {
187
+ expect(check('on off')).toStrictEqual({
188
+ matched: false,
189
+ raw: 'off',
190
+ offset: 3,
191
+ length: 3,
192
+ line: 1,
193
+ column: 4,
194
+ reason: 'extra-token',
195
+ expects: [{ type: 'format', value: 'autocomplete' }],
196
+ ref: 'https://html.spec.whatwg.org/multipage/form-control-infrastructure.html#autofilling-form-controls:-the-autocomplete-attribute:attr-fe-autocomplete-on-2',
197
+ });
198
+ expect(check('off on')).toStrictEqual({
199
+ matched: false,
200
+ raw: 'on',
201
+ offset: 4,
202
+ length: 2,
203
+ line: 1,
204
+ column: 5,
205
+ reason: 'extra-token',
206
+ expects: [{ type: 'format', value: 'autocomplete' }],
207
+ ref: 'https://html.spec.whatwg.org/multipage/form-control-infrastructure.html#autofilling-form-controls:-the-autocomplete-attribute:attr-fe-autocomplete-on-2',
208
+ });
209
+ expect(check('on name')).toStrictEqual({
210
+ matched: false,
211
+ raw: 'name',
212
+ offset: 3,
213
+ length: 4,
214
+ line: 1,
215
+ column: 4,
216
+ reason: 'extra-token',
217
+ expects: [{ type: 'format', value: 'autocomplete' }],
218
+ ref: 'https://html.spec.whatwg.org/multipage/form-control-infrastructure.html#autofilling-form-controls:-the-autocomplete-attribute:attr-fe-autocomplete-on-2',
219
+ });
220
+ expect(check('name on')).toStrictEqual({
221
+ matched: false,
222
+ raw: 'on',
223
+ offset: 5,
224
+ length: 2,
225
+ line: 1,
226
+ column: 6,
227
+ reason: 'extra-token',
228
+ expects: [{ type: 'format', value: 'autocomplete' }],
229
+ ref: 'https://html.spec.whatwg.org/multipage/form-control-infrastructure.html#autofill-field',
230
+ });
231
+ expect(check('section-foo name on')).toStrictEqual({
232
+ matched: false,
233
+ raw: 'on',
234
+ offset: 17,
235
+ length: 2,
236
+ line: 1,
237
+ column: 18,
238
+ reason: 'extra-token',
239
+ expects: [{ type: 'format', value: 'autocomplete' }],
240
+ ref: 'https://html.spec.whatwg.org/multipage/form-control-infrastructure.html#autofill-field',
241
+ });
242
+ expect(check('section-foo billing name on')).toStrictEqual({
243
+ matched: false,
244
+ raw: 'on',
245
+ offset: 25,
246
+ length: 2,
247
+ line: 1,
248
+ column: 26,
249
+ reason: 'extra-token',
250
+ expects: [{ type: 'format', value: 'autocomplete' }],
251
+ ref: 'https://html.spec.whatwg.org/multipage/form-control-infrastructure.html#autofill-field',
252
+ });
253
+ expect(check('billing name on')).toStrictEqual({
254
+ matched: false,
255
+ raw: 'on',
256
+ offset: 13,
257
+ length: 2,
258
+ line: 1,
259
+ column: 14,
260
+ reason: 'extra-token',
261
+ expects: [{ type: 'format', value: 'autocomplete' }],
262
+ ref: 'https://html.spec.whatwg.org/multipage/form-control-infrastructure.html#autofill-field',
263
+ });
264
+ expect(check('tel on')).toStrictEqual({
265
+ matched: false,
266
+ raw: 'on',
267
+ offset: 4,
268
+ length: 2,
269
+ line: 1,
270
+ column: 5,
271
+ reason: 'extra-token',
272
+ expects: [{ type: 'format', value: 'autocomplete' }],
273
+ ref: 'https://html.spec.whatwg.org/multipage/form-control-infrastructure.html#autofill-field',
274
+ });
275
+ expect(check('home tel on')).toStrictEqual({
276
+ matched: false,
277
+ raw: 'on',
278
+ offset: 9,
279
+ length: 2,
280
+ line: 1,
281
+ column: 10,
282
+ reason: 'extra-token',
283
+ expects: [{ type: 'format', value: 'autocomplete' }],
284
+ ref: 'https://html.spec.whatwg.org/multipage/form-control-infrastructure.html#autofill-field',
285
+ });
286
+ expect(check('billing home tel on')).toStrictEqual({
287
+ matched: false,
288
+ raw: 'on',
289
+ offset: 17,
290
+ length: 2,
291
+ line: 1,
292
+ column: 18,
293
+ reason: 'extra-token',
294
+ expects: [{ type: 'format', value: 'autocomplete' }],
295
+ ref: 'https://html.spec.whatwg.org/multipage/form-control-infrastructure.html#autofill-field',
296
+ });
297
+ expect(check('billing home tel on')).toStrictEqual({
298
+ matched: false,
299
+ raw: 'on',
300
+ offset: 17,
301
+ length: 2,
302
+ line: 1,
303
+ column: 18,
304
+ reason: 'extra-token',
305
+ expects: [{ type: 'format', value: 'autocomplete' }],
306
+ ref: 'https://html.spec.whatwg.org/multipage/form-control-infrastructure.html#autofill-field',
307
+ });
308
+ expect(check('section-foo billing home tel on')).toStrictEqual({
309
+ matched: false,
310
+ raw: 'on',
311
+ offset: 29,
312
+ length: 2,
313
+ line: 1,
314
+ column: 30,
315
+ reason: 'extra-token',
316
+ expects: [{ type: 'format', value: 'autocomplete' }],
317
+ ref: 'https://html.spec.whatwg.org/multipage/form-control-infrastructure.html#autofill-field',
318
+ });
319
+ expect(check('section-foo home tel on')).toStrictEqual({
320
+ matched: false,
321
+ raw: 'on',
322
+ offset: 21,
323
+ length: 2,
324
+ line: 1,
325
+ column: 22,
326
+ reason: 'extra-token',
327
+ expects: [{ type: 'format', value: 'autocomplete' }],
328
+ ref: 'https://html.spec.whatwg.org/multipage/form-control-infrastructure.html#autofill-field',
329
+ });
330
+ expect(check('section-foo tel on')).toStrictEqual({
331
+ matched: false,
332
+ raw: 'on',
333
+ offset: 16,
334
+ length: 2,
335
+ line: 1,
336
+ column: 17,
337
+ reason: 'extra-token',
338
+ expects: [{ type: 'format', value: 'autocomplete' }],
339
+ ref: 'https://html.spec.whatwg.org/multipage/form-control-infrastructure.html#autofill-field',
340
+ });
341
+ });
342
+
343
+ test('duplicated section', () => {
344
+ expect(check('section-foo section-bar')).toStrictEqual({
345
+ matched: false,
346
+ raw: 'section-bar',
347
+ offset: 12,
348
+ length: 11,
349
+ line: 1,
350
+ column: 13,
351
+ partName: 'autofill named group',
352
+ reason: 'duplicated',
353
+ ref: 'https://html.spec.whatwg.org/multipage/form-control-infrastructure.html#attr-fe-autocomplete-section',
354
+ });
355
+ });
356
+
357
+ test('duplicated part', () => {
358
+ expect(check('shipping billing')).toStrictEqual({
359
+ matched: false,
360
+ raw: 'billing',
361
+ offset: 9,
362
+ length: 7,
363
+ line: 1,
364
+ column: 10,
365
+ reason: 'duplicated',
366
+ expects: [{ type: 'format', value: 'autocomplete' }],
367
+ ref: 'https://html.spec.whatwg.org/multipage/form-control-infrastructure.html#attr-fe-autocomplete-shipping',
368
+ });
369
+ });
370
+
371
+ test('typo', () => {
372
+ expect(check('secsion-foo name')).toStrictEqual({
373
+ matched: false,
374
+ raw: 'secsion-foo',
375
+ offset: 0,
376
+ length: 11,
377
+ line: 1,
378
+ column: 1,
379
+ reason: 'unexpected-token',
380
+ expects: [
381
+ { type: 'common', value: 'autofill named group' },
382
+ { type: 'common', value: 'autofill field name' },
383
+ ],
384
+ candidate: 'section-foo',
385
+ ref: 'https://html.spec.whatwg.org/multipage/form-control-infrastructure.html#autofill-field',
386
+ });
387
+ });