branch: externals/elpa
commit b6519a5c1ba965bbb3b2853318b28da5e5faa811
Author: Dan Davison <dandavis...@gmail.com>
Commit: João Távora <joaotav...@gmail.com>

    Per #446: Add tests for eglot-server-programs
    
    The tests use eglot--guess-contact, since that is the only gateway to
    that variable's complex semantics.
    
    Co-authored-by: João Távora <joaotav...@gmail.com>
    
    * eglot-tests.el (eglot--guessing-contact): New helper.
    (eglot-server-programs-simple-executable): New test.
    (eglot-server-programs-executable-multiple-major-modes): New test.
    (eglot-server-programs-executable-with-arg): New test.
    (eglot-server-programs-executable-with-args-and-autoport): New test.
    (eglot-server-programs-host-and-port): New test.
    (eglot-server-programs-host-and-port-and-tcp-args): New test.
    (eglot-server-programs-class-name-and-plist): New test.
    (eglot-server-programs-class-name-and-contact-spec): New test.
    (eglot-server-programs-function): New test.
---
 eglot-tests.el | 80 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 80 insertions(+)

diff --git a/eglot-tests.el b/eglot-tests.el
index f2a9b7f..48c3bfd 100644
--- a/eglot-tests.el
+++ b/eglot-tests.el
@@ -880,6 +880,86 @@ pyls prefers autopep over yafp, despite its README stating 
the contrary."
         (((CodeAction) title command)
          (list title command)))))))
 
+(cl-defmacro eglot--guessing-contact ((guessed-class-sym guessed-contact-sym)
+                                      &body body)
+  "Bind the result of `eglot--guess-contact' then evaluate BODY."
+  (declare (indent 1) (debug t))
+  `(let ((buffer-file-name "_"))
+     (cl-destructuring-bind
+         (_ _ ,guessed-class-sym ,guessed-contact-sym)
+         (eglot--guess-contact)
+       ,@body)))
+
+(ert-deftest eglot-server-programs-simple-executable ()
+  (let ((eglot-server-programs '((foo-mode "some-executable")))
+        (major-mode 'foo-mode))
+    (eglot--guessing-contact (guessed-class guessed-contact)
+      (should (equal guessed-class 'eglot-lsp-server))
+      (should (equal guessed-contact '("some-executable"))))))
+
+(ert-deftest eglot-server-programs-executable-multiple-major-modes ()
+  (let ((eglot-server-programs '(((bar-mode foo-mode) "some-executable")))
+        (major-mode 'foo-mode))
+    (eglot--guessing-contact (guessed-class guessed-contact)
+      (should (equal guessed-class 'eglot-lsp-server))
+      (should (equal guessed-contact '("some-executable"))))))
+
+(ert-deftest eglot-server-programs-executable-with-arg ()
+  (let ((eglot-server-programs '((foo-mode "some-executable" "arg1")))
+        (major-mode 'foo-mode))
+    (eglot--guessing-contact (guessed-class guessed-contact)
+      (should (equal guessed-class 'eglot-lsp-server))
+      (should (equal guessed-contact '("some-executable" "arg1"))))))
+
+(ert-deftest eglot-server-programs-executable-with-args-and-autoport ()
+  (let ((eglot-server-programs '((foo-mode "some-executable" "arg1"
+                                           :autoport "arg2")))
+        (major-mode 'foo-mode))
+    (eglot--guessing-contact (guessed-class guessed-contact)
+      (should (equal guessed-class 'eglot-lsp-server))
+      (should (equal guessed-contact '("some-executable" "arg1"
+                                       :autoport "arg2"))))))
+
+(ert-deftest eglot-server-programs-host-and-port ()
+  (let ((eglot-server-programs '((foo-mode "somehost.example.com" 7777)))
+        (major-mode 'foo-mode))
+    (eglot--guessing-contact (guessed-class guessed-contact)
+      (should (equal guessed-class 'eglot-lsp-server))
+      (should (equal guessed-contact '("somehost.example.com" 7777))))))
+
+(ert-deftest eglot-server-programs-host-and-port-and-tcp-args ()
+  (let ((eglot-server-programs '((foo-mode "somehost.example.com" 7777
+                                           :type network)))
+        (major-mode 'foo-mode))
+    (eglot--guessing-contact (guessed-class guessed-contact)
+      (should (equal guessed-class 'eglot-lsp-server))
+      (should (equal guessed-contact '("somehost.example.com" 7777
+                                       :type network))))))
+
+(ert-deftest eglot-server-programs-class-name-and-plist ()
+  (let ((eglot-server-programs '((foo-mode bar-class :init-key init-val)))
+        (major-mode 'foo-mode))
+    (eglot--guessing-contact (guessed-class guessed-contact)
+      (should (equal guessed-class 'bar-class))
+      (should (equal guessed-contact '(:init-key init-val))))))
+
+(ert-deftest eglot-server-programs-class-name-and-contact-spec ()
+  (let ((eglot-server-programs '((foo-mode bar-class "some-executable" "arg1"
+                                           :autoport "arg2")))
+        (major-mode 'foo-mode))
+    (eglot--guessing-contact (guessed-class guessed-contact)
+      (should (equal guessed-class 'bar-class))
+      (should (equal guessed-contact '("some-executable" "arg1"
+                                       :autoport "arg2"))))))
+
+(ert-deftest eglot-server-programs-function ()
+  (let ((eglot-server-programs '((foo-mode . (lambda (&optional _)
+                                               '("some-executable")))))
+        (major-mode 'foo-mode))
+    (eglot--guessing-contact (guessed-class guessed-contact)
+      (should (equal guessed-class 'eglot-lsp-server))
+      (should (equal guessed-contact '("some-executable"))))))
+
 (provide 'eglot-tests)
 ;;; eglot-tests.el ends here
 

Reply via email to