(source: string, line: number)
| 117 | * needs to go. |
| 118 | */ |
| 119 | export function inCfgTestModule(source: string, line: number): boolean { |
| 120 | const lines = blankRustCode(source).split('\n'); |
| 121 | let armed = false; |
| 122 | for (let i = 0; i < lines.length && i < line; i++) { |
| 123 | const text = lines[i]!.trim(); |
| 124 | if (CFG_TEST.test(text)) { armed = true; continue; } |
| 125 | if (!armed) continue; |
| 126 | if (text.startsWith('#[') || text === '') continue; |
| 127 | armed = false; |
| 128 | if (!/^(?:pub(?:\([^)]*\))?\s+)?mod\s+\w+\s*\{/.test(text)) continue; |
| 129 | // Walk the block: it ends on the line where its braces close. |
| 130 | let depth = 0; |
| 131 | for (let j = i; j < lines.length; j++) { |
| 132 | for (const ch of lines[j]!) { |
| 133 | if (ch === '{') depth++; |
| 134 | else if (ch === '}') depth--; |
| 135 | } |
| 136 | if (depth <= 0) { |
| 137 | if (line - 1 > i && line - 1 <= j) return true; |
| 138 | i = j; |
| 139 | break; |
| 140 | } |
| 141 | } |
| 142 | } |
| 143 | return false; |
| 144 | } |
no test coverage detected