1 ;;; ses-tests.el --- Tests for ses.el -*- lexical-binding: t; -*-
3 ;; Copyright (C) 2015-2018 Free Software Foundation, Inc.
5 ;; Author: Vincent Belaïche <vincentb1@users.sourceforge.net>
7 ;; This file is part of GNU Emacs.
9 ;; GNU Emacs is free software: you can redistribute it and/or modify
10 ;; it under the terms of the GNU General Public License as published by
11 ;; the Free Software Foundation, either version 3 of the License, or
12 ;; (at your option) any later version.
14 ;; GNU Emacs is distributed in the hope that it will be useful,
15 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
16 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 ;; GNU General Public License for more details.
19 ;; You should have received a copy of the GNU General Public License
20 ;; along with GNU Emacs. If not, see <https://www.gnu.org/licenses/>.
28 ;; PLAIN FORMULA TESTS
29 ;; ======================================================================
31 (ert-deftest ses-tests-lowlevel-plain-formula
()
32 "Check that setting A1 to 1 and A2 to (1+ A1), makes A2 value
33 equal to 2. This is done with low level functions calls, not like
35 (let ((ses-initial-size '(2 .
1)))
38 (dolist (c '((0 0 1) (1 0 (1+ A1
))))
39 (apply 'ses-cell-set-formula c
)
40 (apply 'ses-calculate-cell
(list (car c
) (cadr c
) nil
)))
41 (should (eq (bound-and-true-p A2
) 2)))))
43 (ert-deftest ses-tests-plain-formula
()
44 "Check that setting A1 to 1 and A2 to (1+ A1), makes A2 value
45 equal to 2. This is done using interactive calls."
46 (let ((ses-initial-size '(2 .
1)))
49 (dolist (c '((0 0 1) (1 0 (1+ A1
))))
50 (apply 'funcall-interactively
'ses-edit-cell c
))
52 (should (eq (bound-and-true-p A2
) 2)))))
54 ;; PLAIN CELL RENAMING TESTS
55 ;; ======================================================================
60 (ert-deftest ses-tests-lowlevel-renamed-cell
()
61 "Check that renaming A1 to `ses--foo' and setting `ses--foo' to 1 and A2 to (1+ ses--foo), makes A2 value equal to 2.
62 This is done using low level functions, `ses-rename-cell' is not
63 called but instead we use text replacement in the buffer
64 previously passed in text mode."
65 (let ((ses-initial-size '(2 .
1)))
68 (dolist (c '((0 0 1) (1 0 (1+ A1
))))
69 (apply 'ses-cell-set-formula c
)
70 (apply 'ses-calculate-cell
(list (car c
) (cadr c
) nil
)))
73 (goto-char (point-min))
74 (while (re-search-forward "\\<A1\\>" nil t
)
75 (replace-match "ses--foo" t t
))
77 (should-not (local-variable-p 'A1
))
78 (should (eq ses--foo
1))
79 (should (equal (ses-cell-formula 1 0) '(ses-safe-formula (1+ ses--foo
))))
80 (should (eq (bound-and-true-p A2
) 2)))))
82 (ert-deftest ses-tests-renamed-cell
()
83 "Check that renaming A1 to `ses--foo' and setting `ses--foo' to 1 and A2
84 to (1+ ses--foo), makes A2 value equal to 2."
85 (let ((ses-initial-size '(2 .
1)))
88 (ses-rename-cell 'ses--foo
(ses-get-cell 0 0))
89 (dolist (c '((0 0 1) (1 0 (1+ ses--foo
))))
90 (apply 'funcall-interactively
'ses-edit-cell c
))
92 (should-not (local-variable-p 'A1
))
93 (should (eq ses--foo
1))
94 (should (equal (ses-cell-formula 1 0) '(1+ ses--foo
)))
95 (should (eq (bound-and-true-p A2
) 2)))))
97 (ert-deftest ses-tests-renamed-cell-after-setting
()
98 "Check that setting A1 to 1 and A2 to (1+ A1), and then
99 renaming A1 to `ses--foo' makes `ses--foo' value equal to 2."
100 (let ((ses-initial-size '(2 .
1)))
103 (dolist (c '((0 0 1) (1 0 (1+ A1
))))
104 (apply 'funcall-interactively
'ses-edit-cell c
))
105 (ses-command-hook); deferred recalc
106 (ses-rename-cell 'ses--foo
(ses-get-cell 0 0))
107 (should-not (local-variable-p 'A1
))
108 (should (eq ses--foo
1))
109 (should (equal (ses-cell-formula 1 0) '(1+ ses--foo
)))
110 (should (eq (bound-and-true-p A2
) 2)))))
112 (ert-deftest ses-tests-renaming-cell-with-one-symbol-formula
()
113 "Check that setting A1 to 1 and A2 to A1, and then renaming A1
114 to `ses--foo' makes `ses--foo' value equal to 1. Then set A1 to 2 and check
115 that `ses--foo' becomes 2."
116 (let ((ses-initial-size '(3 .
1)))
119 (dolist (c '((0 0 1) (1 0 A1
)))
120 (apply 'funcall-interactively
'ses-edit-cell c
))
121 (ses-command-hook); deferred recalc
122 (ses-rename-cell 'ses--foo
(ses-get-cell 0 0))
123 (ses-command-hook); deferred recalc
124 (should-not (local-variable-p 'A1
))
125 (should (eq ses--foo
1))
126 (should (equal (ses-cell-formula 1 0) 'ses--foo
))
127 (should (eq (bound-and-true-p A2
) 1))
128 (funcall-interactively 'ses-edit-cell
0 0 2)
129 (ses-command-hook); deferred recalc
130 (should (eq (bound-and-true-p A2
) 2))
131 (should (eq ses--foo
2)))))
134 ;; ROW INSERTION TESTS
135 ;; ======================================================================
137 (ert-deftest ses-tests-plain-row-insertion
()
138 "Check that setting A1 to 1 and A2 to (1+ A1), and then jumping
139 to A2 and inserting a row, makes A2 value empty, and A3 equal to
141 (let ((ses-initial-size '(2 .
1)))
144 (dolist (c '((0 0 1) (1 0 (1+ A1
))))
145 (apply 'funcall-interactively
'ses-edit-cell c
))
150 (should-not (bound-and-true-p A2
))
151 (should (eq (bound-and-true-p A3
) 2)))))
155 (ert-deftest ses-tests-renamed-cells-row-insertion
()
156 "Check that setting A1 to 1 and A2 to (1+ A1), and then renaming A1 to `ses--foo' and A2 to `ses--bar' jumping
157 to `ses--bar' and inserting a row, makes A2 value empty, and `ses--bar' equal to
159 (let ((ses-initial-size '(2 .
1)))
162 (dolist (c '((0 0 1) (1 0 (1+ A1
))))
163 (apply 'funcall-interactively
'ses-edit-cell c
))
165 (ses-rename-cell 'ses--foo
(ses-get-cell 0 0))
167 (ses-rename-cell 'ses--bar
(ses-get-cell 1 0))
169 (should (eq ses--bar
2))
173 (should-not (bound-and-true-p A2
))
174 (should (eq ses--bar
2)))))