Skip to content

Commit 7c8b7d4

Browse files
committedJan 17, 2018
test: for issue #181
1 parent 87e70de commit 7c8b7d4

File tree

1 file changed

+41
-35
lines changed

1 file changed

+41
-35
lines changed
 

‎test/test.js

+41-35
Original file line numberDiff line numberDiff line change
@@ -1,70 +1,76 @@
11
import postcss from 'postcss';
22
import test from 'ava';
3-
import plugin from '../src/';
3+
import plugin from '../src';
44

55
const processing = (input, opts) => {
6-
return postcss([plugin(opts)]).process(input).css;
6+
return postcss([plugin(opts)]).process(input).css;
77
};
88

9+
test('it change circular reference', t => {
10+
const expected = ':root{ --from: 1; --to: 1}';
11+
const value = ':root{ --from: 1; --to: var(--from)}';
12+
t.is(processing(value), expected);
13+
});
14+
915
test('it change first properties for @for', t => {
10-
const expected = ':root{ --from: 1; } @for $i from 1 to 2';
11-
const value = ':root{ --from: 1; } @for $i from var(--from) to 2';
12-
t.is(processing(value), expected);
16+
const expected = ':root{ --from: 1; } @for $i from 1 to 2';
17+
const value = ':root{ --from: 1; } @for $i from var(--from) to 2';
18+
t.is(processing(value), expected);
1319
});
1420

1521
test('it change second properties for @for', t => {
16-
const expected = ':root{ --to: 2; } @for $i from 1 to 2';
17-
const value = ':root{ --to: 2; } @for $i from 1 to var(--to)';
18-
t.is(processing(value), expected);
22+
const expected = ':root{ --to: 2; } @for $i from 1 to 2';
23+
const value = ':root{ --to: 2; } @for $i from 1 to var(--to)';
24+
t.is(processing(value), expected);
1925
});
2026

2127
test('it change two properties for @for', t => {
22-
const expected = ':root{ --from: 1; --to: 2; } @for $i from 1 to 2';
23-
const value = ':root{ --from: 1; --to: 2; } @for $i from var(--from) to var(--to)';
24-
t.is(processing(value), expected);
28+
const expected = ':root{ --from: 1; --to: 2; } @for $i from 1 to 2';
29+
const value = ':root{ --from: 1; --to: 2; } @for $i from var(--from) to var(--to)';
30+
t.is(processing(value), expected);
2531
});
2632

2733
test('it change three properties for @for', t => {
28-
const expected = ':root{ --from: 1; --to: 2; --step: 5 } @for $i from 1 to 2 by 5';
29-
const value = ':root{ --from: 1; --to: 2; --step: 5 } @for $i from var(--from) to var(--to) by var(--step)';
30-
t.is(processing(value), expected);
34+
const expected = ':root{ --from: 1; --to: 2; --step: 5 } @for $i from 1 to 2 by 5';
35+
const value = ':root{ --from: 1; --to: 2; --step: 5 } @for $i from var(--from) to var(--to) by var(--step)';
36+
t.is(processing(value), expected);
3137
});
3238

3339
test('it change two properties for @if', t => {
34-
const expected = ':root{ --first: 1; --second: 2; } @if 1 < 2';
35-
const value = ':root{ --first: 1; --second: 2; } @if var(--first) < var(--second)';
36-
t.is(processing(value, {atRules: ['if']}), expected);
40+
const expected = ':root{ --first: 1; --second: 2; } @if 1 < 2';
41+
const value = ':root{ --first: 1; --second: 2; } @if var(--first) < var(--second)';
42+
t.is(processing(value, {atRules: ['if']}), expected);
3743
});
3844

3945
test('it change two properties for @if, @else if', t => {
40-
const expected = ':root{ --first: 1; --second: 2; } @if 1 < 2 { color: olive; } @else if 1 > 2 { color: red; }';
41-
const value = ':root{ --first: 1; --second: 2; } @if var(--first) < var(--second) { color: olive; } @else if var(--first) > var(--second) { color: red; }';
42-
t.is(processing(value, {atRules: ['if', 'else']}), expected);
46+
const expected = ':root{ --first: 1; --second: 2; } @if 1 < 2 { color: olive; } @else if 1 > 2 { color: red; }';
47+
const value = ':root{ --first: 1; --second: 2; } @if var(--first) < var(--second) { color: olive; } @else if var(--first) > var(--second) { color: red; }';
48+
t.is(processing(value, {atRules: ['if', 'else']}), expected);
4349
});
4450

4551
test('it change multi properties for @each', t => {
46-
const expected = ':root{ --array: foo, bar, baz; } @each $val in foo, bar, baz {} @for foo, bar, baz {}';
47-
const value = ':root{ --array: foo, bar, baz; } @each $val in var(--array) {} @for var(--array) {}';
48-
t.is(processing(value, {atRules: ['each']}), expected);
52+
const expected = ':root{ --array: foo, bar, baz; } @each $val in foo, bar, baz {} @for foo, bar, baz {}';
53+
const value = ':root{ --array: foo, bar, baz; } @each $val in var(--array) {} @for var(--array) {}';
54+
t.is(processing(value, {atRules: ['each']}), expected);
4955
});
5056

5157
test('it without variables', t => {
52-
const expected = ':root{ --red: red; } @if var(--green) { color: var(--green) }';
53-
const value = ':root{ --red: red; } @if var(--green) { color: var(--green) }';
54-
t.is(processing(value), expected);
58+
const expected = ':root{ --red: red; } @if var(--green) { color: var(--green) }';
59+
const value = ':root{ --red: red; } @if var(--green) { color: var(--green) }';
60+
t.is(processing(value), expected);
5561
});
5662

5763
test('chould change from options variables', t => {
58-
const expected = '@if green { .text-green { color: var(--green) }}';
59-
const value = '@if var(--green) { .text-green { color: var(--green) }}';
60-
const variables = {
61-
'--green': 'green'
62-
};
63-
t.is(processing(value, {variables: variables}), expected);
64+
const expected = '@if green { .text-green { color: var(--green) }}';
65+
const value = '@if var(--green) { .text-green { color: var(--green) }}';
66+
const variables = {
67+
'--green': 'green'
68+
};
69+
t.is(processing(value, {variables: variables}), expected);
6470
});
6571

6672
test('should change for @custom-media', t => {
67-
const expected = ':root{ --breakpoint-xs: 29.25em } @custom-media --viewport-xs (width > 29.25em)';
68-
const value = ':root{ --breakpoint-xs: 29.25em } @custom-media --viewport-xs (width > var(--breakpoint-xs))';
69-
t.is(processing(value, {atRules: ['custom-media']}), expected);
73+
const expected = ':root{ --breakpoint-xs: 29.25em } @custom-media --viewport-xs (width > 29.25em)';
74+
const value = ':root{ --breakpoint-xs: 29.25em } @custom-media --viewport-xs (width > var(--breakpoint-xs))';
75+
t.is(processing(value, {atRules: ['custom-media']}), expected);
7076
});

0 commit comments

Comments
 (0)
Please sign in to comment.