1
0
mirror of https://github.com/yldio/copilot.git synced 2024-11-14 07:10:05 +02:00
copilot/packages/pseudo-json-ast/test/index.js
Sérgio Ramos 8295bd6882 chore: initial lerna setup
this shall be a progressive process
2017-05-25 10:56:50 +01:00

38 lines
1.1 KiB
JavaScript

const { default: jsonAST, loc } = require('../src/index');
const test = require('ava');
test('should accurately add locations', t => {
const ast = jsonAST(`{
"obj": {
"arr": [{
"nums": [1, 2, 3],
"strs1": ["1", "2", "3"],
"strs: ["1", "2", "3"]
}],
"str": "1",
"num": 1
}
}`);
t.deepEqual(Object.keys(ast), ['obj']);
t.deepEqual(ast[loc].start.line, 1);
t.deepEqual(ast[loc].end.line, 11);
t.deepEqual(Object.keys(ast.obj), ['arr', 'str', 'num']);
t.deepEqual(ast.obj[loc].start.line, 2);
t.deepEqual(ast.obj[loc].end.line, 10);
t.deepEqual(ast.obj.str[loc].start.line, 8);
t.deepEqual(ast.obj.str[loc].end.line, 8);
t.deepEqual(ast.obj.num[loc].start.line, 9);
t.deepEqual(ast.obj.num[loc].end.line, 9);
t.deepEqual(ast.obj.arr[0][loc].start.line, 3);
t.deepEqual(ast.obj.arr[0][loc].end.line, 7);
t.deepEqual(Object.keys(ast.obj.arr[0]), ['nums', 'strs1']);
t.deepEqual(ast.obj.arr[0].nums[loc].start.line, 4);
t.deepEqual(ast.obj.arr[0].nums[loc].end.line, 4);
t.deepEqual(ast.obj.arr[0].strs1[loc].start.line, 5);
t.deepEqual(ast.obj.arr[0].strs1[loc].end.line, 5);
});