(tree: Tree, aa: TestData[])
| 24 | } |
| 25 | |
| 26 | function 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 | |
| 45 | function expectFindNodeAtOffset(tree: Tree, aa: TestData[]) { |
| 46 | for (const { id, offset, length, boundOffset, boundLength } of aa) { |
no test coverage detected