minor
[sqlgg.git] / test.ml
blobd83ce769fc8485558497a7f580215fbb4b50ba51
2 open OUnit
3 open RA
4 open Sql.Type
5 open Stmt
7 let tt stmt scheme params =
8 let print_scheme = RA.Scheme.to_string in
9 let print_params = Stmt.params_to_string in
10 let (s1,p1,_) =
11 try
12 Parser.parse_stmt stmt
13 with
14 | _ -> assert_failure "parsing failed"
16 assert_equal ~printer:print_scheme scheme s1;
17 assert_equal ~printer:print_params params p1
19 let test () =
20 tt "CREATE TABLE test (id INT, str TEXT, name TEXT)"
22 [];
23 tt "SELECT str FROM test WHERE id=?"
24 [attr "str" Text]
25 [Next,Some Int];
26 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"
27 [attr "x" Text; attr "z" Int]
28 [Next,Some Int; Named "id", Some Int; Named "lim",Some Int; ];
29 tt "select test.name,other.name from test, test as other where test.id=other.id + @delta"
30 [attr "name" Text; attr "name" Text]
31 [Named "delta", Some Int];
32 tt "select test.name from test where test.id = @x + ? or test.id = @x - ?"
33 [attr "name" Text;]
34 [Named "x", Some Int; Next, Some Int; Named "x", Some Int; Next, Some Int;];
37 let run () =
38 let tests =
40 "test" >:: test ;
43 let test_suite = "main" >::: tests in
44 ignore (run_test_tt test_suite)