(*--------------------------------------------------------------------------- Copyright (c) 2026 Thomas Gazagnaire. All rights reserved. SPDX-License-Identifier: ISC ---------------------------------------------------------------------------*) module Ast = Sql.Ast let parse sql = match Sql.Private.Lexer.parse_statements sql with | Ok stmts -> stmts | Error e -> Fmt.failwith "parse error in %S: %s" sql e let test_desc_is_a_column_reference () = let col q name sql = match parse sql with | [ Ast.Select { cols = [ { expr; _ } ]; _ } ] -> Alcotest.(check bool) sql true (Ast.equal_expr expr (Ast.Col (q, name))) | _ -> Alcotest.failf "not a single-column SELECT: %s" sql in col None "desc" "SELECT desc FROM t"; col (Some "t") "desc" "SELECT t.desc FROM t"; col None "desc" "SELECT desc FROM pragma_index_xinfo('i')"; (* the direction still parses after the name, and after the name alone *) let direction sql expected = match parse sql with | [ Ast.Select { order_by = [ (key, dir) ]; _ } ] -> Alcotest.(check bool) (sql ^ ": key") true (Ast.equal_expr key (Ast.Col (None, "desc"))); Alcotest.(check bool) sql expected (dir = Ast.Desc) | _ -> Alcotest.failf "not a one-key ORDER BY: %s" sql in direction "SELECT desc FROM t ORDER BY desc" false; direction "SELECT desc FROM t ORDER BY desc DESC" true (* [sql] does not parse, as it does not parse in sqlite3. *) let refuses sql = match Sql.Private.Lexer.parse_statements sql with | Error _ -> () | Ok _ -> Alcotest.failf "%S parsed; expected a syntax error" sql let test_a_pragma_value_is_a_bare_keyword () = let takes sql word = match parse sql with | [ Ast.Pragma { value = Some v; _ } ] -> Alcotest.(check bool) sql true (v = Ast.Name word) | _ -> Alcotest.failf "not a PRAGMA with a value: %s" sql in takes "PRAGMA journal_mode=delete" "delete"; takes "PRAGMA journal_mode(delete)" "delete"; takes "PRAGMA temp_store=default" "default"; takes "PRAGMA synchronous=full" "full"; takes "PRAGMA locking_mode=exclusive" "exclusive"; takes "PRAGMA journal_mode=row" "row"; takes "PRAGMA journal_mode=cast" "cast"; takes "PRAGMA journal_mode=unbounded" "unbounded"; takes "PRAGMA journal_mode=column" "column"; takes "PRAGMA journal_mode=current_timestamp" "current_timestamp"; (* the words already taken, which stay taken *) takes "PRAGMA journal_mode=wal" "wal"; takes "PRAGMA foreign_keys=on" "on"; (* names to sqlite3's tokenizer, keywords to this one *) takes "PRAGMA foreign_keys=true" "true"; takes "PRAGMA foreign_keys=FALSE" "FALSE"; refuses "PRAGMA journal_mode=select"; refuses "PRAGMA journal_mode=from"; refuses "PRAGMA journal_mode=not" let test_a_pragma_value_is_a_signed_number () = let takes sql v = match parse sql with | [ Ast.Pragma { value = Some got; _ } ] -> Alcotest.(check bool) sql true (got = v) | _ -> Alcotest.failf "not a PRAGMA with a value: %s" sql in (* sqlite3 hands the pragma the token's text, with "-%T" for a minus_num and a plus_num's token alone (src/parse.y, src/pragma.c) *) takes "PRAGMA journal_mode=-1" (Ast.Num "-1"); takes "PRAGMA cache_size=-2000" (Ast.Num "-2000"); takes "PRAGMA cache_size(-2000)" (Ast.Num "-2000"); takes "PRAGMA cache_size=+2000" (Ast.Num "2000"); takes "PRAGMA journal_mode=-1.5" (Ast.Num "-1.5"); takes "PRAGMA user_version=1e3" (Ast.Num "1e3"); takes "PRAGMA cache_size=0x10" (Ast.Num "0x10"); (* the unsigned forms already taken, which stay taken *) takes "PRAGMA journal_mode=1" (Ast.Num "1"); takes "PRAGMA journal_mode='wal'" (Ast.Name "wal"); (* NULL and a blob are no PRAGMA value *) refuses "PRAGMA journal_mode=NULL"; refuses "PRAGMA journal_mode=null"; refuses "PRAGMA journal_mode=x'00'"; refuses "PRAGMA journal_mode=X'00'"; refuses "PRAGMA journal_mode(NULL)"; refuses "PRAGMA journal_mode(x'00')"; (* and the sign is a number's, not the position's *) refuses "PRAGMA journal_mode=-wal"; refuses "PRAGMA journal_mode=-'wal'" let test_a_bare_default_is_a_string () = let default sql expected = match parse sql with | [ Ast.Create_table { defaults = [ (col, d) ]; _ } ] -> Alcotest.(check string) (sql ^ ": column") "b" col; Alcotest.(check bool) sql true (Ast.equal_expr d.expr expected) | _ -> Alcotest.failf "not a CREATE TABLE with one default: %s" sql in let text s = Ast.Lit (Catalog.Value.Text s) in default "CREATE TABLE t(a, b DEFAULT c)" (text "c"); default "CREATE TABLE t(a, b DEFAULT asc)" (text "asc"); default "CREATE TABLE t(a, b DEFAULT unbounded)" (text "unbounded"); default "CREATE TABLE t(a, b DEFAULT cast)" (text "cast"); default "CREATE TABLE t(a, b DEFAULT row)" (text "row"); (* the clause is still read left to right, so what follows it is the column's own, not part of the default *) default "CREATE TABLE t(a, b TEXT DEFAULT c NOT NULL)" (text "c"); (* a literal still wins where one is written: NULL is a [term] *) default "CREATE TABLE t(a, b DEFAULT null)" (Ast.Lit Catalog.Value.Null); default "CREATE TABLE t(a, b DEFAULT 'c')" (text "c"); refuses "CREATE TABLE t(a, b DEFAULT select)"; (* and ADD COLUMN takes the same clause *) match parse "ALTER TABLE t ADD COLUMN d DEFAULT e" with | [ Ast.Alter_table { op = Add_column { column = { col_default = Some d; _ }; _ }; _ }; ] -> Alcotest.(check bool) "ADD COLUMN" true (Ast.equal_expr d.expr (text "e")) | _ -> Alcotest.fail "not an ADD COLUMN with a default" let test_a_keyword_names_a_written_column () = let assigns sql cols = match parse sql with | [ Ast.Update { sets; _ } ] -> Alcotest.(check (list string)) sql cols (List.map fst sets) | _ -> Alcotest.failf "not an UPDATE: %s" sql in let inserts sql cols = match parse sql with | [ Ast.Insert { columns; _ } ] -> Alcotest.(check (list string)) sql cols columns | _ -> Alcotest.failf "not an INSERT: %s" sql in List.iter (fun w -> assigns (Fmt.str "UPDATE t SET %s = 1" w) [ w ]; inserts (Fmt.str "INSERT INTO t(%s) VALUES(1)" w) [ w ]) [ "row"; "rows"; "desc"; "asc"; "key"; "cast"; "unbounded"; "column"; "action"; "current_timestamp"; "with"; "replace"; ]; assigns "UPDATE t SET row = 1, desc = 2" [ "row"; "desc" ]; inserts "INSERT INTO t(row, desc) VALUES(1, 2)" [ "row"; "desc" ]; (* the upsert names the same two positions *) (match parse "INSERT INTO t(row) VALUES(1) ON CONFLICT(row) DO UPDATE SET row = 2" with | [ Ast.Insert { upsert = Some { target; action = Update (sets, _); _ }; _ } ] -> Alcotest.(check (list string)) "conflict target" [ "row" ] target; Alcotest.(check (list string)) "upsert assignment" [ "row" ] (List.map fst sets) | _ -> Alcotest.fail "not an INSERT with a DO UPDATE upsert"); (* and so does a foreign key's column list *) (match parse "CREATE TABLE t(a, FOREIGN KEY(row) REFERENCES u(row))" with | [ Ast.Create_table { foreign_keys = [ fk ]; _ } ] -> Alcotest.(check (list string)) "child columns" [ "row" ] fk.cols; Alcotest.(check (list string)) "parent columns" [ "row" ] fk.parent_cols | _ -> Alcotest.fail "not a CREATE TABLE with one foreign key"); refuses "UPDATE t SET select = 1"; refuses "INSERT INTO t(select) VALUES(1)" let test_a_keyword_names_an_object () = let created sql name = match parse sql with | [ Ast.Create_table { tbl_name; _ } ] -> Alcotest.(check string) sql name tbl_name | _ -> Alcotest.failf "not a CREATE TABLE: %s" sql in let indexed sql name table = match parse sql with | [ Ast.Create_index i ] -> Alcotest.(check string) (sql ^ ": index") name i.name; Alcotest.(check string) (sql ^ ": table") table i.table | _ -> Alcotest.failf "not a CREATE INDEX: %s" sql in let renamed sql old_name new_name = match parse sql with | [ Ast.Alter_table { op = Rename_column (o, n); _ } ] -> Alcotest.(check string) (sql ^ ": old") old_name o; Alcotest.(check string) (sql ^ ": new") new_name n | _ -> Alcotest.failf "not a RENAME COLUMN: %s" sql in let dropped sql name = match parse sql with | [ Ast.Drop { schema = None; object_ = Table; name = n; if_exists = false }; ] -> Alcotest.(check string) sql name n | _ -> Alcotest.failf "not a DROP TABLE: %s" sql in let triggered sql name table = match parse sql with | [ Ast.Create_trigger tg ] -> Alcotest.(check string) (sql ^ ": trigger") name tg.name; Alcotest.(check string) (sql ^ ": table") table tg.table | _ -> Alcotest.failf "not a CREATE TRIGGER: %s" sql in let inserted sql table = match parse sql with | [ Ast.Insert { table = t; _ } ] -> Alcotest.(check string) sql table t | _ -> Alcotest.failf "not an INSERT: %s" sql in let scanned sql name = match parse sql with | [ Ast.Select { from = Table tr; _ } ] -> Alcotest.(check string) sql name tr.name | _ -> Alcotest.failf "not a SELECT over one named table: %s" sql in (* parse.y's [%fallback ID] lists DEFERRED, IMMEDIATE and EXCLUSIVE: the transaction types BEGIN takes name objects too *) List.iter (fun w -> created (Fmt.str "CREATE TABLE %s(a)" w) w; indexed (Fmt.str "CREATE INDEX %s ON t(a)" w) w "t"; indexed (Fmt.str "CREATE INDEX i ON %s(a)" w) "i" w; renamed (Fmt.str "ALTER TABLE t RENAME COLUMN a TO %s" w) "a" w; dropped (Fmt.str "DROP TABLE %s" w) w; triggered (Fmt.str "CREATE TRIGGER %s AFTER INSERT ON t BEGIN SELECT 1; END" w) w "t"; inserted (Fmt.str "INSERT INTO %s VALUES (1)" w) w; scanned (Fmt.str "SELECT * FROM %s" w) w) [ "row"; "after"; "replace"; "deferred"; "immediate"; "exclusive" ]; (* the table a trigger guards is the same position, and so is a rename's target: an object created under the word is reachable under it *) triggered "CREATE TRIGGER g AFTER INSERT ON row BEGIN SELECT 1; END" "g" "row"; (match parse "ALTER TABLE row RENAME TO after" with | [ Ast.Alter_table { table; op = Rename_table n } ] -> Alcotest.(check string) "ALTER TABLE: table" "row" table; Alcotest.(check string) "RENAME TO: new name" "after" n | _ -> Alcotest.fail "not an ALTER TABLE ... RENAME TO"); (* a reserved word names no object, here as there *) refuses "CREATE TABLE select(a)"; refuses "CREATE TABLE from(a)"; refuses "CREATE INDEX select ON t(a)"; refuses "SELECT * FROM select" (* lang_transaction.html: [BEGIN [DEFERRED | IMMEDIATE | EXCLUSIVE] [TRANSACTION]]; parse.y, [cmd ::= BEGIN transtype trans_opt]. Each form is one statement, and keywords are case-insensitive (lang_keywords.html). *) let test_begin_takes_a_transaction_type () = let one sql = match parse sql with | [ _ ] -> () | _ -> Alcotest.failf "not one statement: %s" sql in List.iter (fun ty -> List.iter one [ Fmt.str "BEGIN %s" ty; Fmt.str "BEGIN %s TRANSACTION" ty; Fmt.str "begin %s" (String.lowercase_ascii ty); Fmt.str "begin %s transaction" (String.lowercase_ascii ty); ]) [ "DEFERRED"; "IMMEDIATE"; "EXCLUSIVE" ]; List.iter one [ "BEGIN"; "BEGIN TRANSACTION"; "begin"; "begin transaction" ] (* parse.y: [transtype] is one optional token of DEFERRED, IMMEDIATE and EXCLUSIVE; sqlite3 refuses any other word there, and two of them. *) let test_begin_refuses_another_transaction_type () = refuses "BEGIN SOON"; refuses "begin soon"; refuses "BEGIN SOON TRANSACTION"; refuses "BEGIN DEFERRED IMMEDIATE"; refuses "BEGIN IMMEDIATE EXCLUSIVE TRANSACTION" (* parse.y: [transtype ::= .] is [TK_DEFERRED], and each of DEFERRED, IMMEDIATE and EXCLUSIVE is its own [transtype]: three statements, and a plain BEGIN is BEGIN DEFERRED. *) let test_begin_names_its_transaction_type () = let begins sql = match parse sql with | [ Ast.Begin Ast.Deferred ] -> "DEFERRED" | [ Ast.Begin Ast.Immediate ] -> "IMMEDIATE" | [ Ast.Begin Ast.Exclusive ] -> "EXCLUSIVE" | _ -> Alcotest.failf "not one BEGIN: %s" sql in let is expected sql = Alcotest.(check string) sql expected (begins sql) in List.iter (is "DEFERRED") [ "BEGIN"; "BEGIN TRANSACTION"; "BEGIN DEFERRED"; "BEGIN DEFERRED TRANSACTION"; "begin deferred"; ]; List.iter (is "IMMEDIATE") [ "BEGIN IMMEDIATE"; "BEGIN IMMEDIATE TRANSACTION"; "begin immediate" ]; List.iter (is "EXCLUSIVE") [ "BEGIN EXCLUSIVE"; "BEGIN EXCLUSIVE TRANSACTION"; "begin exclusive" ] (* After a column's type, only constraints (parse.y, [carglist ::= carglist ccons]): a DEFAULT takes a literal, a signed term, a word or a parenthesised expression, and the first token no constraint begins or continues is the syntax error. The type ends at its parenthesised size. A constraint the column ends inside of is refused at the token after it. Each answer is sqlite3 3.54.1's for CREATE TABLE t(): $ sqlite3 :memory: 'CREATE TABLE t(a DEFAULT 1 + 1)' Parse error in 2nd command line argument: near "+": syntax error *) let test_a_column_holds_only_constraints () = let answer column = match Fmt.kstr Sql.Private.Lexer.parse_statements "CREATE TABLE t(%s)" column with | Ok _ -> "ok" | Error e -> e in List.iter (fun (column, want) -> Alcotest.(check string) column want (answer column)) [ ("a DEFAULT current_date IS NOT NULL", {|near "IS": syntax error|}); ("a DEFAULT 1 + 1", {|near "+": syntax error|}); ("a DEFAULT 1 2", {|near "2": syntax error|}); ("a DEFAULT x y", {|near "y": syntax error|}); ("a DEFAULT 1 asc", {|near "asc": syntax error|}); ("a INT NOT NULL + 1", {|near "+": syntax error|}); ("a INT PRIMARY KEY foo", {|near "foo": syntax error|}); ("a INT CONSTRAINT", {|near ")": syntax error|}); ("a INT NOT", {|near ")": syntax error|}); ("a INT PRIMARY", {|near ")": syntax error|}); ("a INT PRIMARY KEY ON", {|near ")": syntax error|}); ("a INT PRIMARY KEY ON CONFLICT", {|near ")": syntax error|}); ("a INT PRIMARY KEY ON CONFLICT bogus", {|near "bogus": syntax error|}); ("a INT PRIMARY KEY ASC ASC", {|near "ASC": syntax error|}); ("a INT COLLATE", {|near ")": syntax error|}); ("a INT COLLATE nocase nocase", {|near "nocase": syntax error|}); ("a INT DEFERRABLE INITIALLY", {|near ")": syntax error|}); ("a INT NOT DEFERRABLE foo", {|near "foo": syntax error|}); ("a b c (1) d", {|near "d": syntax error|}); ("a b(1) c", {|near "c": syntax error|}); ("a (1)", {|near "(": syntax error|}); ("a varchar 10", {|near "10": syntax error|}); ("a INT ON DELETE CASCADE", {|near "ON": syntax error|}); ("a INT CHECK (a > 0) + 1", {|near "+": syntax error|}); ("a INT REFERENCES p(x) foo", {|near "foo": syntax error|}); ("a DEFAULT -1 CHECK (a > 0)", "ok"); ("a DEFAULT 'x' NOT NULL UNIQUE", "ok"); ("a DEFAULT 1 COLLATE nocase", "ok"); ("a DEFAULT (1 + 1) NOT NULL", "ok"); ("a INTEGER PRIMARY KEY DESC ON CONFLICT REPLACE", "ok"); ("a INTEGER PRIMARY KEY AUTOINCREMENT", "ok"); ("a INT NOT NULL ON CONFLICT ABORT UNIQUE ON CONFLICT FAIL", "ok"); ("a INT NULL ON CONFLICT IGNORE", "ok"); ("a INT CONSTRAINT c1 NOT NULL CONSTRAINT c2 CHECK (a > 0)", "ok"); ("a INT REFERENCES p", "ok"); ( "a INT REFERENCES p(x) ON DELETE CASCADE ON UPDATE SET NULL MATCH simple", "ok" ); ("a INT REFERENCES p NOT DEFERRABLE INITIALLY DEFERRED", "ok"); ("a INT REFERENCES p DEFERRABLE INITIALLY IMMEDIATE", "ok"); ("a INT DEFERRABLE", "ok"); ("a b(1, 2)", "ok"); ("a 'text'", "ok"); ("a \"my type\" NOT NULL", "ok"); ("a INT UNIQUE UNIQUE", "ok"); ("a INT KEY", "ok"); ("a INT UNIQUE ON CONFLICT REPLACE NOT NULL", "ok"); ("a INT GENERATED ALWAYS AS (1) VIRTUAL, b", "ok"); ("a INT AS (1) STORED NOT NULL, b", "ok"); ] (* A column's type is parse.y's [typetoken]: [typename] is one or more [ids], an identifier or a string, where only the %fallback keywords stand as identifiers, and a size in parentheses is one or two [signed] numbers. A [MATCH] after [REFERENCES] takes an [nm], which also admits the join keywords ([idj]). Each answer is sqlite3 3.54.1's for CREATE TABLE t(): $ sqlite3 :memory: 'CREATE TABLE t(a select)' Parse error in 2nd command line argument: near "select": syntax error *) let test_a_column_type_and_match_name () = let answer column = match Fmt.kstr Sql.Private.Lexer.parse_statements "CREATE TABLE t(%s)" column with | Ok _ -> "ok" | Error e -> e in List.iter (fun (column, want) -> Alcotest.(check string) column want (answer column)) [ ("a select", {|near "select": syntax error|}); ("a + 1", {|near "+": syntax error|}); ("a INT from", {|near "from": syntax error|}); ("a INT exists", {|near "exists": syntax error|}); ("a autoincrement", {|near "autoincrement": syntax error|}); ("a on", {|near "on": syntax error|}); ("a b.c", {|near ".": syntax error|}); ("a full", {|near "full": syntax error|}); ("a natural", {|near "natural": syntax error|}); ("a -1", {|near "-": syntax error|}); ("a DECIMAL(abc)", {|near "abc": syntax error|}); ("a DECIMAL(1,2,3)", {|near ",": syntax error|}); ("a DECIMAL('1')", {|near "'1'": syntax error|}); ("a DECIMAL(())", {|near "(": syntax error|}); ("a DECIMAL()", {|near ")": syntax error|}); ("a INT REFERENCES p MATCH select", {|near "select": syntax error|}); ("a INT REFERENCES p MATCH join", {|near "join": syntax error|}); ("a INT COLLATE full", {|near "full": syntax error|}); ("a DECIMAL(+1, -2)", "ok"); ("a DECIMAL(- 1)", "ok"); ("a DECIMAL(1.5e3, 0x10)", "ok"); ("a by", "ok"); ("a like", "ok"); ("a match", "ok"); ("a key", "ok"); ("a 'x' 'y'", "ok"); ("a INT REFERENCES p MATCH full", "ok"); ("a INT REFERENCES p MATCH NATURAL", "ok"); ("a INT REFERENCES p MATCH right", "ok"); ("a INT REFERENCES p MATCH cross", "ok"); ("a INT REFERENCES p MATCH inner", "ok"); ("a INT REFERENCES p MATCH 'x'", "ok"); ("a INT REFERENCES p MATCH full NOT NULL", "ok"); ("a INT CONSTRAINT full NOT NULL", "ok"); ("a INT CONSTRAINT 'c' NOT NULL", "ok"); ("a INT COLLATE 'nocase'", "ok"); ] (* A frame may not end before it starts, and a RANGE offset measures along exactly one ORDER BY term; both are refused as the statement is prepared (window.c, sqlite3WindowAlloc and sqlite3WindowUpdate). UNBOUNDED FOLLOWING cannot start a frame nor UNBOUNDED PRECEDING end one (parse.y, frame_bound_s and frame_bound_e). Each answer is sqlite3 3.54.1's. *) let test_frame_shapes () = let answer over = match Fmt.kstr Sql.Private.Lexer.parse_statements "SELECT count(*) OVER (%s) FROM t" over with | Ok _ -> "ok" | Error e -> e in let unsupported = "unsupported frame specification" and range = "RANGE with offset PRECEDING/FOLLOWING requires one ORDER BY expression" in List.iter (fun (over, want) -> Alcotest.(check string) over want (answer over)) [ ("ORDER BY x ROWS BETWEEN CURRENT ROW AND 1 PRECEDING", unsupported); ("ORDER BY x ROWS BETWEEN 1 FOLLOWING AND CURRENT ROW", unsupported); ("ORDER BY x ROWS BETWEEN 1 FOLLOWING AND 1 PRECEDING", unsupported); ("ORDER BY x ROWS 1 FOLLOWING", unsupported); ("ORDER BY x RANGE BETWEEN 1 FOLLOWING AND 1 PRECEDING", unsupported); ("ORDER BY x, y RANGE 1 PRECEDING", range); ("RANGE 1 PRECEDING", range); ("RANGE BETWEEN CURRENT ROW AND 1 FOLLOWING", range); ( "ORDER BY x ROWS BETWEEN UNBOUNDED FOLLOWING AND CURRENT ROW", {|near "FOLLOWING": syntax error|} ); ( "ORDER BY x ROWS BETWEEN CURRENT ROW AND UNBOUNDED PRECEDING", {|near "PRECEDING": syntax error|} ); ("ORDER BY x ROWS UNBOUNDED FOLLOWING", {|near "FOLLOWING": syntax error|}); ("ORDER BY x ROWS BETWEEN 2 FOLLOWING AND 1 FOLLOWING", "ok"); ("ORDER BY x RANGE BETWEEN 2 PRECEDING AND 1 PRECEDING", "ok"); ( "ORDER BY x RANGE BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING", "ok" ); ("RANGE BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW", "ok"); ("ORDER BY x, y ROWS 1 PRECEDING", "ok"); ] (* sqlite3 hands a pragma its argument token's text (sqlite3Atoi reads 1e3 as 1): a minus is part of the number, a plus is not. *) let test_a_pragma_argument_is_its_text () = match parse "PRAGMA cache_size=-0x10; PRAGMA cache_size=+1e3" with | [ Ast.Pragma a; Ast.Pragma b ] -> Alcotest.(check (pair (option string) (option string))) "as spelled" (Some "-0x10", Some "1e3") (Option.map Ast.pragma_text a.value, Option.map Ast.pragma_text b.value) | _ -> Alcotest.fail "two pragmas" (* A join keeps the ON it was written with, and a CROSS JOIN its own type (parse.y, on_using; optoverview.html#crossjoin). *) let test_a_join_keeps_its_on () = let joins sql = match parse sql with | [ Ast.Select s ] -> List.map (fun (j : Ast.join) -> (j.type_, j.on)) s.joins | _ -> Alcotest.failf "not one SELECT: %s" sql in let check sql want = Alcotest.(check bool) sql true (joins sql = want) in check "SELECT * FROM a, b" [ (Ast.Inner, None) ]; check "SELECT * FROM a JOIN b" [ (Ast.Inner, None) ]; check "SELECT * FROM a JOIN b ON 1" [ (Ast.Inner, Some (Ast.Lit (Ast.Int 1L))) ]; check "SELECT * FROM a CROSS JOIN b" [ (Ast.Cross, None) ]; check "SELECT * FROM a CROSS JOIN b ON a.x = b.x" [ ( Ast.Cross, Some (Ast.Binary (Ast.Eq, Ast.Col (Some "a", "x"), Ast.Col (Some "b", "x"))) ); ] let suite = ( "parser", [ Alcotest.test_case "a pragma argument is its text" `Quick test_a_pragma_argument_is_its_text; Alcotest.test_case "a join keeps its ON" `Quick test_a_join_keeps_its_on; Alcotest.test_case "a column holds only constraints" `Quick test_a_column_holds_only_constraints; Alcotest.test_case "a column's type and MATCH name" `Quick test_a_column_type_and_match_name; Alcotest.test_case "the frame shapes sqlite3 refuses" `Quick test_frame_shapes; Alcotest.test_case "desc is a column reference" `Quick test_desc_is_a_column_reference; Alcotest.test_case "a PRAGMA value is a bare keyword" `Quick test_a_pragma_value_is_a_bare_keyword; Alcotest.test_case "a PRAGMA value is a signed number" `Quick test_a_pragma_value_is_a_signed_number; Alcotest.test_case "a bare DEFAULT word is a string" `Quick test_a_bare_default_is_a_string; Alcotest.test_case "a keyword names a written column" `Quick test_a_keyword_names_a_written_column; Alcotest.test_case "a keyword names an object" `Quick test_a_keyword_names_an_object; Alcotest.test_case "BEGIN takes a transaction type" `Quick test_begin_takes_a_transaction_type; Alcotest.test_case "BEGIN refuses another transaction type" `Quick test_begin_refuses_another_transaction_type; Alcotest.test_case "BEGIN names its transaction type" `Quick test_begin_names_its_transaction_type; ] )