-
Notifications
You must be signed in to change notification settings - Fork 2
/
postcss-custom-units.test.js
86 lines (66 loc) · 1.8 KB
/
postcss-custom-units.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
const postcss = require('postcss');
const PostCSSPlugin = require('./postcss-custom-units.cjs');
const getResultCss = (css) => postcss([
PostCSSPlugin
]).process(css, {
from: undefined
}).then(
({ css }) => css
)
describe('PostCSSPlugin', () => {
it('Common positive case', async () => {
const res = await getResultCss('.f { f: 200--rs; }');
expect(res).toBe('.f { f: calc(200 * var(--rs)); }');
});
it('Common negative case', async () => {
const res = await getResultCss('.f { f: -200--rs; }');
expect(res).toBe('.f { f: calc(-200 * var(--rs)); }');
});
it('Ignore case', async () => {
const css = '.f { f: 200px; }';
const res = await getResultCss(css);
expect(res).toBe(css);
});
it('In calc', async () => {
const res = await getResultCss('.f { f: calc(2 * -200--rs); }');
expect(res).toBe('.f { f: calc(2 * calc(-200 * var(--rs))); }');
});
it('Fraction case', async () => {
const res = await getResultCss('.f { f: 2.5--rs; }');
expect(res).toBe('.f { f: calc(2.5 * var(--rs)); }');
});
it('Complex case', async () => {
const res = await getResultCss(`
.f {
width: 200px;
height: 100--f;
margin: -5--rs;
}
@media (max-width: 300px) {
width: 200px;
height: calc(2 * 2--rs);
margin: 2.5--rs;
}
`);
expect(res).toBe(`
.f {
width: 200px;
height: calc(100 * var(--f));
margin: calc(-5 * var(--rs));
}
@media (max-width: 300px) {
width: 200px;
height: calc(2 * calc(2 * var(--rs)));
margin: calc(2.5 * var(--rs));
}
`);
});
it('One case', async () => {
const res = await getResultCss('.f { f: 1--rs; }');
expect(res).toBe('.f { f: calc(var(--rs)); }');
});
it('Zero case', async () => {
const res = await getResultCss('.f { f: 0--rs; }');
expect(res).toBe('.f { f: calc(0 * var(--rs)); }');
});
});