1 ;;; ses-tests.el --- Tests for ses.el -*- lexical-binding: t; -*-
3 ;; Copyright (C) 2015-2017 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
)))
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
))
54 ;; PLAIN CELL RENAMING TESTS
55 ;; ======================================================================
57 (ert-deftest ses-tests-lowlevel-renamed-cell
()
58 "Check that renaming A1 to `foo' and setting `foo' to 1 and A2 to (1+ foo), makes A2 value equal to 2.
59 This is done using low level functions, `ses-rename-cell' is not
60 called but instead we use text replacement in the buffer
61 previously passed in text mode."
62 (let ((ses-initial-size '(2 .
1)))
65 (dolist (c '((0 0 1) (1 0 (1+ A1
))))
66 (apply 'ses-cell-set-formula c
)
67 (apply 'ses-calculate-cell
(list (car c
) (cadr c
) nil
)))
70 (goto-char (point-min))
71 (while (re-search-forward "\\<A1\\>" nil t
)
72 (replace-match "foo" t t
))
74 (should-not (local-variable-p 'A1
))
76 (should (equal (ses-cell-formula 1 0) '(ses-safe-formula (1+ foo
))))
79 (ert-deftest ses-tests-renamed-cell
()
80 "Check that renaming A1 to `foo' and setting `foo' to 1 and A2
81 to (1+ foo), makes A2 value equal to 2."
82 (let ((ses-initial-size '(2 .
1)))
85 (ses-rename-cell 'foo
(ses-get-cell 0 0))
86 (dolist (c '((0 0 1) (1 0 (1+ foo
))))
87 (apply 'funcall-interactively
'ses-edit-cell c
))
89 (should-not (local-variable-p 'A1
))
91 (should (equal (ses-cell-formula 1 0) '(1+ foo
)))
94 (ert-deftest ses-tests-renamed-cell-after-setting
()
95 "Check that setting A1 to 1 and A2 to (1+ A1), and then
96 renaming A1 to `foo' makes `foo' value equal to 2."
97 (let ((ses-initial-size '(2 .
1)))
100 (dolist (c '((0 0 1) (1 0 (1+ A1
))))
101 (apply 'funcall-interactively
'ses-edit-cell c
))
102 (ses-command-hook); deferred recalc
103 (ses-rename-cell 'foo
(ses-get-cell 0 0))
104 (should-not (local-variable-p 'A1
))
106 (should (equal (ses-cell-formula 1 0) '(1+ foo
)))
107 (should (eq A2
2)))))
109 (ert-deftest ses-tests-renaming-cell-with-one-symbol-formula
()
110 "Check that setting A1 to 1 and A2 to A1, and then renaming A1
111 to `foo' makes `foo' value equal to 1. Then set A1 to 2 and check
112 that `foo' becomes 2."
113 (let ((ses-initial-size '(3 .
1)))
116 (dolist (c '((0 0 1) (1 0 A1
)))
117 (apply 'funcall-interactively
'ses-edit-cell c
))
118 (ses-command-hook); deferred recalc
119 (ses-rename-cell 'foo
(ses-get-cell 0 0))
120 (ses-command-hook); deferred recalc
121 (should-not (local-variable-p 'A1
))
123 (should (equal (ses-cell-formula 1 0) 'foo
))
125 (funcall-interactively 'ses-edit-cell
0 0 2)
126 (ses-command-hook); deferred recalc
128 (should (eq foo
2)))))
131 ;; ROW INSERTION TESTS
132 ;; ======================================================================
134 (ert-deftest ses-tests-plain-row-insertion
()
135 "Check that setting A1 to 1 and A2 to (1+ A1), and then jumping
136 to A2 and inserting a row, makes A2 value empty, and A3 equal to
138 (let ((ses-initial-size '(2 .
1)))
141 (dolist (c '((0 0 1) (1 0 (1+ A1
))))
142 (apply 'funcall-interactively
'ses-edit-cell c
))
148 (should (eq A3
2)))))
150 ; (defvar ses-tests-trigger nil)
152 (ert-deftest ses-tests-renamed-cells-row-insertion
()
153 "Check that setting A1 to 1 and A2 to (1+ A1), and then renaming A1 to `foo' and A2 to `bar' jumping
154 to `bar' and inserting a row, makes A2 value empty, and `bar' equal to
156 (setq ses-tests-trigger nil
)
157 (let ((ses-initial-size '(2 .
1)))
160 (dolist (c '((0 0 1) (1 0 (1+ A1
))))
161 (apply 'funcall-interactively
'ses-edit-cell c
))
163 (ses-rename-cell 'foo
(ses-get-cell 0 0))
165 (ses-rename-cell 'bar
(ses-get-cell 1 0))
172 (should (eq bar
2)))))