-
-
Notifications
You must be signed in to change notification settings - Fork 775
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Shorthand tags with !! whenever possible
fix #258
- Loading branch information
Showing
3 changed files
with
29 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
'use strict'; | ||
|
||
|
||
const assert = require('assert'); | ||
const yaml = require('../../'); | ||
|
||
|
||
it('should shorthand tags with !! whenever possible', function () { | ||
let regexp = new yaml.Type('tag:yaml.org,2002:js/regexp', { | ||
kind: 'scalar', | ||
resolve: () => true, | ||
construct: str => new RegExp(str), | ||
instanceOf: RegExp, | ||
represent: object => object.source | ||
}); | ||
|
||
let schema = yaml.DEFAULT_SCHEMA.extend(regexp); | ||
|
||
let source = 're: !!js/regexp .*\n'; | ||
|
||
let object = yaml.load(source, { schema }); | ||
assert(object.re instanceof RegExp); | ||
|
||
let str = yaml.dump(object, { schema }); | ||
assert.strictEqual(str, source); | ||
}); |