* Bug #10415 fixed - Remove a session line in history causes the removal
[scilab.git] / scilab / modules / history_manager / tests / unit_tests / removelinehistory.tst
1 // =============================================================================
2 // Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
3 // Copyright (C) 2013 - Scilab Enterprises - Simon MARCHETTO
4 //
5 //  This file is distributed under the same license as the Scilab package.
6 // =============================================================================
7
8 function [] = check_history(expected)
9   actual = gethistory();
10   // ignore first line of history which indicates the current session
11   actual(1,1) = []
12   assert_checkequal(actual, expected);
13 endfunction
14
15 // checking removing simple lines
16
17 resethistory()
18 // warning: a session line will be added at the front of this history
19 addhistory("lineA");
20 addhistory("lineB");
21 addhistory("lineC");
22 addhistory("lineD");
23
24 removelinehistory(1);
25 check_history(['lineB';'lineC';'lineD']);
26
27 removelinehistory(2);
28 h = gethistory();
29 check_history(['lineB';'lineD']);
30
31 removelinehistory(2);
32 h = gethistory();
33 check_history(['lineB']);
34
35 removelinehistory(1);
36 check_history([]);
37
38 // check removing of session lines
39
40 resethistory()
41 // warning: a session line will be added at the front of this history
42 expected_history = ["// -- 26/02/2013 10:00:00 -- //";
43                     "lineA";
44                     "lineB";
45                     "// -- 26/02/2013 11:00:00 -- //";
46                     "lineC";
47                     "// -- 26/02/2013 12:00:00 -- //";
48                     "// -- 26/02/2013 13:00:00 -- //"];
49 addhistory(expected_history);
50
51 removelinehistory(1);
52 expected_history(1:3,1) = [];
53 check_history(expected_history);
54
55 removelinehistory(3);
56 expected_history(3,1) = [];
57 check_history(expected_history);
58
59 removelinehistory(3);
60 expected_history(3,1) = [];
61 check_history(expected_history);
62
63 removelinehistory(1);
64 expected_history(1:2,1) = [];
65 check_history(expected_history);
66
67 // check error messages
68
69 resethistory()
70 ierr = execstr("removelinehistory(10)", "errcatch");
71 assert_checkequal(ierr, 999);
72