| 86 | // ── Expectations runner ─────────────────────────────────────────────────────── |
| 87 | |
| 88 | function runExpectations( |
| 89 | exp: NonNullable<E2ECase["expectations"]>, |
| 90 | finalText: string | undefined, |
| 91 | errors: string[], |
| 92 | prefix = "", |
| 93 | ): void { |
| 94 | const tag = prefix ? `${prefix}: ` : ""; |
| 95 | if (exp.finalContains) { |
| 96 | for (const needle of exp.finalContains) { |
| 97 | if (!(finalText ?? "").toLowerCase().includes(needle.toLowerCase())) { |
| 98 | errors.push(`${tag}missing: ${JSON.stringify(needle)}`); |
| 99 | } |
| 100 | } |
| 101 | } |
| 102 | if (exp.finalNotContains) { |
| 103 | for (const needle of exp.finalNotContains) { |
| 104 | if ((finalText ?? "").toLowerCase().includes(needle.toLowerCase())) { |
| 105 | errors.push(`${tag}contained forbidden: ${JSON.stringify(needle)}`); |
| 106 | } |
| 107 | } |
| 108 | } |
| 109 | if (exp.balancedBrackets && finalText && !isBalanced(finalText)) { |
| 110 | errors.push(`${tag}text has unbalanced brackets`); |
| 111 | } |
| 112 | if (exp.minLength && (finalText?.length ?? 0) < exp.minLength) { |
| 113 | errors.push( |
| 114 | `${tag}too short (${finalText?.length ?? 0} < ${exp.minLength})`, |
| 115 | ); |
| 116 | } |
| 117 | } |
| 118 | |
| 119 | // ── Case runner ─────────────────────────────────────────────────────────────── |
| 120 | |