Index `files` and return what a method's edges, `contains` aside, reach.
(files: Record<string, string>)
| 89 | |
| 90 | /** Index `files` and return what a method's edges, `contains` aside, reach. */ |
| 91 | async function indexProject(files: Record<string, string>): Promise<(method: string) => string[]> { |
| 92 | root = fs.mkdtempSync(path.join(os.tmpdir(), 'cg-objc-globals-')); |
| 93 | for (const [rel, content] of Object.entries(files)) { |
| 94 | fs.mkdirSync(path.dirname(path.join(root, rel)), { recursive: true }); |
| 95 | fs.writeFileSync(path.join(root, rel), content); |
| 96 | } |
| 97 | const graph = (cg = await CodeGraph.init(root, { index: true })); |
| 98 | return (method: string) => { |
| 99 | const node = graph.getNodesByName(method).find((n) => n.kind === 'method')!; |
| 100 | expect(node, method).toBeDefined(); |
| 101 | return graph |
| 102 | .getOutgoingEdges(node.id) |
| 103 | .filter((e) => e.kind !== 'contains') |
| 104 | .map((e) => { |
| 105 | const t = graph.getNode(e.target)!; |
| 106 | return `${e.kind} ${t.kind} ${t.name} ${t.filePath}`; |
| 107 | }); |
| 108 | }; |
| 109 | } |
| 110 | |
| 111 | it('reaches a global through the header that declares it', async () => { |
| 112 | const targetsOf = await indexProject({ |
no test coverage detected