Skip to content

Commit 361974b

Browse files
test: add cases and compare parser output with css.parse output
1 parent 977ab56 commit 361974b

File tree

2 files changed

+80
-3
lines changed

2 files changed

+80
-3
lines changed

test/data.js

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
const cases = [
2+
// general
3+
'display: inline-block;',
4+
'color:red;',
5+
'margin: 0 auto;',
6+
'border: 5px solid #BADA55;',
7+
'font-size: .75em; position:absolute;width: 33.3%; z-index:1337;',
8+
9+
// multiple of same property
10+
'color:rgba(0,0,0,1);color:white;',
11+
12+
// missing semicolon
13+
'line-height: 42',
14+
'font-style:italic; text-transform:uppercase',
15+
16+
// extra whitespace
17+
' padding-bottom : 1px',
18+
'padding: 12px 0 ',
19+
`
20+
-moz-border-radius: 10px 5px;
21+
-webkit-border-top-left-radius: 10px;
22+
-webkit-border-top-right-radius: 5px;
23+
-webkit-border-bottom-right-radius: 10px;
24+
-webkit-border-bottom-left-radius: 5px;
25+
border-radius: 10px 5px;
26+
`,
27+
28+
// text and url
29+
'content: "Lorem ipsum";',
30+
'background-image: url(http://example.com/img.png)',
31+
32+
// vendor prefixes
33+
'background: -webkit-linear-gradient(90deg, black, #111)',
34+
'-webkit-transition: all 4s ease; -moz-transition: all 4s ease; -ms-transition: all 4s ease; -o-transition: all 4s ease; transition: all 4s ease;',
35+
36+
// comment
37+
'/* comment */',
38+
'top: 0; /* comment */ bottom: 42rem;',
39+
` top: 0; /* comment */
40+
/* comment */ bottom: 42rem; `,
41+
42+
// custom
43+
'foo: bar;',
44+
'foo:bar; baz:qux'
45+
];
46+
47+
module.exports = {
48+
cases
49+
};

test/index.js

Lines changed: 31 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,36 @@
11
const assert = require('assert');
2+
const css = require('css');
23
const parse = require('..');
4+
const { cases } = require('./data');
35

4-
describe.skip('inline-style-parser', () => {
5-
it('returns with placeholder', () => {
6-
assert.equal(parse(), 'inline-style-parser');
6+
/**
7+
* @param {string} inlineStyle
8+
* @return {Array}
9+
*/
10+
function getDeclarations(inlineStyle) {
11+
const {
12+
stylesheet: { rules }
13+
} = css.parse(`a{${inlineStyle}}`);
14+
return rules[0].declarations;
15+
}
16+
17+
/**
18+
* @param {Object[]} declarations
19+
* @return {Object[]}
20+
*/
21+
function removePosition(declarations) {
22+
return declarations.map(({ type, property, value }) => ({
23+
type,
24+
property,
25+
value
26+
}));
27+
}
28+
29+
cases.forEach(inlineStyle => {
30+
it(`parses \`${inlineStyle}\``, () => {
31+
assert.deepEqual(
32+
removePosition(parse(inlineStyle)),
33+
removePosition(getDeclarations(inlineStyle))
34+
);
735
});
836
});

0 commit comments

Comments
 (0)