fix pos_cnum
[sqlgg.git] / test.ml
blob0ac8727178865df4402838f39765f35fe5e07ca3
2 open OUnit
3 open RA
4 open Sql.Type
5 open Stmt
7 (*
8 CREATE TABLE test (id INTEGER PRIMARY KEY AUTOINCREMENT,name TEXT,descr TEXT);
9 -- [sql2cpp] name=select_all
10 SELECT * FROM test;
11 SELECT name,descr FROM test;
14 let tt stmt scheme params =
15 let print_scheme = RA.Scheme.to_string in
16 let print_params = Stmt.params_to_string in
17 let (s1,p1,_) =
18 try
19 Parser.parse_stmt stmt
20 with
21 | _ -> assert_failure "parsing failed"
23 assert_equal ~printer:print_scheme scheme s1;
24 assert_equal ~printer:print_params params p1
26 let test () =
27 tt "CREATE TABLE test (id INT, str TEXT, name TEXT)"
29 [];
30 tt "SELECT str FROM test WHERE id=?"
31 [attr "str" Text]
32 [Next,Some Int];
33 tt "SELECT x,y+? AS z FROM (SELECT id AS y,CONCAT(str,name) AS x FROM test WHERE id=@id*2) ORDER BY x,x+y LIMIT @lim"
34 [attr "x" Text; attr "z" Int]
35 [Next,Some Int; Named "id", Some Int; Named "lim",Some Int; ];
36 tt "select test.name,other.name from test, test as other where test.id=other.id + @delta"
37 [attr "name" Text; attr "name" Text]
38 [Named "delta", Some Int];
41 let run () =
42 let tests =
44 "test" >:: test ;
47 let test_suite = "main" >::: tests in
48 ignore (run_test_tt test_suite)