mirror of
https://git.savannah.gnu.org/git/emacs.git
synced 2026-09-10 07:46:51 -04:00
Check all SES local variables are always set locally.
This commit is contained in:
parent
b677a90303
commit
ebd982db33
|
|
@ -41,6 +41,19 @@
|
|||
(defvar B2)
|
||||
(defvar ses--toto))
|
||||
|
||||
;; Check no border effects
|
||||
;; ======================================================================
|
||||
(defun ses-tests-check-no-border-effect ()
|
||||
(dolist (symb ses-localvars)
|
||||
(when (consp symb) (setq symb (car symb)))
|
||||
(when (string-match "\\`ses--" (symbol-name symb))
|
||||
(should (null (boundp symb))))))
|
||||
|
||||
(defun ses-tests-unbind-local-vars ()
|
||||
(dolist (symb ses-localvars)
|
||||
(when (consp symb) (setq symb (car symb)))
|
||||
(when (string-match "\\`ses--" (symbol-name symb)) (makunbound symb))))
|
||||
|
||||
;; PLAIN FORMULA TESTS
|
||||
;; ======================================================================
|
||||
|
||||
|
|
@ -48,24 +61,28 @@
|
|||
"Check that setting A1 to 1 and A2 to (1+ A1), makes A2 value
|
||||
equal to 2. This is done with low level functions calls, not like
|
||||
interactively."
|
||||
(ses-tests-unbind-local-vars)
|
||||
(let ((ses-initial-size '(2 . 1)))
|
||||
(with-temp-buffer
|
||||
(ses-mode)
|
||||
(dolist (c '((0 0 1) (1 0 (1+ A1))))
|
||||
(apply 'ses-cell-set-formula c)
|
||||
(apply 'ses-calculate-cell (list (car c) (cadr c) nil)))
|
||||
(should (eq (bound-and-true-p A2) 2)))))
|
||||
(should (eq (bound-and-true-p A2) 2))))
|
||||
(ses-tests-check-no-border-effect))
|
||||
|
||||
(ert-deftest ses-tests-plain-formula ()
|
||||
"Check that setting A1 to 1 and A2 to (1+ A1), makes A2 value
|
||||
equal to 2. This is done using interactive calls."
|
||||
(ses-tests-unbind-local-vars)
|
||||
(let ((ses-initial-size '(2 . 1)))
|
||||
(with-temp-buffer
|
||||
(ses-mode)
|
||||
(dolist (c '((0 0 1) (1 0 (1+ A1))))
|
||||
(apply 'funcall-interactively 'ses-edit-cell c))
|
||||
(ses-command-hook)
|
||||
(should (eq (bound-and-true-p A2) 2)))))
|
||||
(should (eq (bound-and-true-p A2) 2))))
|
||||
(ses-tests-check-no-border-effect))
|
||||
|
||||
;; PLAIN CELL RENAMING TESTS
|
||||
;; ======================================================================
|
||||
|
|
@ -75,6 +92,7 @@ equal to 2. This is done using interactive calls."
|
|||
This is done using low level functions, `ses-rename-cell' is not
|
||||
called but instead we use text replacement in the buffer
|
||||
previously passed in text mode."
|
||||
(ses-tests-unbind-local-vars)
|
||||
(let ((ses-initial-size '(2 . 1)))
|
||||
(with-temp-buffer
|
||||
(ses-mode)
|
||||
|
|
@ -90,11 +108,13 @@ previously passed in text mode."
|
|||
(should-not (local-variable-p 'A1))
|
||||
(should (eq ses--foo 1))
|
||||
(should (equal (ses-cell-formula 1 0) '(ses-safe-formula (1+ ses--foo))))
|
||||
(should (eq (bound-and-true-p A2) 2)))))
|
||||
(should (eq (bound-and-true-p A2) 2))))
|
||||
(ses-tests-check-no-border-effect))
|
||||
|
||||
(ert-deftest ses-tests-renamed-cell ()
|
||||
"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."
|
||||
(ses-tests-unbind-local-vars)
|
||||
(let ((ses-initial-size '(2 . 1)))
|
||||
(with-temp-buffer
|
||||
(ses-mode)
|
||||
|
|
@ -105,11 +125,13 @@ to (1+ ses--foo), makes A2 value equal to 2."
|
|||
(should-not (local-variable-p 'A1))
|
||||
(should (eq ses--foo 1))
|
||||
(should (equal (ses-cell-formula 1 0) '(1+ ses--foo)))
|
||||
(should (eq (bound-and-true-p A2) 2)))))
|
||||
(should (eq (bound-and-true-p A2) 2))))
|
||||
(ses-tests-check-no-border-effect))
|
||||
|
||||
(ert-deftest ses-tests-renamed-cell-after-setting ()
|
||||
"Check that setting A1 to 1 and A2 to (1+ A1), and then
|
||||
renaming A1 to `ses--foo' makes `ses--foo' value equal to 2."
|
||||
(ses-tests-unbind-local-vars)
|
||||
(let ((ses-initial-size '(2 . 1)))
|
||||
(with-temp-buffer
|
||||
(ses-mode)
|
||||
|
|
@ -120,12 +142,14 @@ renaming A1 to `ses--foo' makes `ses--foo' value equal to 2."
|
|||
(should-not (local-variable-p 'A1))
|
||||
(should (eq ses--foo 1))
|
||||
(should (equal (ses-cell-formula 1 0) '(1+ ses--foo)))
|
||||
(should (eq (bound-and-true-p A2) 2)))))
|
||||
(should (eq (bound-and-true-p A2) 2))))
|
||||
(ses-tests-check-no-border-effect))
|
||||
|
||||
(ert-deftest ses-tests-renaming-cell-with-one-symbol-formula ()
|
||||
"Check that setting A1 to 1 and A2 to A1, and then renaming A1
|
||||
to `ses--foo' makes `ses--foo' value equal to 1. Then set A1 to 2 and check
|
||||
that `ses--foo' becomes 2."
|
||||
(ses-tests-unbind-local-vars)
|
||||
(let ((ses-initial-size '(3 . 1)))
|
||||
(with-temp-buffer
|
||||
(ses-mode)
|
||||
|
|
@ -141,7 +165,8 @@ that `ses--foo' becomes 2."
|
|||
(funcall-interactively 'ses-edit-cell 0 0 2)
|
||||
(ses-command-hook); deferred recalc
|
||||
(should (eq (bound-and-true-p A2) 2))
|
||||
(should (eq ses--foo 2)))))
|
||||
(should (eq ses--foo 2))))
|
||||
(ses-tests-check-no-border-effect))
|
||||
|
||||
|
||||
;; ROW INSERTION TESTS
|
||||
|
|
@ -151,6 +176,7 @@ that `ses--foo' becomes 2."
|
|||
"Check that setting A1 to 1 and A2 to (1+ A1), and then jumping
|
||||
to A2 and inserting a row, makes A2 value empty, and A3 equal to
|
||||
2."
|
||||
(ses-tests-unbind-local-vars)
|
||||
(let ((ses-initial-size '(2 . 1)))
|
||||
(with-temp-buffer
|
||||
(ses-mode)
|
||||
|
|
@ -161,13 +187,15 @@ to A2 and inserting a row, makes A2 value empty, and A3 equal to
|
|||
(ses-insert-row 1)
|
||||
(ses-command-hook)
|
||||
(should-not (bound-and-true-p A2))
|
||||
(should (eq (bound-and-true-p A3) 2)))))
|
||||
(should (eq (bound-and-true-p A3) 2))))
|
||||
(ses-tests-check-no-border-effect))
|
||||
|
||||
|
||||
(ert-deftest ses-tests-renamed-cells-row-insertion ()
|
||||
"Check that setting A1 to 1 and A2 to (1+ A1), and then renaming A1 to `ses--foo' and A2 to `ses--bar' jumping
|
||||
to `ses--bar' and inserting a row, makes A2 value empty, and `ses--bar' equal to
|
||||
2."
|
||||
(ses-tests-unbind-local-vars)
|
||||
(let ((ses-initial-size '(2 . 1)))
|
||||
(with-temp-buffer
|
||||
(ses-mode)
|
||||
|
|
@ -183,13 +211,15 @@ to `ses--bar' and inserting a row, makes A2 value empty, and `ses--bar' equal to
|
|||
(ses-insert-row 1)
|
||||
(ses-command-hook)
|
||||
(should-not (bound-and-true-p A2))
|
||||
(should (eq ses--bar 2)))))
|
||||
(should (eq ses--bar 2))))
|
||||
(ses-tests-check-no-border-effect))
|
||||
|
||||
|
||||
;; JUMP tests
|
||||
;; ======================================================================
|
||||
(ert-deftest ses-tests-jump-B2-prefix-arg ()
|
||||
"Test jumping to cell B2 by use of prefix argument"
|
||||
(ses-tests-unbind-local-vars)
|
||||
(let ((ses-initial-size '(3 . 3))
|
||||
ses-after-entry-functions)
|
||||
(with-temp-buffer
|
||||
|
|
@ -197,41 +227,49 @@ to `ses--bar' and inserting a row, makes A2 value empty, and `ses--bar' equal to
|
|||
;; C-u 4 M-x ses-jump
|
||||
(let ((current-prefix-arg 4))
|
||||
(call-interactively 'ses-jump))
|
||||
(should (eq (ses--cell-at-pos (point)) 'B2)))))
|
||||
(should (eq (ses--cell-at-pos (point)) 'B2))))
|
||||
(ses-tests-check-no-border-effect))
|
||||
|
||||
|
||||
(ert-deftest ses-tests-jump-B2-lowcase ()
|
||||
"Test jumping to cell B2 by use of lowercase cell name string"
|
||||
(ses-tests-unbind-local-vars)
|
||||
(let ((ses-initial-size '(3 . 3))
|
||||
ses-after-entry-functions)
|
||||
(with-temp-buffer
|
||||
(ses-mode)
|
||||
(funcall-interactively 'ses-jump "b2")
|
||||
(ses-command-hook)
|
||||
(should (eq (ses--cell-at-pos (point)) 'B2)))))
|
||||
(should (eq (ses--cell-at-pos (point)) 'B2))))
|
||||
(ses-tests-check-no-border-effect))
|
||||
|
||||
(ert-deftest ses-tests-jump-B2-lowcase-keys ()
|
||||
"Test jumping to cell B2 by use of lowercase cell name string with simulating keys"
|
||||
(ses-tests-unbind-local-vars)
|
||||
(let ((ses-initial-size '(3 . 3))
|
||||
ses-after-entry-functions)
|
||||
(with-temp-buffer
|
||||
(ses-mode)
|
||||
(ert-simulate-keys [ ?b ?2 return] (ses-jump))
|
||||
(ses-command-hook)
|
||||
(should (eq (ses--cell-at-pos (point)) 'B2)))))
|
||||
(should (eq (ses--cell-at-pos (point)) 'B2))))
|
||||
(ses-tests-check-no-border-effect))
|
||||
|
||||
(ert-deftest ses-tests-jump-B2-symbol ()
|
||||
"Test jumping to cell B2 by use of cell name symbol"
|
||||
(ses-tests-unbind-local-vars)
|
||||
(let ((ses-initial-size '(3 . 3))
|
||||
ses-after-entry-functions)
|
||||
(with-temp-buffer
|
||||
(ses-mode)
|
||||
(funcall-interactively 'ses-jump 'B2)
|
||||
(ses-command-hook)
|
||||
(should (eq (ses--cell-at-pos (point)) 'B2)))))
|
||||
(should (eq (ses--cell-at-pos (point)) 'B2))))
|
||||
(ses-tests-check-no-border-effect))
|
||||
|
||||
(ert-deftest ses-tests-jump-B2-renamed ()
|
||||
"Test jumping to cell B2 after renaming it `ses--toto'."
|
||||
(ses-tests-unbind-local-vars)
|
||||
(let ((ses-initial-size '(3 . 3))
|
||||
ses-after-entry-functions)
|
||||
(with-temp-buffer
|
||||
|
|
@ -239,12 +277,14 @@ to `ses--bar' and inserting a row, makes A2 value empty, and `ses--bar' equal to
|
|||
(ses-rename-cell 'ses--toto (ses-get-cell 1 1))
|
||||
(ses-jump 'ses--toto)
|
||||
(ses-command-hook)
|
||||
(should (eq (ses--cell-at-pos (point)) 'ses--toto)))))
|
||||
(should (eq (ses--cell-at-pos (point)) 'ses--toto))))
|
||||
(ses-tests-check-no-border-effect))
|
||||
|
||||
(ert-deftest ses-tests-set-formula-write-cells-with-changed-references ()
|
||||
"Test fix of bug#5852.
|
||||
When setting a formula has some cell with changed references, this
|
||||
cell has to be rewritten to data area."
|
||||
(ses-tests-unbind-local-vars)
|
||||
(let ((ses-initial-size '(4 . 3))
|
||||
(ses-after-entry-functions nil))
|
||||
(with-temp-buffer
|
||||
|
|
@ -261,7 +301,8 @@ cell has to be rewritten to data area."
|
|||
(ses-command-hook)
|
||||
(should (equal (ses-cell-references 1 1) '(B3)))
|
||||
(ses-mode)
|
||||
(should (equal (ses-cell-references 1 1) '(B3))))))
|
||||
(should (equal (ses-cell-references 1 1) '(B3)))))
|
||||
(ses-tests-check-no-border-effect))
|
||||
|
||||
(provide 'ses-tests)
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue