diff options
author | Sébastien Dailly <sebastien@chimrod.com> | 2017-01-02 17:56:04 +0100 |
---|---|---|
committer | Sébastien Dailly <sebastien@chimrod.com> | 2017-01-10 14:35:04 +0100 |
commit | 0d1f9ff76aa6df3f17edd2d73c76ab444fec8528 (patch) | |
tree | e6a628b78a08beb7fd9912c3f4b9bbdcee59c3c4 /tests/odf | |
parent | 444c0baa87b6edfb21c002bf9e079e10509ee0e9 (diff) |
Corrected some issues with odf documents
Diffstat (limited to 'tests/odf')
-rwxr-xr-x | tests/odf/odf_ExpressionParser_test.ml | 74 |
1 files changed, 74 insertions, 0 deletions
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;
+
+ ]
|