-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.test.js
88 lines (75 loc) · 3.12 KB
/
index.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
var postcss = require('postcss');
var plugin = require('./');
function run(input, output, opts) {
return postcss([ plugin(opts) ]).process(input)
.then(result => {
expect(result.css).toEqual(output);
expect(result.warnings().length).toBe(0);
});
}
it('transforms space syntax to comma one', () => {
return run(
'a{ color: rgb(255 0 0); }',
'a{ color: rgb(255, 0, 0); }'
);
});
it('transforms rgb function with alpha (comma syntax) to old rgba', () => {
return run(
'a{ border: 1px solid rgb(255, 0, 0, 0.4); }',
'a{ border: 1px solid rgba(255, 0, 0, 0.4); }'
);
});
it('transforms rgb function with percent-alpha (comma syntax) to old rgba', () => {
return run(
'a{ background-image: linear-gradient(to right, rgb(255, 0, 0, 40%), rgba(255,0,0,0.4)); }',
'a{ background-image: linear-gradient(to right, rgba(255, 0, 0, 0.4), rgba(255, 0, 0, 0.4)); }'
);
});
it('transforms rgb function with alpha (space syntax) to old rgba', () => {
return run(
'a{ box-shadow: 0 0 7px 0 rgb(255 0 0 / 0.4); }',
'a{ box-shadow: 0 0 7px 0 rgba(255, 0, 0, 0.4); }'
);
});
it('transforms rgb function with percent-alpha (space syntax) to old rgba', () => {
return run(
'a{ text-decoration-color: rgb(255 0 0 / 40%); }',
'a{ text-decoration-color: rgba(255, 0, 0, 0.4); }'
);
});
it('transforms rgba function with percent-alpha to number-alpha one', () => {
return run(
'a{ outline-color: rgba(255, 0, 0, 40%); }',
'a{ outline-color: rgba(255, 0, 0, 0.4); }'
);
});
it('transforms rgba function (rgb space syntax) to old rgba', () => {
return run(
'a{ background-color: rgba(100% 0% 0% / 0.4); }',
'a{ background-color: rgba(100%, 0%, 0%, 0.4); }'
);
});
it('does not take into account syntax error(s) inside RGB functions', () => {
return run(
'a{ fill: rgba( 255 0 51.2 / 40% ); }',
'a{ fill: rgba(255, 0, 51.2, 0.4); }'
);
});
it('supports complex RGB functions with calc() and var()', () => {
return run(
':root{ --is-red: 0; } a{ background-color: rgb( calc(255 * var(--is-red) + 0 * (1 - var(--is-red))) calc(0 * var(--is-red) + 255 * (1 - var(--is-red))) 0 / 1); }',
':root{ --is-red: 0; } a{ background-color: rgba(calc(255 * var(--is-red) + 0 * (1 - var(--is-red))), calc(0 * var(--is-red) + 255 * (1 - var(--is-red))), 0, 1); }'
);
});
it('supports complex RGB functions with attr()', () => {
return run(
'a{ color: rgba(255 0 51 / attr(data-alpha %, 100%)); }',
'a{ color: rgba(255, 0, 51, attr(data-alpha %, 100%)); }'
);
});
it('supports complex RGB functions with multi-lines value', () => {
return run(
':root{ --is-red: 0; } a{ background-color: rgb( \n\t\t calc(255 * var(--is-red) + 0 * (1 - var(--is-red)))\n\t\t calc(0 * var(--is-red) + 255 * (1 - var(--is-red))) \r\n\t\t0 \r\n\t\t / 1 ); }',
':root{ --is-red: 0; } a{ background-color: rgba(calc(255 * var(--is-red) + 0 * (1 - var(--is-red))), calc(0 * var(--is-red) + 255 * (1 - var(--is-red))), 0, 1); }'
);
});