(document: PseudocodeDocument, answer: string)
| 85 | * name which one fired. |
| 86 | */ |
| 87 | export function refusalReason(document: PseudocodeDocument, answer: string): string { |
| 88 | const incoming = refinedLines(unfence(answer)); |
| 89 | if (incoming.length === 0) { |
| 90 | return REFINE_REASON_EMPTY; |
| 91 | } |
| 92 | if (incoming.length !== document.lines.length) { |
| 93 | return `${REFINE_REASON_COUNT} (${incoming.length} instead of ${document.lines.length})`; |
| 94 | } |
| 95 | for (let index = 0; index < document.lines.length; index++) { |
| 96 | const expected = document.lines[index].order; |
| 97 | const actual = leadingNumberOf(incoming[index]); |
| 98 | if (expected !== actual) { |
| 99 | return `${REFINE_REASON_NUMBERS} (line ${index + 1}: expected ` |
| 100 | + `${expected === undefined ? 'no number' : expected} and got ` |
| 101 | + `${actual === undefined ? 'no number' : actual})`; |
| 102 | } |
| 103 | } |
| 104 | return 'the rewrite did not map onto the block it was built from'; |
| 105 | } |
| 106 | |
| 107 | /** |
| 108 | * Put a model answer back onto the block, or refuse with a reason. |
no test coverage detected