forked from darkreader/darkreader
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtext.tests.ts
More file actions
112 lines (101 loc) · 3.63 KB
/
Copy pathtext.tests.ts
File metadata and controls
112 lines (101 loc) · 3.63 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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
import {formatCSS, getParenthesesRange} from '../../src/utils/text';
test('CSS formatting', () => {
expect(formatCSS('div { color: red; }'))
.toEqual([
'div {',
' color: red;',
'}',
].join('\n'));
expect(formatCSS('div { color: red; } .list-item { background: rgb(0, 0, 0); color: white; }'))
.toEqual([
'div {',
' color: red;',
'}',
'.list-item {',
' background: rgb(0, 0, 0);',
' color: white;',
'}',
].join('\n'));
expect(formatCSS('@media screen { div { color: red; } span { color: red; } } @media all { p { color: green; } }'))
.toEqual([
'@media screen {',
' div {',
' color: red;',
' }',
' span {',
' color: red;',
' }',
'}',
'@media all {',
' p {',
' color: green;',
' }',
'}',
].join('\n'));
expect(formatCSS('div, span { background: green; color: red; }'))
.toEqual([
'div,',
'span {',
' background: green;',
' color: red;',
'}',
].join('\n'));
expect(formatCSS('@media print, screen and (min-width: 20rem) { div, span { background: green; color: red; } }'))
.toEqual([
'@media print,',
'screen and (min-width: 20rem) {',
' div,',
' span {',
' background: green;',
' color: red;',
' }',
'}',
].join('\n'));
expect(formatCSS('.icon { background-image: url(data:image/gif;base64,XYZ); }'))
.toEqual([
'.icon {',
' background-image: url(data:image/gif;base64,XYZ);',
'}',
].join('\n'));
expect(formatCSS('img[src*="a,b;c"] { filter: invert(1); }'))
.toEqual([
'img[src*="a,b;c"] {',
' filter: invert(1);',
'}',
].join('\n'));
expect(formatCSS('img[src*="a,b;c"] {\n filter: invert(1); \n}'))
.toEqual([
'img[src*="a,b;c"] {',
' filter: invert(1);',
'}',
].join('\n'));
expect(formatCSS('div { } span { color: red; } button { }'))
.toEqual([
'span {',
' color: red;',
'}',
].join('\n'));
expect(formatCSS('@media all { div { } span { color: red; } } @media all { div { } } @media all { button { color: green; } }'))
.toEqual([
'@media all {',
' span {',
' color: red;',
' }',
'}',
'@media all {',
' button {',
' color: green;',
' }',
'}',
].join('\n'));
});
test('Parenthesis Range', () => {
expect(getParenthesesRange('missing')).toBe(null);
expect(getParenthesesRange('()')).toEqual({start: 0, end: 2});
expect(getParenthesesRange('rgb(0, 0, 0)')).toEqual({start: 3, end: 12});
expect(getParenthesesRange('rgb(0, 0, 0), rgb(0, 0, 0)')).toEqual({start: 3, end: 12});
expect(getParenthesesRange('rgb(0, 0, 0), rgb(0, 0, 0)', 12)).toEqual({start: 17, end: 26});
expect(getParenthesesRange('rgb(0, var(--x, var(--y)), 0)')).toEqual({start: 3, end: 29});
expect(getParenthesesRange('rgb(0, var(--x, var(--y)), 0)', 4)).toEqual({start: 10, end: 25});
expect(getParenthesesRange('rgb(0, var(--x, var(--y)), 0), rgb(0, 0, 0)')).toEqual({start: 3, end: 29});
});