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.
Add
skipInvalid
dumper option. nodeca#76
Dervus Grim
committed
Jun 4, 2013
1 parent
2c42198
commit 68cbb29
Showing
5 changed files
with
49 additions
and
4 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
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,38 @@ | ||
'use strict'; | ||
/*global it */ | ||
|
||
|
||
var assert = require('assert'); | ||
var yaml = require('../../lib/js-yaml'); | ||
|
||
|
||
var sample = { | ||
number: 42, | ||
undef: undefined, | ||
string: 'hello', | ||
func: function (a, b) { return a + b; }, | ||
regexp: /^hel+o/, | ||
array: [1, 2, 3] | ||
}; | ||
|
||
|
||
var expected = { | ||
number: 42, | ||
undef: null, | ||
string: 'hello', | ||
func: null, | ||
regexp: {}, | ||
array: [1, 2, 3] | ||
}; | ||
|
||
|
||
it('Dumper must throw an exception on invalid type when option `skipInvalid` is false.', function () { | ||
assert.throws(function () { | ||
yaml.safeDump(sample, { skipInvalid: false }); | ||
}, yaml.YAMLException); | ||
}); | ||
|
||
|
||
it('Dumper must write `null` for invalid types when option `skipInvalid` is true.', function () { | ||
assert.deepEqual(yaml.load(yaml.safeDump(sample, { skipInvalid: true })), expected); | ||
}); |