(source: string, line: number)
| 31 | * needs to go. |
| 32 | */ |
| 33 | export function inCfgTestModule(source: string, line: number): boolean { |
| 34 | const lines = blankRustCode(source).split('\n'); |
| 35 | let armed = false; |
| 36 | for (let i = 0; i < lines.length && i < line; i++) { |
| 37 | const text = lines[i]!.trim(); |
| 38 | if (CFG_TEST.test(text)) { armed = true; continue; } |
| 39 | if (!armed) continue; |
| 40 | if (text.startsWith('#[') || text === '') continue; |
| 41 | armed = false; |
| 42 | if (!/^(?:pub(?:\([^)]*\))?\s+)?mod\s+\w+\s*\{/.test(text)) continue; |
| 43 | // Walk the block: it ends on the line where its braces close. |
| 44 | let depth = 0; |
| 45 | for (let j = i; j < lines.length; j++) { |
| 46 | for (const ch of lines[j]!) { |
| 47 | if (ch === '{') depth++; |
| 48 | else if (ch === '}') depth--; |
| 49 | } |
| 50 | if (depth <= 0) { |
| 51 | if (line - 1 > i && line - 1 <= j) return true; |
| 52 | i = j; |
| 53 | break; |
| 54 | } |
| 55 | } |
| 56 | } |
| 57 | return false; |
| 58 | } |
no test coverage detected