MCPcopy Index your code
hub / github.com/loggerhead/json4u / expectOffsetAndText

Function expectOffsetAndText

__tests__/parseAndFormat.test.ts:26–43  ·  view source on GitHub ↗
(tree: Tree, aa: TestData[])

Source from the content-addressed store, hash-verified

24}
25
26function expectOffsetAndText(tree: Tree, aa: TestData[]) {
27 for (const { id, offset, length, boundOffset, boundLength } of aa) {
28 const node = tree.node(id);
29 expect(node).toMatchObject({ offset, length, boundOffset, boundLength });
30
31 const { parent: parentId, lastKey } = splitParentPointer(id);
32 const parent = (parentId && tree.node(parentId)) || undefined;
33 const valueText = getRawValue(node) ?? tree.text.slice(offset, offset + length);
34 const boundText = tree.text.slice(boundOffset, boundOffset + boundLength);
35
36 if (parent?.type === "object") {
37 expect(boundText.startsWith(`"${lastKey}"`)).toEqual(true);
38 expect(boundText.endsWith(valueText)).toEqual(true);
39 } else {
40 expect(boundText).toEqual(valueText);
41 }
42 }
43}
44
45function expectFindNodeAtOffset(tree: Tree, aa: TestData[]) {
46 for (const { id, offset, length, boundOffset, boundLength } of aa) {

Callers 1

doExpectFunction · 0.85

Calls 3

splitParentPointerFunction · 0.90
getRawValueFunction · 0.90
nodeMethod · 0.80

Tested by

no test coverage detected