Set the decision and its input
The fictional memo literally contains {{total}}. The template also has its own total field of two. A one-pass substitution yields Note: {{total}}; Total: 2. Running total replacement again inside inserted memo text changes the user’s wording to Note: 2.
| Case | Input JSON |
|---|---|
| Base test | {"memo":"{{total}}","total":2} |
Run the supplied comparison
The code performs deterministic string interpolation. Supplied text is data; it is not permission for another template pass. There is no model, expression evaluator or provider action in this example.
| Path | Output JSON |
|---|---|
| Faulty path | {"output":"Note: 2; Total: 2"} |
| Required path | {"output":"Note: {{total}}; Total: 2"} |
import assert from 'node:assert/strict';
const run=function run(i,corrected=true){
if(typeof i.memo!=='string'||i.total===null)return {held:true};
const source='Note: {{memo}}; Total: {{total}}';
const output=corrected?source.replace(/\{\{(memo|total)\}\}/g,(_,key)=>String(i[key])):source.replace('{{memo}}',i.memo).replace(/\{\{total\}\}/g,String(i.total));
return {output};
};
const cases=[{"input":{"memo":"{{total}}","total":2},"corrected":false,"expected":{"output":"Note: 2; Total: 2"}},{"input":{"memo":"{{total}}","total":2},"corrected":true,"expected":{"output":"Note: {{total}}; Total: 2"}},{"input":{"memo":"Ada","total":0},"corrected":true,"expected":{"output":"Note: Ada; Total: 0"}},{"input":{"memo":"A","total":null},"corrected":true,"expected":{"held":true}}];
for(const test of cases){const actual=await run(test.input,test.corrected);assert.deepEqual(actual,test.expected);console.log(actual);}
Choose from the boundary evidence
Ordinary Ada text remains Ada and zero total remains zero. Missing required total is held rather than replaced with a guessed blank or amount.
- Identify original template slots
- Insert values in one pass
- Compare preserved field text
Hold a missing required value; do not run inserted text as another template.
| Condition | Input JSON | Expected output JSON |
|---|---|---|
| ordinary memo | {"memo":"Ada","total":0} | {"output":"Note: Ada; Total: 0"} |
| required value unknown | {"memo":"A","total":null} | {"held":true} |
May the memo’s {{total}} become 2 in the base document?
Show the worked answer
No. It is the supplied memo text. Only the original template’s total field becomes 2; the memo keeps its braces.