From 0d1f9ff76aa6df3f17edd2d73c76ab444fec8528 Mon Sep 17 00:00:00 2001 From: Sébastien Dailly Date: Mon, 2 Jan 2017 17:56:04 +0100 Subject: Corrected some issues with odf documents --- tests/odf/odf_ExpressionParser_test.ml | 74 ++++++++++++++++++++++++++++++++++ 1 file changed, 74 insertions(+) create mode 100755 tests/odf/odf_ExpressionParser_test.ml (limited to 'tests/odf') 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; + + ] -- cgit v1.2.3