-
-
Notifications
You must be signed in to change notification settings - Fork 10
/
test.js
111 lines (97 loc) · 4.88 KB
/
test.js
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
import test from 'ava';
import stripCssComments from './index.js';
test('main', t => {
t.is(stripCssComments('/*//comment*/body{}'), 'body{}');
t.is(stripCssComments('body{/*comment*/}'), 'body{}');
t.is(stripCssComments('body{/*\ncomment\n\\*/}'), 'body{}');
t.is(stripCssComments('body{content: "\'/*ad*/\' \\""}'), 'body{content: "\'/*ad*/\' \\""}');
t.is(stripCssComments('body{\r\n /*\n\n\n\nfoo*/\n}'), 'body{\r\n \n}');
t.is(stripCssComments('body/*foo*/{}'), 'body{}');
t.is(stripCssComments('body{/*"*/}'), 'body{}');
t.is(stripCssComments('body{/*\'*/}'), 'body{}');
t.is(stripCssComments('body{/*"\'\\"*/}'), 'body{}');
t.is(stripCssComments('body{/*"\'"\'*/}'), 'body{}');
t.is(stripCssComments('/*!//comment*/body{}'), '/*!//comment*/body{}');
t.is(stripCssComments('/*!//"comment*/body{/*//comment*/}'), '/*!//"comment*/body{}');
t.is(stripCssComments('/*!//\'comment*/body{/*//comment*/}'), '/*!//\'comment*/body{}');
t.is(stripCssComments('body{/*!comment*/}'), 'body{/*!comment*/}');
t.is(stripCssComments('body{/*!\ncomment\n\\*/}'), 'body{/*!\ncomment\n\\*/}');
t.is(stripCssComments('body{content: "\'/*!ad*/\' \\""}'), 'body{content: "\'/*!ad*/\' \\""}');
t.is(stripCssComments('body{\r\n /*!\n\n\n\nfoo*/\n}'), 'body{\r\n /*!\n\n\n\nfoo*/\n}');
t.is(stripCssComments('body/*!foo*/{}'), 'body/*!foo*/{}');
t.is(stripCssComments('body{/*!"*/}/*foo*/'), 'body{/*!"*/}');
t.is(stripCssComments('body{/*!\'*/}/*foo*/'), 'body{/*!\'*/}');
t.is(stripCssComments('body{/*!"\'\\"*/}'), 'body{/*!"\'\\"*/}');
t.is(stripCssComments('body{/*!"\'"\'*/}'), 'body{/*!"\'"\'*/}');
});
test('`preserve` option', t => {
t.is(stripCssComments('/*!//comment*/body{}', {preserve: false}), 'body{}');
t.is(stripCssComments('/*!//"comment*/body{}', {preserve: false}), 'body{}');
t.is(stripCssComments('/*!//\'comment*/body{}', {preserve: false}), 'body{}');
t.is(stripCssComments('body{/*!comment*/}', {preserve: false}), 'body{}');
t.is(stripCssComments('body{/*!\ncomment\n\\*/}', {preserve: false}), 'body{}');
t.is(stripCssComments('body{content: "\'/*!ad*/\' \\""}', {preserve: false}), 'body{content: "\'/*!ad*/\' \\""}');
t.is(stripCssComments('body{\r\n /*!\n\n\n\nfoo*/\n}', {preserve: false}), 'body{\r\n \n}');
t.is(stripCssComments('body/*!foo*/{}', {preserve: false}), 'body{}');
t.is(stripCssComments('body{/*!"*/}/*foo*/', {preserve: false}), 'body{}');
t.is(stripCssComments('body{/*!\'*/}/*foo*/', {preserve: false}), 'body{}');
t.is(stripCssComments('body{/*!"\'\\"*/}', {preserve: false}), 'body{}');
t.is(stripCssComments('body{/*!"\'"\'*/}', {preserve: false}), 'body{}');
t.is(stripCssComments('body{/*##foo##*/}', {preserve: /^##foo##/}), 'body{/*##foo##*/}');
t.is(stripCssComments('body{/*foo*/}', {preserve: /^##foo##/}), 'body{}');
t.is(stripCssComments('body{/*##foo##*//*foo*/}', {preserve: /^##foo##/}), 'body{/*##foo##*/}');
t.is(stripCssComments('body{/*##foo##*//*!foo*/}', {preserve: /^##foo##/}), 'body{/*##foo##*/}');
t.is(stripCssComments('body{/*!##foo##*//*foo*/}', {preserve: /^##foo##/}), 'body{}');
t.is(stripCssComments('body{/*!##foo*//*foo*/}', {preserve: /foo$/}), 'body{/*!##foo*//*foo*/}');
t.is(
stripCssComments('body{/*##foo##*/}', {
preserve: comment => comment.startsWith('##foo##'),
}), 'body{/*##foo##*/}',
);
t.is(
stripCssComments('body{/*foo*/}', {
preserve: comment => comment.startsWith('##foo##'),
}), 'body{}',
);
t.is(
stripCssComments('body{/*##foo##*//*foo*/}', {
preserve: comment => comment.startsWith('##foo##'),
}), 'body{/*##foo##*/}',
);
t.is(
stripCssComments('body{/*##foo##*//*!foo*/}', {
preserve: comment => comment.startsWith('##foo##'),
}), 'body{/*##foo##*/}',
);
t.is(
stripCssComments('body{/*!##foo##*//*foo*/}', {
preserve: comment => comment.startsWith('##foo##'),
}), 'body{}',
);
t.is(
stripCssComments('body{/*!##foo*//*foo*/}', {
preserve: comment => comment.endsWith('foo'),
}),
'body{/*!##foo*//*foo*/}',
);
});
test('`whitespace` option', t => {
t.is(stripCssComments('/* foo */\n\nbody{}', {whitespace: false}), '\nbody{}');
t.is(stripCssComments('/* foo */\r\n\r\nbody{}', {whitespace: false}), '\r\nbody{}');
t.is(stripCssComments('/*! foo */\r\n\r\nbody{}', {whitespace: false}), '/*! foo */\r\n\r\nbody{}');
t.is(stripCssComments('/*! foo */\r\n\r\nbody{}', {preserve: false, whitespace: false}), '\r\nbody{}');
t.is(stripCssComments('/*##foo##*/\nbody{}', {preserve: /^##foo##/, whitespace: false}), '/*##foo##*/\nbody{}');
t.is(stripCssComments('/*##foo##*/\r\nbody{}', {preserve: /^##foo##/, whitespace: false}), '/*##foo##*/\r\nbody{}');
t.is(
stripCssComments('body{/*!##foo*/\n/*foo*/}', {
preserve: comment => comment.endsWith('foo'), whitespace: false,
}),
'body{/*!##foo*/\n/*foo*/}',
);
t.is(
stripCssComments('body{/*!##foo*/\r\n/*foo*/}', {
preserve: comment => comment.endsWith('foo'), whitespace: false,
}),
'body{/*!##foo*/\r\n/*foo*/}',
);
});