summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCraig Jennings <c@cjennings.net>2026-05-14 01:07:49 -0500
committerCraig Jennings <c@cjennings.net>2026-05-14 01:07:49 -0500
commita097e33cbc2027b416f6d4160b55f69bca8c4660 (patch)
treecf43ff43bb30597fb357a8596ef300d89c019257
parent902693e9ea8ccf56d24a977d3d407f585c6cf046 (diff)
downloaddotemacs-a097e33cbc2027b416f6d4160b55f69bca8c4660.tar.gz
dotemacs-a097e33cbc2027b416f6d4160b55f69bca8c4660.zip
test(prog-python+webdev): cover the per-buffer setup mode hooks
`cj/python-setup` and `cj/webdev-setup` are the per-buffer preference functions wired into `python-ts-mode` / `typescript-ts-mode` / `tsx-ts-mode` / `js-ts-mode`. Sibling tests covered the command builders and prettier/mypy wrappers but not these. 9 new tests across two files cover, for each setup: - the setq-local pairs (fill-column, tab-width, standard-indent, indent-tabs-mode) land at the language's defaults (Python: 80/4/4/nil; webdev: 100/2/2/nil), - the mode helpers (company, flyspell-prog, superword, electric-pair-local) all get called, - LSP gating: starts when the language server binary is on PATH, skips otherwise. Plus a check that `cj/webdev-keybindings` binds `C-; f` to the prettier wrapper. External modes and `executable-find` / `lsp-deferred` are stubbed so the tests run without a Python or Node toolchain.
-rw-r--r--tests/test-prog-python-setup.el94
-rw-r--r--tests/test-prog-webdev-setup.el97
2 files changed, 191 insertions, 0 deletions
diff --git a/tests/test-prog-python-setup.el b/tests/test-prog-python-setup.el
new file mode 100644
index 00000000..0b56f8cc
--- /dev/null
+++ b/tests/test-prog-python-setup.el
@@ -0,0 +1,94 @@
+;;; test-prog-python-setup.el --- Tests for cj/python-setup mode hook -*- lexical-binding: t; -*-
+
+;;; Commentary:
+;; Sibling tests cover the pure command builders and the interactive
+;; mypy/debug wrappers. `cj/python-setup' itself -- the per-buffer
+;; preferences applied when `python-ts-mode' starts -- was uncovered.
+;; The external modes (`company-mode', `flyspell-prog-mode',
+;; `superword-mode', `electric-pair-local-mode', `lsp-deferred') are
+;; stubbed so the test exercises the setq-local assignments and the
+;; LSP gating without needing a real Python install or LSP backend.
+
+;;; Code:
+
+(require 'ert)
+(require 'cl-lib)
+
+(add-to-list 'load-path (expand-file-name "modules" user-emacs-directory))
+(add-to-list 'load-path (expand-file-name "tests" user-emacs-directory))
+(require 'testutil-format-wiring)
+(format-test--ensure-packages-init)
+(require 'prog-python)
+
+(defmacro test-pp-setup--with-stubs (&rest body)
+ "Stub mode-toggles and LSP primitives, then evaluate BODY."
+ `(cl-letf (((symbol-function 'company-mode) #'ignore)
+ ((symbol-function 'flyspell-prog-mode) #'ignore)
+ ((symbol-function 'superword-mode) #'ignore)
+ ((symbol-function 'electric-pair-local-mode) #'ignore))
+ ,@body))
+
+(ert-deftest test-prog-python-setup-sets-buffer-local-preferences ()
+ "Normal: fill-column, tab-width, standard-indent, indent-tabs-mode all
+land at the Python defaults (80 / 4 / 4 / nil)."
+ (with-temp-buffer
+ (test-pp-setup--with-stubs
+ (cj/python-setup)
+ (should (= fill-column 80))
+ (should (= tab-width 4))
+ (should (= standard-indent 4))
+ (should-not indent-tabs-mode))))
+
+(ert-deftest test-prog-python-setup-enables-mode-helpers ()
+ "Normal: company-mode, flyspell-prog-mode, superword-mode, and
+electric-pair-local-mode all get called once."
+ (with-temp-buffer
+ (let ((calls nil))
+ (cl-letf (((symbol-function 'company-mode)
+ (lambda (&rest _) (push 'company calls)))
+ ((symbol-function 'flyspell-prog-mode)
+ (lambda (&rest _) (push 'flyspell calls)))
+ ((symbol-function 'superword-mode)
+ (lambda (&rest _) (push 'superword calls)))
+ ((symbol-function 'electric-pair-local-mode)
+ (lambda (arg) (push (cons 'pair arg) calls))))
+ (cj/python-setup))
+ (should (memq 'company calls))
+ (should (memq 'flyspell calls))
+ (should (memq 'superword calls))
+ ;; electric-pair-local-mode gets enabled (truthy arg)
+ (should (assq 'pair calls))
+ (should (cdr (assq 'pair calls))))))
+
+(ert-deftest test-prog-python-setup-starts-lsp-when-pyright-on-path ()
+ "Normal: with pyright on PATH, `lsp-deferred' is called."
+ (with-temp-buffer
+ (let ((started nil))
+ (cl-letf (((symbol-function 'company-mode) #'ignore)
+ ((symbol-function 'flyspell-prog-mode) #'ignore)
+ ((symbol-function 'superword-mode) #'ignore)
+ ((symbol-function 'electric-pair-local-mode) #'ignore)
+ ((symbol-function 'lsp-deferred)
+ (lambda (&rest _) (setq started t)))
+ ((symbol-function 'executable-find)
+ (lambda (path) (when (equal path pyright-path)
+ "/usr/bin/pyright"))))
+ (cj/python-setup))
+ (should started))))
+
+(ert-deftest test-prog-python-setup-skips-lsp-without-pyright ()
+ "Boundary: without pyright on PATH, `lsp-deferred' is NOT called."
+ (with-temp-buffer
+ (let ((started nil))
+ (cl-letf (((symbol-function 'company-mode) #'ignore)
+ ((symbol-function 'flyspell-prog-mode) #'ignore)
+ ((symbol-function 'superword-mode) #'ignore)
+ ((symbol-function 'electric-pair-local-mode) #'ignore)
+ ((symbol-function 'lsp-deferred)
+ (lambda (&rest _) (setq started t)))
+ ((symbol-function 'executable-find) (lambda (_) nil)))
+ (cj/python-setup))
+ (should-not started))))
+
+(provide 'test-prog-python-setup)
+;;; test-prog-python-setup.el ends here
diff --git a/tests/test-prog-webdev-setup.el b/tests/test-prog-webdev-setup.el
new file mode 100644
index 00000000..45310f23
--- /dev/null
+++ b/tests/test-prog-webdev-setup.el
@@ -0,0 +1,97 @@
+;;; test-prog-webdev-setup.el --- Tests for cj/webdev-setup mode hook -*- lexical-binding: t; -*-
+
+;;; Commentary:
+;; Sibling tests cover the prettier format wrapper and command builder.
+;; `cj/webdev-setup' (the shared per-buffer preferences for TS/JS/TSX
+;; modes) was uncovered. Same stub-and-assert shape as the prog-python
+;; setup test.
+
+;;; Code:
+
+(require 'ert)
+(require 'cl-lib)
+
+(add-to-list 'load-path (expand-file-name "modules" user-emacs-directory))
+(add-to-list 'load-path (expand-file-name "tests" user-emacs-directory))
+(require 'testutil-format-wiring)
+(format-test--ensure-packages-init)
+(require 'prog-webdev)
+
+(defmacro test-pw-setup--with-stubs (&rest body)
+ "Stub mode-toggles + LSP primitives, then evaluate BODY."
+ `(cl-letf (((symbol-function 'company-mode) #'ignore)
+ ((symbol-function 'flyspell-prog-mode) #'ignore)
+ ((symbol-function 'superword-mode) #'ignore)
+ ((symbol-function 'electric-pair-local-mode) #'ignore))
+ ,@body))
+
+(ert-deftest test-prog-webdev-setup-sets-buffer-local-preferences ()
+ "Normal: fill-column, tab-width, standard-indent, indent-tabs-mode all
+land at the webdev defaults (100 / 2 / 2 / nil)."
+ (with-temp-buffer
+ (test-pw-setup--with-stubs
+ (cj/webdev-setup)
+ (should (= fill-column 100))
+ (should (= tab-width 2))
+ (should (= standard-indent 2))
+ (should-not indent-tabs-mode))))
+
+(ert-deftest test-prog-webdev-setup-enables-mode-helpers ()
+ "Normal: company-mode, flyspell-prog-mode, superword-mode, and
+electric-pair-local-mode all get called."
+ (with-temp-buffer
+ (let ((calls nil))
+ (cl-letf (((symbol-function 'company-mode)
+ (lambda (&rest _) (push 'company calls)))
+ ((symbol-function 'flyspell-prog-mode)
+ (lambda (&rest _) (push 'flyspell calls)))
+ ((symbol-function 'superword-mode)
+ (lambda (&rest _) (push 'superword calls)))
+ ((symbol-function 'electric-pair-local-mode)
+ (lambda (arg) (push (cons 'pair arg) calls))))
+ (cj/webdev-setup))
+ (should (memq 'company calls))
+ (should (memq 'flyspell calls))
+ (should (memq 'superword calls))
+ (should (assq 'pair calls))
+ (should (cdr (assq 'pair calls))))))
+
+(ert-deftest test-prog-webdev-setup-starts-lsp-when-tsserver-on-path ()
+ "Normal: with typescript-language-server on PATH, `lsp-deferred' fires."
+ (with-temp-buffer
+ (let ((started nil))
+ (cl-letf (((symbol-function 'company-mode) #'ignore)
+ ((symbol-function 'flyspell-prog-mode) #'ignore)
+ ((symbol-function 'superword-mode) #'ignore)
+ ((symbol-function 'electric-pair-local-mode) #'ignore)
+ ((symbol-function 'lsp-deferred)
+ (lambda (&rest _) (setq started t)))
+ ((symbol-function 'executable-find)
+ (lambda (path) (when (equal path ts-language-server-path)
+ "/usr/bin/typescript-language-server"))))
+ (cj/webdev-setup))
+ (should started))))
+
+(ert-deftest test-prog-webdev-setup-skips-lsp-without-tsserver ()
+ "Boundary: without typescript-language-server, `lsp-deferred' is NOT called."
+ (with-temp-buffer
+ (let ((started nil))
+ (cl-letf (((symbol-function 'company-mode) #'ignore)
+ ((symbol-function 'flyspell-prog-mode) #'ignore)
+ ((symbol-function 'superword-mode) #'ignore)
+ ((symbol-function 'electric-pair-local-mode) #'ignore)
+ ((symbol-function 'lsp-deferred)
+ (lambda (&rest _) (setq started t)))
+ ((symbol-function 'executable-find) (lambda (_) nil)))
+ (cj/webdev-setup))
+ (should-not started))))
+
+(ert-deftest test-prog-webdev-keybindings-binds-format-key ()
+ "Normal: `cj/webdev-keybindings' wires C-; f to the prettier wrapper."
+ (with-temp-buffer
+ (use-local-map (make-sparse-keymap))
+ (cj/webdev-keybindings)
+ (should (eq #'cj/webdev-format-buffer (local-key-binding (kbd "C-; f"))))))
+
+(provide 'test-prog-webdev-setup)
+;;; test-prog-webdev-setup.el ends here