From 8e012f4804ecf1665819e761283120a3c0e73643 Mon Sep 17 00:00:00 2001
From: Sébastien Dailly <sebastien@dailly.me>
Date: Fri, 17 Jan 2025 20:48:43 +0100
Subject: Switched from OUnit to alcotest

---
 tests/sql_functions.ml | 45 +++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 45 insertions(+)
 create mode 100644 tests/sql_functions.ml

(limited to 'tests/sql_functions.ml')

diff --git a/tests/sql_functions.ml b/tests/sql_functions.ml
new file mode 100644
index 0000000..524e793
--- /dev/null
+++ b/tests/sql_functions.ml
@@ -0,0 +1,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)
-- 
cgit v1.2.3