diff options
Diffstat (limited to 'tests')
-rwxr-xr-x | tests/expressionParser_test.ml | 4 | ||||
-rwxr-xr-x | tests/expression_test.ml | 9 | ||||
-rwxr-xr-x | tests/odf/odf_ExpressionParser_test.ml | 74 | ||||
-rwxr-xr-x | tests/sheet_test.ml | 29 | ||||
-rwxr-xr-x | tests/test.ml | 1 |
5 files changed, 100 insertions, 17 deletions
diff --git a/tests/expressionParser_test.ml b/tests/expressionParser_test.ml index 7c16233..25d9d00 100755 --- a/tests/expressionParser_test.ml +++ b/tests/expressionParser_test.ml @@ -4,8 +4,8 @@ let u = UTF8.from_utf8string let _msg ~(expected:Expression.t) ~(result:Expression.t) = Printf.sprintf "Expected %s but got %s" - (UTF8.encode @@ Expression.show @@ Expression.load_expr expected) - (UTF8.encode @@ Expression.show @@ Expression.load_expr result) + (UTF8.raw_encode @@ Expression.show @@ Expression.load_expr expected) + (UTF8.raw_encode @@ Expression.show @@ Expression.load_expr result) let load_expr str = Expression.Formula ( diff --git a/tests/expression_test.ml b/tests/expression_test.ml index d1ac2ba..3f00e67 100755 --- a/tests/expression_test.ml +++ b/tests/expression_test.ml @@ -9,14 +9,13 @@ let _msg ~expected ~result = | Expression.Basic ScTypes.Num _ -> "N" | Expression.Basic ScTypes.Str _ -> "S" | Expression.Basic ScTypes.Date _ -> "D" - | Expression.Basic ScTypes.Undefined -> "U" | Expression.Basic ScTypes.Bool _ -> "B" | Expression.Formula _ -> "F" in Printf.sprintf "Expected %s:%s but got %s:%s" - (UTF8.encode @@ Expression.show expected) + (UTF8.raw_encode @@ Expression.show expected) (get_type expected) - (UTF8.encode @@ Expression.show result) + (UTF8.raw_encode @@ Expression.show result) (get_type result) let assert_equal expected result = @@ -86,8 +85,8 @@ let test_sources ctx = begin let expected = Cell.Set.singleton (1, 1) in let msg = Printf.sprintf "Expected %s but got %s" - (UTF8.encode @@ Tools.String.print_buffer Cell.Set.printb expected) - (UTF8.encode @@ Tools.String.print_buffer Cell.Set.printb result) in + (UTF8.raw_encode @@ Tools.String.print_buffer Cell.Set.printb expected) + (UTF8.raw_encode @@ Tools.String.print_buffer Cell.Set.printb result) in OUnit2.assert_equal ~msg expected result diff --git a/tests/odf/odf_ExpressionParser_test.ml b/tests/odf/odf_ExpressionParser_test.ml new file mode 100755 index 0000000..2cdb3bb --- /dev/null +++ b/tests/odf/odf_ExpressionParser_test.ml @@ -0,0 +1,74 @@ +open OUnit2
+
+let u = UTF8.from_utf8string
+
+let _msg ~(expected:ScTypes.expression) ~(result:ScTypes.expression) =
+ let b1 = UTF8.Buffer.create 16
+ and b2 = UTF8.Buffer.create 16 in
+ ScTypes.show_expr b1 expected;
+ ScTypes.show_expr b2 result;
+
+ Printf.sprintf "Expected \n\t%s but got \n\t%s"
+ (UTF8.raw_encode @@ UTF8.Buffer.contents b1)
+ (UTF8.raw_encode @@ UTF8.Buffer.contents b2)
+
+
+let test_formula ctx = begin
+
+ let test1 = "of:=CONCATENATE(SUM([.F16:.AJ16]);\"/\";8*NETWORKDAYS([.F6]; [.F6]+(ORG.OPENOFFICE.DAYSINMONTH([.F6])-1)))" in
+
+ let line = Lexing.from_string test1 in
+ let result = Odf_ExpressionParser.value Odf_ExpressionLexer.read line in
+
+ let expected = ScTypes.(
+
+ Call(u"CONCATENATE", [
+ Call (u"SUM", [
+ 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"))));
+ Call(u"NETWORKDAYS", [
+ Ref (Cell ((6, 6), (false, false)));
+ Call(u"+", [
+ Ref (Cell ((6, 6), (false, false)));
+ Expression (
+ Call( u"-", [
+ Call(u"ORG.OPENOFFICE.DAYSINMONTH", [
+ Ref (Cell ((6, 6), (false, false)))]);
+ Value (Num ((Num.num_of_int 1, Some (u"1"))));
+ ]))])])])])) in
+
+ assert_equal
+ ~msg:(_msg ~expected ~result)
+ expected
+ result
+
+end
+
+let test_formula2 ctx = begin
+ let value = "of:=+[.H51]*[.G52]" in
+ let line = Lexing.from_string value in
+ let result = Odf_ExpressionParser.value Odf_ExpressionLexer.read line in
+
+ let expected = ScTypes.(
+
+ Call (u"+", [
+ Call(u"*", [
+ Ref (Cell ((8, 51), (false, false)));
+ Ref (Cell ((7, 52), (false, false)))
+ ])])) in
+
+ assert_equal
+ ~msg:(_msg ~expected ~result)
+ expected
+ result
+
+end
+
+let tests = "odf_ExpressionParser_test">::: [
+
+ "test_formula" >:: test_formula;
+ "test_formula2" >:: test_formula2;
+
+ ]
diff --git a/tests/sheet_test.ml b/tests/sheet_test.ml index de42730..1a1bef3 100755 --- a/tests/sheet_test.ml +++ b/tests/sheet_test.ml @@ -1,11 +1,20 @@ open OUnit2 +module Option = Tools.Option + let u = UTF8.from_utf8string -let _msg ~expected ~result = +let _msg ~expected ~result = begin + + let get_string v = match v with + | None -> "Undefined" + | Some x -> UTF8.raw_encode @@ ScTypes.Result.show x + in + Printf.sprintf "Expected %s but got %s" - (UTF8.encode @@ ScTypes.Result.show expected) - (UTF8.encode @@ ScTypes.Result.show result) + (get_string expected) + (get_string result) +end (** Test a simple references between two cells *) let test_create_ref_1 ctx = begin @@ -15,7 +24,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 = (ScTypes.Result (ScTypes.Num (Num.num_of_int (-1), None))) in + let expected = Some (ScTypes.Result (ScTypes.Num (Num.num_of_int (-1), None))) in assert_equal ~msg:(_msg ~expected ~result) @@ -33,7 +42,7 @@ let test_create_ref_2 ctx = begin let result = (Sheet.Raw.get_value (2, 2) s) in - let expected = ScTypes.Result (ScTypes.Num (Num.num_of_int 123, None)) in + let expected = Some (ScTypes.Result (ScTypes.Num (Num.num_of_int 123, None))) in assert_equal ~msg:(_msg ~expected ~result) @@ -47,7 +56,7 @@ let test_create_direct_cycle ctx = begin |> Sheet.Raw.add (2,2) @@ Expression.load @@ u"=B2" |> snd in let result = (Sheet.Raw.get_value (2, 2) s) in - let expected = ScTypes.Error Errors.TypeError in + let expected = Some (ScTypes.Error Errors.TypeError) in assert_equal ~msg:(_msg ~expected ~result) @@ -63,7 +72,7 @@ let test_create_indirect_cycle ctx = begin |> snd |> Sheet.Raw.add (0,0) @@ Expression.load @@ u"=A1" |> snd in let result = (Sheet.Raw.get_value (0, 0) s) in - let expected = ScTypes.Error Errors.TypeError in + let expected = Some (ScTypes.Error Errors.TypeError) in assert_equal ~msg:(_msg ~expected ~result) @@ -80,7 +89,7 @@ let test_delete ctx = begin |> snd |> Sheet.Raw.remove (3,3) |> snd in let result = (Sheet.Raw.get_value (3, 3) s) in - let expected = ScTypes.Result ScTypes.Undefined in + let expected = None in assert_equal ~msg:(_msg ~expected ~result) @@ -101,8 +110,8 @@ let test_update_succs1 ctx = begin let expected = Cell.Set.of_list [(1,1); (1, 2); (2,2)] in let msg = Printf.sprintf "Expected %s but got %s" - (UTF8.encode @@ Tools.String.print_buffer Cell.Set.printb expected) - (UTF8.encode @@ Tools.String.print_buffer Cell.Set.printb result) in + (UTF8.raw_encode @@ Tools.String.print_buffer Cell.Set.printb expected) + (UTF8.raw_encode @@ Tools.String.print_buffer Cell.Set.printb result) in assert_equal ~msg expected diff --git a/tests/test.ml b/tests/test.ml index 8a24cd5..b9672ab 100755 --- a/tests/test.ml +++ b/tests/test.ml @@ -5,6 +5,7 @@ let () = ExpressionParser_test.tests; Expression_test.tests; Sheet_test.tests; + Odf_ExpressionParser_test.tests; ] in OUnit2.run_test_tt_main tests |