-
Notifications
You must be signed in to change notification settings - Fork 137
/
Copy pathparseJson.test.ts
57 lines (50 loc) · 1.9 KB
/
parseJson.test.ts
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
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
import * as assert from 'assert';
import { getLineAndColumnFromOffset, parseJson } from '../extension.bundle';
suite('parseJson', () => {
test('Valid json', () => {
const data: string = '{"a": "1"}';
assert.deepStrictEqual(parseJson(data), { a: '1' });
});
test('Trailing comma', () => {
const data: string = '{"a": "1",}';
assert.deepStrictEqual(parseJson(data), { a: '1' });
});
test('With comment', () => {
const data: string = '{"a": /*comment*/"1"}';
assert.deepStrictEqual(parseJson(data), { a: '1' });
});
test('Invalid json', () => {
const data: string = '{"a": "1}';
// eslint-disable-next-line @typescript-eslint/no-unsafe-return
assert.throws(() => parseJson(data));
});
});
suite('getLineAndColumnFromOffset', () => {
const data: string = `{
"version": "2.0",
"logging": {
"applicationInsights": {
"samplingExcludedTypes": "Request",
"samplingSettings": {
"isEnabled": true
}
}
}
}`;
test('First character', () => {
assert.deepStrictEqual(getLineAndColumnFromOffset(data, 1), [1, 1]);
});
test('Middle of random line', () => {
assert.deepStrictEqual(getLineAndColumnFromOffset(data, 28), [3, 4]);
});
test('End of random line', () => {
assert.deepStrictEqual(getLineAndColumnFromOffset(data, 74), [4, 33]);
});
test('Last character', () => {
assert.deepStrictEqual(getLineAndColumnFromOffset(data, 221), [11, 1]);
});
});