open Test_migration let check = Alcotest.check Test_migration.sql_testable let test_suit = [ ( "Parse date" >:: fun () -> let text_date = Sqlite3.Data.TEXT "2002-04-08 15:59:41.000" and format_date = Sqlite3.Data.TEXT "%Y-%m-%d %H:%M:%S.000" in check "parsing date" (Sqlite3.Data.INT 37354L) (ImportSQL.Date.f format_date text_date) ); ( "Parse date as int" >:: fun () -> let int_date = Sqlite3.Data.INT 37354L and format_date = Sqlite3.Data.TEXT "%Y-%m-%d %H:%M:%S.000" in check "parsing int date" int_date (ImportSQL.Date.f format_date int_date) ); ( "Parse out of bound date" >:: fun () -> let text_date = Sqlite3.Data.TEXT "4002-04-08" and format_date = Sqlite3.Data.TEXT "%Y-%m-%d" in check "Out of bound" Sqlite3.Data.NULL (ImportSQL.Date.f format_date text_date) ); ( "Parse regex" >:: fun _ -> let text = Sqlite3.Data.TEXT "hello world" and regex = Sqlite3.Data.TEXT "hello ([A-Za-z]+)" in check "Extracting regex" (Sqlite3.Data.TEXT "world") (ImportSQL.Match.f regex text) ); (* Test the int function *) ( "Int_of_int" >:: fun _ -> check "Converting int from int" (Sqlite3.Data.INT 37354L) (ImportSQL.Math.int (Sqlite3.Data.INT 37354L)) ); ( "Int_of_string" >:: fun _ -> check "Converting int from string" (Sqlite3.Data.INT 37354L) (ImportSQL.Math.int (Sqlite3.Data.TEXT "37354")) ); ( "Int_of_string2" >:: fun _ -> check "Converting int from string as float" (Sqlite3.Data.INT 37354L) (ImportSQL.Math.int (Sqlite3.Data.TEXT "37354.0")) ); ( "Int_of_float" >:: fun _ -> check "Converting int from float" (Sqlite3.Data.INT 37354L) (ImportSQL.Math.int (Sqlite3.Data.FLOAT 37354.0)) ); ( "Int_of_Text" >:: fun _ -> check "Converting int from invalid text" Sqlite3.Data.NULL (ImportSQL.Math.int (Sqlite3.Data.TEXT "-")) ); ] let tests = ("sql_functions", test_suit)