Skip to content

Commit

Permalink
test(data): refactor test data from object to array format
Browse files Browse the repository at this point in the history
  • Loading branch information
remarkablemark committed Jun 22, 2019
1 parent 75d084d commit 1a07a38
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 103 deletions.
134 changes: 32 additions & 102 deletions test/data.js
Original file line number Diff line number Diff line change
@@ -1,138 +1,68 @@
const invalid = [
// boolean
{
style: true,
expected: null
},

// null
{
style: null,
expected: null
},

// undefined
{
style: undefined,
expected: null
},

// number
{
style: 42,
expected: null
},

// string (empty)
{
style: '',
expected: null
},

// object
{
style: {},
expected: null
},

// array
{
style: ['Array'],
expected: null
},

// function
{
style: function() {},
expected: null
},

// date
{
style: new Date(),
expected: null
}
[undefined, null],
[null, null],
[true, null],
[false, null],
[0, null],
[1, null],
['', null],
[{}, null],
[['Array'], null],
[() => Function, null],
[new Date(), null]
];

const styles = [
// single without semicolon
{
style: 'color: #f00',
expected: { color: '#f00' }
},
['color: #f00', { color: '#f00' }],

// multiple with semicolons
{
style: `
font-size: 42px;
font-family: "Open Sans", Helvetica, sans-serif;
`,
expected: {
[
'font-size: 42px; font-family: "Open Sans", Helvetica, sans-serif;',
{
'font-size': '42px',
'font-family': '"Open Sans", Helvetica, sans-serif'
}
},
],

// url
{
style: 'background-image: url("http://cdn.example.com/image.png?v=42");',
expected: {
[
'background-image: url("http://cdn.example.com/image.png?v=42");',
{
'background-image': 'url("http://cdn.example.com/image.png?v=42")'
}
},
],

// property prefix
{
style: `
-webkit-hyphens: auto;
-moz-hyphens: auto;
-ms-hyphens: auto;
hyphens: auto;
`,
expected: {
[
'-webkit-hyphens: auto; -moz-hyphens: auto; -ms-hyphens: auto; hyphens: auto;',
{
'-webkit-hyphens': 'auto',
'-moz-hyphens': 'auto',
'-ms-hyphens': 'auto',
hyphens: 'auto'
}
},
],

// value prefix
{
style: `
display: -webkit-box;
display: -ms-flexbox;
display: -webkit-flex;
display: flex;
`,
expected: {
[
'display: -webkit-box; display: -ms-flexbox; display: -webkit-flex; display: flex;',
{
display: 'flex'
}
},
],

// missing value
{
style: 'z-index:',
expected: null
},
['z-index:', null],

// missing property
{
style: ': 42',
expected: Error
},
[': 42', Error],

// comment
{
style: '/* color: #f00; */',
expected: null
},
['/* color: #f00; */', null],

// comment with declaration
{
style: '/* color: #f00; */ background: blue;',
expected: { background: 'blue' }
}
['/* color: #f00; */ background: blue;', { background: 'blue' }]
];

module.exports = {
Expand Down
4 changes: 3 additions & 1 deletion test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@ const data = require('./data');
const parse = require('..');

describe('parser', () => {
data.default.forEach(({ style, expected }) => {
data.default.forEach(cases => {
const [style, expected] = cases;

// error case
describe(`when style=\`${style}\``, () => {
if (expected === Error) {
Expand Down

0 comments on commit 1a07a38

Please sign in to comment.