(source: string, line: number)
| 87 | * needs to go. |
| 88 | */ |
| 89 | export function inCfgTestModule(source: string, line: number): boolean { |
| 90 | const lines = blankRustCode(source).split('\n'); |
| 91 | let armed = false; |
| 92 | for (let i = 0; i < lines.length && i < line; i++) { |
| 93 | const text = lines[i]!.trim(); |
| 94 | if (CFG_TEST.test(text)) { armed = true; continue; } |
| 95 | if (!armed) continue; |
| 96 | if (text.startsWith('#[') || text === '') continue; |
| 97 | armed = false; |
| 98 | if (!/^(?:pub(?:\([^)]*\))?\s+)?mod\s+\w+\s*\{/.test(text)) continue; |
| 99 | // Walk the block: it ends on the line where its braces close. |
| 100 | let depth = 0; |
| 101 | for (let j = i; j < lines.length; j++) { |
| 102 | for (const ch of lines[j]!) { |
| 103 | if (ch === '{') depth++; |
| 104 | else if (ch === '}') depth--; |
| 105 | } |
| 106 | if (depth <= 0) { |
| 107 | if (line - 1 > i && line - 1 <= j) return true; |
| 108 | i = j; |
| 109 | break; |
| 110 | } |
| 111 | } |
| 112 | } |
| 113 | return false; |
| 114 | } |
no test coverage detected