forked from nodeca/js-yaml
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Squashed commit of the following: commit e3b379d Author: Robert (Jamie) Munro <rjmunro@arjam.net> Date: Fri May 8 16:10:54 2015 +0100 Add some tests commit febe465 Author: Robert (Jamie) Munro <rjmunro@arjam.net> Date: Fri May 8 15:35:14 2015 +0100 Document options.sortKeys for dumper commit 70e7e3d Author: Robert (Jamie) Munro <rjmunro@arjam.net> Date: Fri May 8 15:33:20 2015 +0100 Allow sortKeys option in dumper Can be `false` (no sorting), `true` (default sorting), or a function (passed to `array.sort(function)` to allow custom ordering commit dee34b1 Author: Robert (Jamie) Munro <rjmunro@arjam.net> Date: Fri May 8 09:43:03 2015 +0100 Sort keys so that the output is deterministic
- Loading branch information
Showing
4 changed files
with
47 additions
and
0 deletions.
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
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,26 @@ | ||
'use strict'; | ||
|
||
|
||
var assert = require('assert'); | ||
var yaml = require('../../'); | ||
|
||
var sample = { b: 1, a: 2, c: 3 }; | ||
var unsortedExpected = 'b: 1\na: 2\nc: 3\n'; | ||
var simpleExpected = 'a: 2\nb: 1\nc: 3\n'; | ||
var reverseExpected = 'c: 3\nb: 1\na: 2\n'; | ||
|
||
test('Dumper should sort preserve key insertion order', function () { | ||
assert.deepEqual(yaml.safeDump(sample, { sortKeys: false }), unsortedExpected); | ||
}); | ||
|
||
test('Dumper should sort keys when sortKeys is true', function () { | ||
assert.deepEqual(yaml.safeDump(sample, { sortKeys: true }), simpleExpected); | ||
}); | ||
|
||
test('Dumper should sort keys by sortKeys function when specified', function () { | ||
assert.deepEqual(yaml.safeDump(sample, { | ||
sortKeys: function (a, b) { | ||
return a < b ? 1 : a > b ? -1 : 0; | ||
} | ||
}), reverseExpected); | ||
}); |