diff options
author | Tim King <kingtim@gmail.com> | 2013-02-19 07:36:05 -0800 |
---|---|---|
committer | Tim King <kingtim@gmail.com> | 2013-02-19 07:36:05 -0800 |
commit | dba299e5c68042112738cbc50b827bf64299d06a (patch) | |
tree | 2d1fcf8b3c8290b8245b7549746338c246cf6bc6 /test | |
parent | 770f9b9f1bbdd6bb9c161c01a8db0f0330bfd4ac (diff) |
Merge #281: Clean up killed connections.
Diffstat (limited to 'test')
-rw-r--r-- | test/nrepl-tests.el | 49 |
1 files changed, 49 insertions, 0 deletions
diff --git a/test/nrepl-tests.el b/test/nrepl-tests.el index 6b6b92e7..b18a0e93 100644 --- a/test/nrepl-tests.el +++ b/test/nrepl-tests.el @@ -134,3 +134,52 @@ (should (equal (nrepl-server-buffer-name) "*nrepl-server*"))) (let ((nrepl-hide-special-buffers t)) (should (equal (nrepl-server-buffer-name) " *nrepl-server*")))) + +(defmacro nrepl-test-with-two-buffers (buffer-names &rest body) + (lexical-let ((create (lambda (b) (list b `(generate-new-buffer " *temp*"))))) + `(lexical-let (,@(mapcar create buffer-names)) + (unwind-protect + ,@body + (mapc 'kill-buffer (list ,@buffer-names)))))) + +(ert-deftest test-nrepl-make-repl-connection-default () + (lexical-let ((connections (nrepl-connection-buffers))) + (nrepl-test-with-two-buffers + (a b) + (should (get-buffer a)) + (should (get-buffer b)) + ;; Add one connection + (nrepl-make-repl-connection-default a) + (should (equal (append (list (buffer-name a)) connections) + (nrepl-connection-buffers))) + (should (equal (buffer-name a) (nrepl-current-connection-buffer))) + ;; Add second connection + (nrepl-make-repl-connection-default b) + (should (equal (append (list (buffer-name b) (buffer-name a)) connections) + (nrepl-connection-buffers))) + (should (equal (buffer-name b) (nrepl-current-connection-buffer)))))) + +(ert-deftest test-nrepl-connection-buffers () + (lexical-let ((connections (nrepl-connection-buffers))) + (nrepl-test-with-two-buffers + (a b) + (nrepl-make-repl-connection-default a) + (nrepl-make-repl-connection-default b) + ;; killing a buffer should see it purged from the connection list + (kill-buffer a) + (should (equal (append (list (buffer-name b)) connections) + (nrepl-connection-buffers))) + (should (equal (buffer-name b) (nrepl-current-connection-buffer)))))) + +(ert-deftest test-nrepl-close () + (lexical-let ((connections (nrepl-connection-buffers))) + (nrepl-test-with-two-buffers + (a b) + (nrepl-make-repl-connection-default a) + (nrepl-make-repl-connection-default b) + ;; closing a buffer should see it removed from the connection list + (nrepl-close a) + (should (not (buffer-live-p a))) + (should (equal (append (list (buffer-name b)) connections) + (nrepl-connection-buffers))) + (should (equal (buffer-name b) (nrepl-current-connection-buffer)))))) |