aboutsummaryrefslogtreecommitdiff
path: root/tests/expression_test.ml
diff options
context:
space:
mode:
Diffstat (limited to 'tests/expression_test.ml')
-rwxr-xr-xtests/expression_test.ml45
1 files changed, 26 insertions, 19 deletions
diff --git a/tests/expression_test.ml b/tests/expression_test.ml
index 5def730..6743a09 100755
--- a/tests/expression_test.ml
+++ b/tests/expression_test.ml
@@ -5,18 +5,9 @@ let u = UTF8.from_utf8string
let _msg ~expected ~result =
- let get_type = function
- | 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"
+ Printf.sprintf "Expected %s but got %s"
(UTF8.raw_encode @@ Expression.show expected)
- (get_type expected)
(UTF8.raw_encode @@ Expression.show result)
- (get_type result)
let assert_equal expected result =
OUnit2.assert_equal
@@ -28,7 +19,7 @@ let assert_equal expected result =
let test_str ctx = begin
let result = Expression.load @@ u"cafe" in
let expected = Expression.load_expr @@ Expression.Basic (
- ScTypes.string (u"cafe")) in
+ ScTypes.Type.string (u"cafe")) in
assert_equal expected result
end
@@ -36,7 +27,7 @@ end
let test_str_space ctx = begin
let result = Expression.load @@ u" =cafe" in
let expected = Expression.load_expr @@ Expression.Basic (
- ScTypes.string (u" =cafe")) in
+ ScTypes.Type.string (u" =cafe")) in
assert_equal expected result
end
@@ -44,15 +35,15 @@ let test_formula_str ctx = begin
let result = Expression.load @@ u"=\"cafe\"" in
let expected = Expression.load_expr @@ Expression.Formula (
Expression.Expression (
- ScTypes.Value (
- ScTypes.string (u"cafe")))) in
+ ScTypes.Expr.value (
+ ScTypes.Type.string (u"cafe")))) in
assert_equal expected result
end
let test_num ctx = begin
let result = Expression.load @@ u"123" in
let expected = Expression.load_expr @@ Expression.Basic (
- ScTypes.number (
+ ScTypes.Type.number (
DataType.Num.of_int 123
)) in
assert_equal expected result
@@ -61,7 +52,7 @@ end
let test_float ctx = begin
let result = Expression.load @@ u"12.45" in
let expected = Expression.load_expr @@ Expression.Basic (
- ScTypes.number (
+ ScTypes.Type.number (
DataType.Num.of_float @@ float_of_string "12.45"
)) in
assert_equal expected result
@@ -70,7 +61,7 @@ end
let test_relative ctx = begin
let result = Expression.load @@ u"-123" in
let expected = Expression.load_expr @@ Expression.Basic (
- ScTypes.number (
+ ScTypes.Type.number (
DataType.Num.of_int (-123)
)) in
assert_equal expected result
@@ -79,7 +70,7 @@ end
let test_date ctx = begin
let result = Expression.load @@ u"1900/01/01"
and expected = Expression.load_expr @@ Expression.Basic (
- ScTypes.date (
+ ScTypes.Type.date (
DataType.Date.get_julian_day 1900 01 01
)) in
assert_equal expected result
@@ -96,6 +87,22 @@ let test_sources ctx = begin
(UTF8.raw_encode @@ Tools.String.print_buffer Cell.Set.printb result) in
OUnit2.assert_equal ~msg expected result
+end
+
+let test_sources2 ctx = begin
+ let result = Expression.load @@ u"=if($A$1>0;rand()*10+1;0)"
+ |> Expression.collect_sources
+ and expected = Cell.Set.singleton (1, 1) in
+
+ let msg_buffer = UTF8.Buffer.create 16 in
+ UTF8.Printf.bprintf msg_buffer "Expected %a but got %a"
+ Cell.Set.printb expected
+ Cell.Set.printb result;
+
+ OUnit2.assert_equal
+ ~msg:(UTF8.to_utf8string @@ UTF8.Buffer.contents msg_buffer)
+ expected
+ result
end
@@ -114,5 +121,5 @@ let tests = "expression_test">::: [
"test_date" >:: test_date;
"test_sources" >:: test_sources;
-
+ "test_sources2" >:: test_sources2;
]