aboutsummaryrefslogtreecommitdiff
path: root/ext/wasm/SQLTester/SQLTester.run.mjs
blob: 36d1ab5dcd878cc3a0e51d758d8ee7f20b83601e (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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
import {default as ns} from './SQLTester.mjs';

globalThis.sqlite3 = ns.sqlite3;
const log = function f(...args){
  console.log('SQLTester.run:',...args);
  return f;
};

const out = function f(...args){ return f.outer.out(...args) };
out.outer = new ns.Outer();
out.outer.getOutputPrefix = ()=>'SQLTester.run: ';
const outln = (...args)=>{ return out.outer.outln(...args) };

const affirm = function(expr, msg){
  if( !expr ){
    throw new Error(arguments[1]
                    ? ("Assertion failed: "+arguments[1])
                    : "Assertion failed");
  }
}

console.log("Loaded",ns);

log("ns =",ns);
out("Hi there. ").outln("SQLTester is ostensibly ready.");

let ts = new ns.TestScript('/foo.test', ns.Util.utf8Encode(
`
--close all
--oom
--db 0
--new my.db
--null zilch
--testcase 1.0
SELECT 1, null;
--result 1 zilch
--glob *zil*
--notglob *ZIL*
SELECT 1, 2;
intentional error;
--run
--testcase json-1
SELECT json_array(1,2,3)
--json [1,2,3]
--testcase tableresult-1
  select 1, 'a';
  select 2, 'b';
--tableresult
  # [a-z]
  2 b
--end
--testcase json-block-1
  select json_array(1,2,3);
  select json_object('a',1,'b',2);
--json-block
  [1,2,3]
  {"a":1,"b":2}
--end
--testcase col-names-on
--column-names 1
  select 1 as 'a', 2 as 'b';
--result a 1 b 2
--testcase col-names-off
--column-names 0
  select 1 as 'a', 2 as 'b';
--result 1 2
--close
`));

const sqt = new ns.SQLTester();
try{
  log( 'sqt.getCurrentDb()', sqt.getCurrentDb() );
  sqt.openDb('/foo.db', true);
  log( 'sqt.getCurrentDb()', sqt.getCurrentDb() );
  sqt.verbosity(0);
  affirm( 'zilch' !== sqt.nullValue() );
  ts.run(sqt);
  affirm( 'zilch' === sqt.nullValue() );
}finally{
  sqt.reset();
}
log( 'sqt.getCurrentDb()', sqt.getCurrentDb() );
log( "Metrics:", sqt.metrics );