Define the local evaluation task
An invented drafting checker flags the lowercase word guaranteed only outside balanced double quotes. Words use ASCII letter boundaries; quoted teaching examples are allowed. Backslash escapes the next character. Unclosed quotes or a dangling escape yield a grammar error, never a clean result. This is an exact text policy, not legal interpretation.
- Track quote and escape states
- Mask text inside balanced quotes
- Locate declared unquoted word spans
Malformed quotation is held separately from a clean draft.
Use the filled cases
| Case | Supplied input | Expected structured output | Decision and reason |
|---|---|---|---|
| Quoted teaching word | {"text":"Avoid \"guaranteed\" in a promise."} | {"starts":[]} | The only occurrence is inside balanced quotes, which this local policy allows. |
| Unquoted word | {"text":"It is guaranteed."} | {"starts":[6]} | The unquoted word begins at zero-based text index six. |
| Quote not closed | {"text":"Avoid \"guaranteed"} | {"error":"quote-grammar"} | A broken quote cannot hide the word as an accepted teaching example. |
Work the unclosed-quote case. Which output is required, and why?
Show the worked answer
{"error":"quote-grammar"} — A broken quote cannot hide the word as an accepted teaching example.
Run the self-contained evaluator
import assert from 'node:assert/strict';
function evaluate(x){
let quoted=false,escaped=false;const unquoted=[];for(const ch of x.text){if(escaped){unquoted.push(quoted?' ':ch);escaped=false;}else if(ch.charCodeAt(0)===92){escaped=true;unquoted.push(' ');}else if(ch==='"'){quoted=!quoted;unquoted.push(' ');}else unquoted.push(quoted?' ':ch);}
if(quoted||escaped)return {error:'quote-grammar'};
const text=unquoted.join(''),hits=[];const pattern=/(?<![A-Za-z])guaranteed(?![A-Za-z])/g;for(const m of text.matchAll(pattern))hits.push(m.index);return {starts:hits};
}
const cases = [
{
"id": "quoted-example-only",
"input": {
"text": "Avoid \"guaranteed\" in a promise."
},
"expected": {
"starts": []
}
},
{
"id": "unquoted-promise",
"input": {
"text": "It is guaranteed."
},
"expected": {
"starts": [
6
]
}
},
{
"id": "unclosed-quote",
"input": {
"text": "Avoid \"guaranteed"
},
"expected": {
"error": "quote-grammar"
}
}
];
for (const c of cases) assert.deepEqual(evaluate(c.input), c.expected, c.id);
console.log(JSON.stringify({checked:cases.length,caseIds:cases.map(c=>c.id)}));
Keep flagged offsets for staff inspection. The supplied detector handles one exact word/quotation convention and cannot establish that other promises are acceptable or unacceptable.