From 1127de66a710f722d385089041d26cc23195f50c Mon Sep 17 00:00:00 2001 From: Takafumi Arakaki Date: Sat, 16 Jun 2012 20:11:51 +0200 Subject: [PATCH] Add two tests for undo in notebook --- tests/test-ein-notebook.el | 77 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 77 insertions(+) diff --git a/tests/test-ein-notebook.el b/tests/test-ein-notebook.el index 05fde5d..5f3da2e 100644 --- a/tests/test-ein-notebook.el +++ b/tests/test-ein-notebook.el @@ -388,6 +388,83 @@ some text (should (search-forward "\nHello World\n" nil t)) ; stream output (should-not (search-forward "Hello World" nil t)))))) + +;; Notebook undo + +(ert-deftest ein:notebook-undo-after-execution () + (with-current-buffer (eintest:notebook-make-empty) + (ein:notebook-insert-cell-below-command) + (let* ((text "print 'Hello World'") + (output-text "Hello World\n") + (cell (ein:notebook-get-current-cell)) + (kernel (ein:$notebook-kernel ein:notebook)) + (msg-id "DUMMY-MSG-ID") + (callbacks (ein:cell-make-callbacks cell)) + (check-output + (lambda () + (save-excursion + (goto-char (point-min)) + (should (search-forward (concat "\n" output-text) nil t)) + (should-not (search-forward "Hello World" nil t)))))) + (eintest:notebook-check-kernel-and-codecell kernel cell) + ;; Execute + (insert text) + (undo-boundary) + (eintest:notebook-fake-execution kernel text msg-id callbacks) + (ein:kernel-set-callbacks-for-msg kernel msg-id callbacks) + ;; Stream output + (eintest:kernel-fake-stream kernel msg-id output-text) + (funcall check-output) + ;; Undo + (should (equal (ein:cell-get-text cell) text)) + (undo) + (should (equal (ein:cell-get-text cell) "")) + ;; FIXME: Known bug. (it must succeed.) + (should-error (funcall check-output))))) + +(ert-deftest ein:notebook-undo-after-execution-2-cells () + (with-current-buffer (eintest:notebook-make-empty) + (ein:notebook-insert-cell-below-command) + (ein:notebook-insert-cell-above-command) + (let* ((text "print 'Hello World\\n' * 10") + (next-text "something") + (output-text + (apply #'concat (loop repeat 10 collect "Hello World\n"))) + (cell (ein:notebook-get-current-cell)) + (next-cell (ein:cell-next cell)) + (kernel (ein:$notebook-kernel ein:notebook)) + (msg-id "DUMMY-MSG-ID") + (callbacks (ein:cell-make-callbacks cell)) + (check-output + (lambda () + (save-excursion + (goto-char (point-min)) + (should (search-forward (concat "\n" output-text) nil t)) + (should-not (search-forward "Hello World" nil t)))))) + (eintest:notebook-check-kernel-and-codecell kernel cell) + ;; Execute + (insert text) + (undo-boundary) + (let ((pos (point))) + ;; Do not use `save-excursion' because it does not record undo. + (ein:notebook-goto-next-input-command) + (insert next-text) + (undo-boundary) + (goto-char pos)) + (eintest:notebook-fake-execution kernel text msg-id callbacks) + (ein:kernel-set-callbacks-for-msg kernel msg-id callbacks) + ;; Stream output + (eintest:kernel-fake-stream kernel msg-id output-text) + (funcall check-output) + ;; Undo + (should (equal (ein:cell-get-text cell) text)) + (should (equal (ein:cell-get-text next-cell) next-text)) + (undo) + (should (equal (ein:cell-get-text cell) text)) + ;; FIXME: Known bug. (these two must succeed.) + (should-error (should (equal (ein:cell-get-text next-cell) ""))) + (should-error (funcall check-output))))) + ;; Notebook mode