| 5 | import { readFileIfNeed } from "./utils"; |
| 6 | |
| 7 | function expectEq(text: string, expected: string, options: ParseOptions = {}) { |
| 8 | const tree = parseJSON(text, options); |
| 9 | expect(tree.hasError()).toEqual(false); |
| 10 | expect(tree.stringify(options)).toEqual(expected); |
| 11 | expect(tree.toJSON()).toEqual(JSON.parse(expected)); |
| 12 | |
| 13 | const check = (node: Node) => { |
| 14 | expect(node.id.startsWith(rootMarker)).toEqual(true); |
| 15 | if (!isIterable(node)) { |
| 16 | expect(tree.text.substring(node.offset, node.offset + node.length)).toEqual(getRawValue(node)); |
| 17 | } |
| 18 | tree.mapChildren(node, (child) => check(child)); |
| 19 | }; |
| 20 | |
| 21 | check(tree.root()); |
| 22 | } |
| 23 | |
| 24 | function genJSON(maxDepth = 5): any { |
| 25 | switch (random(0, 2)) { |