(text)
| 36 | } |
| 37 | |
| 38 | function verify(text) { |
| 39 | const lines = text.split('\n'); |
| 40 | const issues = []; |
| 41 | |
| 42 | // Check 1: No tabs |
| 43 | lines.forEach((line, i) => { |
| 44 | if (line.includes('\t')) { |
| 45 | issues.push({ line: i + 1, type: 'tab', msg: `Line ${i + 1} contains tab characters — use spaces only` }); |
| 46 | } |
| 47 | }); |
| 48 | |
| 49 | // Check 2: Find ALL corners (ASCII + Unicode) and verify connectivity |
| 50 | const corners = []; |
| 51 | lines.forEach((line, y) => { |
| 52 | for (let x = 0; x < line.length; x++) { |
| 53 | if (isCorner(line[x])) corners.push({ x, y, ch: line[x] }); |
| 54 | } |
| 55 | }); |
| 56 | |
| 57 | corners.forEach(({ x, y, ch }) => { |
| 58 | const right = charAt(lines, x + 1, y); |
| 59 | const left = charAt(lines, x - 1, y); |
| 60 | const below = charAt(lines, x, y + 1); |
| 61 | const above = charAt(lines, x, y - 1); |
| 62 | |
| 63 | const hasRight = isHBorder(right) || isCorner(right); |
| 64 | const hasLeft = isHBorder(left) || isCorner(left); |
| 65 | const hasBelow = isVBorder(below) || isCorner(below); |
| 66 | const hasAbove = isVBorder(above) || isCorner(above); |
| 67 | |
| 68 | const connections = [hasRight, hasLeft, hasBelow, hasAbove].filter(Boolean).length; |
| 69 | // 0 connections: likely a text character (e.g., "+ sealed"), not a corner — skip |
| 70 | // 1 connection: probably a misaligned corner — flag it |
| 71 | // For ASCII '+', also check if it's clearly text (surrounded by alphanumeric/space) |
| 72 | if (connections === 1) { |
| 73 | issues.push({ |
| 74 | line: y + 1, col: x + 1, type: 'corner', |
| 75 | msg: `Corner '${ch}' at (${y + 1}:${x + 1}) only connects in 1 direction — may be misaligned` |
| 76 | }); |
| 77 | } else if (connections === 0 && ch !== '+') { |
| 78 | // Unicode corners with 0 connections are definitely misaligned |
| 79 | issues.push({ |
| 80 | line: y + 1, col: x + 1, type: 'corner', |
| 81 | msg: `Corner '${ch}' at (${y + 1}:${x + 1}) has no connections — misplaced or misaligned` |
| 82 | }); |
| 83 | } |
| 84 | }); |
| 85 | |
| 86 | // Check 3: Vertical pipe alignment |
| 87 | const pipeColumns = new Map(); |
| 88 | lines.forEach((line, y) => { |
| 89 | for (let x = 0; x < line.length; x++) { |
| 90 | if (isVBorder(line[x])) { |
| 91 | if (!pipeColumns.has(x)) pipeColumns.set(x, []); |
| 92 | pipeColumns.get(x).push(y); |
| 93 | } |
| 94 | } |
| 95 | }); |
no test coverage detected