Skip to content

Commit

Permalink
chore: fix linting issues
Browse files Browse the repository at this point in the history
  • Loading branch information
Mark Owsiak committed Jan 4, 2018
1 parent fca0206 commit c94f2f1
Showing 1 changed file with 105 additions and 54 deletions.
159 changes: 105 additions & 54 deletions test/stringify.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@ function cson(obj, visitor, space) {
return CSON.stringify(obj, visitor, space);
}

describe('CSON.stringify', function () {
describe('CSON.stringify', function() {
it('handles null', () => equal('null', cson(null)));

it('handles boolean values', function () {
it('handles boolean values', function() {
equal('true', cson(true));
return equal('false', cson(false));
});
Expand All @@ -24,39 +24,53 @@ describe('CSON.stringify', function () {

it('handles the empty array', () => equal('[]', cson([])));

it('handles numbers', function () {
it('handles numbers', function() {
equal('0.42', cson(0.42));
equal('42', cson(42));
return equal('1.2e+90', cson(1.2e+90));
return equal('1.2e+90', cson(1.2e90));
});

it('handles single-line strings', () => equal("'hello!'", cson('hello!')));

it('handles multi-line strings', () => equal(`\
it('handles multi-line strings', () =>
equal(
`\
'''
I am your average multi-line string,
and I have a sneaky \\''' in here, too
'''\
`, cson(`\
`,
cson(`\
I am your average multi-line string,
and I have a sneaky ''' in here, too\
`)));
`)
));

it('handles multi-line strings (with 0 indentation)', () => equal(`\
it('handles multi-line strings (with 0 indentation)', () =>
equal(
`\
"I am your average multi-line string,\\nand I have a sneaky ''' in here, too"\
`, cson(`\
`,
cson(
`\
I am your average multi-line string,
and I have a sneaky ''' in here, too\
`, null, 0)));
`,
null,
0
)
));

it('handles multi-line strings w/ backslash', function () {
it('handles multi-line strings w/ backslash', function() {
const test = '\\\n\\';
const expected = "'''\n \\\\\n \\\\\n'''";
equal(test, CSON.parse(cson(test)));
return equal(expected, cson(test));
});

it('handles arrays', () => equal(`\
it('handles arrays', () =>
equal(
`\
[
[
1
Expand All @@ -68,13 +82,21 @@ and I have a sneaky ''' in here, too\
}
{}
]\
`, cson([[1], null, [], { a: 'str' }, {}])));
`,
cson([[1], null, [], { a: 'str' }, {}])
));

it('handles arrays (with 0 indentation)', () => equal(`\
it('handles arrays (with 0 indentation)', () =>
equal(
`\
[[1],null,[],{a:'str'},{}]\
`, cson([[1], null, [], { a: 'str' }, {}], null, 0)));
`,
cson([[1], null, [], { a: 'str' }, {}], null, 0)
));

it('handles objects', () => equal(`\
it('handles objects', () =>
equal(
`\
'': 'empty'
'non\\nidentifier': true
default: false
Expand All @@ -85,63 +107,92 @@ array: [
{}
[]
]\
`, cson({
'': 'empty',
"non\nidentifier": true,
default: false,
emptyObject: {},
nested: {
string: 'too'
},
array: [{}, []]
})));

it('handles objects (with 0 indentation)', () => equal(`\
`,
cson({
'': 'empty',
'non\nidentifier': true,
default: false,
emptyObject: {},
nested: {
string: 'too',
},
array: [{}, []],
})
));

it('handles objects (with 0 indentation)', () =>
equal(
`\
'':'empty','non\\nidentifier':true,default:false,nested:{string:'too'},array:[{},[]]\
`, cson({
'': 'empty',
"non\nidentifier": true,
default: false,
nested: {
string: 'too'
},
array: [{}, []]
}, null, 0)));

it('handles NaN and +/-Infinity like JSON.stringify does', function () {
`,
cson(
{
'': 'empty',
'non\nidentifier': true,
default: false,
nested: {
string: 'too',
},
array: [{}, []],
},
null,
0
)
));

it('handles NaN and +/-Infinity like JSON.stringify does', function() {
equal('null', cson(NaN));
equal('null', cson(+Infinity));
return equal('null', cson(-Infinity));
});

it('handles undefined like JSON.stringify does', () => equal(undefined, cson(undefined)));
it('handles undefined like JSON.stringify does', () =>
equal(undefined, cson(undefined)));

it('handles functions like JSON.stringify does', () => equal(undefined, cson(function () {})));
it('handles functions like JSON.stringify does', () =>
equal(undefined, cson(function() {})));

it('accepts no more than ten indentation steps, just like JSON.stringify', () => equal(`\
it('accepts no more than ten indentation steps, just like JSON.stringify', () =>
equal(
`\
x:
"don't": "be silly, will'ya?"\
`, cson({ x: { "don't": "be silly, will'ya?" } }, null, Infinity)));
`,
cson({ x: { "don't": "be silly, will'ya?" } }, null, Infinity)
));

it('lets people that really want to indent with tabs', () => equal(`\
it('lets people that really want to indent with tabs', () =>
equal(
`\
x:
\t\t'super-tabby': true\
`, cson({ x: { 'super-tabby': true } }, null, '\t\t')));
`,
cson({ x: { 'super-tabby': true } }, null, '\t\t')
));

it('handles indentation by NaN', () => equal('[1]', cson([1], null, NaN)));

it('handles indentation by floating point numbers', () => equal('[\n 1\n]', cson([1], null, 3.9)));
it('handles indentation by floating point numbers', () =>
equal('[\n 1\n]', cson([1], null, 3.9)));

it('is bug compatible with JSON.stringify for non-whitespace indention', () => equal(`\
it('is bug compatible with JSON.stringify for non-whitespace indention', () =>
equal(
`\
x:
ecma-262strange: true\
`, cson({ x: { strange: true } }, null, 'ecma-262')));
`,
cson({ x: { strange: true } }, null, 'ecma-262')
));

it('handles visitor functions', () => equal(`\
it('handles visitor functions', () =>
equal(
`\
keep: 1\
`, cson({ filter: 'me', keep: 1 }, function (k, v) {
if (typeof v !== 'string') {
return v;
}
})));
`,
cson({ filter: 'me', keep: 1 }, function(k, v) {
if (typeof v !== 'string') {
return v;
}
})
));
});

0 comments on commit c94f2f1

Please sign in to comment.