aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSébastien Dailly <sebastien@chimrod.com>2019-08-30 20:24:31 +0200
committerSébastien Dailly <sebastien@chimrod.com>2019-08-30 20:24:31 +0200
commit05b3868f44c125b4ca7fcdb3d9dd7d92954d8178 (patch)
tree476e30b7061293445b884338c9ff003de1d88f89
parenteea6c106dd959dec19dc70991010bf2008fcf6c6 (diff)
Added tests
-rw-r--r--tests/expressions/buildExpression.ml27
-rw-r--r--tests/expressions/evaluate_test.ml55
-rw-r--r--tests/expressions/show_expr_test.ml75
3 files changed, 157 insertions, 0 deletions
diff --git a/tests/expressions/buildExpression.ml b/tests/expressions/buildExpression.ml
new file mode 100644
index 0000000..e8a32c6
--- /dev/null
+++ b/tests/expressions/buildExpression.ml
@@ -0,0 +1,27 @@
+let u = UTF8.from_utf8string
+
+module M(E:Sym_expr.SYM_EXPR) = struct
+
+ let string =
+ let v = E.value (E.T.str @@ u "This is a test string") in
+ E.observe v
+
+ let date0 =
+ let zero = E.value (E.T.date @@ DataType.Num.zero) in
+ E.observe zero
+
+ let true0 =
+ let v = E.call0 (u "true") in
+ E.observe v
+
+ let f3 =
+ let zero = E.value (E.T.num @@ DataType.Num.zero) in
+ let v = E.call3 (u "register3") zero zero zero in
+ E.observe v
+
+ let calln =
+ let zero = E.value (E.T.num @@ DataType.Num.zero) in
+ let one = E.value (E.T.num @@ DataType.Num.one) in
+ E.observe (E.callN (u "calln") [zero; one])
+
+end
diff --git a/tests/expressions/evaluate_test.ml b/tests/expressions/evaluate_test.ml
new file mode 100644
index 0000000..e571831
--- /dev/null
+++ b/tests/expressions/evaluate_test.ml
@@ -0,0 +1,55 @@
+open OUnit2
+
+open Functions
+let f_string = ScTypes.ReturnType.f_string
+
+let u = UTF8.from_utf8string
+
+let catalog = Functions.C.compile (
+ Functions.built_in Functions.C.empty
+ |> Functions.C.register3 "register3" (t_int, t_int, t_int) f_string
+ (fun a b c -> u "register3")
+)
+
+let _msg ~(expected:ScTypes.Result.t) ~(result:ScTypes.Result.t) =
+ Printf.sprintf "Expected %s but got %s"
+ (UTF8.raw_encode @@ ScTypes.Result.show expected)
+ (UTF8.raw_encode @@ ScTypes.Result.show result)
+
+module M = BuildExpression.M(Evaluate)
+
+let test_value_string e = begin
+ assert_equal
+ (ScTypes.Result.Ok (ScTypes.Type.string @@ u "This is a test string"))
+ (M.string (catalog, fun _ -> None))
+end
+
+let test_value_date e = begin
+
+ let expected = ScTypes.Result.Ok (ScTypes.Type.date DataType.Num.zero)
+ and result = M.date0 (catalog, fun _ -> None) in
+
+ assert_equal
+ ~msg:(_msg ~expected ~result)
+ expected result
+end
+
+let test_evaluate0 e = begin
+ assert_equal
+ (ScTypes.Result.Ok (ScTypes.Type.boolean true))
+ (M.true0 (catalog, fun _ -> None))
+end
+
+let test_evaluate3 e = begin
+ assert_equal
+ (ScTypes.Result.Ok (ScTypes.Type.string @@ u "register3"))
+ (M.f3 (catalog, fun _ -> None))
+end
+
+let tests = "evaluate_test">::: [
+ "test_value_string" >:: test_value_string;
+ "test_value_date" >:: test_value_date;
+ "test_evaluate0" >:: test_evaluate0;
+ "test_evaluate3" >:: test_evaluate3;
+]
+
diff --git a/tests/expressions/show_expr_test.ml b/tests/expressions/show_expr_test.ml
new file mode 100644
index 0000000..aa07685
--- /dev/null
+++ b/tests/expressions/show_expr_test.ml
@@ -0,0 +1,75 @@
+open OUnit2
+
+open Functions
+let f_string = ScTypes.ReturnType.f_string
+
+let u = UTF8.from_utf8string
+
+let _msg ~expected ~result =
+ Printf.sprintf "Expected %s but got %s"
+ (UTF8.raw_encode expected)
+ (UTF8.raw_encode result)
+
+module M = BuildExpression.M(Show_expr.Show_Expr(Show_ref)(Show_type))
+
+let test_value_string e = begin
+ let buffer = UTF8.Buffer.create 16 in
+
+ let expected = u "This is a test string"
+ and result = M.string buffer; UTF8.Buffer.contents buffer in
+
+ assert_equal
+ ~msg:(_msg ~expected ~result)
+ expected result
+
+end
+
+let test_value_date e = begin
+
+ let buffer = UTF8.Buffer.create 16 in
+ let expected = u "1899/12/30"
+ and result = M.date0 buffer; UTF8.Buffer.contents buffer in
+
+ assert_equal
+ ~msg:(_msg ~expected ~result)
+ expected result
+end
+
+let test_evaluate0 e = begin
+ let buffer = UTF8.Buffer.create 16 in
+ let expected = u "true()"
+ and result = M.true0 buffer; UTF8.Buffer.contents buffer in
+ assert_equal
+ ~msg:(_msg ~expected ~result)
+ expected result
+end
+
+let test_evaluate3 e = begin
+ let buffer = UTF8.Buffer.create 16 in
+ let expected = u "register3(0;0;0)"
+ and result = M.f3 buffer; UTF8.Buffer.contents buffer in
+
+ assert_equal
+ ~msg:(_msg ~expected ~result)
+ expected result
+end
+
+let test_calln e = begin
+ let buffer = UTF8.Buffer.create 16 in
+ let expected = u "calln(0;1)"
+ and result = M.calln buffer; UTF8.Buffer.contents buffer in
+
+ assert_equal
+ ~msg:(_msg ~expected ~result)
+ expected result
+end
+
+let tests = "show_expr_test">::: [
+ "test_value_string" >:: test_value_string;
+ "test_value_date" >:: test_value_date;
+ "test_evaluate0" >:: test_evaluate0;
+ "test_evaluate3" >:: test_evaluate3;
+ "test_calln" >:: test_calln;
+]
+
+