-
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.
- Loading branch information
Showing
1 changed file
with
94 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
/** | ||
* Created by Windom on 2017/4/12. | ||
*/ | ||
const test = require('ava') | ||
|
||
const {stringJSON2YAML, stringYAML2JSON} = require('../lib/transcode') | ||
|
||
test('transcode.stringJSON2YAML fail', t => { | ||
try { | ||
stringJSON2YAML(null) | ||
t.fail('should be catch error') | ||
} catch (e) { | ||
t.pass() | ||
} | ||
|
||
try { | ||
stringJSON2YAML(1) | ||
t.fail('should be catch error') | ||
} catch (e) { | ||
t.pass() | ||
} | ||
|
||
try { | ||
stringJSON2YAML('') | ||
t.fail('should be catch error') | ||
} catch (e) { | ||
t.pass() | ||
} | ||
|
||
try { | ||
stringJSON2YAML('xxx') | ||
t.fail('should be catch error') | ||
} catch (e) { | ||
t.pass() | ||
} | ||
}) | ||
|
||
test('transcode.stringJSON2YAML pass', t => { | ||
try { | ||
let result = stringJSON2YAML('{"a":1, "b":2}') | ||
t.is(result, 'a: 1\nb: 2\n') | ||
t.pass() | ||
} catch (e) { | ||
t.fail(e) | ||
} | ||
|
||
try { | ||
let result = stringJSON2YAML({'a': 1, 'b': 2}) | ||
t.is(result, 'a: 1\nb: 2\n') | ||
t.pass() | ||
} catch (e) { | ||
t.fail(e) | ||
} | ||
}) | ||
|
||
test('transcode.stringYAML2JSON fail', t => { | ||
try { | ||
stringYAML2JSON(null) | ||
t.fail('should be catch error') | ||
} catch (e) { | ||
t.pass() | ||
} | ||
|
||
try { | ||
stringYAML2JSON(1) | ||
t.fail('should be catch error') | ||
} catch (e) { | ||
t.pass() | ||
} | ||
|
||
try { | ||
stringYAML2JSON('') | ||
t.fail('should be catch error') | ||
} catch (e) { | ||
t.pass() | ||
} | ||
|
||
try { | ||
stringYAML2JSON('xxx:xxx:xxx') | ||
t.fail('should be catch error') | ||
} catch (e) { | ||
t.pass() | ||
} | ||
}) | ||
|
||
test('transcode.stringYAML2JSON pass', t => { | ||
try { | ||
let result = stringYAML2JSON('a: 1\nb: 2') | ||
t.is(result, '{"a":1,"b":2}') | ||
t.pass() | ||
} catch (e) { | ||
t.fail(e) | ||
} | ||
}) |