Skip to content

Commit

Permalink
test: add transcode testings
Browse files Browse the repository at this point in the history
  • Loading branch information
WindomZ committed Apr 12, 2017
1 parent 75b8cbe commit 48fa878
Showing 1 changed file with 94 additions and 0 deletions.
94 changes: 94 additions & 0 deletions test/transcode.test.js
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)
}
})

0 comments on commit 48fa878

Please sign in to comment.