-
-
Notifications
You must be signed in to change notification settings - Fork 765
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #343 from onebytegone/fix_342_array_eol_space
[writer] Prevent space after dash for arrays that wrap
- Loading branch information
Showing
2 changed files
with
69 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
'use strict'; | ||
|
||
|
||
var assert = require('assert'); | ||
var yaml = require('../../'); | ||
var simpleArray = [ 'a', 'b' ]; | ||
var arrayOfSimpleObj = [ { a: 1 }, { b: 2 } ]; | ||
var arrayOfObj = [ { a: 1, b: 'abc' }, { c: 'def', d: 2 } ]; | ||
|
||
|
||
test('space should be added for array, regardless of indent', function () { | ||
assert.deepEqual( | ||
yaml.dump(simpleArray, { indent: 1 }), | ||
'- a\n- b\n' | ||
); | ||
assert.deepEqual( | ||
yaml.dump(simpleArray, { indent: 2 }), | ||
'- a\n- b\n' | ||
); | ||
assert.deepEqual( | ||
yaml.dump(simpleArray, { indent: 3 }), | ||
'- a\n- b\n' | ||
); | ||
assert.deepEqual( | ||
yaml.dump(simpleArray, { indent: 4 }), | ||
'- a\n- b\n' | ||
); | ||
}); | ||
|
||
test('array of objects should not wrap at indentation of 2', function () { | ||
assert.deepEqual( | ||
yaml.dump(arrayOfSimpleObj, { indent: 2 }), | ||
'- a: 1\n- b: 2\n' | ||
); | ||
assert.deepEqual( | ||
yaml.dump(arrayOfObj, { indent: 2 }), | ||
'- a: 1\n b: abc\n- c: def\n d: 2\n' | ||
); | ||
}); | ||
|
||
test('EOL space should not be added on array of objects at indentation of 3', function () { | ||
assert.deepEqual( | ||
yaml.dump(arrayOfSimpleObj, { indent: 3 }), | ||
'-\n a: 1\n-\n b: 2\n' | ||
); | ||
assert.deepEqual( | ||
yaml.dump(arrayOfObj, { indent: 3 }), | ||
'-\n a: 1\n b: abc\n-\n c: def\n d: 2\n' | ||
); | ||
}); | ||
|
||
test('EOL space should not be added on array of objects at indentation of 4', function () { | ||
assert.deepEqual( | ||
yaml.dump(arrayOfSimpleObj, { indent: 4 }), | ||
'-\n a: 1\n-\n b: 2\n' | ||
); | ||
assert.deepEqual( | ||
yaml.dump(arrayOfObj, { indent: 4 }), | ||
'-\n a: 1\n b: abc\n-\n c: def\n d: 2\n' | ||
); | ||
}); |