blob: 524e793c036f8bb52fda418bc4295bee85659725 (
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
|
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 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)
|