aboutsummaryrefslogtreecommitdiff
path: root/tests/expressions/evaluate_test.ml
blob: e57183138acd2f11d4a80f9b7af2e1a190254b77 (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
46
47
48
49
50
51
52
53
54
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;
]