MCPcopy
hub / github.com/loggerhead/json4u / expectEq

Function expectEq

__tests__/parse.test.ts:7–22  ·  view source on GitHub ↗
(text: string, expected: string, options: ParseOptions = {})

Source from the content-addressed store, hash-verified

5import { readFileIfNeed } from "./utils";
6
7function 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
24function genJSON(maxDepth = 5): any {
25 switch (random(0, 2)) {

Callers 1

parse.test.tsFile · 0.70

Calls 6

parseJSONFunction · 0.90
checkFunction · 0.85
hasErrorMethod · 0.80
stringifyMethod · 0.80
toJSONMethod · 0.80
rootMethod · 0.80

Tested by

no test coverage detected