diff options
Diffstat (limited to 'test/lisp/ses-tests.el')
-rw-r--r-- | test/lisp/ses-tests.el | 151 |
1 files changed, 111 insertions, 40 deletions
diff --git a/test/lisp/ses-tests.el b/test/lisp/ses-tests.el index 3194b261565..ea3f9d05d70 100644 --- a/test/lisp/ses-tests.el +++ b/test/lisp/ses-tests.el @@ -1,6 +1,6 @@ ;;; ses-tests.el --- Tests for ses.el -*- lexical-binding: t; -*- -;; Copyright (C) 2015-2017 Free Software Foundation, Inc. +;; Copyright (C) 2015-2022 Free Software Foundation, Inc. ;; Author: Vincent Belaïche <vincentb1@users.sourceforge.net> @@ -22,8 +22,24 @@ ;;; Code: (require 'ert) +(eval-when-compile (require 'ert-x)) (require 'ses) +;; Silence byte-compiler. +(with-suppressed-warnings ((lexical ses--cells) + (lexical A2) + (lexical A3) + (lexical ses--foo) + (lexical ses--bar) + (lexical B2) + (lexical ses--toto)) + (defvar ses--cells) + (defvar A2) + (defvar A3) + (defvar ses--foo) + (defvar ses--bar) + (defvar B2) + (defvar ses--toto)) ;; PLAIN FORMULA TESTS ;; ====================================================================== @@ -38,7 +54,7 @@ interactively." (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 A2 2))))) + (should (eq (bound-and-true-p A2) 2))))) (ert-deftest ses-tests-plain-formula () "Check that setting A1 to 1 and A2 to (1+ A1), makes A2 value @@ -49,13 +65,13 @@ equal to 2. This is done using interactive calls." (dolist (c '((0 0 1) (1 0 (1+ A1)))) (apply 'funcall-interactively 'ses-edit-cell c)) (ses-command-hook) - (should (eq A2 2))))) + (should (eq (bound-and-true-p A2) 2))))) ;; PLAIN CELL RENAMING TESTS ;; ====================================================================== (ert-deftest ses-tests-lowlevel-renamed-cell () - "Check that renaming A1 to `foo' and setting `foo' to 1 and A2 to (1+ foo), makes A2 value equal to 2. + "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. 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." @@ -69,63 +85,63 @@ previously passed in text mode." (text-mode) (goto-char (point-min)) (while (re-search-forward "\\<A1\\>" nil t) - (replace-match "foo" t t)) + (replace-match "ses--foo" t t)) (ses-mode) (should-not (local-variable-p 'A1)) - (should (eq foo 1)) - (should (equal (ses-cell-formula 1 0) '(ses-safe-formula (1+ foo)))) - (should (eq A2 2))))) + (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))))) (ert-deftest ses-tests-renamed-cell () - "Check that renaming A1 to `foo' and setting `foo' to 1 and A2 -to (1+ foo), makes A2 value equal to 2." + "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." (let ((ses-initial-size '(2 . 1))) (with-temp-buffer (ses-mode) - (ses-rename-cell 'foo (ses-get-cell 0 0)) - (dolist (c '((0 0 1) (1 0 (1+ foo)))) + (ses-rename-cell 'ses--foo (ses-get-cell 0 0)) + (dolist (c '((0 0 1) (1 0 (1+ ses--foo)))) (apply 'funcall-interactively 'ses-edit-cell c)) (ses-command-hook) (should-not (local-variable-p 'A1)) - (should (eq foo 1)) - (should (equal (ses-cell-formula 1 0) '(1+ foo))) - (should (eq A2 2))))) + (should (eq ses--foo 1)) + (should (equal (ses-cell-formula 1 0) '(1+ ses--foo))) + (should (eq (bound-and-true-p A2) 2))))) (ert-deftest ses-tests-renamed-cell-after-setting () "Check that setting A1 to 1 and A2 to (1+ A1), and then -renaming A1 to `foo' makes `foo' value equal to 2." +renaming A1 to `ses--foo' makes `ses--foo' value equal to 2." (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); deferred recalc - (ses-rename-cell 'foo (ses-get-cell 0 0)) + (ses-rename-cell 'ses--foo (ses-get-cell 0 0)) (should-not (local-variable-p 'A1)) - (should (eq foo 1)) - (should (equal (ses-cell-formula 1 0) '(1+ foo))) - (should (eq A2 2))))) + (should (eq ses--foo 1)) + (should (equal (ses-cell-formula 1 0) '(1+ ses--foo))) + (should (eq (bound-and-true-p A2) 2))))) (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 `foo' makes `foo' value equal to 1. Then set A1 to 2 and check -that `foo' becomes 2." +to `ses--foo' makes `ses--foo' value equal to 1. Then set A1 to 2 and check +that `ses--foo' becomes 2." (let ((ses-initial-size '(3 . 1))) (with-temp-buffer (ses-mode) (dolist (c '((0 0 1) (1 0 A1))) (apply 'funcall-interactively 'ses-edit-cell c)) (ses-command-hook); deferred recalc - (ses-rename-cell 'foo (ses-get-cell 0 0)) + (ses-rename-cell 'ses--foo (ses-get-cell 0 0)) (ses-command-hook); deferred recalc (should-not (local-variable-p 'A1)) - (should (eq foo 1)) - (should (equal (ses-cell-formula 1 0) 'foo)) - (should (eq A2 1)) + (should (eq ses--foo 1)) + (should (equal (ses-cell-formula 1 0) 'ses--foo)) + (should (eq (bound-and-true-p A2) 1)) (funcall-interactively 'ses-edit-cell 0 0 2) (ses-command-hook); deferred recalc - (should (eq A2 2)) - (should (eq foo 2))))) + (should (eq (bound-and-true-p A2) 2)) + (should (eq ses--foo 2))))) ;; ROW INSERTION TESTS @@ -144,32 +160,87 @@ to A2 and inserting a row, makes A2 value empty, and A3 equal to (ses-jump 'A2) (ses-insert-row 1) (ses-command-hook) - (should-not A2) - (should (eq A3 2))))) + (should-not (bound-and-true-p A2)) + (should (eq (bound-and-true-p A3) 2))))) -; (defvar ses-tests-trigger nil) (ert-deftest ses-tests-renamed-cells-row-insertion () - "Check that setting A1 to 1 and A2 to (1+ A1), and then renaming A1 to `foo' and A2 to `bar' jumping -to `bar' and inserting a row, makes A2 value empty, and `bar' equal to + "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." - (setq ses-tests-trigger nil) (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) - (ses-rename-cell 'foo (ses-get-cell 0 0)) + (ses-rename-cell 'ses--foo (ses-get-cell 0 0)) (ses-command-hook) - (ses-rename-cell 'bar (ses-get-cell 1 0)) + (ses-rename-cell 'ses--bar (ses-get-cell 1 0)) (ses-command-hook) - (should (eq bar 2)) - (ses-jump 'bar) + (should (eq ses--bar 2)) + (ses-jump 'ses--bar) (ses-insert-row 1) (ses-command-hook) - (should-not A2) - (should (eq bar 2))))) + (should-not (bound-and-true-p A2)) + (should (eq ses--bar 2))))) +;; JUMP tests +;; ====================================================================== +(ert-deftest ses-jump-B2-prefix-arg () + "Test jumping to cell B2 by use of prefix argument" + (let ((ses-initial-size '(3 . 3)) + ses-after-entry-functions) + (with-temp-buffer + (ses-mode) + ;; C-u 4 M-x ses-jump + (let ((current-prefix-arg 4)) + (call-interactively 'ses-jump)) + (should (eq (ses--cell-at-pos (point)) 'B2))))) + + +(ert-deftest ses-jump-B2-lowcase () + "Test jumping to cell B2 by use of lowcase cell name string" + (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))))) + +(ert-deftest ses-jump-B2-lowcase-keys () + "Test jumping to cell B2 by use of lowcase cell name string with simulating keys" + (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))))) + +(ert-deftest ses-jump-B2-symbol () + "Test jumping to cell B2 by use of cell name symbol" + (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))))) + +(ert-deftest ses-jump-B2-renamed () + "Test jumping to cell B2 after renaming it `ses--toto'." + (let ((ses-initial-size '(3 . 3)) + ses-after-entry-functions) + (with-temp-buffer + (ses-mode) + (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))))) + (provide 'ses-tests) + +;;; ses-tests.el ends here |