aboutsummaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests')
-rwxr-xr-xtests/expressionParser_test.ml9
-rwxr-xr-xtests/expression_test.ml29
-rwxr-xr-xtests/odf/odf_ExpressionParser_test.ml11
-rwxr-xr-xtests/sheet_test.ml11
4 files changed, 44 insertions, 16 deletions
diff --git a/tests/expressionParser_test.ml b/tests/expressionParser_test.ml
index 25d9d00..476e3aa 100755
--- a/tests/expressionParser_test.ml
+++ b/tests/expressionParser_test.ml
@@ -21,7 +21,9 @@ let test_num ctx = begin
Expression.Expression (
ScTypes.Value (
ScTypes.Num (
- Num.num_of_int 1, Some (u"1"))))) in
+ ScTypes.Number,
+ DataType.Num.of_num (Num.num_of_int 1)
+ )))) in
let result = load_expr "=1" in
assert_equal
@@ -52,7 +54,10 @@ let test_call2 ctx = begin
let expected = Expression.Formula (
Expression.Expression (
ScTypes.Call (
- u"foo2", [ScTypes.Value (ScTypes.Num (Num.num_of_int 4, Some (u"4")))]))) in
+ u"foo2", [ScTypes.Value (ScTypes.Num (
+ ScTypes.Number,
+ DataType.Num.of_num (Num.num_of_int 4)
+ ))]))) in
let result = load_expr "=foo2(4)" in
assert_equal
diff --git a/tests/expression_test.ml b/tests/expression_test.ml
index 3f00e67..0950383 100755
--- a/tests/expression_test.ml
+++ b/tests/expression_test.ml
@@ -6,11 +6,11 @@ let u = UTF8.from_utf8string
let _msg ~expected ~result =
let get_type = function
- | Expression.Basic ScTypes.Num _ -> "N"
- | Expression.Basic ScTypes.Str _ -> "S"
- | Expression.Basic ScTypes.Date _ -> "D"
- | Expression.Basic ScTypes.Bool _ -> "B"
- | Expression.Formula _ -> "F" in
+ | Expression.Basic ScTypes.Num (ScTypes.Number, _) -> "N"
+ | Expression.Basic ScTypes.Num (ScTypes.Date, _) -> "D"
+ | Expression.Basic ScTypes.Str _ -> "S"
+ | Expression.Basic ScTypes.Bool _ -> "B"
+ | Expression.Formula _ -> "F" in
Printf.sprintf "Expected %s:%s but got %s:%s"
(UTF8.raw_encode @@ Expression.show expected)
@@ -52,7 +52,10 @@ end
let test_num ctx = begin
let result = Expression.load @@ u"123" in
let expected = Expression.load_expr @@ Expression.Basic (
- ScTypes.Num (Num.num_of_int 123, None)) in
+ ScTypes.Num (
+ ScTypes.Number,
+ DataType.Num.of_num @@ Num.num_of_int 123
+ )) in
assert_equal expected result
end
@@ -60,21 +63,29 @@ let test_float ctx = begin
let result = Expression.load @@ u"12.45" in
let expected = Expression.load_expr @@ Expression.Basic (
ScTypes.Num (
- T.Num.of_float_string "12.45", None)) in
+ ScTypes.Number,
+ DataType.Num.of_num @@ T.Num.of_float_string "12.45"
+ )) in
assert_equal expected result
end
let test_relative ctx = begin
let result = Expression.load @@ u"-123" in
let expected = Expression.load_expr @@ Expression.Basic (
- ScTypes.Num (Num.num_of_int (-123), None)) in
+ ScTypes.Num (
+ ScTypes.Number,
+ DataType.Num.of_num @@ Num.num_of_int (-123)
+ )) in
assert_equal expected result
end
let test_date ctx = begin
let result = Expression.load @@ u"1900/01/01"
and expected = Expression.load_expr @@ Expression.Basic (
- ScTypes.Date (Tools.Date.get_julian_day 1900 01 01)) in
+ ScTypes.Num (
+ ScTypes.Date,
+ DataType.Num.of_num @@ Date.get_julian_day 1900 01 01
+ )) in
assert_equal expected result
end
diff --git a/tests/odf/odf_ExpressionParser_test.ml b/tests/odf/odf_ExpressionParser_test.ml
index 2cdb3bb..becf9ab 100755
--- a/tests/odf/odf_ExpressionParser_test.ml
+++ b/tests/odf/odf_ExpressionParser_test.ml
@@ -13,6 +13,13 @@ let _msg ~(expected:ScTypes.expression) ~(result:ScTypes.expression) =
(UTF8.raw_encode @@ UTF8.Buffer.contents b2)
+
+let build_num value = ScTypes.Num (
+ ScTypes.Number,
+ DataType.Num.of_num @@ Num.num_of_int value
+)
+
+
let test_formula ctx = begin
let test1 = "of:=CONCATENATE(SUM([.F16:.AJ16]);\"/\";8*NETWORKDAYS([.F6]; [.F6]+(ORG.OPENOFFICE.DAYSINMONTH([.F6])-1)))" in
@@ -27,7 +34,7 @@ let test_formula ctx = begin
Ref (Range (((6, 16), (false, false)), (((36, 16), (false, false)))))]);
Value (Str (u"/"));
Call(u"*", [
- Value (Num ((Num.num_of_int 8, Some (u"8"))));
+ Value (build_num 8);
Call(u"NETWORKDAYS", [
Ref (Cell ((6, 6), (false, false)));
Call(u"+", [
@@ -36,7 +43,7 @@ let test_formula ctx = begin
Call( u"-", [
Call(u"ORG.OPENOFFICE.DAYSINMONTH", [
Ref (Cell ((6, 6), (false, false)))]);
- Value (Num ((Num.num_of_int 1, Some (u"1"))));
+ Value (build_num 1);
]))])])])])) in
assert_equal
diff --git a/tests/sheet_test.ml b/tests/sheet_test.ml
index 71f5749..084118f 100755
--- a/tests/sheet_test.ml
+++ b/tests/sheet_test.ml
@@ -16,6 +16,11 @@ let _msg ~expected ~result = begin
(get_string result)
end
+let build_num value = ScTypes.Num (
+ ScTypes.Number,
+ DataType.Num.of_num @@ Num.num_of_int value
+)
+
(** Test a simple references between two cells *)
let test_create_ref_1 ctx = begin
@@ -24,7 +29,7 @@ let test_create_ref_1 ctx = begin
|> snd |> Sheet.Raw.add (0,0) @@ Expression.load @@ u"=C3"
|> snd in
let result = (Sheet.Raw.get_value (0, 0) s) in
- let expected = Some (ScTypes.Result (ScTypes.Num (Num.num_of_int (-1), None))) in
+ let expected = Some (ScTypes.Result (build_num (-1))) in
assert_equal
~msg:(_msg ~expected ~result)
@@ -42,7 +47,7 @@ let test_create_ref_2 ctx = begin
let result = (Sheet.Raw.get_value (2, 2) s) in
- let expected = Some (ScTypes.Result (ScTypes.Num (Num.num_of_int 123, None))) in
+ let expected = Some (ScTypes.Result (build_num 123)) in
assert_equal
~msg:(_msg ~expected ~result)
@@ -96,7 +101,7 @@ let test_check_cycle3 ctx = begin
|> snd in
let result = (Sheet.Raw.get_value (1, 3) s) in
(* A3 = A1 + A1 = 4 *)
- let expected = Some (ScTypes.Result (ScTypes.Num (Num.num_of_int 4, None))) in
+ let expected = Some (ScTypes.Result (build_num 4)) in
assert_equal
~msg:(_msg ~expected ~result)