forked from peterbe/minimalcss
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathutils.test.js
More file actions
61 lines (57 loc) · 1.96 KB
/
utils.test.js
File metadata and controls
61 lines (57 loc) · 1.96 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
const utils = require('../src/utils');
test('Test unquoteString', async () => {
const f = utils.unquoteString;
expect(f('"peter"')).toEqual('peter');
expect(f(`'peter'`)).toEqual('peter');
// but leave it if it isn't balanced
expect(f('"peter')).toEqual('"peter');
// empty strings
expect(f('')).toEqual('');
});
test('Test reduceCSSSelector', async () => {
const f = utils.reduceCSSSelector;
// Most basic case.
expect(f('a:hover')).toEqual('a');
// More advanced case.
expect(f('a[href^="javascript:"]:after')).toEqual('a[href^="javascript:"]');
// Should work with ' instead of " too.
expect(f("a[href^='javascript:']:after")).toEqual("a[href^='javascript:']");
});
test('Test removeSequentialSemis', () => {
const f = utils.removeSequentialSemis;
// empty string
expect(f('')).toEqual('');
// more than two semicolons
expect(f(';;;')).toEqual(';');
// whitespace between semicolons
expect(f(';\r\n\t;')).toEqual(';');
// multiple semicolon sequences
expect(f('a;b;;c;;;d;;;;')).toEqual('a;b;c;d;');
});
test('Test parentSelectors', async () => {
const f = utils.getParentSelectors;
// Simplest possible
expect(f('.foo .bar')).toEqual(['.foo']);
// Slightly less simple
expect(f('.foo .bar .baz')).toEqual(['.foo', '.foo .bar']);
// Empty array
expect(f('.foo')).toEqual([]);
// Less trivial
expect(f('.ui.dropdown>.dropdown.icon:before')).toEqual(['.ui.dropdown']);
expect(f('.ui.vertical.menu .dropdown.item>.dropdown.icon:before')).toEqual([
'.ui.vertical.menu',
'.ui.vertical.menu .dropdown.item'
]);
expect(
f(
'.ui.search.selection>.icon.input:not([class*="left icon"])>.icon~.remove.icon'
)
).toEqual([
'.ui.search.selection',
'.ui.search.selection>.icon.input:not([class*="left icon"])',
'.ui.search.selection>.icon.input:not([class*="left icon"])>.icon'
]);
expect(f('.ui[class*="right aligned"].search>.results')).toEqual([
'.ui[class*="right aligned"].search'
]);
});