-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathjsonParser.test.js
More file actions
71 lines (57 loc) · 1.46 KB
/
jsonParser.test.js
File metadata and controls
71 lines (57 loc) · 1.46 KB
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 parser = require('./jsonParser')
test('parse null', () => {
expect(parser.parseJSON(`null`))
.toEqual([null, ''])
})
test('parse array', () => {
expect(parser.parseJSON(`[1,2,3]`))
.toEqual([[1, 2, 3], ''])
})
test('parse true', () => {
expect(parser.parseJSON(`true`))
.toEqual([true, ''])
})
test('parse false', () => {
expect(parser.parseJSON(`false`))
.toEqual([false, ''])
})
test('parse number', () => {
expect(parser.parseJSON(`132.2e-5`))
.toEqual([132.2e-5, ''])
})
test('parse object', () => {
expect(parser.parseJSON(`{ "key" : "value" }`))
.toEqual([{ 'key': 'value' }, ''])
})
test('parse string', () => {
expect(parser.parseJSON(`"String\\n \\u1234"`))
.toEqual(['String\n ሴ', ''])
})
test('parse large number', () => {
expect(() => parser.parseJSON(`132.2e520`))
.toThrow()
})
test('parse tralling comma object', () => {
expect(() => parser.parseJSON(`{ "ADSF":12, }`))
.toThrow()
})
test('parse object only containing comma', () => {
expect(() => parser.parseJSON(`{ , }`))
.toThrow()
})
test('parse object only containing key', () => {
expect(() => parser.parseJSON(`{"fkaljd"}`))
.toThrow()
})
test('parse object only containing key:', () => {
expect(() => parser.parseJSON(`{"fkaljd":}`))
.toThrow()
})
test('parse array traling comma', () => {
expect(() => parser.parseJSON(`[1,]`))
.toThrow()
})
test('parse array containing True', () => {
expect(() => parser.parseJSON(`[True]`))
.toThrow()
})