Skip to content
Astera Technology

Wrap a long receipt reference without clipping it

Preserve the complete token under an explicit character-cell contract.

Download complete case notes and answer keys ↓

Set the decision and its input

This synthetic receipt permits twenty ASCII character cells per line and allows a long reference to break after every twentieth character. The25-character A…Y reference must render as a20-character line plus UVWXY. Clipping to one line loses the last five characters.

Filled local test worksheet
CaseInput JSON
Base test{"cells":20,"reference":"ABCDEFGHIJKLMNOPQRSTUVWXY"}
Download editable CSV ↓

Run the supplied comparison

The program generates a PDF and extracts its actual reference lines, comparing their joined text with the source. The cell limit is an original contract, not a statement that real glyphs or printers all have equal physical widths.

Faulty and required outputs
PathOutput JSON
Faulty path{"lines":["ABCDEFGHIJKLMNOPQRST"],"complete":false}
Required path{"lines":["ABCDEFGHIJKLMNOPQRST","UVWXY"],"complete":true}
Download editable CSV ↓
Node24.14.1 programme; Playwright1.63 Chromium and PDF.js6.4.299 required
import assert from 'node:assert/strict';
const smallWhole=(x,max)=>Number.isSafeInteger(x)&&x>=0&&x<=max;
import {createRequire} from 'node:module';
import {pathToFileURL} from 'node:url';
const htmlEscape=s=>String(s).replace(/&/g,'&amp;').replace(/</g,'&lt;').replace(/>/g,'&gt;').replace(/"/g,'&quot;');
async function withPage(action,options={}){
  const require=createRequire(import.meta.url);const {chromium}=require('playwright');
  const browser=await chromium.launch({headless:true});
  try{const context=await browser.newContext(options);const page=await context.newPage();
    const requests=[];await page.route('**/*',route=>{requests.push(route.request().url());return route.abort();});
    return await action(page,context,requests);
  }finally{await browser.close();}
}
async function pdfObservation(html){
  const bytes=await withPage(async page=>{await page.setContent(html);return page.pdf({preferCSSPageSize:true,printBackground:true});});
  const require=createRequire(import.meta.url);
  const {getDocument}=await import(pathToFileURL(require.resolve('pdfjs-dist/legacy/build/pdf.mjs')).href);
  const loadingTask=getDocument({data:Uint8Array.from(bytes),useSystemFonts:true,disableFontFace:true});
  try{const document=await loadingTask.promise;const pages=[];for(let n=1;n<=document.numPages;n++){
    const page=await document.getPage(n);const content=await page.getTextContent();
    pages.push(content.items.filter(x=>typeof x.str==='string'&&x.str).map(x=>({text:x.str,x:x.transform[4],y:x.transform[5]})));
  }return {pageCount:document.numPages,pages};}finally{await loadingTask.destroy();}
}
const printStyle='<style>@page{size:100mm 100mm;margin:10mm}body{margin:0;font:10px Arial}p{margin:0}</style>';

const run=async function run(i,corrected=true){
    if(!smallWhole(i.cells,20)||i.cells<1||typeof i.reference!=='string'||!/^[\x21-\x7E]{1,40}$/.test(i.reference))return {held:true};
    const lines=corrected?Array.from({length:Math.ceil(i.reference.length/i.cells)},(_,n)=>i.reference.slice(n*i.cells,(n+1)*i.cells)):[i.reference.slice(0,i.cells)];
    const out=await pdfObservation(printStyle+'<pre style="margin:0;font:10px Courier;line-height:5mm">'+htmlEscape(lines.join('\n'))+'</pre>');
    const extracted=out.pages.flat().map(x=>x.text);return {lines:extracted,complete:extracted.join('')===i.reference};
  };
const cases=[{"input":{"cells":20,"reference":"ABCDEFGHIJKLMNOPQRSTUVWXY"},"corrected":false,"expected":{"lines":["ABCDEFGHIJKLMNOPQRST"],"complete":false}},{"input":{"cells":20,"reference":"ABCDEFGHIJKLMNOPQRSTUVWXY"},"corrected":true,"expected":{"lines":["ABCDEFGHIJKLMNOPQRST","UVWXY"],"complete":true}},{"input":{"cells":20,"reference":"ABCDEFGHIJKLMNOPQRST"},"corrected":true,"expected":{"lines":["ABCDEFGHIJKLMNOPQRST"],"complete":true}},{"input":{"cells":null,"reference":"A"},"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);}
Download runnable example ↓

Choose from the boundary evidence

Exactly twenty characters remain one complete line. Unknown cell allowance is held before producing the receipt.

  1. Read the supplied cell contract
  2. Wrap without deleting characters
  3. Extract and reconstruct the reference

A physical printer’s raster or glyph-width policy must be supplied separately.

Editable boundary inputs and outputs
ConditionInput JSONExpected output JSON
exact twenty-cell reference{"cells":20,"reference":"ABCDEFGHIJKLMNOPQRST"}{"lines":["ABCDEFGHIJKLMNOPQRST"],"complete":true}
cell allowance not supplied{"cells":null,"reference":"A"}{"held":true}
Download editable CSV ↓

Which second line is required in the base case?

Show the worked answer

UVWXY. The first line is ABCDEFGHIJKLMNOPQRST; joining both reproduces all25 source characters.

Example files

Related resources