aboutsummaryrefslogtreecommitdiff
path: root/test/js
blob: 3f1bccedbe774f8189734b569986585a6197fd73 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
#! /usr/bin/env node

let bqn = require(__dirname+'/../docs/bqn.js');
let read = require('fs').readFileSync;
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'];

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 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 {
  console.log(args.map(bqn));
}