aboutsummaryrefslogtreecommitdiff
path: root/tests/expressions/show_expr_test.ml
blob: aa0768590ab62dcdb60cad245632a6d0e6a26fb3 (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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
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;
]