Skip to content

Commit c2d56fd

Browse files
refactor: remove unnecessary stuff
1 parent 190f9bc commit c2d56fd

File tree

3 files changed

+156
-97
lines changed

3 files changed

+156
-97
lines changed

Diff for: src/__tests__/attributes.js

+60-9
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,11 @@ test('select elements with or without a namespace', '[*|href]', (t, tree) => {
5151
t.deepEqual(tree.nodes[0].nodes[0].attribute, 'href');
5252
});
5353

54+
test('select elements with or without a namespace (3)', '[ |href ]', (t, tree) => {
55+
t.deepEqual(tree.nodes[0].nodes[0].namespace, true);
56+
t.deepEqual(tree.nodes[0].nodes[0].attribute, 'href');
57+
});
58+
5459
test('namespace with escapes', '[\\31 \\#\\32 |href]', (t, tree) => {
5560
let attr = tree.nodes[0].nodes[0];
5661
t.deepEqual(attr.namespace, '1#2');
@@ -99,6 +104,30 @@ test('attribute selector with escaped quote', '[title="Something \\"weird\\""]',
99104
t.deepEqual(tree.toString(), '[title="Something \\"weird\\""]');
100105
});
101106

107+
test('attribute selector with escaped quote with comments', '[/*t*/title/*t*/=/*t*/"Something \\"weird\\""/*t*/]', (t, tree) => {
108+
let attr = tree.nodes[0].nodes[0];
109+
t.deepEqual(attr.value, 'Something "weird"');
110+
t.deepEqual(attr.getQuotedValue(), '\"Something \\"weird\\"\"');
111+
t.deepEqual(attr.getQuotedValue({smart: true}), '\'Something "weird"\'');
112+
t.deepEqual(attr.getQuotedValue({quoteMark: null}), 'Something\\ \\"weird\\"');
113+
t.deepEqual(attr.quoteMark, '"');
114+
t.truthy(attr.quoted);
115+
t.deepEqual(attr.raws.value, '"Something \\"weird\\""/*t*/');
116+
t.deepEqual(tree.toString(), '[/*t*/title/*t*/=/*t*/"Something \\"weird\\""/*t*/]');
117+
});
118+
119+
test('attribute selector with escaped quote with comments (2)', '[ /*t*/ title /*t*/ = /*t*/ "Something \\"weird\\"" /*t*/ ]', (t, tree) => {
120+
let attr = tree.nodes[0].nodes[0];
121+
t.deepEqual(attr.value, 'Something "weird"');
122+
t.deepEqual(attr.getQuotedValue(), '\"Something \\"weird\\"\"');
123+
t.deepEqual(attr.getQuotedValue({smart: true}), '\'Something "weird"\'');
124+
t.deepEqual(attr.getQuotedValue({quoteMark: null}), 'Something\\ \\"weird\\"');
125+
t.deepEqual(attr.quoteMark, '"');
126+
t.truthy(attr.quoted);
127+
t.deepEqual(attr.raws.value, '"Something \\"weird\\""');
128+
t.deepEqual(tree.toString(), '[ /*t*/ title /*t*/ = /*t*/ "Something \\"weird\\"" /*t*/ ]');
129+
});
130+
102131
test('attribute selector with escaped colon', '[ng\\:cloak]', (t, tree) => {
103132
t.deepEqual(tree.toString(), '[ng\\:cloak]');
104133
let attr = tree.nodes[0].nodes[0];
@@ -328,36 +357,58 @@ test('spaces in attribute selectors', 'h1[ href *= "test" ]', (t, tree) => {
328357
t.truthy(tree.nodes[0].nodes[1].quoted);
329358
});
330359

331-
test('insensitive attribute selector 1', '[href="test" i]', (t, tree) => {
360+
test('insensitive attribute selector', '[href=test i]', (t, tree) => {
332361
t.deepEqual(tree.nodes[0].nodes[0].value, 'test');
333362
t.deepEqual(tree.nodes[0].nodes[0].insensitive, true);
334-
t.deepEqual(tree.nodes[0].nodes[0].insensitive, true);
335363
});
336364

337-
test('insensitive attribute selector with a empty value', '[href="" i]', (t, tree) => {
338-
t.deepEqual(tree.nodes[0].nodes[0].attribute, 'href');
339-
t.deepEqual(tree.nodes[0].nodes[0].operator, '=');
340-
t.deepEqual(tree.nodes[0].nodes[0].value, '');
365+
test('insensitive attribute selector 2', '[href="test" i]', (t, tree) => {
366+
t.deepEqual(tree.nodes[0].nodes[0].value, 'test');
341367
t.deepEqual(tree.nodes[0].nodes[0].insensitive, true);
342-
t.true(tree.nodes[0].nodes[0].quoted);
343368
});
344369

345-
test('insensitive attribute selector 2', '[href=TEsT i ]', (t, tree) => {
370+
test('insensitive attribute selector 3', '[href=TEsT i ]', (t, tree) => {
346371
t.deepEqual(tree.nodes[0].nodes[0].value, 'TEsT');
347372
t.deepEqual(tree.nodes[0].nodes[0].insensitive, true);
348373
t.deepEqual(tree.nodes[0].nodes[0].spaces.value.after, ' ');
349374
t.deepEqual(tree.nodes[0].nodes[0].spaces.insensitive.after, ' ');
350375
});
351376

352-
test('insensitive attribute selector 3', '[href=test i]', (t, tree) => {
377+
test('insensitive attribute selector 4', '[href=test i]', (t, tree) => {
353378
t.deepEqual(tree.nodes[0].nodes[0].value, 'test');
354379
t.deepEqual(tree.nodes[0].nodes[0].insensitive, true);
355380
});
381+
382+
test('insensitive attribute selector 5', '[href="" i]', (t, tree) => {
383+
t.deepEqual(tree.nodes[0].nodes[0].value, '');
384+
t.deepEqual(tree.nodes[0].nodes[0].insensitive, true);
385+
});
386+
387+
test('sensitive attribute selector', '[href=test s]', (t, tree) => {
388+
t.deepEqual(tree.nodes[0].nodes[0].value, 'test');
389+
t.deepEqual(tree.nodes[0].nodes[0].insensitive, false);
390+
t.deepEqual(tree.nodes[0].nodes[0].raws.insensitiveFlag, 's');
391+
});
392+
393+
test('multiple flags attribute selector', '[href=test qwer]', (t, tree) => {
394+
t.deepEqual(tree.nodes[0].nodes[0].value, 'test');
395+
t.deepEqual(tree.nodes[0].nodes[0].insensitive, false);
396+
t.deepEqual(tree.nodes[0].nodes[0].raws.insensitiveFlag, 'qwer');
397+
});
398+
356399
test('capitalized insensitive attribute selector 3', '[href=test I]', (t, tree) => {
357400
t.deepEqual(tree.nodes[0].nodes[0].value, 'test');
358401
t.deepEqual(tree.nodes[0].nodes[0].insensitive, true);
359402
});
360403

404+
test('insensitive attribute selector with a empty value', '[href="" i]', (t, tree) => {
405+
t.deepEqual(tree.nodes[0].nodes[0].attribute, 'href');
406+
t.deepEqual(tree.nodes[0].nodes[0].operator, '=');
407+
t.deepEqual(tree.nodes[0].nodes[0].value, '');
408+
t.deepEqual(tree.nodes[0].nodes[0].insensitive, true);
409+
t.true(tree.nodes[0].nodes[0].quoted);
410+
});
411+
361412
test('extraneous non-combinating whitespace', ' [href] , [class] ', (t, tree) => {
362413
t.deepEqual(tree.nodes[0].nodes[0].attribute, 'href');
363414
t.deepEqual(tree.nodes[0].nodes[0].spaces.before, ' ');

Diff for: src/__tests__/exceptions.js

+28-15
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,40 @@
11
import {throws} from './util/helpers';
22

33
// Unclosed elements
4-
throws('unclosed string', 'a[href="wow]');
5-
throws('unclosed comment', '/* oops');
6-
throws('unclosed pseudo element', 'button::');
7-
throws('unclosed pseudo class', 'a:');
8-
throws('unclosed attribute selector', '[name="james"][href');
4+
throws('unclosed string', 'a[href="wow]', 'Unclosed quote');
5+
throws('unclosed comment', '/* oops', 'Unclosed comment');
6+
throws('unclosed pseudo element', 'button::', 'Expected a pseudo-class or pseudo-element.');
7+
throws('unclosed pseudo class', 'a:', 'Expected a pseudo-class or pseudo-element.');
8+
throws('unclosed attribute selector', '[name', 'Expected a closing square bracket.');
9+
throws('unclosed attribute selector (2)', '[name=', 'Expected a closing square bracket.');
10+
throws('unclosed attribute selector (3)', '[name="james"', 'Expected a closing square bracket.');
11+
throws('unclosed attribute selector (4)', '[name="james"][href', 'Expected a closing square bracket.');
12+
throws('unclosed attribute selector (5)', '[name="james"][href', 'Expected a closing square bracket.');
913

10-
throws('no opening parenthesis', ')');
11-
throws('no opening parenthesis (2)', ':global.foo)');
12-
throws('no opening parenthesis (3)', 'h1:not(h2:not(h3)))');
14+
throws('invalid attribute selector', '[]', 'Expected an attribute.');
15+
throws('invalid attribute selector (2)', '["hello"]', 'Expected an attribute.');
16+
throws('invalid attribute selector (3)', '[="hello"]', 'Expected an attribute, found "=" instead.');
1317

14-
throws('no opening square bracket', ']');
15-
throws('no opening square bracket (2)', ':global.foo]');
16-
throws('no opening square bracket (3)', '[global]]');
18+
throws('no opening parenthesis', ')', 'Expected an opening parenthesis.');
19+
throws('no opening parenthesis (2)', ':global.foo)', 'Expected an opening parenthesis.');
20+
throws('no opening parenthesis (3)', 'h1:not(h2:not(h3)))', 'Expected an opening parenthesis.');
1721

18-
throws('bad pseudo element', 'button::"after"');
19-
throws('missing closing parenthesis in pseudo', ':not([attr="test"]:not([attr="test"])');
22+
throws('no opening square bracket', ']', 'Expected an opening square bracket.');
23+
throws('no opening square bracket (2)', ':global.foo]', 'Expected an opening square bracket.');
24+
throws('no opening square bracket (3)', '[global]]', 'Expected an opening square bracket.');
2025

21-
throws('bad syntax', '-moz-osx-font-smoothing: grayscale');
22-
throws('bad syntax (2)', '! .body');
26+
throws('bad pseudo element', 'button::"after"', 'Expected a pseudo-class or pseudo-element.');
27+
throws('missing closing parenthesis in pseudo', ':not([attr="test"]:not([attr="test"])', 'Expected a closing parenthesis.');
28+
29+
throws('bad syntax', '-moz-osx-font-smoothing: grayscale', 'Expected a pseudo-class or pseudo-element.');
30+
throws('bad syntax (2)', '! .body', 'Unexpected \'!\'. Escaping special characters with \\ may help.');
2331

2432
throws('missing backslash for semicolon', '.;');
2533
throws('missing backslash for semicolon (2)', '.\;');
2634
throws('unexpected / foo', '-Option\/root', "Unexpected '/'. Escaping special characters with \\ may help.");
2735
throws('bang in selector', '.foo !optional', "Unexpected '!'. Escaping special characters with \\ may help.");
36+
37+
throws('misplaced parenthesis', ':not(', 'Expected a closing parenthesis.');
38+
throws('misplaced parenthesis (2)', ':not)', 'Expected an opening parenthesis.');
39+
throws('misplaced parenthesis (3)', ':not((', 'Expected a closing parenthesis.');
40+
throws('misplaced parenthesis (4)', ':not))', 'Expected an opening parenthesis.');

0 commit comments

Comments
 (0)