diff options
| author | Marshall Lochbaum <mwlochbaum@gmail.com> | 2021-01-30 20:22:47 -0500 |
|---|---|---|
| committer | Marshall Lochbaum <mwlochbaum@gmail.com> | 2021-01-30 20:22:47 -0500 |
| commit | 99f37de695119fd643b36f373771bcdcc4a626af (patch) | |
| tree | d30db1ea6cfe1dda0685b271f124f968d5accae5 /test/js | |
| parent | 5ecf5494573e7c4f554329646edf072e2bd6cb7c (diff) | |
Move direct command-line execution from test/js to docs/bqn.js
Diffstat (limited to 'test/js')
| -rwxr-xr-x | test/js | 41 |
1 files changed, 15 insertions, 26 deletions
@@ -6,31 +6,20 @@ let cases = f=>read(__dirname+'/cases/'+f+'.bqn','utf8').split('\n') .filter(x=>x.length>0 && x.charAt(0)!=='#') .map(x=>x.indexOf('%')===-1?[1,x]:x.split(' % ')); let args = process.argv.slice(2); -let onfiles = args[0]==='--'; -let files = onfiles ? args.slice(1) : ['simple','syntax']; +let files = args.length ? args : ['simple','syntax']; -if (onfiles || args.length==0) { - let t = [].concat.apply([],files.map(cases)); - let test = t.map(e=>e[1]); - let expt = t.map(e=>e[0]==='!'?null:+e[0]); +let t = [].concat.apply([],files.map(cases)); +let test = t.map(e=>e[1]); +let expt = t.map(e=>e[0]==='!'?null:+e[0]); - let rslt = test.map(t => {try{return bqn(t);}catch(e){return null;}}); - let pass = rslt.map((r,i)=>r===expt[i]); - let fail = pass.map((p,i)=>p?-1:i).filter(i=>i>=0); - console.log( - fail.length - ? fail.map(i=>'"'+test[i]+'": expected ' - +(e=>e===null?'to fail':e)(expt[i]) - +' but ' - +(r=>r===null?'evaluation failed':'received '+r)(rslt[i])) - : "All "+test.length+" passed!" - ); -} else { - args.map(a=>{ - try { - console.log(bqn.fmt(bqn(a))) - } catch(e) { - console.error('[31m'+bqn.fmtErr(Array.from(a),e)+'[39m'); - } - }); -} +let rslt = test.map(t => {try{return bqn(t);}catch(e){return null;}}); +let pass = rslt.map((r,i)=>r===expt[i]); +let fail = pass.map((p,i)=>p?-1:i).filter(i=>i>=0); +console.log( + fail.length + ? fail.map(i=>'"'+test[i]+'": expected ' + +(e=>e===null?'to fail':e)(expt[i]) + +' but ' + +(r=>r===null?'evaluation failed':'received '+r)(rslt[i])) + : "All "+test.length+" passed!" +); |
