aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--test/lisp/ses-tests.el79
1 files changed, 42 insertions, 37 deletions
diff --git a/test/lisp/ses-tests.el b/test/lisp/ses-tests.el
index d08237e285b..c773c9b396f 100644
--- a/test/lisp/ses-tests.el
+++ b/test/lisp/ses-tests.el
@@ -38,7 +38,7 @@ interactively."
38 (dolist (c '((0 0 1) (1 0 (1+ A1)))) 38 (dolist (c '((0 0 1) (1 0 (1+ A1))))
39 (apply 'ses-cell-set-formula c) 39 (apply 'ses-cell-set-formula c)
40 (apply 'ses-calculate-cell (list (car c) (cadr c) nil))) 40 (apply 'ses-calculate-cell (list (car c) (cadr c) nil)))
41 (should (eq A2 2))))) 41 (should (eq (bound-and-true-p A2) 2)))))
42 42
43(ert-deftest ses-tests-plain-formula () 43(ert-deftest ses-tests-plain-formula ()
44 "Check that setting A1 to 1 and A2 to (1+ A1), makes A2 value 44 "Check that setting A1 to 1 and A2 to (1+ A1), makes A2 value
@@ -49,13 +49,16 @@ equal to 2. This is done using interactive calls."
49 (dolist (c '((0 0 1) (1 0 (1+ A1)))) 49 (dolist (c '((0 0 1) (1 0 (1+ A1))))
50 (apply 'funcall-interactively 'ses-edit-cell c)) 50 (apply 'funcall-interactively 'ses-edit-cell c))
51 (ses-command-hook) 51 (ses-command-hook)
52 (should (eq A2 2))))) 52 (should (eq (bound-and-true-p A2) 2)))))
53 53
54;; PLAIN CELL RENAMING TESTS 54;; PLAIN CELL RENAMING TESTS
55;; ====================================================================== 55;; ======================================================================
56 56
57(defvar ses--foo)
58(defvar ses--cells)
59
57(ert-deftest ses-tests-lowlevel-renamed-cell () 60(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. 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.
59This is done using low level functions, `ses-rename-cell' is not 62This is done using low level functions, `ses-rename-cell' is not
60called but instead we use text replacement in the buffer 63called but instead we use text replacement in the buffer
61previously passed in text mode." 64previously passed in text mode."
@@ -69,63 +72,63 @@ previously passed in text mode."
69 (text-mode) 72 (text-mode)
70 (goto-char (point-min)) 73 (goto-char (point-min))
71 (while (re-search-forward "\\<A1\\>" nil t) 74 (while (re-search-forward "\\<A1\\>" nil t)
72 (replace-match "foo" t t)) 75 (replace-match "ses--foo" t t))
73 (ses-mode) 76 (ses-mode)
74 (should-not (local-variable-p 'A1)) 77 (should-not (local-variable-p 'A1))
75 (should (eq foo 1)) 78 (should (eq ses--foo 1))
76 (should (equal (ses-cell-formula 1 0) '(ses-safe-formula (1+ foo)))) 79 (should (equal (ses-cell-formula 1 0) '(ses-safe-formula (1+ ses--foo))))
77 (should (eq A2 2))))) 80 (should (eq (bound-and-true-p A2) 2)))))
78 81
79(ert-deftest ses-tests-renamed-cell () 82(ert-deftest ses-tests-renamed-cell ()
80 "Check that renaming A1 to `foo' and setting `foo' to 1 and A2 83 "Check that renaming A1 to `ses--foo' and setting `ses--foo' to 1 and A2
81to (1+ foo), makes A2 value equal to 2." 84to (1+ ses--foo), makes A2 value equal to 2."
82 (let ((ses-initial-size '(2 . 1))) 85 (let ((ses-initial-size '(2 . 1)))
83 (with-temp-buffer 86 (with-temp-buffer
84 (ses-mode) 87 (ses-mode)
85 (ses-rename-cell 'foo (ses-get-cell 0 0)) 88 (ses-rename-cell 'ses--foo (ses-get-cell 0 0))
86 (dolist (c '((0 0 1) (1 0 (1+ foo)))) 89 (dolist (c '((0 0 1) (1 0 (1+ ses--foo))))
87 (apply 'funcall-interactively 'ses-edit-cell c)) 90 (apply 'funcall-interactively 'ses-edit-cell c))
88 (ses-command-hook) 91 (ses-command-hook)
89 (should-not (local-variable-p 'A1)) 92 (should-not (local-variable-p 'A1))
90 (should (eq foo 1)) 93 (should (eq ses--foo 1))
91 (should (equal (ses-cell-formula 1 0) '(1+ foo))) 94 (should (equal (ses-cell-formula 1 0) '(1+ ses--foo)))
92 (should (eq A2 2))))) 95 (should (eq (bound-and-true-p A2) 2)))))
93 96
94(ert-deftest ses-tests-renamed-cell-after-setting () 97(ert-deftest ses-tests-renamed-cell-after-setting ()
95 "Check that setting A1 to 1 and A2 to (1+ A1), and then 98 "Check that setting A1 to 1 and A2 to (1+ A1), and then
96renaming A1 to `foo' makes `foo' value equal to 2." 99renaming A1 to `ses--foo' makes `ses--foo' value equal to 2."
97 (let ((ses-initial-size '(2 . 1))) 100 (let ((ses-initial-size '(2 . 1)))
98 (with-temp-buffer 101 (with-temp-buffer
99 (ses-mode) 102 (ses-mode)
100 (dolist (c '((0 0 1) (1 0 (1+ A1)))) 103 (dolist (c '((0 0 1) (1 0 (1+ A1))))
101 (apply 'funcall-interactively 'ses-edit-cell c)) 104 (apply 'funcall-interactively 'ses-edit-cell c))
102 (ses-command-hook); deferred recalc 105 (ses-command-hook); deferred recalc
103 (ses-rename-cell 'foo (ses-get-cell 0 0)) 106 (ses-rename-cell 'ses--foo (ses-get-cell 0 0))
104 (should-not (local-variable-p 'A1)) 107 (should-not (local-variable-p 'A1))
105 (should (eq foo 1)) 108 (should (eq ses--foo 1))
106 (should (equal (ses-cell-formula 1 0) '(1+ foo))) 109 (should (equal (ses-cell-formula 1 0) '(1+ ses--foo)))
107 (should (eq A2 2))))) 110 (should (eq (bound-and-true-p A2) 2)))))
108 111
109(ert-deftest ses-tests-renaming-cell-with-one-symbol-formula () 112(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 113 "Check that setting A1 to 1 and A2 to A1, and then renaming A1
111to `foo' makes `foo' value equal to 1. Then set A1 to 2 and check 114to `ses--foo' makes `ses--foo' value equal to 1. Then set A1 to 2 and check
112that `foo' becomes 2." 115that `ses--foo' becomes 2."
113 (let ((ses-initial-size '(3 . 1))) 116 (let ((ses-initial-size '(3 . 1)))
114 (with-temp-buffer 117 (with-temp-buffer
115 (ses-mode) 118 (ses-mode)
116 (dolist (c '((0 0 1) (1 0 A1))) 119 (dolist (c '((0 0 1) (1 0 A1)))
117 (apply 'funcall-interactively 'ses-edit-cell c)) 120 (apply 'funcall-interactively 'ses-edit-cell c))
118 (ses-command-hook); deferred recalc 121 (ses-command-hook); deferred recalc
119 (ses-rename-cell 'foo (ses-get-cell 0 0)) 122 (ses-rename-cell 'ses--foo (ses-get-cell 0 0))
120 (ses-command-hook); deferred recalc 123 (ses-command-hook); deferred recalc
121 (should-not (local-variable-p 'A1)) 124 (should-not (local-variable-p 'A1))
122 (should (eq foo 1)) 125 (should (eq ses--foo 1))
123 (should (equal (ses-cell-formula 1 0) 'foo)) 126 (should (equal (ses-cell-formula 1 0) 'ses--foo))
124 (should (eq A2 1)) 127 (should (eq (bound-and-true-p A2) 1))
125 (funcall-interactively 'ses-edit-cell 0 0 2) 128 (funcall-interactively 'ses-edit-cell 0 0 2)
126 (ses-command-hook); deferred recalc 129 (ses-command-hook); deferred recalc
127 (should (eq A2 2)) 130 (should (eq (bound-and-true-p A2) 2))
128 (should (eq foo 2))))) 131 (should (eq ses--foo 2)))))
129 132
130 133
131;; ROW INSERTION TESTS 134;; ROW INSERTION TESTS
@@ -144,12 +147,14 @@ to A2 and inserting a row, makes A2 value empty, and A3 equal to
144 (ses-jump 'A2) 147 (ses-jump 'A2)
145 (ses-insert-row 1) 148 (ses-insert-row 1)
146 (ses-command-hook) 149 (ses-command-hook)
147 (should-not A2) 150 (should-not (bound-and-true-p A2))
148 (should (eq A3 2))))) 151 (should (eq (bound-and-true-p A3) 2)))))
152
153(defvar ses--bar)
149 154
150(ert-deftest ses-tests-renamed-cells-row-insertion () 155(ert-deftest ses-tests-renamed-cells-row-insertion ()
151 "Check that setting A1 to 1 and A2 to (1+ A1), and then renaming A1 to `foo' and A2 to `bar' jumping 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
152to `bar' and inserting a row, makes A2 value empty, and `bar' equal to 157to `ses--bar' and inserting a row, makes A2 value empty, and `ses--bar' equal to
1532." 1582."
154 (let ((ses-initial-size '(2 . 1))) 159 (let ((ses-initial-size '(2 . 1)))
155 (with-temp-buffer 160 (with-temp-buffer
@@ -157,16 +162,16 @@ to `bar' and inserting a row, makes A2 value empty, and `bar' equal to
157 (dolist (c '((0 0 1) (1 0 (1+ A1)))) 162 (dolist (c '((0 0 1) (1 0 (1+ A1))))
158 (apply 'funcall-interactively 'ses-edit-cell c)) 163 (apply 'funcall-interactively 'ses-edit-cell c))
159 (ses-command-hook) 164 (ses-command-hook)
160 (ses-rename-cell 'foo (ses-get-cell 0 0)) 165 (ses-rename-cell 'ses--foo (ses-get-cell 0 0))
161 (ses-command-hook) 166 (ses-command-hook)
162 (ses-rename-cell 'bar (ses-get-cell 1 0)) 167 (ses-rename-cell 'ses--bar (ses-get-cell 1 0))
163 (ses-command-hook) 168 (ses-command-hook)
164 (should (eq bar 2)) 169 (should (eq ses--bar 2))
165 (ses-jump 'bar) 170 (ses-jump 'ses--bar)
166 (ses-insert-row 1) 171 (ses-insert-row 1)
167 (ses-command-hook) 172 (ses-command-hook)
168 (should-not A2) 173 (should-not (bound-and-true-p A2))
169 (should (eq bar 2))))) 174 (should (eq ses--bar 2)))))
170 175
171 176
172(provide 'ses-tests) 177(provide 'ses-tests)