From 112ab4b1c396fc2117191297227d8e411f9b9bb3 Mon Sep 17 00:00:00 2001 From: Sébastien Dailly Date: Fri, 19 Jan 2018 11:24:29 +0100 Subject: Better memory management --- tests/sheet_test.ml | 76 +++++++++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 68 insertions(+), 8 deletions(-) (limited to 'tests/sheet_test.ml') diff --git a/tests/sheet_test.ml b/tests/sheet_test.ml index 9218134..3960c4b 100755 --- a/tests/sheet_test.ml +++ b/tests/sheet_test.ml @@ -66,6 +66,22 @@ let test_create_direct_cycle ctx = begin result end +(** Overide the value after a cycle. *) +let test_recover_from_cycle ctx = begin + + let s = Sheet.Raw.empty + |> Sheet.Raw.add (2,2) @@ Expression.load @@ u"=B2 + 1" + |> snd |> Sheet.Raw.add (2,2) @@ Expression.load @@ u"=6" + |> snd in + let result = (Sheet.Raw.get_value (2, 2) s) in + let expected = Some (ScTypes.Result (build_num (6))) in + + assert_equal + ~msg:(_msg ~expected ~result) + expected + result +end + let test_create_indirect_cycle ctx = begin let s = Sheet.Raw.empty @@ -160,13 +176,57 @@ let test_update_succs2 ctx = begin result end +let test_paste_undo ctx = begin + + let empty = Sheet.create Sheet.Raw.empty in + + (* The expected result for the whole test *) + let expected = Some (ScTypes.Result (ScTypes.number (DataType.Num.of_int 6))) in + + let sheet = empty + |> Tools.Option.test @@ Sheet.move (Actions.Absolute (2, 1)) + |> Sheet.add (Expression.load @@ u"=6") + |> snd + |> Tools.Option.test @@ Sheet.move (Actions.Absolute (1, 1)) + |> Sheet.add (Expression.load @@ u"=B1") + |> snd in + let result = Sheet.Raw.get_value (1, 1) sheet.Sheet.data in + + (* Ensure the value is correctly evaluated *) + assert_equal + ~msg:(_msg ~expected ~result) + expected + result; + + let sheet2 = + (* Copy the cell *) + fst @@ Sheet.yank sheet + |> Tools.Option.test @@ Sheet.move (Actions.Absolute (2, 1)) + (* Paste it on another value *) + |> Sheet.paste + |> fst + (* Undo the paste *) + |> Tools.Option.test @@ Sheet.undo in + + let result = Sheet.Raw.get_value (1, 1) sheet2.Sheet.data in + + (* The value should be the same as the first evaluation *) + assert_equal + ~msg:(_msg ~expected ~result) + expected + result + +end + let tests = "sheet_test">::: [ - "test_ref1" >:: test_create_ref_1; - "test_ref2" >:: test_create_ref_2; - "test_cycle1" >:: test_create_direct_cycle; - "test_cycle2" >:: test_create_indirect_cycle; - "test_cycle3" >:: test_check_cycle3; - "test_delete" >:: test_delete; - "test_update_succs1" >:: test_update_succs1; - "test_update_succs2" >:: test_update_succs2; + "test_ref1" >:: test_create_ref_1; + "test_ref2" >:: test_create_ref_2; + "test_cycle1" >:: test_create_direct_cycle; + "test_recover_cycle" >:: test_recover_from_cycle; + "test_cycle2" >:: test_create_indirect_cycle; + "test_cycle3" >:: test_check_cycle3; + "test_delete" >:: test_delete; + "test_update_succs1" >:: test_update_succs1; + "test_update_succs2" >:: test_update_succs2; + "test_paste_undo" >:: test_paste_undo; ] -- cgit v1.2.3