MCPcopy Create free account
hub / github.com/colbymchenry/codegraph / rustModDeclaration

Function rustModDeclaration

src/graph/test-code.ts:63–81  ·  view source on GitHub ↗

How `source` declares the out-of-line module `name` at its top level: under a test `cfg`, plainly, or not at all.

(source: string, name: string)

Source from the content-addressed store, hash-verified

61
62/** How `source` declares the out-of-line module `name` at its top level: under a test `cfg`, plainly, or not at all. */
63function rustModDeclaration(source: string, name: string): 'cfg-test' | 'plain' | undefined {
64 // `name` is an identifier (inCfgTestFile); `mod r#type;` loads `type.rs`.
65 const decl = new RegExp(`^(?:pub(?:\\([^)]*\\))?\\s+)?mod\\s+(?:r#)?${name}\\s*;`);
66 let armed = false;
67 let found: 'plain' | undefined;
68 for (const raw of blankRustCode(source).split('\n')) {
69 const text = raw.trimEnd();
70 // Indented: inside a block, where a `mod x;` loads a file further down.
71 if (/^\s/.test(text)) { armed = false; continue; }
72 if (CFG_TEST.test(text)) { armed = true; continue; }
73 if (text.startsWith('#[') || text === '') continue;
74 if (decl.test(text)) {
75 if (armed) return 'cfg-test';
76 found = 'plain';
77 }
78 armed = false;
79 }
80 return found;
81}
82
83/**
84 * `line` (1-based) is inside a module declared under a test `cfg`. The

Callers 1

inCfgTestFileFunction · 0.85

Calls 1

blankRustCodeFunction · 0.90

Tested by

no test coverage detected