import-folds-probe.mjs (2869B)
1 // Packaged page, real canonical editor and actual selected compiler/runtime. 2 import {sourceEditor as editor,input,change,status,el,inspect,pause} from './source-probe-helpers.mjs'; 3 const assert=(ok,message)=>{if(!ok)throw Error(message);}; 4 export async function run(_control,backend='haskell-wasm'){ 5 await status('Ready'); 6 const catalog=await(await fetch(new URL('../reference/libraries.json',document.querySelector('script[type=module][src]').src))).json(); 7 const releases=catalog.releases; 8 const hash=name=>releases.find(row=>row.name==='tricu-lib-'+name&&row.version==='0.3.0').manifest; 9 const math=hash('native-math'),base=hash('base'); 10 const source=`-- λ🙂 canonical offsets\n!import ${math} as N\n!import ${base} as B\n!import ${math} as P\n!export answer\nanswer = N.add 40 2`; 11 document.querySelector('[data-compiler-example=identity]').click();input('source-editor',source);await status('Compiled'); 12 const widgets=()=>[...editor.dom.querySelectorAll('.import-hash')],full=()=>editor.dom.querySelectorAll('.import-hash-full').length; 13 assert(widgets().length===3&&widgets()[0].textContent===math.slice(0,3)+'...'+math.slice(-3),'Exact per-hash abbreviation'); 14 assert(editor.getSource()===source,'Compilation sees canonical source'); 15 let edits=0;const unsubscribe=editor.onChange(()=>edits++); 16 widgets()[0].click();assert(full()===1&&widgets().length===2,'Folded click places cursor on import'); 17 editor.view.contentDOM.blur();await pause(0);assert(full()===1,'Focus changes preserve cursor-line expansion'); 18 editor.select(source.indexOf(' as N')+4);assert(full()===1&&widgets().length===2,'Only cursor line reveals'); 19 editor.select(source.indexOf('!import'),source.indexOf('!import '+math+' as P'));assert(full()===1&&widgets().length===2,'Only selection head line reveals'); 20 editor.select(source.length);await pause(0);assert(widgets().length===3&&edits===0,'Presentation/selection preserves source and revision'); 21 editor.edit(0,0,`!import ${math} as Q\n`);editor.select(editor.getSource().length); 22 assert(widgets().length===4,'New import receives decoration');assert(editor.undo(),'Insertion undo');assert(editor.getSource()===source,'One undo restores entire canonical document'); 23 assert(editor.redo()&&widgets().length===4,'Redo preserves dynamic folding');assert(editor.undo()&&editor.getSource()===source,'Undo remains complete'); 24 await status('Compiled');assert(await inspect('answer','number')==='42','Actual compiler/runtime accepts full-hash imports'); 25 document.querySelector('[aria-label="Close definition inspection"]').click(); 26 editor.select(source.length);editor.view.contentDOM.blur();await pause(0);unsubscribe(); 27 return {checks:['per-line import hash folding; cursor placement; selection head; focus independence; immutable canonical source/revisions; dynamic import undo/redo; actual compiler/runtime'],source,math}; 28 }