-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.test.js
executable file
·72 lines (53 loc) · 2.17 KB
/
index.test.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
const assert = require('assert')
const fs = require('fs')
const notJSON = require('.')
describe('notJSON', () => {
describe('parse JSON', () => {
let json, obj
before(() => {
json = fs.readFileSync('example.json', 'utf8')
obj = notJSON.parse(json)
})
it('should parse JSON', () => {
assert(obj, 'should obj be defined')
assert.equal(obj.a, 1, 'should property match')
assert.equal(obj.b, '2', 'should property match')
assert.equal(obj.c, '3', 'should property match')
assert(obj.d, 'should property match')
assert.equal(obj.d.length, 3, 'should property match')
assert.equal(obj.d[0], 1, 'should property match')
assert.equal(obj.d[1], '2', 'should property match')
assert.equal(obj.d[2], '3', 'should property match')
})
})
describe('parse not-JSON', () => {
let notJson, obj
before(() => {
notJson = fs.readFileSync('example.not-json', 'utf8')
obj = notJSON.parse(notJson)
})
it('should parse not-JSON', () => {
assert(obj, 'should obj be defined')
assert.equal(obj.a, 1, 'should property match')
assert.equal(obj.b, '2', 'should property match')
assert.equal(obj.c, '3', 'should property match')
assert(obj.d, 'should property match')
assert.equal(obj.d.length, 3, 'should property match')
assert.equal(obj.d[0], 1, 'should property match')
assert.equal(obj.d[1], '2', 'should property match')
assert.equal(obj.d[2], '3', 'should property match')
})
})
describe('stringify object', () => {
let notJson, obj, json
before(() => {
notJson = fs.readFileSync('example.not-json', 'utf8')
obj = notJSON.parse(notJson)
json = notJSON.stringify(obj)
})
it('should stringify object', () => {
assert(json, 'should json be defined')
assert.equal(json, '{"a":1,"b":"2","c":"3","d":[1,"2","3"]}', 'should json match')
})
})
})