This repository has been archived by the owner on Aug 23, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathcss.js
53 lines (46 loc) · 1.54 KB
/
css.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
'use strict';
const assert = require('assert');
const _expand = require('../').expand;
const expand = (abbr, options) => _expand(abbr, Object.assign({syntax: 'css'}, options));
describe('CSS expand', () => {
it('basic', () => {
assert.equal(expand('p10'), 'padding: 10px;');
assert.equal(expand('c'), 'color: #000;');
assert.equal(expand('fl-l'), 'float: left;');
assert.equal(expand('fl-r'), 'float: right;');
assert.equal(expand('@k'), '@keyframes identifier {\n\t\n}');
assert.equal(expand('fll'), 'float: left;');
assert.equal(expand('ovh'), 'overflow: hidden;');
// insert TextMate-style fields/tabstops in output
const field = (index, placeholder) => `\${${index}${placeholder ? ':' + placeholder : ''}}`;
assert.equal(expand('bg-u', {field}), 'background: url(${1});');
assert.equal(expand('c', {field}), 'color: #${2:000};');
});
it('linear-gradient', () => {
assert.equal(expand('lg(to right, black, #f00.4)'), 'background-image: linear-gradient(to right, black, rgba(255, 0, 0, 0.4));');
});
it('chains', () => {
assert.equal(expand('p.5+m-a'), 'padding: 0.5em;\nmargin: auto;');
});
it('formatter options', () => {
let options = {
format: {
between: '::',
after: ';;'
},
options: {
intUnit: 'pt',
floatUnit: 'vh',
unitAliases: {
e: 'em',
p: '%',
x: 'ex',
r: ' / @rem'
}
}
};
assert.equal(expand('p10', options), 'padding::10pt;;');
assert.equal(expand('p10.2', options), 'padding::10.2vh;;');
assert.equal(expand('p10r', options), 'padding::10 / @rem;;');
});
});