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)
| 61 | |
| 62 | /** How `source` declares the out-of-line module `name` at its top level: under a test `cfg`, plainly, or not at all. */ |
| 63 | function 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 |
no test coverage detected