From 8f214c92fde68a97a147799daa84c074f5a38c32 Mon Sep 17 00:00:00 2001 From: Bozhidar Batsov Date: Fri, 30 May 2014 22:47:33 +0300 Subject: [PATCH 001/199] Lay the groundwork of a test suite --- clojure-mode-test.el | 83 ++++++++++++++++++++++++++++++++++++++++++++ test-helper.el | 39 +++++++++++++++++++++ 2 files changed, 122 insertions(+) create mode 100644 clojure-mode-test.el create mode 100644 test-helper.el diff --git a/clojure-mode-test.el b/clojure-mode-test.el new file mode 100644 index 0000000..5eb5402 --- /dev/null +++ b/clojure-mode-test.el @@ -0,0 +1,83 @@ +;;; clojure-mode-test.el --- Clojure Mode: Unit test suite -*- lexical-binding: t; -*- + +;; Copyright (C) 2014 Bozhidar Batsov + +;; This file is not part of GNU Emacs. + +;; This program is free software; you can redistribute it and/or modify +;; it under the terms of the GNU General Public License as published by +;; the Free Software Foundation, either version 3 of the License, or +;; (at your option) any later version. + +;; This program is distributed in the hope that it will be useful, +;; but WITHOUT ANY WARRANTY; without even the implied warranty of +;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +;; GNU General Public License for more details. + +;; You should have received a copy of the GNU General Public License +;; along with this program. If not, see . + +;;; Commentary: + +;; The unit test suite of Clojure Mode + +;;; Code: + +(require 'clojure-mode) +(require 'ert) + + +;;;; Utilities + +(defmacro clojure-test-with-temp-buffer (content &rest body) + "Evaluate BODY in a temporary buffer with CONTENTS." + (declare (debug t) + (indent 1)) + `(with-temp-buffer + (insert ,content) + (clojure-mode) + (font-lock-fontify-buffer) + (goto-char (point-min)) + ,@body)) + +(defun clojure-test-face-at (pos &optional content) + "Get the face at POS in CONTENT. + +If CONTENT is not given, return the face at POS in the current +buffer." + (if content + (clojure-test-with-temp-buffer content + (get-text-property pos 'face)) + (get-text-property pos 'face))) + +(defconst clojure-test-syntax-classes + [whitespace punctuation word symbol open-paren close-paren expression-prefix + string-quote paired-delim escape character-quote comment-start + comment-end inherit generic-comment generic-string] + "Readable symbols for syntax classes. + +Each symbol in this vector corresponding to the syntax code of +its index.") + +(defun clojure-test-syntax-at (pos) + "Get the syntax at POS. + +Get the syntax class symbol at POS, or nil if there is no syntax a +POS." + (let ((code (syntax-class (syntax-after pos)))) + (aref clojure-test-syntax-classes code))) + + +;;;; Font locking + +(ert-deftest clojure-mode-syntax-table/fontify-clojure-keyword () + :tags '(fontification syntax-table) + (should (eq (clojure-test-face-at 2 "{:something 20}") 'font-lock-constant-face))) + +(provide 'clojure-mode-test) + +;; Local Variables: +;; indent-tabs-mode: nil +;; End: + +;;; clojure-mode-test.el ends here diff --git a/test-helper.el b/test-helper.el new file mode 100644 index 0000000..558d4ed --- /dev/null +++ b/test-helper.el @@ -0,0 +1,39 @@ +;;; test-helper.el --- Clojure Mode: Non-interactive unit-test setup -*- lexical-binding: t; -*- + +;; Copyright (C) 2014 Bozhidar Batsov + +;; This file is not part of GNU Emacs. + +;; This program is free software; you can redistribute it and/or modify +;; it under the terms of the GNU General Public License as published by +;; the Free Software Foundation, either version 3 of the License, or +;; (at your option) any later version. + +;; This program is distributed in the hope that it will be useful, +;; but WITHOUT ANY WARRANTY; without even the implied warranty of +;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +;; GNU General Public License for more details. + +;; You should have received a copy of the GNU General Public License +;; along with this program. If not, see . + +;;; Commentary: + +;; Non-interactive test suite setup for ERT Runner. + +;;; Code: + +(message "Running tests on Emacs %s" emacs-version) + +(let* ((current-file (if load-in-progress load-file-name (buffer-file-name))) + (source-directory (locate-dominating-file current-file "Cask")) + ;; Do not load outdated byte code for tests + (load-prefer-newer t)) + ;; Load the file under test + (load (expand-file-name "clojure-mode" source-directory))) + +;; Local Variables: +;; indent-tabs-mode: nil +;; End: + +;;; test-helper.el ends here From a1ecf40aa3cb32b62228358f7aa0a58044d682f6 Mon Sep 17 00:00:00 2001 From: Bozhidar Batsov Date: Sat, 31 May 2014 01:13:20 +0300 Subject: [PATCH 002/199] Make it possible to check a range for a specific face --- clojure-mode-test.el | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/clojure-mode-test.el b/clojure-mode-test.el index 5eb5402..50639fb 100644 --- a/clojure-mode-test.el +++ b/clojure-mode-test.el @@ -40,15 +40,22 @@ (goto-char (point-min)) ,@body)) -(defun clojure-test-face-at (pos &optional content) - "Get the face at POS in CONTENT. +(defun clojure-get-face-at-range (start end) + (let ((start-face (get-text-property start 'face)) + (all-faces (cl-loop for i from start to end collect (get-text-property i 'face)))) + (if (cl-every (lambda (face) (eq face start-face)) all-faces) + start-face + 'various-faces))) -If CONTENT is not given, return the face at POS in the current +(defun clojure-test-face-at (start end &optional content) + "Get the face between START and END in CONTENT. + +If CONTENT is not given, return the face at the specified range in the current buffer." (if content (clojure-test-with-temp-buffer content - (get-text-property pos 'face)) - (get-text-property pos 'face))) + (clojure-get-face-at-range start end)) + (clojure-get-face-at-range start end))) (defconst clojure-test-syntax-classes [whitespace punctuation word symbol open-paren close-paren expression-prefix @@ -72,7 +79,7 @@ POS." (ert-deftest clojure-mode-syntax-table/fontify-clojure-keyword () :tags '(fontification syntax-table) - (should (eq (clojure-test-face-at 2 "{:something 20}") 'font-lock-constant-face))) + (should (eq (clojure-test-face-at 2 11 "{:something 20}") 'font-lock-constant-face))) (provide 'clojure-mode-test) From 38c4b4df1e5a3725a964601ea27f85a2fc5daaa6 Mon Sep 17 00:00:00 2001 From: Bozhidar Batsov Date: Sat, 7 Jun 2014 13:34:43 +0300 Subject: [PATCH 003/199] Add a couple more font-lock tests --- clojure-mode-test.el | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/clojure-mode-test.el b/clojure-mode-test.el index 50639fb..21d5aba 100644 --- a/clojure-mode-test.el +++ b/clojure-mode-test.el @@ -81,6 +81,17 @@ POS." :tags '(fontification syntax-table) (should (eq (clojure-test-face-at 2 11 "{:something 20}") 'font-lock-constant-face))) +(ert-deftest clojure-mode-syntax-table/type () + :tags '(fontification syntax-table) + (should (eq (clojure-test-face-at 1 9 "SomeClass") 'font-lock-type-face))) + +(ert-deftest clojure-mode-syntax-table/namespaced-symbol () + :tags '(fontification syntax-table) + (clojure-test-with-temp-buffer "clo.core/something" + (should (eq (clojure-test-face-at 9 9) nil)) + (should (eq (clojure-test-face-at 1 8) 'font-lock-type-face)) + (should (eq (clojure-test-face-at 10 18) nil)))) + (provide 'clojure-mode-test) ;; Local Variables: From 9c08ad2cd041ee2ba5ae911d3e63ae82cf40472c Mon Sep 17 00:00:00 2001 From: Bozhidar Batsov Date: Sun, 8 Jun 2014 15:16:42 +0300 Subject: [PATCH 004/199] Font-lock lambda params (%, %1, %2, etc) --- clojure-mode-test.el | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/clojure-mode-test.el b/clojure-mode-test.el index 21d5aba..afa0465 100644 --- a/clojure-mode-test.el +++ b/clojure-mode-test.el @@ -92,6 +92,13 @@ POS." (should (eq (clojure-test-face-at 1 8) 'font-lock-type-face)) (should (eq (clojure-test-face-at 10 18) nil)))) +(ert-deftest clojure-mode-syntax-table/lambda-params () + :tags '(fontification syntax-table) + (clojure-test-with-temp-buffer "#(+ % %2 %3)" + (should (eq (clojure-test-face-at 5 5) 'font-lock-variable-name-face)) + (should (eq (clojure-test-face-at 7 8) 'font-lock-variable-name-face)) + (should (eq (clojure-test-face-at 10 11) 'font-lock-variable-name-face)))) + (provide 'clojure-mode-test) ;; Local Variables: From d4dbbdfd94131646ab7dd662db688e3d7234b352 Mon Sep 17 00:00:00 2001 From: Bozhidar Batsov Date: Mon, 9 Jun 2014 15:12:13 +0300 Subject: [PATCH 005/199] Fix font-locking bug for namespaced definitions --- clojure-mode-test.el | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/clojure-mode-test.el b/clojure-mode-test.el index afa0465..80edee0 100644 --- a/clojure-mode-test.el +++ b/clojure-mode-test.el @@ -92,6 +92,14 @@ POS." (should (eq (clojure-test-face-at 1 8) 'font-lock-type-face)) (should (eq (clojure-test-face-at 10 18) nil)))) +(ert-deftest clojure-mode-syntax-table/namespaced-def () + :tags '(fontification syntax-table) + (clojure-test-with-temp-buffer "(clo/defbar foo nil)" + (should (eq (clojure-test-face-at 2 4) 'font-lock-type-face)) + (should (eq (clojure-test-face-at 5 5) nil)) + (should (eq (clojure-test-face-at 6 11) 'font-lock-keyword-face)) + (should (eq (clojure-test-face-at 13 15) 'font-lock-function-name-face)))) + (ert-deftest clojure-mode-syntax-table/lambda-params () :tags '(fontification syntax-table) (clojure-test-with-temp-buffer "#(+ % %2 %3)" From 196d8d41d70903cb8363f13666d0dc54c980a022 Mon Sep 17 00:00:00 2001 From: Bozhidar Batsov Date: Mon, 9 Jun 2014 15:13:40 +0300 Subject: [PATCH 006/199] Add missing require --- clojure-mode-test.el | 1 + 1 file changed, 1 insertion(+) diff --git a/clojure-mode-test.el b/clojure-mode-test.el index 80edee0..1088d5c 100644 --- a/clojure-mode-test.el +++ b/clojure-mode-test.el @@ -24,6 +24,7 @@ ;;; Code: (require 'clojure-mode) +(require 'cl-lib) (require 'ert) From 2f21638aed980d14c91e98eb2da4fee5b244c048 Mon Sep 17 00:00:00 2001 From: Bozhidar Batsov Date: Mon, 9 Jun 2014 16:49:58 +0300 Subject: [PATCH 007/199] Use different font-locking for "variables", types and functions --- clojure-mode-test.el | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/clojure-mode-test.el b/clojure-mode-test.el index 1088d5c..c27b7a5 100644 --- a/clojure-mode-test.el +++ b/clojure-mode-test.el @@ -101,6 +101,24 @@ POS." (should (eq (clojure-test-face-at 6 11) 'font-lock-keyword-face)) (should (eq (clojure-test-face-at 13 15) 'font-lock-function-name-face)))) +(ert-deftest clojure-mode-syntax-table/variable-def () + :tags '(fontification syntax-table) + (clojure-test-with-temp-buffer "(def foo 10)" + (should (eq (clojure-test-face-at 2 4) 'font-lock-keyword-face)) + (should (eq (clojure-test-face-at 6 8) 'font-lock-variable-name-face)))) + +(ert-deftest clojure-mode-syntax-table/type-def () + :tags '(fontification syntax-table) + (clojure-test-with-temp-buffer "(deftype Foo)" + (should (eq (clojure-test-face-at 2 8) 'font-lock-keyword-face)) + (should (eq (clojure-test-face-at 10 12) 'font-lock-type-face)))) + +(ert-deftest clojure-mode-syntax-table/function-def () + :tags '(fontification syntax-table) + (clojure-test-with-temp-buffer "(defn foo [x] x)" + (should (eq (clojure-test-face-at 2 5) 'font-lock-keyword-face)) + (should (eq (clojure-test-face-at 7 9) 'font-lock-function-name-face)))) + (ert-deftest clojure-mode-syntax-table/lambda-params () :tags '(fontification syntax-table) (clojure-test-with-temp-buffer "#(+ % %2 %3)" From 5f268e139fa58ce8def60d263744a68688f72670 Mon Sep 17 00:00:00 2001 From: Bozhidar Batsov Date: Wed, 11 Jun 2014 17:25:28 +0300 Subject: [PATCH 008/199] Font lock static method calls like SomeClass/someMethod --- clojure-mode-test.el | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/clojure-mode-test.el b/clojure-mode-test.el index c27b7a5..fd4615c 100644 --- a/clojure-mode-test.el +++ b/clojure-mode-test.el @@ -93,6 +93,13 @@ POS." (should (eq (clojure-test-face-at 1 8) 'font-lock-type-face)) (should (eq (clojure-test-face-at 10 18) nil)))) +(ert-deftest clojure-mode-syntax-table/static-method () + :tags '(fontification syntax-table) + (clojure-test-with-temp-buffer "Class/methodName" + (should (eq (clojure-test-face-at 6 6) nil)) + (should (eq (clojure-test-face-at 1 5) 'font-lock-type-face)) + (should (eq (clojure-test-face-at 7 16) 'font-lock-preprocessor-face)))) + (ert-deftest clojure-mode-syntax-table/namespaced-def () :tags '(fontification syntax-table) (clojure-test-with-temp-buffer "(clo/defbar foo nil)" From 4aa8c8d51606c62019c5c5e3cc72f332908a9f16 Mon Sep 17 00:00:00 2001 From: Bozhidar Batsov Date: Wed, 11 Jun 2014 17:52:55 +0300 Subject: [PATCH 009/199] Font-lock SNAKE_CASE constants --- clojure-mode-test.el | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/clojure-mode-test.el b/clojure-mode-test.el index fd4615c..fe48713 100644 --- a/clojure-mode-test.el +++ b/clojure-mode-test.el @@ -100,6 +100,18 @@ POS." (should (eq (clojure-test-face-at 1 5) 'font-lock-type-face)) (should (eq (clojure-test-face-at 7 16) 'font-lock-preprocessor-face)))) +(ert-deftest clojure-mode-syntax-table/constant () + :tags '(fontification syntax-table) + (should (eq (clojure-test-face-at 1 5 "CONST") 'font-lock-constant-face)) + (should (eq (clojure-test-face-at 1 10 "CONST_NAME") 'font-lock-constant-face))) + +(ert-deftest clojure-mode-syntax-table/class-constant () + :tags '(fontification syntax-table) + (clojure-test-with-temp-buffer "Class/CONST_NAME" + (should (eq (clojure-test-face-at 6 6) nil)) + (should (eq (clojure-test-face-at 1 5) 'font-lock-type-face)) + (should (eq (clojure-test-face-at 7 16) 'font-lock-constant-face)))) + (ert-deftest clojure-mode-syntax-table/namespaced-def () :tags '(fontification syntax-table) (clojure-test-with-temp-buffer "(clo/defbar foo nil)" From 1227c5393d3ec2c43abdd031596a7c11c6dba956 Mon Sep 17 00:00:00 2001 From: Bozhidar Batsov Date: Fri, 13 Jun 2014 15:51:33 +0300 Subject: [PATCH 010/199] Correct the boundaries of nil/true/false font-locking --- clojure-mode-test.el | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/clojure-mode-test.el b/clojure-mode-test.el index fe48713..f0aff76 100644 --- a/clojure-mode-test.el +++ b/clojure-mode-test.el @@ -145,6 +145,11 @@ POS." (should (eq (clojure-test-face-at 7 8) 'font-lock-variable-name-face)) (should (eq (clojure-test-face-at 10 11) 'font-lock-variable-name-face)))) +(ert-deftest clojure-mode-syntax-table/nil () + :tags '(fontification syntax-table) + (should (eq (clojure-test-face-at 4 6 "(= nil x)") 'font-lock-constant-face)) + (should-not (eq (clojure-test-face-at 3 5 "(fnil x)") 'font-lock-constant-face))) + (provide 'clojure-mode-test) ;; Local Variables: From d50c5db11f204dfd46a63ee5d0f9710bbd95a7c6 Mon Sep 17 00:00:00 2001 From: Bozhidar Batsov Date: Fri, 13 Jun 2014 15:53:15 +0300 Subject: [PATCH 011/199] Add a couple of font-locking tests --- clojure-mode-test.el | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/clojure-mode-test.el b/clojure-mode-test.el index f0aff76..3db0ea6 100644 --- a/clojure-mode-test.el +++ b/clojure-mode-test.el @@ -150,6 +150,14 @@ POS." (should (eq (clojure-test-face-at 4 6 "(= nil x)") 'font-lock-constant-face)) (should-not (eq (clojure-test-face-at 3 5 "(fnil x)") 'font-lock-constant-face))) +(ert-deftest clojure-mode-syntax-table/true () + :tags '(fontification syntax-table) + (should (eq (clojure-test-face-at 4 7 "(= true x)") 'font-lock-constant-face))) + +(ert-deftest clojure-mode-syntax-table/false () + :tags '(fontification syntax-table) + (should (eq (clojure-test-face-at 4 8 "(= false x)") 'font-lock-constant-face))) + (provide 'clojure-mode-test) ;; Local Variables: From badb6f29cc14a5fb0b2a0cdd28d6b3dc6c0bfb1b Mon Sep 17 00:00:00 2001 From: Bozhidar Batsov Date: Mon, 16 Jun 2014 09:39:25 +0300 Subject: [PATCH 012/199] Font-lock character literals --- clojure-mode-test.el | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/clojure-mode-test.el b/clojure-mode-test.el index 3db0ea6..e837af0 100644 --- a/clojure-mode-test.el +++ b/clojure-mode-test.el @@ -158,6 +158,13 @@ POS." :tags '(fontification syntax-table) (should (eq (clojure-test-face-at 4 8 "(= false x)") 'font-lock-constant-face))) +(ert-deftest clojure-mode-syntax-table/characters () + :tags '(fontification syntax-table) + (should (eq (clojure-test-face-at 1 2 "\\a") 'font-lock-string-face)) + (should (eq (clojure-test-face-at 1 8 "\\newline") 'font-lock-string-face)) + (should (eq (clojure-test-face-at 1 2 "\\1") 'font-lock-string-face)) + (should (eq (clojure-test-face-at 1 6 "\\u0032") 'font-lock-string-face))) + (provide 'clojure-mode-test) ;; Local Variables: From 1a9b88b7743220400309f84f70e5ec8019183289 Mon Sep 17 00:00:00 2001 From: Bozhidar Batsov Date: Wed, 16 Jul 2014 18:48:00 +0300 Subject: [PATCH 013/199] Font-lock cljx features --- clojure-mode-test.el | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/clojure-mode-test.el b/clojure-mode-test.el index e837af0..4f0a38b 100644 --- a/clojure-mode-test.el +++ b/clojure-mode-test.el @@ -165,6 +165,11 @@ POS." (should (eq (clojure-test-face-at 1 2 "\\1") 'font-lock-string-face)) (should (eq (clojure-test-face-at 1 6 "\\u0032") 'font-lock-string-face))) +(ert-deftest clojure-mode-syntax-table/cljx () + :tags '(fontification syntax-table) + (should (eq (clojure-test-face-at 1 5 "#+clj x") 'font-lock-preprocessor-face)) + (should (eq (clojure-test-face-at 1 6 "#+cljs x") 'font-lock-preprocessor-face))) + (provide 'clojure-mode-test) ;; Local Variables: From fa63ec40b8bb091fa52b9536dcb8dfd2b741345f Mon Sep 17 00:00:00 2001 From: Bozhidar Batsov Date: Mon, 21 Jul 2014 19:23:29 +0300 Subject: [PATCH 014/199] Introduce a few custom faces for things not covered by the standard font-lock faces --- clojure-mode-test.el | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/clojure-mode-test.el b/clojure-mode-test.el index 4f0a38b..fa7396a 100644 --- a/clojure-mode-test.el +++ b/clojure-mode-test.el @@ -80,7 +80,7 @@ POS." (ert-deftest clojure-mode-syntax-table/fontify-clojure-keyword () :tags '(fontification syntax-table) - (should (eq (clojure-test-face-at 2 11 "{:something 20}") 'font-lock-constant-face))) + (should (eq (clojure-test-face-at 2 11 "{:something 20}") 'clojure-keyword-face))) (ert-deftest clojure-mode-syntax-table/type () :tags '(fontification syntax-table) @@ -98,7 +98,7 @@ POS." (clojure-test-with-temp-buffer "Class/methodName" (should (eq (clojure-test-face-at 6 6) nil)) (should (eq (clojure-test-face-at 1 5) 'font-lock-type-face)) - (should (eq (clojure-test-face-at 7 16) 'font-lock-preprocessor-face)))) + (should (eq (clojure-test-face-at 7 16) 'clojure-interop-method-face)))) (ert-deftest clojure-mode-syntax-table/constant () :tags '(fontification syntax-table) @@ -160,10 +160,10 @@ POS." (ert-deftest clojure-mode-syntax-table/characters () :tags '(fontification syntax-table) - (should (eq (clojure-test-face-at 1 2 "\\a") 'font-lock-string-face)) - (should (eq (clojure-test-face-at 1 8 "\\newline") 'font-lock-string-face)) - (should (eq (clojure-test-face-at 1 2 "\\1") 'font-lock-string-face)) - (should (eq (clojure-test-face-at 1 6 "\\u0032") 'font-lock-string-face))) + (should (eq (clojure-test-face-at 1 2 "\\a") 'clojure-character-face)) + (should (eq (clojure-test-face-at 1 8 "\\newline") 'clojure-character-face)) + (should (eq (clojure-test-face-at 1 2 "\\1") 'clojure-character-face)) + (should (eq (clojure-test-face-at 1 6 "\\u0032") 'clojure-character-face))) (ert-deftest clojure-mode-syntax-table/cljx () :tags '(fontification syntax-table) From ff01ae5765df33b4ef20ef796e4a299cc91a36a5 Mon Sep 17 00:00:00 2001 From: Bozhidar Batsov Date: Mon, 4 Aug 2014 16:40:50 +0300 Subject: [PATCH 015/199] Fix font-locking of namespaced constructor calls --- clojure-mode-test.el | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/clojure-mode-test.el b/clojure-mode-test.el index fa7396a..43e9471 100644 --- a/clojure-mode-test.el +++ b/clojure-mode-test.el @@ -86,6 +86,13 @@ POS." :tags '(fontification syntax-table) (should (eq (clojure-test-face-at 1 9 "SomeClass") 'font-lock-type-face))) +(ert-deftest clojure-mode-syntax-table/constructor () + :tags '(fontification syntax-table) + (should (eq (clojure-test-face-at 2 11 "(SomeClass.)") 'font-lock-type-face)) + (clojure-test-with-temp-buffer "(ns/SomeClass.)" + (should (eq (clojure-test-face-at 2 3) 'font-lock-type-face)) + (should (eq (clojure-test-face-at 5 14) 'font-lock-type-face)))) + (ert-deftest clojure-mode-syntax-table/namespaced-symbol () :tags '(fontification syntax-table) (clojure-test-with-temp-buffer "clo.core/something" From e3b81aa5fd9d6c8490644fcaf0ba5ad270ad159a Mon Sep 17 00:00:00 2001 From: Bozhidar Batsov Date: Mon, 4 Aug 2014 16:41:23 +0300 Subject: [PATCH 016/199] Indentation fixes --- clojure-mode-test.el | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/clojure-mode-test.el b/clojure-mode-test.el index 43e9471..3ba3af8 100644 --- a/clojure-mode-test.el +++ b/clojure-mode-test.el @@ -103,9 +103,9 @@ POS." (ert-deftest clojure-mode-syntax-table/static-method () :tags '(fontification syntax-table) (clojure-test-with-temp-buffer "Class/methodName" - (should (eq (clojure-test-face-at 6 6) nil)) - (should (eq (clojure-test-face-at 1 5) 'font-lock-type-face)) - (should (eq (clojure-test-face-at 7 16) 'clojure-interop-method-face)))) + (should (eq (clojure-test-face-at 6 6) nil)) + (should (eq (clojure-test-face-at 1 5) 'font-lock-type-face)) + (should (eq (clojure-test-face-at 7 16) 'clojure-interop-method-face)))) (ert-deftest clojure-mode-syntax-table/constant () :tags '(fontification syntax-table) @@ -115,9 +115,9 @@ POS." (ert-deftest clojure-mode-syntax-table/class-constant () :tags '(fontification syntax-table) (clojure-test-with-temp-buffer "Class/CONST_NAME" - (should (eq (clojure-test-face-at 6 6) nil)) - (should (eq (clojure-test-face-at 1 5) 'font-lock-type-face)) - (should (eq (clojure-test-face-at 7 16) 'font-lock-constant-face)))) + (should (eq (clojure-test-face-at 6 6) nil)) + (should (eq (clojure-test-face-at 1 5) 'font-lock-type-face)) + (should (eq (clojure-test-face-at 7 16) 'font-lock-constant-face)))) (ert-deftest clojure-mode-syntax-table/namespaced-def () :tags '(fontification syntax-table) From 43d7203f073c21176a643207d88b83ac546cae3a Mon Sep 17 00:00:00 2001 From: Bozhidar Batsov Date: Mon, 4 Aug 2014 18:13:15 +0300 Subject: [PATCH 017/199] Simplify font-locking of types used as type hints --- clojure-mode-test.el | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/clojure-mode-test.el b/clojure-mode-test.el index 3ba3af8..cca945e 100644 --- a/clojure-mode-test.el +++ b/clojure-mode-test.el @@ -86,6 +86,12 @@ POS." :tags '(fontification syntax-table) (should (eq (clojure-test-face-at 1 9 "SomeClass") 'font-lock-type-face))) +(ert-deftest clojure-mode-syntax-table/type-hint () + :tags '(fontification syntax-table) + (clojure-test-with-temp-buffer "#^SomeClass" + (should (eq (clojure-test-face-at 3 11) 'font-lock-type-face)) + (should (eq (clojure-test-face-at 1 2) nil)))) + (ert-deftest clojure-mode-syntax-table/constructor () :tags '(fontification syntax-table) (should (eq (clojure-test-face-at 2 11 "(SomeClass.)") 'font-lock-type-face)) From 699c3b2cab6acba6e163dd797d04b16b84c9ffd1 Mon Sep 17 00:00:00 2001 From: Bozhidar Batsov Date: Mon, 4 Aug 2014 18:23:20 +0300 Subject: [PATCH 018/199] Refine keyword literals font-locking --- clojure-mode-test.el | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/clojure-mode-test.el b/clojure-mode-test.el index cca945e..2773fa4 100644 --- a/clojure-mode-test.el +++ b/clojure-mode-test.el @@ -171,6 +171,12 @@ POS." :tags '(fontification syntax-table) (should (eq (clojure-test-face-at 4 8 "(= false x)") 'font-lock-constant-face))) +(ert-deftest clojure-mode-syntax-table/keyword-meta () + :tags '(fontification syntax-table) + (clojure-test-with-temp-buffer "^:meta-data" + (should (eq (clojure-test-face-at 1 1) nil)) + (should (eq (clojure-test-face-at 2 11) 'clojure-keyword-face)))) + (ert-deftest clojure-mode-syntax-table/characters () :tags '(fontification syntax-table) (should (eq (clojure-test-face-at 1 2 "\\a") 'clojure-character-face)) From d71ff5266b81aa4286c34df505b860955795324e Mon Sep 17 00:00:00 2001 From: Bozhidar Batsov Date: Tue, 12 Aug 2014 19:38:15 +0300 Subject: [PATCH 019/199] Improve namespace font-locking --- clojure-mode-test.el | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/clojure-mode-test.el b/clojure-mode-test.el index 2773fa4..04eadcc 100644 --- a/clojure-mode-test.el +++ b/clojure-mode-test.el @@ -99,6 +99,11 @@ POS." (should (eq (clojure-test-face-at 2 3) 'font-lock-type-face)) (should (eq (clojure-test-face-at 5 14) 'font-lock-type-face)))) +(ert-deftest clojure-mode-syntax-table/namespace () + :tags '(fontification syntax-table) + (should (eq (clojure-test-face-at 1 5 "one.p") 'font-lock-type-face)) + (should (eq (clojure-test-face-at 1 11 "one.p.top13") 'font-lock-type-face))) + (ert-deftest clojure-mode-syntax-table/namespaced-symbol () :tags '(fontification syntax-table) (clojure-test-with-temp-buffer "clo.core/something" From 001ee7dbba4f065d56ff89f48a35d2a9790e321f Mon Sep 17 00:00:00 2001 From: Bozhidar Batsov Date: Wed, 13 Aug 2014 18:51:55 +0300 Subject: [PATCH 020/199] Fix the font-lock of interop calls like getX --- clojure-mode-test.el | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/clojure-mode-test.el b/clojure-mode-test.el index 04eadcc..80b636d 100644 --- a/clojure-mode-test.el +++ b/clojure-mode-test.el @@ -118,6 +118,13 @@ POS." (should (eq (clojure-test-face-at 1 5) 'font-lock-type-face)) (should (eq (clojure-test-face-at 7 16) 'clojure-interop-method-face)))) +(ert-deftest clojure-mode-syntax-table/interop-method () + :tags '(fontification syntax-table) + (should (eq (clojure-test-face-at 1 11 ".someMethod") 'clojure-interop-method-face)) + (should (eq (clojure-test-face-at 1 10 "someMethod") 'clojure-interop-method-face)) + (should (eq (clojure-test-face-at 1 11 "topHttpTest") 'clojure-interop-method-face)) + (should (eq (clojure-test-face-at 1 4 "getX") 'clojure-interop-method-face))) + (ert-deftest clojure-mode-syntax-table/constant () :tags '(fontification syntax-table) (should (eq (clojure-test-face-at 1 5 "CONST") 'font-lock-constant-face)) From 4f6441595b976595cfacdeded0a36a37e32473ce Mon Sep 17 00:00:00 2001 From: Bozhidar Batsov Date: Thu, 21 Aug 2014 13:14:23 +0300 Subject: [PATCH 021/199] Font lock properly fully qualified type hints --- clojure-mode-test.el | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/clojure-mode-test.el b/clojure-mode-test.el index 80b636d..58c77cf 100644 --- a/clojure-mode-test.el +++ b/clojure-mode-test.el @@ -102,7 +102,8 @@ POS." (ert-deftest clojure-mode-syntax-table/namespace () :tags '(fontification syntax-table) (should (eq (clojure-test-face-at 1 5 "one.p") 'font-lock-type-face)) - (should (eq (clojure-test-face-at 1 11 "one.p.top13") 'font-lock-type-face))) + (should (eq (clojure-test-face-at 1 11 "one.p.top13") 'font-lock-type-face)) + (should (eq (clojure-test-face-at 2 12 "^one.p.top13") 'font-lock-type-face))) (ert-deftest clojure-mode-syntax-table/namespaced-symbol () :tags '(fontification syntax-table) From a8b250fe57fc935cfda5953b468ee98f2680537a Mon Sep 17 00:00:00 2001 From: Ryan Smith Date: Thu, 21 Aug 2014 14:57:28 -0700 Subject: [PATCH 022/199] @(dynamic)variable shouldn't break fontlock Currently `foo/some-var` will fontlock `foo`, but if this item is something that can be dereffed and you type `@foo/some-var`, `foo` is no longer font-locked. Similarly: `*dynamic-var*` is font locked, but `@` breaks the regex. In this change the `@` sign isn't font locked, but the var that follows it is. Conflicts: clojure-mode.el Add tests for dynamic-var and ns/refer fontlock --- clojure-mode-test.el | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/clojure-mode-test.el b/clojure-mode-test.el index 58c77cf..ba5cce4 100644 --- a/clojure-mode-test.el +++ b/clojure-mode-test.el @@ -202,6 +202,16 @@ POS." (should (eq (clojure-test-face-at 1 5 "#+clj x") 'font-lock-preprocessor-face)) (should (eq (clojure-test-face-at 1 6 "#+cljs x") 'font-lock-preprocessor-face))) +(ert-deftest clojure-mode-syntax-table/refer-ns () + :tags '(fontification syntax-table) + (should (eq (clojure-test-face-at 1 3 "foo/var") 'font-lock-type-face)) + (should (eq (clojure-test-face-at 2 4 "@foo/var") 'font-lock-type-face))) + +(ert-deftest clojure-mode-syntax-table/dynamic-var () + :tags '(fontification syntax-table) + (should (eq (clojure-test-face-at 1 10 "*some-var*") 'font-lock-variable-name-face)) + (should (eq (clojure-test-face-at 2 11 "@*some-var*") 'font-lock-variable-name-face))) + (provide 'clojure-mode-test) ;; Local Variables: From 49ee7f8fd779357b423cdbc563de773d5f07d5e8 Mon Sep 17 00:00:00 2001 From: Bozhidar Batsov Date: Fri, 22 Aug 2014 17:55:37 +0300 Subject: [PATCH 023/199] Improve font-locking of punctuation characters --- clojure-mode-test.el | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/clojure-mode-test.el b/clojure-mode-test.el index ba5cce4..572c948 100644 --- a/clojure-mode-test.el +++ b/clojure-mode-test.el @@ -195,7 +195,9 @@ POS." (should (eq (clojure-test-face-at 1 2 "\\a") 'clojure-character-face)) (should (eq (clojure-test-face-at 1 8 "\\newline") 'clojure-character-face)) (should (eq (clojure-test-face-at 1 2 "\\1") 'clojure-character-face)) - (should (eq (clojure-test-face-at 1 6 "\\u0032") 'clojure-character-face))) + (should (eq (clojure-test-face-at 1 6 "\\u0032") 'clojure-character-face)) + (should (eq (clojure-test-face-at 1 2 "\\+") 'clojure-character-face)) + (should (eq (clojure-test-face-at 1 2 "\\.") 'clojure-character-face))) (ert-deftest clojure-mode-syntax-table/cljx () :tags '(fontification syntax-table) From 90d3a43eb7dc9513d4c39912a438e7a4ac088ae5 Mon Sep 17 00:00:00 2001 From: Bozhidar Batsov Date: Tue, 2 Sep 2014 19:40:08 +0300 Subject: [PATCH 024/199] Fix font-locking of single-segment names in ns macro --- clojure-mode-test.el | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/clojure-mode-test.el b/clojure-mode-test.el index 572c948..d236d6d 100644 --- a/clojure-mode-test.el +++ b/clojure-mode-test.el @@ -214,6 +214,11 @@ POS." (should (eq (clojure-test-face-at 1 10 "*some-var*") 'font-lock-variable-name-face)) (should (eq (clojure-test-face-at 2 11 "@*some-var*") 'font-lock-variable-name-face))) +(ert-deftest clojure-mode-syntax-table/ns-macro () + :tags '(fontification syntax-table) + (should (eq (clojure-test-face-at 5 8 "(ns name)") 'font-lock-type-face)) + (should (eq (clojure-test-face-at 5 13 "(ns name.name)") 'font-lock-type-face))) + (provide 'clojure-mode-test) ;; Local Variables: From e569ab8865085b72dc6de38cb0ea2e38fb142911 Mon Sep 17 00:00:00 2001 From: Bozhidar Batsov Date: Fri, 19 Sep 2014 15:45:10 +0300 Subject: [PATCH 025/199] Fix a ns font-locking bug Everything appearing after the word ns was treated as namespace (.e.g. [ns name]). Now we check if ns is preceded by a (. --- clojure-mode-test.el | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/clojure-mode-test.el b/clojure-mode-test.el index d236d6d..e08604a 100644 --- a/clojure-mode-test.el +++ b/clojure-mode-test.el @@ -217,7 +217,8 @@ POS." (ert-deftest clojure-mode-syntax-table/ns-macro () :tags '(fontification syntax-table) (should (eq (clojure-test-face-at 5 8 "(ns name)") 'font-lock-type-face)) - (should (eq (clojure-test-face-at 5 13 "(ns name.name)") 'font-lock-type-face))) + (should (eq (clojure-test-face-at 5 13 "(ns name.name)") 'font-lock-type-face)) + (should (eq (clojure-test-face-at 1 10 "[ns name]") nil))) (provide 'clojure-mode-test) From ef7cbf3b5dfe757bc6256992d29f29e0e8a9537a Mon Sep 17 00:00:00 2001 From: Bozhidar Batsov Date: Sun, 21 Sep 2014 18:45:57 +0300 Subject: [PATCH 026/199] Font-lock properly fully-qualified static method invocations E.g. clojure.lang.Var/cloneThreadBindingFrame --- clojure-mode-test.el | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/clojure-mode-test.el b/clojure-mode-test.el index e08604a..22d9420 100644 --- a/clojure-mode-test.el +++ b/clojure-mode-test.el @@ -117,7 +117,11 @@ POS." (clojure-test-with-temp-buffer "Class/methodName" (should (eq (clojure-test-face-at 6 6) nil)) (should (eq (clojure-test-face-at 1 5) 'font-lock-type-face)) - (should (eq (clojure-test-face-at 7 16) 'clojure-interop-method-face)))) + (should (eq (clojure-test-face-at 7 16) 'clojure-interop-method-face))) + (clojure-test-with-temp-buffer "clojure.lang.Var/someMethod" + (should (eq (clojure-test-face-at 17 17) nil)) + (should (eq (clojure-test-face-at 1 16) 'font-lock-type-face)) + (should (eq (clojure-test-face-at 18 27) 'clojure-interop-method-face)))) (ert-deftest clojure-mode-syntax-table/interop-method () :tags '(fontification syntax-table) From 0267302ece24d803e54534440ea9c0ed5fa34991 Mon Sep 17 00:00:00 2001 From: Bozhidar Batsov Date: Sun, 21 Sep 2014 18:47:47 +0300 Subject: [PATCH 027/199] Code style --- clojure-mode-test.el | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/clojure-mode-test.el b/clojure-mode-test.el index 22d9420..94842be 100644 --- a/clojure-mode-test.el +++ b/clojure-mode-test.el @@ -115,12 +115,12 @@ POS." (ert-deftest clojure-mode-syntax-table/static-method () :tags '(fontification syntax-table) (clojure-test-with-temp-buffer "Class/methodName" - (should (eq (clojure-test-face-at 6 6) nil)) (should (eq (clojure-test-face-at 1 5) 'font-lock-type-face)) + (should (eq (clojure-test-face-at 6 6) nil)) (should (eq (clojure-test-face-at 7 16) 'clojure-interop-method-face))) (clojure-test-with-temp-buffer "clojure.lang.Var/someMethod" - (should (eq (clojure-test-face-at 17 17) nil)) (should (eq (clojure-test-face-at 1 16) 'font-lock-type-face)) + (should (eq (clojure-test-face-at 17 17) nil)) (should (eq (clojure-test-face-at 18 27) 'clojure-interop-method-face)))) (ert-deftest clojure-mode-syntax-table/interop-method () From e03cb1f17ac8d46ab277b5d5bc8f209c4ebfa5f5 Mon Sep 17 00:00:00 2001 From: Bozhidar Batsov Date: Sat, 1 Nov 2014 09:01:52 +0200 Subject: [PATCH 028/199] Fix the font-locking of classes in scenarios like URLDecoder/decode --- clojure-mode-test.el | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/clojure-mode-test.el b/clojure-mode-test.el index 94842be..41d3298 100644 --- a/clojure-mode-test.el +++ b/clojure-mode-test.el @@ -118,6 +118,10 @@ POS." (should (eq (clojure-test-face-at 1 5) 'font-lock-type-face)) (should (eq (clojure-test-face-at 6 6) nil)) (should (eq (clojure-test-face-at 7 16) 'clojure-interop-method-face))) + (clojure-test-with-temp-buffer "SomeClass/methodName" + (should (eq (clojure-test-face-at 1 9) 'font-lock-type-face)) + (should (eq (clojure-test-face-at 10 10) nil)) + (should (eq (clojure-test-face-at 11 20) 'clojure-interop-method-face))) (clojure-test-with-temp-buffer "clojure.lang.Var/someMethod" (should (eq (clojure-test-face-at 1 16) 'font-lock-type-face)) (should (eq (clojure-test-face-at 17 17) nil)) From a4dc62c36f4a46552377594f8044766ae1576fc5 Mon Sep 17 00:00:00 2001 From: Bozhidar Batsov Date: Sat, 10 Jan 2015 12:10:15 +0200 Subject: [PATCH 029/199] Update the copyright years --- clojure-mode-test.el | 2 +- test-helper.el | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/clojure-mode-test.el b/clojure-mode-test.el index 41d3298..4cab810 100644 --- a/clojure-mode-test.el +++ b/clojure-mode-test.el @@ -1,6 +1,6 @@ ;;; clojure-mode-test.el --- Clojure Mode: Unit test suite -*- lexical-binding: t; -*- -;; Copyright (C) 2014 Bozhidar Batsov +;; Copyright (C) 2014-2015 Bozhidar Batsov ;; This file is not part of GNU Emacs. diff --git a/test-helper.el b/test-helper.el index 558d4ed..ee93188 100644 --- a/test-helper.el +++ b/test-helper.el @@ -1,6 +1,6 @@ ;;; test-helper.el --- Clojure Mode: Non-interactive unit-test setup -*- lexical-binding: t; -*- -;; Copyright (C) 2014 Bozhidar Batsov +;; Copyright (C) 2014-2015 Bozhidar Batsov ;; This file is not part of GNU Emacs. From 1b7a61db89617924002f705f0abaab38b3f18dab Mon Sep 17 00:00:00 2001 From: m00nlight Date: Thu, 5 Mar 2015 20:47:32 +0800 Subject: [PATCH 030/199] [Fix #274] Correct font-locking of punctuation character literals --- clojure-mode-test.el | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/clojure-mode-test.el b/clojure-mode-test.el index 41d3298..d7d8747 100644 --- a/clojure-mode-test.el +++ b/clojure-mode-test.el @@ -205,7 +205,9 @@ POS." (should (eq (clojure-test-face-at 1 2 "\\1") 'clojure-character-face)) (should (eq (clojure-test-face-at 1 6 "\\u0032") 'clojure-character-face)) (should (eq (clojure-test-face-at 1 2 "\\+") 'clojure-character-face)) - (should (eq (clojure-test-face-at 1 2 "\\.") 'clojure-character-face))) + (should (eq (clojure-test-face-at 1 2 "\\.") 'clojure-character-face)) + (should (eq (clojure-test-face-at 1 2 "\\,") 'clojure-character-face)) + (should (eq (clojure-test-face-at 1 2 "\\;") 'clojure-character-face))) (ert-deftest clojure-mode-syntax-table/cljx () :tags '(fontification syntax-table) From c1c4628eae4fdec73bd898dacc67789d13608c81 Mon Sep 17 00:00:00 2001 From: Bozhidar Batsov Date: Sun, 15 Mar 2015 11:56:38 +0200 Subject: [PATCH 031/199] Fix font-locking of namespace-prefixed dynamic vars --- clojure-mode-test.el | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/clojure-mode-test.el b/clojure-mode-test.el index f5b7f62..5fe79bd 100644 --- a/clojure-mode-test.el +++ b/clojure-mode-test.el @@ -222,7 +222,8 @@ POS." (ert-deftest clojure-mode-syntax-table/dynamic-var () :tags '(fontification syntax-table) (should (eq (clojure-test-face-at 1 10 "*some-var*") 'font-lock-variable-name-face)) - (should (eq (clojure-test-face-at 2 11 "@*some-var*") 'font-lock-variable-name-face))) + (should (eq (clojure-test-face-at 2 11 "@*some-var*") 'font-lock-variable-name-face)) + (should (eq (clojure-test-face-at 9 13 "some.ns/*var*") 'font-lock-variable-name-face))) (ert-deftest clojure-mode-syntax-table/ns-macro () :tags '(fontification syntax-table) From 73f263549586d61bb12443556bec381cc95f2b0f Mon Sep 17 00:00:00 2001 From: Bozhidar Batsov Date: Sun, 17 May 2015 11:32:42 +0300 Subject: [PATCH 032/199] [Fix #271] Add indentation tests --- clojure-mode-indentation-test.el | 116 +++++++++++++++++++++++++++++++ 1 file changed, 116 insertions(+) create mode 100644 clojure-mode-indentation-test.el diff --git a/clojure-mode-indentation-test.el b/clojure-mode-indentation-test.el new file mode 100644 index 0000000..32084cd --- /dev/null +++ b/clojure-mode-indentation-test.el @@ -0,0 +1,116 @@ +;;; clojure-mode-indentation-test.el --- Clojure Mode: indentation tests -*- lexical-binding: t; -*- + +;; Copyright (C) 2015 Bozhidar Batsov + +;; This file is not part of GNU Emacs. + +;; This program is free software; you can redistribute it and/or modify +;; it under the terms of the GNU General Public License as published by +;; the Free Software Foundation, either version 3 of the License, or +;; (at your option) any later version. + +;; This program is distributed in the hope that it will be useful, +;; but WITHOUT ANY WARRANTY; without even the implied warranty of +;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +;; GNU General Public License for more details. + +;; You should have received a copy of the GNU General Public License +;; along with this program. If not, see . + +;;; Commentary: + +;; The unit test suite of Clojure Mode + +;;; Code: + +(require 'clojure-mode) +(require 'cl-lib) +(require 'ert) +(require 's) + +(defmacro check-indentation (description before after &optional var-bindings) + "Declare an ert test for indentation behaviour. +The test will check that the swift indentation command changes the buffer +from one state to another. It will also test that point is moved to an +expected position. + +DESCRIPTION is a symbol describing the test. + +BEFORE is the buffer string before indenting, where a pipe (|) represents +point. + +AFTER is the expected buffer string after indenting, where a pipe (|) +represents the expected position of point. + +VAR-BINDINGS is an optional let-bindings list. It can be used to set the +values of customisable variables." + (declare (indent 1)) + (let ((fname (intern (format "indentation/%s" description)))) + `(ert-deftest ,fname () + (let* ((after ,after) + (expected-cursor-pos (1+ (s-index-of "|" after))) + (expected-state (delete ?| after)) + ,@var-bindings) + (with-temp-buffer + (insert ,before) + (goto-char (point-min)) + (search-forward "|") + (delete-char -1) + (clojure-mode) + (indent-according-to-mode) + + (should (equal expected-state (buffer-string))) + (should (equal expected-cursor-pos (point)))))))) + +;; Provide font locking for easier test editing. + +(font-lock-add-keywords + 'emacs-lisp-mode + `((,(rx "(" (group "check-indentation") eow) + (1 font-lock-keyword-face)) + (,(rx "(" + (group "check-indentation") (+ space) + (group bow (+ (not space)) eow) + ) + (1 font-lock-keyword-face) + (2 font-lock-function-name-face)))) + + +;;; Tests + + +(check-indentation no-indentation-at-top-level + "|x" + "|x") + +(check-indentation cond-indentation + " +(cond +|x)" + " +(cond + |x)") + +(check-indentation threading-with-expression-on-first-line + " +(->> expr + |ala)" + " +(->> expr + |ala)") + +(check-indentation threading-with-expression-on-second-line + " +(->> +|expr)" + " +(->> + |expr)") + +(provide 'clojure-mode-indentation-test) + +;; Local Variables: +;; indent-tabs-mode: nil +;; End: + +;;; clojure-mode-indentation-test.el ends here From ac2ae956a69e19df2eab171fb959bba04bd7bf32 Mon Sep 17 00:00:00 2001 From: Bozhidar Batsov Date: Sun, 17 May 2015 12:26:05 +0300 Subject: [PATCH 033/199] Rename clojure-mode-test.el to clojure-mode-font-lock-test.el --- clojure-mode-test.el => clojure-mode-font-lock-test.el | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) rename clojure-mode-test.el => clojure-mode-font-lock-test.el (98%) diff --git a/clojure-mode-test.el b/clojure-mode-font-lock-test.el similarity index 98% rename from clojure-mode-test.el rename to clojure-mode-font-lock-test.el index 5fe79bd..4c08fd8 100644 --- a/clojure-mode-test.el +++ b/clojure-mode-font-lock-test.el @@ -1,4 +1,4 @@ -;;; clojure-mode-test.el --- Clojure Mode: Unit test suite -*- lexical-binding: t; -*- +;;; clojure-mode-font-lock-test.el --- Clojure Mode: Font lock test suite -*- lexical-binding: t; -*- ;; Copyright (C) 2014-2015 Bozhidar Batsov @@ -231,10 +231,10 @@ POS." (should (eq (clojure-test-face-at 5 13 "(ns name.name)") 'font-lock-type-face)) (should (eq (clojure-test-face-at 1 10 "[ns name]") nil))) -(provide 'clojure-mode-test) +(provide 'clojure-mode-font-lock-test) ;; Local Variables: ;; indent-tabs-mode: nil ;; End: -;;; clojure-mode-test.el ends here +;;; clojure-mode-font-lock-test.el ends here From e98c459e563dee1fbfa8e4d30a0f542e20ea5d53 Mon Sep 17 00:00:00 2001 From: Achint Sandhu Date: Mon, 27 Apr 2015 09:48:05 -0400 Subject: [PATCH 034/199] Fix doctring indentation issue in #241 Added code to only apply the prefix if the current indent level is <= the default prefix spacing. --- clojure-mode-indentation-test.el | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/clojure-mode-indentation-test.el b/clojure-mode-indentation-test.el index 32084cd..81a9376 100644 --- a/clojure-mode-indentation-test.el +++ b/clojure-mode-indentation-test.el @@ -107,6 +107,32 @@ values of customisable variables." (->> |expr)") +(check-indentation doc-strings-without-indent-specified + " +(defn some-fn +|\"some doc string\"" + " +(defn some-fn + |\"some doc string\"") + +(check-indentation doc-strings-with-correct-indent-specified + " +(defn some-fn + |\"some doc string\"" + " +(defn some-fn + |\"some doc string\"") + +(check-indentation doc-strings-with-additional-indent-specified + " +(defn some-fn + |\"some doc string + - some note\"" + " +(defn some-fn + |\"some doc string + - some note\"") + (provide 'clojure-mode-indentation-test) ;; Local Variables: From 9e13a002ad0490d2edaf80c5f9539642c454648f Mon Sep 17 00:00:00 2001 From: Bozhidar Batsov Date: Sat, 20 Jun 2015 09:30:33 +0300 Subject: [PATCH 035/199] Add tests and documentation for the indentation config changes --- clojure-mode-indentation-test.el | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/clojure-mode-indentation-test.el b/clojure-mode-indentation-test.el index 81a9376..5c547cf 100644 --- a/clojure-mode-indentation-test.el +++ b/clojure-mode-indentation-test.el @@ -133,6 +133,27 @@ values of customisable variables." |\"some doc string - some note\"") +;; we can specify different indentation for symbol with some ns prefix +(put-clojure-indent 'bala 0) +(put-clojure-indent 'ala/bala 1) + +(check-indentation symbol-without-ns + " +(bala +|one)" + " +(bala + |one)") + +(check-indentation symbol-with-ns + " +(ala/bala top +|one)" + " +(ala/bala top + |one)") + + (provide 'clojure-mode-indentation-test) ;; Local Variables: From 009c639c17087ba3e28b6923fcaf13743f6ef765 Mon Sep 17 00:00:00 2001 From: Artur Malabarba Date: Tue, 30 Jun 2015 20:51:10 +0100 Subject: [PATCH 036/199] Implement commands for navigating over logical sexps --- clojure-mode-sexp-test.el | 45 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) create mode 100644 clojure-mode-sexp-test.el diff --git a/clojure-mode-sexp-test.el b/clojure-mode-sexp-test.el new file mode 100644 index 0000000..3cfcc70 --- /dev/null +++ b/clojure-mode-sexp-test.el @@ -0,0 +1,45 @@ +;;; clojure-mode-sexp-test.el --- Clojure Mode: sexp tests -*- lexical-binding: t; -*- + +;; Copyright (C) 2015 Artur Malabarba + +;; This file is not part of GNU Emacs. + +;; This program is free software; you can redistribute it and/or modify +;; it under the terms of the GNU General Public License as published by +;; the Free Software Foundation, either version 3 of the License, or +;; (at your option) any later version. + +;; This program is distributed in the hope that it will be useful, +;; but WITHOUT ANY WARRANTY; without even the implied warranty of +;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +;; GNU General Public License for more details. + +;; You should have received a copy of the GNU General Public License +;; along with this program. If not, see . + +;;; Code: + +(require 'clojure-mode) +(require 'ert) + +(ert-deftest test-sexp () + (with-temp-buffer + (insert "^String #macro ^dynamic reverse") + (clojure-mode) + (clojure-backward-logical-sexp 1) + (should (looking-at-p "\\^String \\#macro \\^dynamic reverse")) + (clojure-forward-logical-sexp 1) + (should (looking-back "\\^String \\#macro \\^dynamic reverse")) + (insert " ^String biverse inverse") + (clojure-backward-logical-sexp 1) + (should (looking-at-p "inverse")) + (clojure-backward-logical-sexp 2) + (should (looking-at-p "\\^String \\#macro \\^dynamic reverse")) + (clojure-forward-logical-sexp 2) + (should (looking-back "\\^String biverse")) + (clojure-backward-logical-sexp 1) + (should (looking-at-p "\\^String biverse")))) + +(provide 'clojure-mode-sexp-test) + +;;; clojure-mode-sexp-test.el ends here From a9fc8cb5bfe80d060cc46d0d97ef794bf3045f9f Mon Sep 17 00:00:00 2001 From: Bozhidar Batsov Date: Wed, 22 Jul 2015 19:40:59 +0300 Subject: [PATCH 037/199] Fix font-locking tests --- clojure-mode-font-lock-test.el | 27 ++++++++++++++++++++++++--- 1 file changed, 24 insertions(+), 3 deletions(-) diff --git a/clojure-mode-font-lock-test.el b/clojure-mode-font-lock-test.el index 4c08fd8..6bbd2ed 100644 --- a/clojure-mode-font-lock-test.el +++ b/clojure-mode-font-lock-test.el @@ -41,6 +41,17 @@ (goto-char (point-min)) ,@body)) +(defmacro clojurex-test-with-temp-buffer (content &rest body) + "Evaluate BODY in a temporary buffer with CONTENTS." + (declare (debug t) + (indent 1)) + `(with-temp-buffer + (insert ,content) + (clojurex-mode) + (font-lock-fontify-buffer) + (goto-char (point-min)) + ,@body)) + (defun clojure-get-face-at-range (start end) (let ((start-face (get-text-property start 'face)) (all-faces (cl-loop for i from start to end collect (get-text-property i 'face)))) @@ -58,6 +69,16 @@ buffer." (clojure-get-face-at-range start end)) (clojure-get-face-at-range start end))) +(defun clojurex-test-face-at (start end &optional content) + "Get the face between START and END in CONTENT. + +If CONTENT is not given, return the face at the specified range in the current +buffer." + (if content + (clojurex-test-with-temp-buffer content + (clojure-get-face-at-range start end)) + (clojure-get-face-at-range start end))) + (defconst clojure-test-syntax-classes [whitespace punctuation word symbol open-paren close-paren expression-prefix string-quote paired-delim escape character-quote comment-start @@ -209,10 +230,10 @@ POS." (should (eq (clojure-test-face-at 1 2 "\\,") 'clojure-character-face)) (should (eq (clojure-test-face-at 1 2 "\\;") 'clojure-character-face))) -(ert-deftest clojure-mode-syntax-table/cljx () +(ert-deftest clojurex-mode-syntax-table/cljx () :tags '(fontification syntax-table) - (should (eq (clojure-test-face-at 1 5 "#+clj x") 'font-lock-preprocessor-face)) - (should (eq (clojure-test-face-at 1 6 "#+cljs x") 'font-lock-preprocessor-face))) + (should (eq (clojurex-test-face-at 1 5 "#+clj x") 'font-lock-preprocessor-face)) + (should (eq (clojurex-test-face-at 1 6 "#+cljs x") 'font-lock-preprocessor-face))) (ert-deftest clojure-mode-syntax-table/refer-ns () :tags '(fontification syntax-table) From ccf307e760f5fc17d11e30c72f0b63c6311f99bf Mon Sep 17 00:00:00 2001 From: Lars Andersen Date: Wed, 29 Jul 2015 15:00:22 +0200 Subject: [PATCH 038/199] [Fix #310,#311] clojure-expected-ns with src/cljc When the source path is src/clj{,c,s,x} instead of just src/ clojure-expected ns would create namespaces like clj.my-project.my-ns whereas what's wanted is my-project.my-ns. Reading boot.clj or project.clj to find out the user's src dirs is out of scope for clojure-mode, so we use the simply heuristic that no namespace should start with clj, cljc or cljs because these are the idiomatic source directories in multi-source projects. When improving clojure-expected-ns I extracted out two utilities, clojure-project-dir and clojure-project-relative-path. These utilities already exist in clj-refactor so I opted to make them public rather than private, as they are generally useful. --- clojure-mode-util-test.el | 53 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 53 insertions(+) create mode 100644 clojure-mode-util-test.el diff --git a/clojure-mode-util-test.el b/clojure-mode-util-test.el new file mode 100644 index 0000000..3736757 --- /dev/null +++ b/clojure-mode-util-test.el @@ -0,0 +1,53 @@ +;;; clojure-mode-util-test.el --- Clojure Mode: util test suite -*- lexical-binding: t; -*- + +;; Copyright (C) 2014-2015 Bozhidar Batsov + +;; This file is not part of GNU Emacs. + +;; This program is free software; you can redistribute it and/or modify +;; it under the terms of the GNU General Public License as published by +;; the Free Software Foundation, either version 3 of the License, or +;; (at your option) any later version. + +;; This program is distributed in the hope that it will be useful, +;; but WITHOUT ANY WARRANTY; without even the implied warranty of +;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +;; GNU General Public License for more details. + +;; You should have received a copy of the GNU General Public License +;; along with this program. If not, see . + +;;; Commentary: + +;; The unit test suite of Clojure Mode + +;;; Code: +(require 'clojure-mode) +(require 'cl-lib) +(require 'ert) + +(let ((project-dir "/home/user/projects/my-project/") + (clj-file-path "/home/user/projects/my-project/src/clj/my_project/my_ns/my_file.clj") + (project-relative-clj-file-path "src/clj/my_project/my_ns/my_file.clj") + (clj-file-ns "my-project.my-ns.my-file")) + + (ert-deftest project-relative-path () + :tags '(utils) + (cl-letf (((symbol-function 'clojure-project-dir) (lambda () project-dir))) + (should (string= (clojure-project-relative-path clj-file-path) + project-relative-clj-file-path)))) + + (ert-deftest expected-ns () + :tags '(utils) + (cl-letf (((symbol-function 'clojure-project-relative-path) + (lambda (&optional current-buffer-file-name) + project-relative-clj-file-path))) + (should (string= (clojure-expected-ns clj-file-path) clj-file-ns))))) + +(provide 'clojure-mode-util-test) + +;; Local Variables: +;; indent-tabs-mode: nil +;; End: + +;;; clojure-mode-util-test.el ends here From c855d1eefd8e54ba25f3f52eeb9eab80b968196c Mon Sep 17 00:00:00 2001 From: Jinseop Kim Date: Thu, 30 Jul 2015 18:31:49 +0900 Subject: [PATCH 039/199] Fix for error in `clojure-expected-ns` When call `clojure-expected-ns` function without arguments, error occured. --- clojure-mode-util-test.el | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/clojure-mode-util-test.el b/clojure-mode-util-test.el index 3736757..5fd689b 100644 --- a/clojure-mode-util-test.el +++ b/clojure-mode-util-test.el @@ -42,7 +42,16 @@ (cl-letf (((symbol-function 'clojure-project-relative-path) (lambda (&optional current-buffer-file-name) project-relative-clj-file-path))) - (should (string= (clojure-expected-ns clj-file-path) clj-file-ns))))) + (should (string= (clojure-expected-ns clj-file-path) clj-file-ns)))) + + (ert-deftest expected-ns-without-argument () + :tags '(utils) + (cl-letf (((symbol-function 'clojure-project-relative-path) + (lambda (&optional current-buffer-file-name) + project-relative-clj-file-path))) + (should (string= (let ((buffer-file-name clj-file-path)) + (clojure-expected-ns)) + clj-file-ns))))) (provide 'clojure-mode-util-test) From eecf34ef10ef07a9f4d07f7ea4695aafd2bf5ee5 Mon Sep 17 00:00:00 2001 From: Bruno Bonacci Date: Mon, 3 Aug 2015 15:33:45 +0100 Subject: [PATCH 040/199] Handle properly def* symbols, containing special chars --- clojure-mode-font-lock-test.el | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/clojure-mode-font-lock-test.el b/clojure-mode-font-lock-test.el index 4c08fd8..ab42a53 100644 --- a/clojure-mode-font-lock-test.el +++ b/clojure-mode-font-lock-test.el @@ -172,6 +172,18 @@ POS." (should (eq (clojure-test-face-at 2 5) 'font-lock-keyword-face)) (should (eq (clojure-test-face-at 7 9) 'font-lock-function-name-face)))) +(ert-deftest clojure-mode-syntax-table/custom-def-with-special-chars1 () + :tags '(fontification syntax-table) + (clojure-test-with-temp-buffer "(defn* foo [x] x)" + (should (eq (clojure-test-face-at 2 6) 'font-lock-keyword-face)) + (should (eq (clojure-test-face-at 8 10) 'font-lock-function-name-face)))) + +(ert-deftest clojure-mode-syntax-table/custom-def-with-special-chars2 () + :tags '(fontification syntax-table) + (clojure-test-with-temp-buffer "(defsomething! foo [x] x)" + (should (eq (clojure-test-face-at 2 14) 'font-lock-keyword-face)) + (should (eq (clojure-test-face-at 16 18) 'font-lock-function-name-face)))) + (ert-deftest clojure-mode-syntax-table/lambda-params () :tags '(fontification syntax-table) (clojure-test-with-temp-buffer "#(+ % %2 %3)" From 34658f044bd878513defeace5e94b110ed0d0309 Mon Sep 17 00:00:00 2001 From: Artur Malabarba Date: Thu, 10 Sep 2015 18:19:56 +0100 Subject: [PATCH 041/199] [Fix #304] Indentation of forms with metadata specs We were indenting like this (ns ^:doc app.core (:gen-class)) Now we indent like this (ns ^:doc app.core (:gen-class)) --- clojure-mode-indentation-test.el | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/clojure-mode-indentation-test.el b/clojure-mode-indentation-test.el index 5c547cf..60485cd 100644 --- a/clojure-mode-indentation-test.el +++ b/clojure-mode-indentation-test.el @@ -153,6 +153,14 @@ values of customisable variables." (ala/bala top |one)") +(check-indentation form-with-metadata + " +(ns ^:doc app.core +|(:gen-class))" +" +(ns ^:doc app.core + |(:gen-class))") + (provide 'clojure-mode-indentation-test) From db77aa7a3634ec7fa9dd1208d34ed2fdfa2ecf30 Mon Sep 17 00:00:00 2001 From: Artur Malabarba Date: Thu, 10 Sep 2015 18:22:12 +0100 Subject: [PATCH 042/199] [Fix #308 Fix #287 Fix #45] Corner-case indentation of multi-line sexps We were indenting like this [[ 2] a x] Now we indent like this [[ 2] a x] --- clojure-mode-indentation-test.el | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/clojure-mode-indentation-test.el b/clojure-mode-indentation-test.el index 60485cd..de0176d 100644 --- a/clojure-mode-indentation-test.el +++ b/clojure-mode-indentation-test.el @@ -161,6 +161,16 @@ values of customisable variables." (ns ^:doc app.core |(:gen-class))") +(check-indentation multiline-sexps + " +[[ + 2] a +|x]" +" +[[ + 2] a + |x]") + (provide 'clojure-mode-indentation-test) From 29ce149a55f732dd667ed6c0278e82dc1a10b919 Mon Sep 17 00:00:00 2001 From: Artur Malabarba Date: Thu, 10 Sep 2015 18:38:45 +0100 Subject: [PATCH 043/199] [Fix #292] Indentation in reader conditionals Before #?(:clj :foo :cljs :bar) Now #?(:clj :foo :cljs :bar) --- clojure-mode-indentation-test.el | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/clojure-mode-indentation-test.el b/clojure-mode-indentation-test.el index de0176d..867126c 100644 --- a/clojure-mode-indentation-test.el +++ b/clojure-mode-indentation-test.el @@ -171,6 +171,14 @@ values of customisable variables." 2] a |x]") +(check-indentation reader-conditionals + " +#?(:clj :foo +|:cljs :bar)" + " +#?(:clj :foo + |:cljs :bar)") + (provide 'clojure-mode-indentation-test) From fe0659d4c9f90815504eb6f103a7a11619ef9f3b Mon Sep 17 00:00:00 2001 From: Artur Malabarba Date: Thu, 10 Sep 2015 19:13:51 +0100 Subject: [PATCH 044/199] [Fix #278] Understand namespace aliases in backtracking indent --- clojure-mode-indentation-test.el | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/clojure-mode-indentation-test.el b/clojure-mode-indentation-test.el index 867126c..93de734 100644 --- a/clojure-mode-indentation-test.el +++ b/clojure-mode-indentation-test.el @@ -179,6 +179,15 @@ values of customisable variables." #?(:clj :foo |:cljs :bar)") +(check-indentation backtracking-with-aliases + " +(clojure.core/letfn [(twice [x] +|(* x 2))] + :a)" + " +(clojure.core/letfn [(twice [x] + |(* x 2))] + :a)") (provide 'clojure-mode-indentation-test) From b708c7f15fb22b8b4547f8ffa8d2a84faa0422c9 Mon Sep 17 00:00:00 2001 From: Artur Malabarba Date: Sat, 12 Sep 2015 19:55:09 +0100 Subject: [PATCH 045/199] Rewrite the indent logic MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit [Fix #282 Fix #296] Use custom-code to calculate normal-indent. Add tests for backtracking indent and several other scenarios. Support a new notation for indent specs. An indent spec can be: - `nil` (or absent), meaning “indent like a regular function”. - A list/vector meaning that this function/macro takes a number of “special” arguments which are indented by more spaces (in CIDER that's 4 spaces), and then all other arguments are indented like a body (in CIDER that's 2 spaces). - The first element is a number indicating how many "special" arguments this function/macro takes. - Each following element is an indent spec on its own, and it applies to the argument on the same position as this element. So, when the argument is a form, it specifies how to indent that argument internally (if it's not a form the spec is irrelevant). - If the function/macro has more aguments than the list has elements, the last element of the list applies to all remaining arguments. So, for instance, if I specify the `deftype` spec as `[2 nil nil fn]` (equivalent to `[2 nil nil [1]]`), it would be indented like this: ``` (deftype ImageSelection [data] Transferable (getTransferDataFlavors [this] (some-function)) SomethingElse (isDataFlavorSupported [this flavor] (= imageFlavor flavor))) ``` (I put `ImageSelection` and `[data]` on their own lines just to show the indentation). Another example, `reify` as `[1 nil fn]` ``` (reify Object (toString [this] (f) asodkaodkap)) ``` Or something more complicated, `letfn` as `[1 [fn] nil]` ``` (letfn [(twice [x] (* x 2)) (six-times [y] (* (twice y) 3))] (println "Twice 15 =" (twice 15)) (println "Six times 15 =" (six-times 15))) ``` --- clojure-mode-indentation-test.el | 85 +++++++++++++++++++++++++++++--- 1 file changed, 79 insertions(+), 6 deletions(-) diff --git a/clojure-mode-indentation-test.el b/clojure-mode-indentation-test.el index 93de734..01f4ebd 100644 --- a/clojure-mode-indentation-test.el +++ b/clojure-mode-indentation-test.el @@ -110,28 +110,28 @@ values of customisable variables." (check-indentation doc-strings-without-indent-specified " (defn some-fn -|\"some doc string\"" +|\"some doc string\")" " (defn some-fn - |\"some doc string\"") + |\"some doc string\")") (check-indentation doc-strings-with-correct-indent-specified " (defn some-fn - |\"some doc string\"" + |\"some doc string\")" " (defn some-fn - |\"some doc string\"") + |\"some doc string\")") (check-indentation doc-strings-with-additional-indent-specified " (defn some-fn |\"some doc string - - some note\"" + - some note\")" " (defn some-fn |\"some doc string - - some note\"") + - some note\")") ;; we can specify different indentation for symbol with some ns prefix (put-clojure-indent 'bala 0) @@ -189,6 +189,79 @@ values of customisable variables." |(* x 2))] :a)") +(check-indentation fixed-normal-indent + "(cond + (or 1 + 2) 3 +|:else 4)" + "(cond + (or 1 + 2) 3 + |:else 4)") + +(check-indentation fixed-normal-indent-2 + "(fact {:spec-type + :charnock-column-id} #{\"charnock\"} +|{:spec-type + :charnock-column-id} #{\"current_charnock\"})" + "(fact {:spec-type + :charnock-column-id} #{\"charnock\"} + |{:spec-type + :charnock-column-id} #{\"current_charnock\"})") + + +;;; Backtracking indent +(defmacro def-full-indent-test (name form) + "Verify that FORM corresponds to a properly indented sexp." + (declare (indent 1)) + `(ert-deftest ,(intern (format "test-backtracking-%s" name)) () + (with-temp-buffer + (clojure-mode) + (insert "\n" ,(replace-regexp-in-string "\n +" "\n " form)) + (indent-region (point-min) (point-max)) + (should (equal (buffer-string) + ,(concat "\n" form)))))) + +(def-full-indent-test closing-paren + "(ns ca + (:gen-class) + )") + +(def-full-indent-test non-symbol-at-start + "{\"1\" 2 + *3 4}") + +(def-full-indent-test non-symbol-at-start-2 + "(\"1\" 2 + *3 4)") + +(def-full-indent-test defrecord + "(defrecord TheNameOfTheRecord + [a pretty long argument list] + SomeType + (assoc [_ x] + (.assoc pretty x 10)))") + +(def-full-indent-test defrecord-2 + "(defrecord TheNameOfTheRecord [a pretty long argument list] + SomeType (assoc [_ x] + (.assoc pretty x 10)))") + +(def-full-indent-test letfn + "(letfn [(f [x] + (* x 2)) + (f [x] + (* x 2))] + (a b + c) (d) + e)") + +(def-full-indent-test reify + "(reify + Object + (x [_] + 1))") + (provide 'clojure-mode-indentation-test) ;; Local Variables: From e5b6783bacc8e96b3993829fdc469d0b2b2609a6 Mon Sep 17 00:00:00 2001 From: Artur Malabarba Date: Tue, 15 Sep 2015 13:21:28 +0100 Subject: [PATCH 046/199] [Fix clojure-emacs/cider#1323] Sexp navigation near end of buffer --- clojure-mode-sexp-test.el | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/clojure-mode-sexp-test.el b/clojure-mode-sexp-test.el index 3cfcc70..22dcb8d 100644 --- a/clojure-mode-sexp-test.el +++ b/clojure-mode-sexp-test.el @@ -40,6 +40,31 @@ (clojure-backward-logical-sexp 1) (should (looking-at-p "\\^String biverse")))) +(ert-deftest test-buffer-corners () + (with-temp-buffer + (insert "^String reverse") + (clojure-mode) + ;; Return nil and don't error + (should-not (clojure-backward-logical-sexp 100)) + (should (looking-at-p "\\^String reverse")) + (should-not (clojure-forward-logical-sexp 100)) + (should (looking-at-p "$"))) + (with-temp-buffer + (clojure-mode) + (insert "(+ 10") + (should-error (clojure-backward-logical-sexp 100)) + (goto-char (point-min)) + (should-error (clojure-forward-logical-sexp 100)) + ;; Just don't hang. + (goto-char (point-max)) + (should-not (clojure-forward-logical-sexp 1)) + (erase-buffer) + (insert "(+ 10") + (newline) + (erase-buffer) + (insert "(+ 10") + (newline-and-indent))) + (provide 'clojure-mode-sexp-test) ;;; clojure-mode-sexp-test.el ends here From bf62b1bde01a34718693104e4d833cc6800626d1 Mon Sep 17 00:00:00 2001 From: Artur Malabarba Date: Mon, 28 Sep 2015 13:39:43 +0100 Subject: [PATCH 047/199] [Fix #325] Fix indent for spliced reader conditionals --- clojure-mode-indentation-test.el | 39 ++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) diff --git a/clojure-mode-indentation-test.el b/clojure-mode-indentation-test.el index 01f4ebd..ba11482 100644 --- a/clojure-mode-indentation-test.el +++ b/clojure-mode-indentation-test.el @@ -262,6 +262,45 @@ values of customisable variables." (x [_] 1))") +(def-full-indent-test reader-conditionals + "#?@ (:clj [] + :cljs [])") + + +;;; Misc + +(defun non-func (form-a form-b) + (with-temp-buffer + (clojure-mode) + (insert form-a) + (save-excursion (insert form-b)) + (clojure--not-function-form-p))) + +(ert-deftest non-function-form () + (dolist (form '(("#?@ " "(c d)") + ("#?@" "(c d)") + ("#? " "(c d)") + ("#?" "(c d)") + ("" "[asda]") + ("" "{a b}") + ("#" "{a b}") + ("" "(~)"))) + (should (apply #'non-func form))) + (dolist (form '("(c d)" + "(.c d)" + "(:c d)" + "(c/a d)" + "(.c/a d)" + "(:c/a d)" + "(c/a)" + "(:c/a)" + "(.c/a)")) + (should-not (non-func "" form)) + (should-not (non-func "^hint" form)) + (should-not (non-func "#macro" form)) + (should-not (non-func "^hint " form)) + (should-not (non-func "#macro " form)))) + (provide 'clojure-mode-indentation-test) ;; Local Variables: From 1018c6e7690884069e3b49e22ca5fa7d587bb438 Mon Sep 17 00:00:00 2001 From: Artur Malabarba Date: Tue, 29 Sep 2015 20:55:22 +0100 Subject: [PATCH 048/199] Font-lock namespaced keywords --- clojure-mode-font-lock-test.el | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/clojure-mode-font-lock-test.el b/clojure-mode-font-lock-test.el index 7763bdf..db3e1f4 100644 --- a/clojure-mode-font-lock-test.el +++ b/clojure-mode-font-lock-test.el @@ -101,7 +101,16 @@ POS." (ert-deftest clojure-mode-syntax-table/fontify-clojure-keyword () :tags '(fontification syntax-table) - (should (eq (clojure-test-face-at 2 11 "{:something 20}") 'clojure-keyword-face))) + (should (equal (clojure-test-face-at 2 11 "{:something 20}") '(clojure-keyword-face)))) + +(ert-deftest clojure-mode-syntax-table/fontify-namespaced-keyword () + :tags '(fontification syntax-table) + (should (equal (clojure-test-face-at 2 2 "{:alias/some 20}") '(clojure-keyword-face))) + (should (equal (clojure-test-face-at 3 7 "{:alias/some 20}") '(font-lock-type-face clojure-keyword-face))) + (should (equal (clojure-test-face-at 8 12 "{:alias/some 20}") '(clojure-keyword-face))) + (should (equal (clojure-test-face-at 2 2 "{:a.ias/some 20}") '(clojure-keyword-face))) + (should (equal (clojure-test-face-at 3 7 "{:a.ias/some 20}") '(font-lock-type-face clojure-keyword-face))) + (should (equal (clojure-test-face-at 8 12 "{:a.ias/some 20}") '(clojure-keyword-face)))) (ert-deftest clojure-mode-syntax-table/type () :tags '(fontification syntax-table) @@ -229,7 +238,7 @@ POS." :tags '(fontification syntax-table) (clojure-test-with-temp-buffer "^:meta-data" (should (eq (clojure-test-face-at 1 1) nil)) - (should (eq (clojure-test-face-at 2 11) 'clojure-keyword-face)))) + (should (equal (clojure-test-face-at 2 11) '(clojure-keyword-face))))) (ert-deftest clojure-mode-syntax-table/characters () :tags '(fontification syntax-table) From a7609cffa119613c4361736018f055780ef52082 Mon Sep 17 00:00:00 2001 From: Artur Malabarba Date: Thu, 1 Oct 2015 23:02:51 +0100 Subject: [PATCH 049/199] [Fix #327] Indentation of a lonely close paren Indent like this (if (pred?) ) not like this (if (pred?) ) --- clojure-mode-indentation-test.el | 29 +++++++++++++++++++++-------- 1 file changed, 21 insertions(+), 8 deletions(-) diff --git a/clojure-mode-indentation-test.el b/clojure-mode-indentation-test.el index ba11482..0253540 100644 --- a/clojure-mode-indentation-test.el +++ b/clojure-mode-indentation-test.el @@ -211,16 +211,18 @@ values of customisable variables." ;;; Backtracking indent -(defmacro def-full-indent-test (name form) - "Verify that FORM corresponds to a properly indented sexp." +(defmacro def-full-indent-test (name &rest forms) + "Verify that all FORMs correspond to a properly indented sexps." (declare (indent 1)) `(ert-deftest ,(intern (format "test-backtracking-%s" name)) () - (with-temp-buffer - (clojure-mode) - (insert "\n" ,(replace-regexp-in-string "\n +" "\n " form)) - (indent-region (point-min) (point-max)) - (should (equal (buffer-string) - ,(concat "\n" form)))))) + (progn + ,@(dolist (form forms) + `(with-temp-buffer + (clojure-mode) + (insert "\n" ,(replace-regexp-in-string "\n +" "\n " form)) + (indent-region (point-min) (point-max)) + (should (equal (buffer-string) + ,(concat "\n" form)))))))) (def-full-indent-test closing-paren "(ns ca @@ -266,6 +268,17 @@ values of customisable variables." "#?@ (:clj [] :cljs [])") +(def-full-indent-test empty-close-paren + "(let [x] + )" + + "(ns ok + )" + + "(ns ^{:zen :dikar} + ok + )") + ;;; Misc From c1e84d0949645c722c944b3507061dae758b54a1 Mon Sep 17 00:00:00 2001 From: Artur Malabarba Date: Thu, 1 Oct 2015 23:47:46 +0100 Subject: [PATCH 050/199] [Fix #327] Indentation when a symbol ends in ? or ' --- clojure-mode-indentation-test.el | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/clojure-mode-indentation-test.el b/clojure-mode-indentation-test.el index 0253540..aa5d6b4 100644 --- a/clojure-mode-indentation-test.el +++ b/clojure-mode-indentation-test.el @@ -279,6 +279,15 @@ values of customisable variables." ok )") +(def-full-indent-test symbols-ending-in-crap + "(msg? ExceptionInfo + 10)" + "(thrown-with-msg? ExceptionInfo + #\"Storage must be initialized before use\" + (f))" + "(msg' 1 + 10)") + ;;; Misc From 552edf753047e606a2b80d51175d95242cebcf8f Mon Sep 17 00:00:00 2001 From: Artur Malabarba Date: Tue, 13 Oct 2015 16:45:21 +0100 Subject: [PATCH 051/199] [Fix #331] Indentation in buffers without a final newline --- clojure-mode-indentation-test.el | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/clojure-mode-indentation-test.el b/clojure-mode-indentation-test.el index aa5d6b4..fe61d26 100644 --- a/clojure-mode-indentation-test.el +++ b/clojure-mode-indentation-test.el @@ -28,6 +28,16 @@ (require 'ert) (require 's) +(ert-deftest dont-hang-on-eob () + (with-temp-buffer + (insert "(let [a b]") + (clojure-mode) + (goto-char (point-max)) + (should + (with-timeout (2) + (newline-and-indent) + t)))) + (defmacro check-indentation (description before after &optional var-bindings) "Declare an ert test for indentation behaviour. The test will check that the swift indentation command changes the buffer From c8b0551399729f3c8a053f75bc66011ffb1efc75 Mon Sep 17 00:00:00 2001 From: Artur Malabarba Date: Mon, 19 Oct 2015 14:29:13 +0100 Subject: [PATCH 052/199] Add regression tests for function specs --- clojure-mode-indentation-test.el | 38 ++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) diff --git a/clojure-mode-indentation-test.el b/clojure-mode-indentation-test.el index fe61d26..3089483 100644 --- a/clojure-mode-indentation-test.el +++ b/clojure-mode-indentation-test.el @@ -298,6 +298,44 @@ values of customisable variables." "(msg' 1 10)") + +(defun indent-cond (indent-point state) + (goto-char (elt state 1)) + (let ((pos -1) + (base-col (current-column))) + (forward-char 1) + ;; `forward-sexp' will error if indent-point is after + ;; the last sexp in the current sexp. + (condition-case nil + (while (and (<= (point) indent-point) + (not (eobp))) + (clojure-forward-logical-sexp 1) + (cl-incf pos)) + ;; If indent-point is _after_ the last sexp in the + ;; current sexp, we detect that by catching the + ;; `scan-error'. In that case, we should return the + ;; indentation as if there were an extra sexp at point. + (scan-error (cl-incf pos))) + (+ base-col (if (evenp pos) 0 2)))) +(put-clojure-indent 'test-cond #'indent-cond) + +(defun indent-cond-0 (_indent-point _state) 0) +(put-clojure-indent 'test-cond-0 #'indent-cond-0) + +(def-full-indent-test function-spec + "(when me + (test-cond + x + 1 + 2 + 3))" + "(when me + (test-cond-0 +x +1 +2 +3))") + ;;; Misc From 9a1415cd7617e5a68ac3e193314be6c2cbb8b9fe Mon Sep 17 00:00:00 2001 From: Artur Malabarba Date: Sun, 25 Oct 2015 21:35:41 +0000 Subject: [PATCH 053/199] [Fix #336] Fix empty indent tests --- clojure-mode-indentation-test.el | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/clojure-mode-indentation-test.el b/clojure-mode-indentation-test.el index 3089483..7e9c4e3 100644 --- a/clojure-mode-indentation-test.el +++ b/clojure-mode-indentation-test.el @@ -226,13 +226,14 @@ values of customisable variables." (declare (indent 1)) `(ert-deftest ,(intern (format "test-backtracking-%s" name)) () (progn - ,@(dolist (form forms) - `(with-temp-buffer - (clojure-mode) - (insert "\n" ,(replace-regexp-in-string "\n +" "\n " form)) - (indent-region (point-min) (point-max)) - (should (equal (buffer-string) - ,(concat "\n" form)))))))) + ,@(mapcar (lambda (form) + `(with-temp-buffer + (clojure-mode) + (insert "\n" ,(replace-regexp-in-string "\n +" "\n " form)) + (indent-region (point-min) (point-max)) + (should (equal (buffer-string) + ,(concat "\n" form))))) + forms)))) (def-full-indent-test closing-paren "(ns ca From 279d46432532a3709b44c42832bfb8658a1dc39a Mon Sep 17 00:00:00 2001 From: Artur Malabarba Date: Sun, 25 Oct 2015 21:42:41 +0000 Subject: [PATCH 054/199] Add a regression test for #335 --- clojure-mode-indentation-test.el | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/clojure-mode-indentation-test.el b/clojure-mode-indentation-test.el index 7e9c4e3..acab19b 100644 --- a/clojure-mode-indentation-test.el +++ b/clojure-mode-indentation-test.el @@ -270,10 +270,18 @@ values of customisable variables." e)") (def-full-indent-test reify - "(reify - Object + "(reify Object (x [_] - 1))") + 1))" + "(reify + om/IRender + (render [this] + (let [indent-test :fail] + ...)) + om/IRender + (render [this] + (let [indent-test :fail] + ...)))") (def-full-indent-test reader-conditionals "#?@ (:clj [] From d81631423d51defdcf64b2f45a3e2211af3cad85 Mon Sep 17 00:00:00 2001 From: Artur Malabarba Date: Sun, 25 Oct 2015 21:57:13 +0000 Subject: [PATCH 055/199] [Fix #338] Font-locking of stuff in backticks --- clojure-mode-font-lock-test.el | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/clojure-mode-font-lock-test.el b/clojure-mode-font-lock-test.el index db3e1f4..96b18ab 100644 --- a/clojure-mode-font-lock-test.el +++ b/clojure-mode-font-lock-test.el @@ -103,6 +103,16 @@ POS." :tags '(fontification syntax-table) (should (equal (clojure-test-face-at 2 11 "{:something 20}") '(clojure-keyword-face)))) +(ert-deftest clojure-mode-syntax-table/stuff-in-backticks () + :tags '(fontification syntax-table) + (should (equal (clojure-test-face-at 1 2 "\"`#'s/trim`\"") font-lock-string-face)) + (should (equal (clojure-test-face-at 3 10 "\"`#'s/trim`\"") '(font-lock-constant-face font-lock-string-face))) + (should (equal (clojure-test-face-at 11 12 "\"`#'s/trim`\"") font-lock-string-face)) + (should (equal (clojure-test-face-at 1 1 ";`#'s/trim`") font-lock-comment-delimiter-face)) + (should (equal (clojure-test-face-at 2 2 ";`#'s/trim`") font-lock-comment-face)) + (should (equal (clojure-test-face-at 3 10 ";`#'s/trim`") '(font-lock-constant-face font-lock-comment-face))) + (should (equal (clojure-test-face-at 11 11 ";`#'s/trim`") font-lock-comment-face))) + (ert-deftest clojure-mode-syntax-table/fontify-namespaced-keyword () :tags '(fontification syntax-table) (should (equal (clojure-test-face-at 2 2 "{:alias/some 20}") '(clojure-keyword-face))) From 51bf8995a60e25c29d4844890aeb4a1068ca7616 Mon Sep 17 00:00:00 2001 From: Artur Malabarba Date: Sun, 25 Oct 2015 22:05:25 +0000 Subject: [PATCH 056/199] Fix void-function in tests --- clojure-mode-indentation-test.el | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/clojure-mode-indentation-test.el b/clojure-mode-indentation-test.el index acab19b..b800e65 100644 --- a/clojure-mode-indentation-test.el +++ b/clojure-mode-indentation-test.el @@ -325,7 +325,8 @@ values of customisable variables." ;; `scan-error'. In that case, we should return the ;; indentation as if there were an extra sexp at point. (scan-error (cl-incf pos))) - (+ base-col (if (evenp pos) 0 2)))) + (+ base-col (if (= (% pos 2) 0) + 0 2)))) (put-clojure-indent 'test-cond #'indent-cond) (defun indent-cond-0 (_indent-point _state) 0) From 1b9891178d5676e49d476011070b352ef10c1132 Mon Sep 17 00:00:00 2001 From: Artur Malabarba Date: Sun, 25 Oct 2015 22:59:07 +0000 Subject: [PATCH 057/199] [Fix #315] Indentation of unfinished sexps A.K.A not everybody uses paredit. --- clojure-mode-indentation-test.el | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/clojure-mode-indentation-test.el b/clojure-mode-indentation-test.el index b800e65..23e153b 100644 --- a/clojure-mode-indentation-test.el +++ b/clojure-mode-indentation-test.el @@ -298,6 +298,10 @@ values of customisable variables." ok )") +(def-full-indent-test unfinished-sexps + "(letfn [(tw [x] + dd") + (def-full-indent-test symbols-ending-in-crap "(msg? ExceptionInfo 10)" From f9e7bdf1091e6fc012d25de912c29ca18731def5 Mon Sep 17 00:00:00 2001 From: Artur Malabarba Date: Sun, 25 Oct 2015 23:45:29 +0000 Subject: [PATCH 058/199] Fix tests broken by the / font-lock --- clojure-mode-font-lock-test.el | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/clojure-mode-font-lock-test.el b/clojure-mode-font-lock-test.el index 96b18ab..d13d1c9 100644 --- a/clojure-mode-font-lock-test.el +++ b/clojure-mode-font-lock-test.el @@ -117,10 +117,12 @@ POS." :tags '(fontification syntax-table) (should (equal (clojure-test-face-at 2 2 "{:alias/some 20}") '(clojure-keyword-face))) (should (equal (clojure-test-face-at 3 7 "{:alias/some 20}") '(font-lock-type-face clojure-keyword-face))) - (should (equal (clojure-test-face-at 8 12 "{:alias/some 20}") '(clojure-keyword-face))) + (should (equal (clojure-test-face-at 8 8 "{:alias/some 20}") '(default clojure-keyword-face))) + (should (equal (clojure-test-face-at 9 12 "{:alias/some 20}") '(clojure-keyword-face))) (should (equal (clojure-test-face-at 2 2 "{:a.ias/some 20}") '(clojure-keyword-face))) (should (equal (clojure-test-face-at 3 7 "{:a.ias/some 20}") '(font-lock-type-face clojure-keyword-face))) - (should (equal (clojure-test-face-at 8 12 "{:a.ias/some 20}") '(clojure-keyword-face)))) + (should (equal (clojure-test-face-at 8 8 "{:a.ias/some 20}") '(default clojure-keyword-face))) + (should (equal (clojure-test-face-at 9 12 "{:a.ias/some 20}") '(clojure-keyword-face)))) (ert-deftest clojure-mode-syntax-table/type () :tags '(fontification syntax-table) @@ -148,7 +150,7 @@ POS." (ert-deftest clojure-mode-syntax-table/namespaced-symbol () :tags '(fontification syntax-table) (clojure-test-with-temp-buffer "clo.core/something" - (should (eq (clojure-test-face-at 9 9) nil)) + (should (eq (clojure-test-face-at 9 9) 'default)) (should (eq (clojure-test-face-at 1 8) 'font-lock-type-face)) (should (eq (clojure-test-face-at 10 18) nil)))) @@ -156,15 +158,15 @@ POS." :tags '(fontification syntax-table) (clojure-test-with-temp-buffer "Class/methodName" (should (eq (clojure-test-face-at 1 5) 'font-lock-type-face)) - (should (eq (clojure-test-face-at 6 6) nil)) + (should (eq (clojure-test-face-at 6 6) 'default)) (should (eq (clojure-test-face-at 7 16) 'clojure-interop-method-face))) (clojure-test-with-temp-buffer "SomeClass/methodName" (should (eq (clojure-test-face-at 1 9) 'font-lock-type-face)) - (should (eq (clojure-test-face-at 10 10) nil)) + (should (eq (clojure-test-face-at 10 10) 'default)) (should (eq (clojure-test-face-at 11 20) 'clojure-interop-method-face))) (clojure-test-with-temp-buffer "clojure.lang.Var/someMethod" (should (eq (clojure-test-face-at 1 16) 'font-lock-type-face)) - (should (eq (clojure-test-face-at 17 17) nil)) + (should (eq (clojure-test-face-at 17 17) 'default)) (should (eq (clojure-test-face-at 18 27) 'clojure-interop-method-face)))) (ert-deftest clojure-mode-syntax-table/interop-method () @@ -182,7 +184,7 @@ POS." (ert-deftest clojure-mode-syntax-table/class-constant () :tags '(fontification syntax-table) (clojure-test-with-temp-buffer "Class/CONST_NAME" - (should (eq (clojure-test-face-at 6 6) nil)) + (should (eq (clojure-test-face-at 6 6) 'default)) (should (eq (clojure-test-face-at 1 5) 'font-lock-type-face)) (should (eq (clojure-test-face-at 7 16) 'font-lock-constant-face)))) @@ -190,7 +192,7 @@ POS." :tags '(fontification syntax-table) (clojure-test-with-temp-buffer "(clo/defbar foo nil)" (should (eq (clojure-test-face-at 2 4) 'font-lock-type-face)) - (should (eq (clojure-test-face-at 5 5) nil)) + (should (eq (clojure-test-face-at 5 5) 'default)) (should (eq (clojure-test-face-at 6 11) 'font-lock-keyword-face)) (should (eq (clojure-test-face-at 13 15) 'font-lock-function-name-face)))) From 077e3491bcc77ec84f2e57b0dc007909351a8da7 Mon Sep 17 00:00:00 2001 From: Marian Schubert Date: Tue, 13 Oct 2015 16:28:25 +0200 Subject: [PATCH 059/199] Improve clojure-find-def matching (support hyphens) Custom def... macros might contain hyphens (e.g. defxxx-yyy). --- clojure-mode-font-lock-test.el | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/clojure-mode-font-lock-test.el b/clojure-mode-font-lock-test.el index db3e1f4..6d8ad39 100644 --- a/clojure-mode-font-lock-test.el +++ b/clojure-mode-font-lock-test.el @@ -214,6 +214,12 @@ POS." (should (eq (clojure-test-face-at 2 14) 'font-lock-keyword-face)) (should (eq (clojure-test-face-at 16 18) 'font-lock-function-name-face)))) +(ert-deftest clojure-mode-syntax-table/custom-def-with-special-chars3 () + :tags '(fontification syntax-table) + (clojure-test-with-temp-buffer "(def-something foo [x] x)" + (should (eq (clojure-test-face-at 2 14) 'font-lock-keyword-face)) + (should (eq (clojure-test-face-at 16 18) 'font-lock-function-name-face)))) + (ert-deftest clojure-mode-syntax-table/lambda-params () :tags '(fontification syntax-table) (clojure-test-with-temp-buffer "#(+ % %2 %3)" From 358f9b73a86acf650b643594c67c79a35cad30e8 Mon Sep 17 00:00:00 2001 From: Bozhidar Batsov Date: Mon, 26 Oct 2015 23:56:05 +0200 Subject: [PATCH 060/199] Use cl-evenp in one of the tests --- clojure-mode-indentation-test.el | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/clojure-mode-indentation-test.el b/clojure-mode-indentation-test.el index 23e153b..620a715 100644 --- a/clojure-mode-indentation-test.el +++ b/clojure-mode-indentation-test.el @@ -329,8 +329,7 @@ values of customisable variables." ;; `scan-error'. In that case, we should return the ;; indentation as if there were an extra sexp at point. (scan-error (cl-incf pos))) - (+ base-col (if (= (% pos 2) 0) - 0 2)))) + (+ base-col (if (cl-evenp pos) 0 2)))) (put-clojure-indent 'test-cond #'indent-cond) (defun indent-cond-0 (_indent-point _state) 0) From a33c3e2dfddbf8d84d4b4a487971f5d0377b650f Mon Sep 17 00:00:00 2001 From: Artur Malabarba Date: Sun, 8 Nov 2015 16:44:32 +0000 Subject: [PATCH 061/199] Don't treat the symbol default as def* macro. See https://github.com/clojure-emacs/clojure-mode/commit/b31e941366b318706023949a0ca579c08dbe46be#commitcomment-14257272 --- clojure-mode-indentation-test.el | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/clojure-mode-indentation-test.el b/clojure-mode-indentation-test.el index 620a715..db963a4 100644 --- a/clojure-mode-indentation-test.el +++ b/clojure-mode-indentation-test.el @@ -240,6 +240,11 @@ values of customisable variables." (:gen-class) )") +(def-full-indent-test default-is-not-a-define + "(default a + b + b)") + (def-full-indent-test non-symbol-at-start "{\"1\" 2 *3 4}") From bff5ddc1b530b60a58d2c8fa22e646fbfe3cf3da Mon Sep 17 00:00:00 2001 From: Artur Malabarba Date: Sun, 8 Nov 2015 17:18:40 +0000 Subject: [PATCH 062/199] [Fix #344] Indentation for extend-type --- clojure-mode-indentation-test.el | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/clojure-mode-indentation-test.el b/clojure-mode-indentation-test.el index db963a4..da100fa 100644 --- a/clojure-mode-indentation-test.el +++ b/clojure-mode-indentation-test.el @@ -245,6 +245,22 @@ values of customisable variables." b b)") +(def-full-indent-test extend-type-allow-multiarity + "(extend-type Banana + Fruit + (subtotal + ([item] + (* 158 (:qty item))) + ([item a] + (* a (:qty item)))))" + "(extend-protocol Banana + Fruit + (subtotal + ([item] + (* 158 (:qty item))) + ([item a] + (* a (:qty item)))))") + (def-full-indent-test non-symbol-at-start "{\"1\" 2 *3 4}") From ebf33a3a060bfca7358ed33c196003dd97642243 Mon Sep 17 00:00:00 2001 From: Artur Malabarba Date: Tue, 10 Nov 2015 11:41:40 +0000 Subject: [PATCH 063/199] Add a test for namespaced default* symbols --- clojure-mode-indentation-test.el | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/clojure-mode-indentation-test.el b/clojure-mode-indentation-test.el index da100fa..470b395 100644 --- a/clojure-mode-indentation-test.el +++ b/clojure-mode-indentation-test.el @@ -243,7 +243,10 @@ values of customisable variables." (def-full-indent-test default-is-not-a-define "(default a b - b)") + b)" + "(some.namespace/default a + b + b)") (def-full-indent-test extend-type-allow-multiarity "(extend-type Banana From b4e8a209f01e939165abb67173839c9ecbc381c2 Mon Sep 17 00:00:00 2001 From: Artur Malabarba Date: Fri, 27 Nov 2015 13:09:39 +0000 Subject: [PATCH 064/199] [Fix #349] Indent and font-lock (let|when|while)-* forms --- clojure-mode-font-lock-test.el | 6 ++++++ clojure-mode-indentation-test.el | 4 ++++ 2 files changed, 10 insertions(+) diff --git a/clojure-mode-font-lock-test.el b/clojure-mode-font-lock-test.el index fa901e4..04fd265 100644 --- a/clojure-mode-font-lock-test.el +++ b/clojure-mode-font-lock-test.el @@ -124,6 +124,12 @@ POS." (should (equal (clojure-test-face-at 8 8 "{:a.ias/some 20}") '(default clojure-keyword-face))) (should (equal (clojure-test-face-at 9 12 "{:a.ias/some 20}") '(clojure-keyword-face)))) +(ert-deftest clojure-mode-syntax-table/fontify-let-when-while-type-forms () + :tags '(fontification syntax-table) + (should (equal (clojure-test-face-at 2 11 "(when-alist [x 1]\n ())") 'font-lock-keyword-face)) + (should (equal (clojure-test-face-at 2 11 "(while-alist [x 1]\n ())") 'font-lock-keyword-face)) + (should (equal (clojure-test-face-at 2 11 "(let-alist [x 1]\n ())") 'various-faces))) + (ert-deftest clojure-mode-syntax-table/type () :tags '(fontification syntax-table) (should (eq (clojure-test-face-at 1 9 "SomeClass") 'font-lock-type-face))) diff --git a/clojure-mode-indentation-test.el b/clojure-mode-indentation-test.el index 470b395..9a8325b 100644 --- a/clojure-mode-indentation-test.el +++ b/clojure-mode-indentation-test.el @@ -335,6 +335,10 @@ values of customisable variables." "(msg' 1 10)") +(def-full-indent-test let-when-while-forms + "(let-alist [x 1]\n ())" + "(while-alist [x 1]\n ())" + "(when-alist [x 1]\n ())") (defun indent-cond (indent-point state) (goto-char (elt state 1)) From 0534a3eaf4ba8b7a53cc42b0b92b4342264b07bd Mon Sep 17 00:00:00 2001 From: Artur Malabarba Date: Fri, 27 Nov 2015 13:30:39 +0000 Subject: [PATCH 065/199] Document indentation and font-locking of (let|when|while)-* forms Also improve a test. --- clojure-mode-font-lock-test.el | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/clojure-mode-font-lock-test.el b/clojure-mode-font-lock-test.el index 04fd265..4b64053 100644 --- a/clojure-mode-font-lock-test.el +++ b/clojure-mode-font-lock-test.el @@ -127,8 +127,8 @@ POS." (ert-deftest clojure-mode-syntax-table/fontify-let-when-while-type-forms () :tags '(fontification syntax-table) (should (equal (clojure-test-face-at 2 11 "(when-alist [x 1]\n ())") 'font-lock-keyword-face)) - (should (equal (clojure-test-face-at 2 11 "(while-alist [x 1]\n ())") 'font-lock-keyword-face)) - (should (equal (clojure-test-face-at 2 11 "(let-alist [x 1]\n ())") 'various-faces))) + (should (equal (clojure-test-face-at 2 12 "(while-alist [x 1]\n ())") 'font-lock-keyword-face)) + (should (equal (clojure-test-face-at 2 10 "(let-alist [x 1]\n ())") 'font-lock-keyword-face))) (ert-deftest clojure-mode-syntax-table/type () :tags '(fontification syntax-table) From 18fd66793950e16176b57f4f194d9bb82e2a1761 Mon Sep 17 00:00:00 2001 From: Lars Andersen Date: Thu, 26 Nov 2015 11:53:45 +0100 Subject: [PATCH 066/199] Make the ns regexp more permissive Any valid symbol can be used to name an ns. The current regexp would fail to parse symbols ending in certain characters, e.g. `+`. This closes clojure-emacs/cider#1433 --- clojure-mode-util-test.el | 42 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) diff --git a/clojure-mode-util-test.el b/clojure-mode-util-test.el index 5fd689b..00d4cd0 100644 --- a/clojure-mode-util-test.el +++ b/clojure-mode-util-test.el @@ -53,6 +53,48 @@ (clojure-expected-ns)) clj-file-ns))))) +(ert-deftest clojure-namespace-name-regex-test () + :tags '(regexp) + (let ((ns "(ns foo)")) + (should (string-match clojure-namespace-name-regex ns)) + (match-string 4 ns)) + (let ((ns "(ns +foo)")) + (should (string-match clojure-namespace-name-regex ns)) + (should (equal "foo" (match-string 4 ns)))) + (let ((ns "(ns foo.baz)")) + (should (string-match clojure-namespace-name-regex ns)) + (should (equal "foo.baz" (match-string 4 ns)))) + (let ((ns "(ns ^:bar foo)")) + (should (string-match clojure-namespace-name-regex ns)) + (should (equal "foo" (match-string 4 ns)))) + (let ((ns "(ns ^:bar ^:baz foo)")) + (should (string-match clojure-namespace-name-regex ns)) + (should (equal "foo" (match-string 4 ns)))) + (let ((ns "(ns ^{:bar true} foo)")) + (should (string-match clojure-namespace-name-regex ns)) + (should (equal "foo" (match-string 4 ns)))) + (let ((ns "(ns #^{:bar true} foo)")) + (should (string-match clojure-namespace-name-regex ns)) + (should (equal "foo" (match-string 4 ns)))) + ;; TODO + ;; (let ((ns "(ns #^{:fail {}} foo)")) + ;; (should (string-match clojure-namespace-name-regex ns)) + ;; (match-string 4 ns)) + ;; (let ((ns "(ns ^{:fail2 {}} foo.baz)")) + ;; (should (string-match clojure-namespace-name-regex ns)) + ;; (should (equal "foo.baz" (match-string 4 ns)))) + (let ((ns "(ns ^{} foo)")) + (should (string-match clojure-namespace-name-regex ns)) + (should (equal "foo" (match-string 4 ns)))) + (let ((ns "(ns ^{:skip-wiki true} + aleph.netty")) + (should (string-match clojure-namespace-name-regex ns)) + (should (equal "aleph.netty" (match-string 4 ns)))) + (let ((ns "(ns foo+)")) + (should (string-match clojure-namespace-name-regex ns)) + (should (equal "foo+" (match-string 4 ns))))) + (provide 'clojure-mode-util-test) ;; Local Variables: From 89f18b3c8e21ed6b8b55978b8c964377fe5d94b4 Mon Sep 17 00:00:00 2001 From: Rostislav Svoboda Date: Mon, 30 Nov 2015 19:37:51 +0100 Subject: [PATCH 067/199] Namespace font-locking according to clojure.lang.LispReader Fix namespace alias font-locking for aliases containing non-letter charactes like $, 0-9, _, etc. --- clojure-mode-font-lock-test.el | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/clojure-mode-font-lock-test.el b/clojure-mode-font-lock-test.el index 4b64053..b1a1480 100644 --- a/clojure-mode-font-lock-test.el +++ b/clojure-mode-font-lock-test.el @@ -196,6 +196,11 @@ POS." (ert-deftest clojure-mode-syntax-table/namespaced-def () :tags '(fontification syntax-table) + (clojure-test-with-temp-buffer "(_c4/defconstrainedfn bar [] nil)" + (should (eq (clojure-test-face-at 2 4) 'font-lock-type-face)) + (should (eq (clojure-test-face-at 5 5) 'default)) + (should (eq (clojure-test-face-at 6 18) 'font-lock-keyword-face)) + (should (eq (clojure-test-face-at 23 25) 'font-lock-function-name-face))) (clojure-test-with-temp-buffer "(clo/defbar foo nil)" (should (eq (clojure-test-face-at 2 4) 'font-lock-type-face)) (should (eq (clojure-test-face-at 5 5) 'default)) From 8e32037be1d0cff5a52ac083421b409485e6e1b0 Mon Sep 17 00:00:00 2001 From: Artur Malabarba Date: Mon, 7 Dec 2015 23:45:22 +0000 Subject: [PATCH 068/199] [Fix #277] Apply font-lock-comment-face to #_ --- clojure-mode-font-lock-test.el | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/clojure-mode-font-lock-test.el b/clojure-mode-font-lock-test.el index b1a1480..6d8e623 100644 --- a/clojure-mode-font-lock-test.el +++ b/clojure-mode-font-lock-test.el @@ -130,6 +130,11 @@ POS." (should (equal (clojure-test-face-at 2 12 "(while-alist [x 1]\n ())") 'font-lock-keyword-face)) (should (equal (clojure-test-face-at 2 10 "(let-alist [x 1]\n ())") 'font-lock-keyword-face))) +(ert-deftest clojure-mode-syntax-table/comment-macros () + :tags '(fontification syntax-table) + (should (not (clojure-test-face-at 1 2 "#_ \n;; some crap\n (lala 0101\n lao\n\n 0 0i)"))) + (should (equal (clojure-test-face-at 5 41 "#_ \n;; some crap\n (lala 0101\n lao\n\n 0 0i)") 'font-lock-comment-face))) + (ert-deftest clojure-mode-syntax-table/type () :tags '(fontification syntax-table) (should (eq (clojure-test-face-at 1 9 "SomeClass") 'font-lock-type-face))) From 3a6ce6b177409795e676b18e673ae104c516a576 Mon Sep 17 00:00:00 2001 From: Bozhidar Batsov Date: Sun, 13 Dec 2015 20:38:04 +0200 Subject: [PATCH 069/199] [Fix #355] Font-lock properly single-char ns aliases --- clojure-mode-font-lock-test.el | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/clojure-mode-font-lock-test.el b/clojure-mode-font-lock-test.el index 6d8e623..57fafcb 100644 --- a/clojure-mode-font-lock-test.el +++ b/clojure-mode-font-lock-test.el @@ -163,7 +163,15 @@ POS." (clojure-test-with-temp-buffer "clo.core/something" (should (eq (clojure-test-face-at 9 9) 'default)) (should (eq (clojure-test-face-at 1 8) 'font-lock-type-face)) - (should (eq (clojure-test-face-at 10 18) nil)))) + (should (eq (clojure-test-face-at 10 18) nil))) + (clojure-test-with-temp-buffer "a/something" + (should (eq (clojure-test-face-at 1 1) 'font-lock-type-face)) + (should (eq (clojure-test-face-at 3 12) 'nil)) + (should (eq (clojure-test-face-at 2 2) 'default))) + (clojure-test-with-temp-buffer "abc/something" + (should (eq (clojure-test-face-at 1 3) 'font-lock-type-face)) + (should (eq (clojure-test-face-at 5 14) 'nil)) + (should (eq (clojure-test-face-at 4 4) 'default)))) (ert-deftest clojure-mode-syntax-table/static-method () :tags '(fontification syntax-table) From 0fda86e980b53e22d243b15d428ba7ad4ed8aab7 Mon Sep 17 00:00:00 2001 From: Artur Malabarba Date: Tue, 29 Dec 2015 20:43:22 +0000 Subject: [PATCH 070/199] [Fix #356] defprotocol docstring indentation --- clojure-mode-indentation-test.el | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/clojure-mode-indentation-test.el b/clojure-mode-indentation-test.el index 9a8325b..1158583 100644 --- a/clojure-mode-indentation-test.el +++ b/clojure-mode-indentation-test.el @@ -264,6 +264,14 @@ values of customisable variables." ([item a] (* a (:qty item)))))") +(def-full-indent-test defprotocol + "(defprotocol IFoo + (foo [this] + \"Why is this over here?\") + (foo-2 + [this] + \"Why is this over here?\"))") + (def-full-indent-test non-symbol-at-start "{\"1\" 2 *3 4}") From 221319742ef116c4fd7cb6b1b4d65c53bdf3f745 Mon Sep 17 00:00:00 2001 From: Artur Malabarba Date: Tue, 17 Nov 2015 12:06:10 +0000 Subject: [PATCH 071/199] Implement alignment of binding forms and map literals --- clojure-mode-indentation-test.el | 86 ++++++++++++++++++++++++++++++++ 1 file changed, 86 insertions(+) diff --git a/clojure-mode-indentation-test.el b/clojure-mode-indentation-test.el index 1158583..57ff30c 100644 --- a/clojure-mode-indentation-test.el +++ b/clojure-mode-indentation-test.el @@ -385,6 +385,92 @@ x 2 3))") +;;; Alignment +(defmacro def-full-align-test (name &rest forms) + "Verify that all FORMs correspond to a properly indented sexps." + (declare (indent defun)) + `(ert-deftest ,(intern (format "test-align-%s" name)) () + (let ((clojure-align-forms-automatically t)) + ,@(mapcar (lambda (form) + `(with-temp-buffer + (clojure-mode) + (insert "\n" ,(replace-regexp-in-string " +" " " form)) + (indent-region (point-min) (point-max)) + (should (equal (buffer-substring-no-properties (point-min) (point-max)) + ,(concat "\n" form))))) + forms)) + (let ((clojure-align-forms-automatically nil)) + ,@(mapcar (lambda (form) + `(with-temp-buffer + (clojure-mode) + (insert "\n" ,(replace-regexp-in-string " +" " " form)) + (indent-region (point-min) (point-max)) + (should (equal (buffer-substring-no-properties + (point-min) (point-max)) + ,(concat "\n" (replace-regexp-in-string + "\\([a-z]\\) +" "\\1 " form)))))) + forms)))) + +(def-full-align-test basic + "{:this-is-a-form b + c d}" + "{:this-is b + c d}" + "{:this b + c d}" + "{:a b + c d}" + + "(let [this-is-a-form b + c d])" + "(let [this-is b + c d])" + "(let [this b + c d])" + "(let [a b + c d])") + +(def-full-align-test basic-reversed + "{c d + :this-is-a-form b}" + "{c d + :this-is b}" + "{c d + :this b}" + "{c d + :a b}" + + "(let [c d + this-is-a-form b])" + "(let [c d + this-is b])" + "(let [c d + this b])" + "(let [c d + a b])") + +(def-full-align-test incomplete-sexp + "(cond aa b + casodkas )" + "(cond aa b + casodkas)" + "(cond aa b + casodkas " + "(cond aa b + casodkas" + "(cond aa b + casodkas a)" + "(cond casodkas a + aa b)" + "(cond casodkas + aa b)") + +(def-full-align-test multiple-words + "(cond this is just + a test of + how well + multiple words will work)") + ;;; Misc From 1ddadceed86131192c358d451cf7e1fd852e020f Mon Sep 17 00:00:00 2001 From: Bozhidar Batsov Date: Sat, 2 Jan 2016 09:09:01 +0000 Subject: [PATCH 072/199] Update the copyright years --- clojure-mode-font-lock-test.el | 2 +- clojure-mode-indentation-test.el | 2 +- clojure-mode-sexp-test.el | 2 +- clojure-mode-util-test.el | 2 +- test-helper.el | 2 +- 5 files changed, 5 insertions(+), 5 deletions(-) diff --git a/clojure-mode-font-lock-test.el b/clojure-mode-font-lock-test.el index 57fafcb..418f917 100644 --- a/clojure-mode-font-lock-test.el +++ b/clojure-mode-font-lock-test.el @@ -1,6 +1,6 @@ ;;; clojure-mode-font-lock-test.el --- Clojure Mode: Font lock test suite -*- lexical-binding: t; -*- -;; Copyright (C) 2014-2015 Bozhidar Batsov +;; Copyright (C) 2014-2016 Bozhidar Batsov ;; This file is not part of GNU Emacs. diff --git a/clojure-mode-indentation-test.el b/clojure-mode-indentation-test.el index 57ff30c..f8d1c89 100644 --- a/clojure-mode-indentation-test.el +++ b/clojure-mode-indentation-test.el @@ -1,6 +1,6 @@ ;;; clojure-mode-indentation-test.el --- Clojure Mode: indentation tests -*- lexical-binding: t; -*- -;; Copyright (C) 2015 Bozhidar Batsov +;; Copyright (C) 2015-2016 Bozhidar Batsov ;; This file is not part of GNU Emacs. diff --git a/clojure-mode-sexp-test.el b/clojure-mode-sexp-test.el index 22dcb8d..23dbe42 100644 --- a/clojure-mode-sexp-test.el +++ b/clojure-mode-sexp-test.el @@ -1,6 +1,6 @@ ;;; clojure-mode-sexp-test.el --- Clojure Mode: sexp tests -*- lexical-binding: t; -*- -;; Copyright (C) 2015 Artur Malabarba +;; Copyright (C) 2015-2016 Artur Malabarba ;; This file is not part of GNU Emacs. diff --git a/clojure-mode-util-test.el b/clojure-mode-util-test.el index 00d4cd0..84e53af 100644 --- a/clojure-mode-util-test.el +++ b/clojure-mode-util-test.el @@ -1,6 +1,6 @@ ;;; clojure-mode-util-test.el --- Clojure Mode: util test suite -*- lexical-binding: t; -*- -;; Copyright (C) 2014-2015 Bozhidar Batsov +;; Copyright (C) 2014-2016 Bozhidar Batsov ;; This file is not part of GNU Emacs. diff --git a/test-helper.el b/test-helper.el index ee93188..7403ed6 100644 --- a/test-helper.el +++ b/test-helper.el @@ -1,6 +1,6 @@ ;;; test-helper.el --- Clojure Mode: Non-interactive unit-test setup -*- lexical-binding: t; -*- -;; Copyright (C) 2014-2015 Bozhidar Batsov +;; Copyright (C) 2014-2016 Bozhidar Batsov ;; This file is not part of GNU Emacs. From 59f4cdc6cf59dac84ffe8c84011daa0ec2f0102d Mon Sep 17 00:00:00 2001 From: Bozhidar Batsov Date: Sun, 3 Jan 2016 12:01:32 +0200 Subject: [PATCH 073/199] Add indentation tests for `specify` and `specify!` --- clojure-mode-indentation-test.el | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/clojure-mode-indentation-test.el b/clojure-mode-indentation-test.el index f8d1c89..566df29 100644 --- a/clojure-mode-indentation-test.el +++ b/clojure-mode-indentation-test.el @@ -272,6 +272,24 @@ values of customisable variables." [this] \"Why is this over here?\"))") +(def-full-indent-test specify + "(specify obj + ISwap + (-swap! + ([this f] (reset! this (f @this))) + ([this f a] (reset! this (f @this a))) + ([this f a b] (reset! this (f @this a b))) + ([this f a b xs] (reset! this (apply f @this a b xs)))))") + +(def-full-indent-test specify! + "(specify! obj + ISwap + (-swap! + ([this f] (reset! this (f @this))) + ([this f a] (reset! this (f @this a))) + ([this f a b] (reset! this (f @this a b))) + ([this f a b xs] (reset! this (apply f @this a b xs)))))") + (def-full-indent-test non-symbol-at-start "{\"1\" 2 *3 4}") From cfdf1c4351c06293210bf6de7af3b67a741be69e Mon Sep 17 00:00:00 2001 From: Artur Malabarba Date: Sat, 16 Jan 2016 07:31:27 +0000 Subject: [PATCH 074/199] [Fix #360] Reindent after aligning --- clojure-mode-indentation-test.el | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/clojure-mode-indentation-test.el b/clojure-mode-indentation-test.el index 566df29..8213b13 100644 --- a/clojure-mode-indentation-test.el +++ b/clojure-mode-indentation-test.el @@ -489,6 +489,11 @@ x how well multiple words will work)") +(def-full-align-test nested-maps + "{:a {:a :a + :bbbb :b} + :bbbb :b}") + ;;; Misc From 3ec544ccacc5ae26ed82c21f98970b5ad0c72699 Mon Sep 17 00:00:00 2001 From: Artur Malabarba Date: Sat, 16 Jan 2016 09:01:38 +0000 Subject: [PATCH 075/199] Fix a stupid failing test --- clojure-mode-indentation-test.el | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/clojure-mode-indentation-test.el b/clojure-mode-indentation-test.el index 8213b13..1e8c124 100644 --- a/clojure-mode-indentation-test.el +++ b/clojure-mode-indentation-test.el @@ -490,8 +490,8 @@ x multiple words will work)") (def-full-align-test nested-maps - "{:a {:a :a - :bbbb :b} + "{:a {:a :a + :bbbb :b} :bbbb :b}") From e7749f5c6328da47324e8aa79e8496e8d4afbff6 Mon Sep 17 00:00:00 2001 From: Bozhidar Batsov Date: Sat, 16 Jan 2016 13:21:02 +0200 Subject: [PATCH 076/199] Remove redundant file-local variables --- clojure-mode-font-lock-test.el | 4 ---- clojure-mode-indentation-test.el | 4 ---- clojure-mode-util-test.el | 4 ---- test-helper.el | 4 ---- 4 files changed, 16 deletions(-) diff --git a/clojure-mode-font-lock-test.el b/clojure-mode-font-lock-test.el index 418f917..64bcaeb 100644 --- a/clojure-mode-font-lock-test.el +++ b/clojure-mode-font-lock-test.el @@ -317,8 +317,4 @@ POS." (provide 'clojure-mode-font-lock-test) -;; Local Variables: -;; indent-tabs-mode: nil -;; End: - ;;; clojure-mode-font-lock-test.el ends here diff --git a/clojure-mode-indentation-test.el b/clojure-mode-indentation-test.el index 1e8c124..527e8aa 100644 --- a/clojure-mode-indentation-test.el +++ b/clojure-mode-indentation-test.el @@ -531,8 +531,4 @@ x (provide 'clojure-mode-indentation-test) -;; Local Variables: -;; indent-tabs-mode: nil -;; End: - ;;; clojure-mode-indentation-test.el ends here diff --git a/clojure-mode-util-test.el b/clojure-mode-util-test.el index 84e53af..5682d33 100644 --- a/clojure-mode-util-test.el +++ b/clojure-mode-util-test.el @@ -97,8 +97,4 @@ foo)")) (provide 'clojure-mode-util-test) -;; Local Variables: -;; indent-tabs-mode: nil -;; End: - ;;; clojure-mode-util-test.el ends here diff --git a/test-helper.el b/test-helper.el index 7403ed6..4846360 100644 --- a/test-helper.el +++ b/test-helper.el @@ -32,8 +32,4 @@ ;; Load the file under test (load (expand-file-name "clojure-mode" source-directory))) -;; Local Variables: -;; indent-tabs-mode: nil -;; End: - ;;; test-helper.el ends here From 00273312ad2aa6d7b29a61fe5a9ed77490c9fc39 Mon Sep 17 00:00:00 2001 From: Artur Malabarba Date: Sat, 16 Jan 2016 16:00:36 +0000 Subject: [PATCH 077/199] Fix the nil case for align tests --- clojure-mode-indentation-test.el | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/clojure-mode-indentation-test.el b/clojure-mode-indentation-test.el index 527e8aa..d5e2424 100644 --- a/clojure-mode-indentation-test.el +++ b/clojure-mode-indentation-test.el @@ -422,11 +422,12 @@ x `(with-temp-buffer (clojure-mode) (insert "\n" ,(replace-regexp-in-string " +" " " form)) + ;; This is to check that we did NOT align anything. Run + ;; `indent-region' and then check that no extra spaces + ;; where inserted besides the start of the line. (indent-region (point-min) (point-max)) - (should (equal (buffer-substring-no-properties - (point-min) (point-max)) - ,(concat "\n" (replace-regexp-in-string - "\\([a-z]\\) +" "\\1 " form)))))) + (goto-char (point-min)) + (should-not (search-forward-regexp "\\([^\s\n]\\) +" nil 'noerror)))) forms)))) (def-full-align-test basic From 8f111a53886bb48c534b00995b2168d05ffc1a45 Mon Sep 17 00:00:00 2001 From: Artur Malabarba Date: Sat, 16 Jan 2016 16:31:09 +0000 Subject: [PATCH 078/199] [Fix #360] Convert END to a marker in clojure-align --- clojure-mode-indentation-test.el | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/clojure-mode-indentation-test.el b/clojure-mode-indentation-test.el index d5e2424..5c6f554 100644 --- a/clojure-mode-indentation-test.el +++ b/clojure-mode-indentation-test.el @@ -495,6 +495,12 @@ x :bbbb :b} :bbbb :b}") +(def-full-align-test end-is-a-marker + "{:a {:a :a + :aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa :a} + :b {:a :a + :aa :a}}") + ;;; Misc From e60d0a75f1c87794cfbb7be57e406cc1000bbe2c Mon Sep 17 00:00:00 2001 From: Artur Malabarba Date: Sun, 24 Jan 2016 12:29:24 +0000 Subject: [PATCH 079/199] [Fix #362] Define a custom option clojure-indent-style --- clojure-mode-indentation-test.el | 29 +++++++++++++++++++++++++++-- 1 file changed, 27 insertions(+), 2 deletions(-) diff --git a/clojure-mode-indentation-test.el b/clojure-mode-indentation-test.el index 5c6f554..b26904c 100644 --- a/clojure-mode-indentation-test.el +++ b/clojure-mode-indentation-test.el @@ -58,6 +58,7 @@ values of customisable variables." (let ((fname (intern (format "indentation/%s" description)))) `(ert-deftest ,fname () (let* ((after ,after) + (clojure-indent-style :always-align) (expected-cursor-pos (1+ (s-index-of "|" after))) (expected-state (delete ?| after)) ,@var-bindings) @@ -221,16 +222,20 @@ values of customisable variables." ;;; Backtracking indent -(defmacro def-full-indent-test (name &rest forms) +(defmacro def-full-indent-test (name &optional style &rest forms) "Verify that all FORMs correspond to a properly indented sexps." (declare (indent 1)) + (when (stringp style) + (setq forms (cons style forms)) + (setq style :always-align)) `(ert-deftest ,(intern (format "test-backtracking-%s" name)) () (progn ,@(mapcar (lambda (form) `(with-temp-buffer (clojure-mode) (insert "\n" ,(replace-regexp-in-string "\n +" "\n " form)) - (indent-region (point-min) (point-max)) + (let ((clojure-indent-style ,style)) + (indent-region (point-min) (point-max))) (should (equal (buffer-string) ,(concat "\n" form))))) forms)))) @@ -403,6 +408,26 @@ x 2 3))") +(def-full-indent-test align-arguments + :align-arguments + "(some-function + 10 + 1 + 2)" + "(some-function 10 + 1 + 2)") + +(def-full-indent-test always-indent + :always-indent + "(some-function + 10 + 1 + 2)" + "(some-function 10 + 1 + 2)") + ;;; Alignment (defmacro def-full-align-test (name &rest forms) "Verify that all FORMs correspond to a properly indented sexps." From 39262aeaf7dd242edcc9f330c453220dbcdb4244 Mon Sep 17 00:00:00 2001 From: Bozhidar Batsov Date: Fri, 29 Jan 2016 12:48:44 +0200 Subject: [PATCH 080/199] [#361] Add a regression test --- clojure-mode-font-lock-test.el | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/clojure-mode-font-lock-test.el b/clojure-mode-font-lock-test.el index 64bcaeb..07db811 100644 --- a/clojure-mode-font-lock-test.el +++ b/clojure-mode-font-lock-test.el @@ -256,6 +256,12 @@ POS." (should (eq (clojure-test-face-at 2 14) 'font-lock-keyword-face)) (should (eq (clojure-test-face-at 16 18) 'font-lock-function-name-face)))) +(ert-deftest clojure-mode-syntax-table/fn () + :tags '(fontification syntax-table) + (clojure-test-with-temp-buffer "(fn foo [x] x)" + (should (eq (clojure-test-face-at 2 3) 'font-lock-keyword-face)) + (should (eq (clojure-test-face-at 5 7) 'font-lock-function-name-face)))) + (ert-deftest clojure-mode-syntax-table/lambda-params () :tags '(fontification syntax-table) (clojure-test-with-temp-buffer "#(+ % %2 %3)" From 0e671ec3f1f965c30a3d8003888cc951b8843440 Mon Sep 17 00:00:00 2001 From: Artur Malabarba Date: Sat, 30 Jan 2016 20:30:42 +0000 Subject: [PATCH 081/199] Add a test for %& font-locking --- clojure-mode-font-lock-test.el | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/clojure-mode-font-lock-test.el b/clojure-mode-font-lock-test.el index 07db811..899de53 100644 --- a/clojure-mode-font-lock-test.el +++ b/clojure-mode-font-lock-test.el @@ -264,10 +264,11 @@ POS." (ert-deftest clojure-mode-syntax-table/lambda-params () :tags '(fontification syntax-table) - (clojure-test-with-temp-buffer "#(+ % %2 %3)" + (clojure-test-with-temp-buffer "#(+ % %2 %3 %&)" (should (eq (clojure-test-face-at 5 5) 'font-lock-variable-name-face)) (should (eq (clojure-test-face-at 7 8) 'font-lock-variable-name-face)) - (should (eq (clojure-test-face-at 10 11) 'font-lock-variable-name-face)))) + (should (eq (clojure-test-face-at 10 11) 'font-lock-variable-name-face)) + (should (eq (clojure-test-face-at 13 14) 'font-lock-variable-name-face)))) (ert-deftest clojure-mode-syntax-table/nil () :tags '(fontification syntax-table) From 09abee8a6ed760d703674161627c1eb699b27398 Mon Sep 17 00:00:00 2001 From: Artur Malabarba Date: Mon, 29 Feb 2016 10:17:42 -0300 Subject: [PATCH 082/199] Add a test for proxy indentation --- clojure-mode-indentation-test.el | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/clojure-mode-indentation-test.el b/clojure-mode-indentation-test.el index b26904c..a3df6cc 100644 --- a/clojure-mode-indentation-test.el +++ b/clojure-mode-indentation-test.el @@ -338,6 +338,20 @@ values of customisable variables." (let [indent-test :fail] ...)))") +(def-full-indent-test proxy + "(proxy [Writer] [] + (close [] (.flush ^Writer this)) + (write + ([x] + (with-out-binding [out messages] + (.write out x))) + ([x ^Integer off ^Integer len] + (with-out-binding [out messages] + (.write out x off len)))) + (flush [] + (with-out-binding [out messages] + (.flush out))))") + (def-full-indent-test reader-conditionals "#?@ (:clj [] :cljs [])") From f196516d7f219a42028f71eca60e151c8dea5ee8 Mon Sep 17 00:00:00 2001 From: Artur Malabarba Date: Tue, 15 Mar 2016 01:49:13 -0300 Subject: [PATCH 083/199] Add a test for the previous fix --- clojure-mode-font-lock-test.el | 1 + 1 file changed, 1 insertion(+) diff --git a/clojure-mode-font-lock-test.el b/clojure-mode-font-lock-test.el index 899de53..4bf3d11 100644 --- a/clojure-mode-font-lock-test.el +++ b/clojure-mode-font-lock-test.el @@ -115,6 +115,7 @@ POS." (ert-deftest clojure-mode-syntax-table/fontify-namespaced-keyword () :tags '(fontification syntax-table) + (should (equal (clojure-test-face-at 9 11 "(:alias/def x 10)") '(clojure-keyword-face))) (should (equal (clojure-test-face-at 2 2 "{:alias/some 20}") '(clojure-keyword-face))) (should (equal (clojure-test-face-at 3 7 "{:alias/some 20}") '(font-lock-type-face clojure-keyword-face))) (should (equal (clojure-test-face-at 8 8 "{:alias/some 20}") '(default clojure-keyword-face))) From 10c359115be7aba4ef0917d6891efe831d571c84 Mon Sep 17 00:00:00 2001 From: Reid 'arrdem' McKenzie Date: Sat, 26 Mar 2016 23:57:34 -0500 Subject: [PATCH 084/199] Add a test case --- clojure-mode-indentation-test.el | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/clojure-mode-indentation-test.el b/clojure-mode-indentation-test.el index a3df6cc..05b801d 100644 --- a/clojure-mode-indentation-test.el +++ b/clojure-mode-indentation-test.el @@ -540,6 +540,12 @@ x :b {:a :a :aa :a}}") +(def-full-align-test trailing-commas + "{:a {:a :a, + :aa :a}, + :b {:a :a, + :aa :a}}") + ;;; Misc From 35062b412eb50c9369f9dc583350a2053186592a Mon Sep 17 00:00:00 2001 From: Artur Malabarba Date: Mon, 28 Mar 2016 01:21:55 -0300 Subject: [PATCH 085/199] Make clojure-align cleanup commas --- clojure-mode-indentation-test.el | 6 ++++++ clojure-mode-sexp-test.el | 10 ++++++++++ 2 files changed, 16 insertions(+) diff --git a/clojure-mode-indentation-test.el b/clojure-mode-indentation-test.el index 05b801d..30659fd 100644 --- a/clojure-mode-indentation-test.el +++ b/clojure-mode-indentation-test.el @@ -546,6 +546,12 @@ x :b {:a :a, :aa :a}}") +(ert-deftest clojure-align-remove-extra-commas () + (with-temp-buffer + (clojure-mode) + (insert "{:a 2, ,:c 4}") + (call-interactively #'clojure-align) + (should (string= (buffer-string) "{:a 2, :c 4}")))) ;;; Misc diff --git a/clojure-mode-sexp-test.el b/clojure-mode-sexp-test.el index 23dbe42..0a9a4fb 100644 --- a/clojure-mode-sexp-test.el +++ b/clojure-mode-sexp-test.el @@ -22,6 +22,16 @@ (require 'clojure-mode) (require 'ert) +(ert-deftest test-sexp-with-commas () + (with-temp-buffer + (insert "[], {}, :a, 2") + (clojure-mode) + (goto-char (point-min)) + (clojure-forward-logical-sexp 1) + (should (looking-back " {}, :a, 2")) + (clojure-forward-logical-sexp 1) + (should (looking-at-p " :a, 2")))) + (ert-deftest test-sexp () (with-temp-buffer (insert "^String #macro ^dynamic reverse") From 44beeb05ce5120d9c6a8564f0490e1b124ebb23d Mon Sep 17 00:00:00 2001 From: Artur Malabarba Date: Mon, 28 Mar 2016 01:36:57 -0300 Subject: [PATCH 086/199] Fix a silly test --- clojure-mode-sexp-test.el | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/clojure-mode-sexp-test.el b/clojure-mode-sexp-test.el index 0a9a4fb..bd18087 100644 --- a/clojure-mode-sexp-test.el +++ b/clojure-mode-sexp-test.el @@ -28,7 +28,7 @@ (clojure-mode) (goto-char (point-min)) (clojure-forward-logical-sexp 1) - (should (looking-back " {}, :a, 2")) + (should (looking-at-p " {}, :a, 2")) (clojure-forward-logical-sexp 1) (should (looking-at-p " :a, 2")))) From 317b740cc00e3cec6b986ae9cd458d7f6edaae9c Mon Sep 17 00:00:00 2001 From: Artur Malabarba Date: Wed, 13 Apr 2016 20:15:05 -0300 Subject: [PATCH 087/199] Add a test for align separation and fix the feature --- clojure-mode-indentation-test.el | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/clojure-mode-indentation-test.el b/clojure-mode-indentation-test.el index 30659fd..35975e4 100644 --- a/clojure-mode-indentation-test.el +++ b/clojure-mode-indentation-test.el @@ -488,6 +488,18 @@ x "(let [a b c d])") +(def-full-align-test blank-line + "(let [this-is-a-form b + c d + + another form + k g])" + "{:this-is-a-form b + c d + + :another form + k g}") + (def-full-align-test basic-reversed "{c d :this-is-a-form b}" From 55b6fe7d94f5af034af08df988c2f830d3260106 Mon Sep 17 00:00:00 2001 From: Artur Malabarba Date: Sat, 30 Apr 2016 18:14:36 -0300 Subject: [PATCH 088/199] Add tests for the escape char font-locking --- clojure-mode-font-lock-test.el | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/clojure-mode-font-lock-test.el b/clojure-mode-font-lock-test.el index 4bf3d11..fac495f 100644 --- a/clojure-mode-font-lock-test.el +++ b/clojure-mode-font-lock-test.el @@ -113,6 +113,14 @@ POS." (should (equal (clojure-test-face-at 3 10 ";`#'s/trim`") '(font-lock-constant-face font-lock-comment-face))) (should (equal (clojure-test-face-at 11 11 ";`#'s/trim`") font-lock-comment-face))) +(ert-deftest clojure-mode-syntax-table/stuff-in-backticks () + :tags '(fontification syntax-table) + (should (equal (clojure-test-face-at 1 2 "\"a\\bc\\n\"") font-lock-string-face)) + (should (equal (clojure-test-face-at 3 4 "\"a\\bc\\n\"") '(bold font-lock-string-face))) + (should (equal (clojure-test-face-at 5 5 "\"a\\bc\\n\"") font-lock-string-face)) + (should (equal (clojure-test-face-at 6 7 "\"a\\bc\\n\"") '(bold font-lock-string-face))) + (should (equal (clojure-test-face-at 4 5 "#\"a\\bc\\n\"") '(bold font-lock-string-face)))) + (ert-deftest clojure-mode-syntax-table/fontify-namespaced-keyword () :tags '(fontification syntax-table) (should (equal (clojure-test-face-at 9 11 "(:alias/def x 10)") '(clojure-keyword-face))) From f199d201419b6ca02f074ce23584a732e9f416c9 Mon Sep 17 00:00:00 2001 From: Benedek Fazekas Date: Tue, 26 Apr 2016 12:36:12 +0100 Subject: [PATCH 089/199] Add threading macros related refactorings Code is ported from clj-refactor.el. Originally was mainly the work of Magnar Sveen (@magnars) and Alex Baranosky (@AlexBaranosky). The code here does not use paredit and have minor adjustments but should have the same feature set as the original, see the related tests ported. Also clojure-emacs/clj-refactor.el#259 is fixed. --- clojure-mode-refactor-threading-test.el | 477 ++++++++++++++++++++++++ 1 file changed, 477 insertions(+) create mode 100644 clojure-mode-refactor-threading-test.el diff --git a/clojure-mode-refactor-threading-test.el b/clojure-mode-refactor-threading-test.el new file mode 100644 index 0000000..a92a3e1 --- /dev/null +++ b/clojure-mode-refactor-threading-test.el @@ -0,0 +1,477 @@ +;;; clojure-mode-refactor-threading-test.el --- Clojure Mode: refactor threading tests -*- lexical-binding: t; -*- + +;; Copyright (C) 2016 Benedek Fazekas + +;; This file is not part of GNU Emacs. + +;; This program is free software; you can redistribute it and/or modify +;; it under the terms of the GNU General Public License as published by +;; the Free Software Foundation, either version 3 of the License, or +;; (at your option) any later version. + +;; This program is distributed in the hope that it will be useful, +;; but WITHOUT ANY WARRANTY; without even the implied warranty of +;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +;; GNU General Public License for more details. + +;; You should have received a copy of the GNU General Public License +;; along with this program. If not, see . + +;;; Commentary: + +;; The threading refactoring code is ported from clj-refactor.el +;; and mainly the work of Magnar Sveen, Alex Baranosky and +;; the rest of the clj-reafctor.el team. + +;;; Code: + +(require 'clojure-mode) +(require 'ert) + +;; thread first + +(ert-deftest test-thread-first-one-step () + (with-temp-buffer + (insert "(-> (dissoc (assoc {} :key \"value\") :lock))") + (clojure-mode) + (clojure-thread) + (should + (equal + "(-> (assoc {} :key \"value\") + (dissoc :lock))" + (buffer-string))))) + +(ert-deftest test-thread-first-two-steps () + (with-temp-buffer + (insert "(-> (dissoc (assoc {} :key \"value\") :lock))") + (clojure-mode) + (clojure-thread) + (clojure-thread) + (should + (equal + "(-> {} + (assoc :key \"value\") + (dissoc :lock))" + (buffer-string))))) + +(ert-deftest test-thread-first-dont-thread-maps () + (with-temp-buffer + (insert "(-> (dissoc (assoc {} :key \"value\") :lock))") + (clojure-mode) + (clojure-thread) + (clojure-thread) + (clojure-thread) + (should + (equal + "(-> {} + (assoc :key \"value\") + (dissoc :lock))" + (buffer-string))))) + +(ert-deftest test-thread-first-dont-thread-last-one () + (with-temp-buffer + (insert "(-> (dissoc (assoc (get-a-map) :key \"value\") :lock))") + (clojure-mode) + (clojure-thread) + (clojure-thread) + (clojure-thread) + (should + (equal + "(-> (get-a-map) + (assoc :key \"value\") + (dissoc :lock))" + (buffer-string))))) + +(ert-deftest test-thread-first-easy-on-whitespace () + (with-temp-buffer + (insert "(-> + (dissoc (assoc {} :key \"value\") :lock))") + (clojure-mode) + (clojure-thread) + (should + (equal + "(-> + (assoc {} :key \"value\") + (dissoc :lock))" + (buffer-string))))) + +(ert-deftest test-thread-first-remove-superfluous-parens () + (with-temp-buffer + (insert "(-> (square (sum [1 2 3 4 5])))") + (clojure-mode) + (clojure-thread) + (clojure-thread) + (should + (equal + "(-> [1 2 3 4 5] + sum + square)" + (buffer-string))))) + +(ert-deftest test-thread-first-cursor-before-threading () + (with-temp-buffer + (insert "(-> (not (s-acc/mobile? session)))") + (clojure-mode) + (beginning-of-buffer) + (clojure-thread) + (should + (equal + "(-> (s-acc/mobile? session) + not)" + (buffer-string))))) + +;; unwind thread first +(ert-deftest test-unwind-first-one-step () + (with-temp-buffer + (insert "(-> {} + (assoc :key \"value\") + (dissoc :lock))") + (clojure-mode) + (clojure-unwind) + (should + (equal + "(-> (assoc {} :key \"value\") + (dissoc :lock))" + (buffer-string))))) + +(ert-deftest test-unwind-first-two-steps () + (with-temp-buffer + (insert "(-> {} + (assoc :key \"value\") + (dissoc :lock))") + (clojure-mode) + (clojure-unwind) + (clojure-unwind) + (should + (equal + "(-> (dissoc (assoc {} :key \"value\") :lock))" + (buffer-string))))) + +(ert-deftest test-unwind-first-jump-out-of-threading () + (with-temp-buffer + (insert "(-> {} + (assoc :key \"value\") + (dissoc :lock))") + (clojure-mode) + (clojure-unwind) + (clojure-unwind) + (clojure-unwind) + (should + (equal + "(dissoc (assoc {} :key \"value\") :lock)" + (buffer-string))))) + +;; thread last +(ert-deftest test-thread-last-one-step () + (with-temp-buffer + (insert "(->> (map square (filter even? [1 2 3 4 5])))") + (clojure-mode) + (clojure-thread) + (should + (equal + "(->> (filter even? [1 2 3 4 5]) + (map square))" + (buffer-string))))) + +(ert-deftest test-thread-last-two-steps () + (with-temp-buffer + (insert "(->> (map square (filter even? [1 2 3 4 5])))") + (clojure-mode) + (clojure-thread) + (clojure-thread) + (should + (equal + "(->> [1 2 3 4 5] + (filter even?) + (map square))" + (buffer-string))))) + +(ert-deftest test-thread-last-dont-thread-vectors () + (with-temp-buffer + (insert "(->> (map square (filter even? [1 2 3 4 5])))") + (clojure-mode) + (clojure-thread) + (clojure-thread) + (clojure-thread) + (should + (equal + "(->> [1 2 3 4 5] + (filter even?) + (map square))" + (buffer-string))))) + +(ert-deftest test-thread-last-dont-thread-last-one () + (with-temp-buffer + (insert "(->> (map square (filter even? (get-a-list))))") + (clojure-mode) + (clojure-thread) + (clojure-thread) + (clojure-thread) + (should + (equal + "(->> (get-a-list) + (filter even?) + (map square))" + (buffer-string))))) + +;; unwind thread last +(ert-deftest test-unwind-last-one-step () + (with-temp-buffer + (insert "(->> [1 2 3 4 5] + (filter even?) + (map square))") + (clojure-mode) + (clojure-unwind) + (should + (equal + "(->> (filter even? [1 2 3 4 5]) + (map square))" + (buffer-string))))) + +(ert-deftest test-unwind-last-two-steps () + (with-temp-buffer + (insert "(->> [1 2 3 4 5] + (filter even?) + (map square))") + (clojure-mode) + (clojure-unwind) + (clojure-unwind) + (should + (equal + "(->> (map square (filter even? [1 2 3 4 5])))" + (buffer-string))))) + +(ert-deftest test-unwind-last-jump-out-of-threading () + (with-temp-buffer + (insert "(->> [1 2 3 4 5] + (filter even?) + (map square))") + (clojure-mode) + (clojure-unwind) + (clojure-unwind) + (clojure-unwind) + (should + (equal + "(map square (filter even? [1 2 3 4 5]))" + (buffer-string))))) + +(ert-deftest test-unwind-function-name () + (with-temp-buffer + (insert "(->> [1 2 3 4 5] + sum + square)") + (clojure-mode) + (clojure-unwind) + (should + (equal + "(->> (sum [1 2 3 4 5]) + square)" + (buffer-string))))) + +(ert-deftest test-unwind-function-name-twice () + (with-temp-buffer + (insert "(-> [1 2 3 4 5] + sum + square)") + (clojure-mode) + (clojure-unwind) + (clojure-unwind) + (should + (equal + "(-> (square (sum [1 2 3 4 5])))" + (buffer-string))))) + +(ert-deftest test-unwind-issue-6-1 () + (with-temp-buffer + (insert "(defn plus [a b] + (-> a (+ b)))") + (clojure-mode) + (clojure-unwind) + (should + (equal + "(defn plus [a b] + (-> (+ a b)))" + (buffer-string))))) + +(ert-deftest test-unwind-issue-6-2 () + (with-temp-buffer + (insert "(defn plus [a b] + (->> a (+ b)))") + (clojure-mode) + (clojure-unwind) + (should + (equal + "(defn plus [a b] + (->> (+ b a)))" + (buffer-string))))) + +(ert-deftest test-thread-first-some () + (with-temp-buffer + (insert "(some-> (+ (val (find {:a 1} :b)) 5))") + (clojure-mode) + (clojure-thread) + (clojure-thread) + (clojure-thread) + (should + (equal + "(some-> {:a 1} + (find :b) + val + (+ 5))" + (buffer-string))))) + +(ert-deftest test-thread-last-some () + (with-temp-buffer + (insert "(some->> (+ 5 (val (find {:a 1} :b))))") + (clojure-mode) + (clojure-thread) + (clojure-thread) + (clojure-thread) + (should + (equal + "(some->> :b + (find {:a 1}) + val + (+ 5))" + (buffer-string))))) + +(ert-deftest test-unwind-last-first-some () + (with-temp-buffer + (insert "(some-> {:a 1} + (find :b) + val + (+ 5))") + (clojure-mode) + (clojure-unwind) + (clojure-unwind) + (clojure-unwind) + (should + (equal + "(some-> (+ (val (find {:a 1} :b)) 5))" + (buffer-string))))) + +(ert-deftest test-unwind-thread-last-some () + (with-temp-buffer + (insert "(some->> :b + (find {:a 1}) + val + (+ 5))") + (clojure-mode) + (clojure-unwind) + (clojure-unwind) + (clojure-unwind) + (should + (equal + "(some->> (+ 5 (val (find {:a 1} :b))))" + (buffer-string))))) + +(ert-deftest test-thread-first-all () + (with-temp-buffer + (insert "(->map (assoc {} :key \"value\") :lock)") + (clojure-mode) + (beginning-of-buffer) + (clojure-thread-first-all nil) + (should + (equal + "(-> {} + (assoc :key \"value\") + (->map :lock))" + (buffer-string))))) + +(ert-deftest test-thread-first-all-but-last () + (with-temp-buffer + (insert "(->map (assoc {} :key \"value\") :lock)") + (clojure-mode) + (beginning-of-buffer) + (clojure-thread-first-all t) + (should + (equal + "(-> (assoc {} :key \"value\") + (->map :lock))" + (buffer-string))))) + +(ert-deftest test-thread-last-all () + (with-temp-buffer + (insert "(map square (filter even? (make-things)))") + (clojure-mode) + (beginning-of-buffer) + (clojure-thread-last-all nil) + (should + (equal + "(->> (make-things) + (filter even?) + (map square))" + (buffer-string))))) + +(ert-deftest test-thread-last-all-but-last () + (with-temp-buffer + (insert "(map square (filter even? (make-things)))") + (clojure-mode) + (beginning-of-buffer) + (clojure-thread-last-all t) + (should + (equal + "(->> (filter even? (make-things)) + (map square))" + (buffer-string))))) + +(ert-deftest test-unwind-all-thread-first () + (with-temp-buffer + (insert "(-> {} + (assoc :key \"value\") + (dissoc :lock))") + (clojure-mode) + (beginning-of-buffer) + (clojure-unwind-all) + (should + (equal + "(dissoc (assoc {} :key \"value\") :lock)" + (buffer-string))))) + +(ert-deftest test-unwind-all-thread-last () + (with-temp-buffer + (insert "(->> (make-things) + (filter even?) + (map square))") + (clojure-mode) + (beginning-of-buffer) + (clojure-unwind-all) + (should + (equal + "(map square (filter even? (make-things)))" + (buffer-string))))) + +(ert-deftest test-thread-last-dangling-parens () + (with-temp-buffer + (insert "(map inc + (range))") + (clojure-mode) + (beginning-of-buffer) + (clojure-thread-last-all nil) + (should + (equal + "(->> (range) + (map inc))" + (buffer-string))))) + +;; fix for clojure-emacs/clj-refactor.el#259 +(ert-deftest test-unwind-last-leaves-multiline-sexp-alone () + (with-temp-buffer + (insert + "(->> [a b] + (some (fn [x] + (when x + 10))))") + (clojure-mode) + (clojure-unwind-all) + (should + (equal + "(some (fn [x] + (when x + 10)) + [a b])" + (buffer-string))))) + +(provide 'clojure-mode-refactor-threading-test) + +;;; clojure-mode-refactor-threading-test.el ends here From f2fb35bd80135c7ad87457c11dc843ba5ce502a4 Mon Sep 17 00:00:00 2001 From: Artur Malabarba Date: Wed, 11 May 2016 11:46:48 -0300 Subject: [PATCH 090/199] Standardize threading tests --- clojure-mode-refactor-threading-test.el | 590 +++++++++--------------- 1 file changed, 218 insertions(+), 372 deletions(-) diff --git a/clojure-mode-refactor-threading-test.el b/clojure-mode-refactor-threading-test.el index a92a3e1..56bed59 100644 --- a/clojure-mode-refactor-threading-test.el +++ b/clojure-mode-refactor-threading-test.el @@ -28,449 +28,295 @@ (require 'clojure-mode) (require 'ert) +(defmacro def-threading-test (name before after &rest body) + (declare (indent 3)) + `(ert-deftest ,(intern (format "test-thread-%s" name)) () + (let ((clojure-thread-all-but-last nil)) + (with-temp-buffer + (insert ,before) + (clojure-mode) + ,@body + (should (equal ,(concat "\n" after) + (concat "\n" (buffer-substring-no-properties + (point-min) (point-max))))))))) + ;; thread first -(ert-deftest test-thread-first-one-step () - (with-temp-buffer - (insert "(-> (dissoc (assoc {} :key \"value\") :lock))") - (clojure-mode) - (clojure-thread) - (should - (equal - "(-> (assoc {} :key \"value\") +(def-threading-test first-one-step + "(-> (dissoc (assoc {} :key \"value\") :lock))" + "(-> (assoc {} :key \"value\") (dissoc :lock))" - (buffer-string))))) - -(ert-deftest test-thread-first-two-steps () - (with-temp-buffer - (insert "(-> (dissoc (assoc {} :key \"value\") :lock))") - (clojure-mode) - (clojure-thread) - (clojure-thread) - (should - (equal - "(-> {} + (clojure-thread)) + +(def-threading-test first-two-steps + "(-> (dissoc (assoc {} :key \"value\") :lock))" + "(-> {} (assoc :key \"value\") (dissoc :lock))" - (buffer-string))))) - -(ert-deftest test-thread-first-dont-thread-maps () - (with-temp-buffer - (insert "(-> (dissoc (assoc {} :key \"value\") :lock))") - (clojure-mode) - (clojure-thread) - (clojure-thread) - (clojure-thread) - (should - (equal - "(-> {} + (clojure-thread) + (clojure-thread)) + +(def-threading-test first-dont-thread-maps + "(-> (dissoc (assoc {} :key \"value\") :lock))" + "(-> {} (assoc :key \"value\") (dissoc :lock))" - (buffer-string))))) - -(ert-deftest test-thread-first-dont-thread-last-one () - (with-temp-buffer - (insert "(-> (dissoc (assoc (get-a-map) :key \"value\") :lock))") - (clojure-mode) - (clojure-thread) - (clojure-thread) - (clojure-thread) - (should - (equal - "(-> (get-a-map) + (clojure-thread) + (clojure-thread) + (clojure-thread)) + +(def-threading-test first-dont-thread-last-one + "(-> (dissoc (assoc (get-a-map) :key \"value\") :lock))" + "(-> (get-a-map) (assoc :key \"value\") (dissoc :lock))" - (buffer-string))))) - -(ert-deftest test-thread-first-easy-on-whitespace () - (with-temp-buffer - (insert "(-> - (dissoc (assoc {} :key \"value\") :lock))") - (clojure-mode) - (clojure-thread) - (should - (equal - "(-> + (clojure-thread) + (clojure-thread) + (clojure-thread)) + +(def-threading-test first-easy-on-whitespace + "(-> + (dissoc (assoc {} :key \"value\") :lock))" + "(-> (assoc {} :key \"value\") (dissoc :lock))" - (buffer-string))))) - -(ert-deftest test-thread-first-remove-superfluous-parens () - (with-temp-buffer - (insert "(-> (square (sum [1 2 3 4 5])))") - (clojure-mode) - (clojure-thread) - (clojure-thread) - (should - (equal - "(-> [1 2 3 4 5] + (clojure-thread)) + +(def-threading-test first-remove-superfluous-parens + "(-> (square (sum [1 2 3 4 5])))" + "(-> [1 2 3 4 5] sum square)" - (buffer-string))))) - -(ert-deftest test-thread-first-cursor-before-threading () - (with-temp-buffer - (insert "(-> (not (s-acc/mobile? session)))") - (clojure-mode) - (beginning-of-buffer) - (clojure-thread) - (should - (equal - "(-> (s-acc/mobile? session) + (clojure-thread) + (clojure-thread)) + +(def-threading-test first-cursor-before-threading + "(-> (not (s-acc/mobile? session)))" + "(-> (s-acc/mobile? session) not)" - (buffer-string))))) + (beginning-of-buffer) + (clojure-thread)) ;; unwind thread first -(ert-deftest test-unwind-first-one-step () - (with-temp-buffer - (insert "(-> {} +(def-threading-test first-one-step + "(-> {} (assoc :key \"value\") - (dissoc :lock))") - (clojure-mode) - (clojure-unwind) - (should - (equal - "(-> (assoc {} :key \"value\") (dissoc :lock))" - (buffer-string))))) + "(-> (assoc {} :key \"value\") + (dissoc :lock))" + (clojure-unwind)) -(ert-deftest test-unwind-first-two-steps () - (with-temp-buffer - (insert "(-> {} +(def-threading-test first-two-steps + "(-> {} (assoc :key \"value\") - (dissoc :lock))") - (clojure-mode) - (clojure-unwind) - (clojure-unwind) - (should - (equal - "(-> (dissoc (assoc {} :key \"value\") :lock))" - (buffer-string))))) - -(ert-deftest test-unwind-first-jump-out-of-threading () - (with-temp-buffer - (insert "(-> {} + (dissoc :lock))" + "(-> (dissoc (assoc {} :key \"value\") :lock))" + (clojure-unwind) + (clojure-unwind)) + +(def-threading-test first-jump-out-of-threading + "(-> {} (assoc :key \"value\") - (dissoc :lock))") - (clojure-mode) - (clojure-unwind) - (clojure-unwind) - (clojure-unwind) - (should - (equal - "(dissoc (assoc {} :key \"value\") :lock)" - (buffer-string))))) + (dissoc :lock))" + "(dissoc (assoc {} :key \"value\") :lock)" + (clojure-unwind) + (clojure-unwind) + (clojure-unwind)) ;; thread last -(ert-deftest test-thread-last-one-step () - (with-temp-buffer - (insert "(->> (map square (filter even? [1 2 3 4 5])))") - (clojure-mode) - (clojure-thread) - (should - (equal - "(->> (filter even? [1 2 3 4 5]) +(def-threading-test last-one-step + "(->> (map square (filter even? [1 2 3 4 5])))" + "(->> (filter even? [1 2 3 4 5]) (map square))" - (buffer-string))))) - -(ert-deftest test-thread-last-two-steps () - (with-temp-buffer - (insert "(->> (map square (filter even? [1 2 3 4 5])))") - (clojure-mode) - (clojure-thread) - (clojure-thread) - (should - (equal - "(->> [1 2 3 4 5] + (clojure-thread)) + +(def-threading-test last-two-steps + "(->> (map square (filter even? [1 2 3 4 5])))" + "(->> [1 2 3 4 5] (filter even?) (map square))" - (buffer-string))))) - -(ert-deftest test-thread-last-dont-thread-vectors () - (with-temp-buffer - (insert "(->> (map square (filter even? [1 2 3 4 5])))") - (clojure-mode) - (clojure-thread) - (clojure-thread) - (clojure-thread) - (should - (equal - "(->> [1 2 3 4 5] + (clojure-thread) + (clojure-thread)) + +(def-threading-test last-dont-thread-vectors + "(->> (map square (filter even? [1 2 3 4 5])))" + "(->> [1 2 3 4 5] (filter even?) (map square))" - (buffer-string))))) - -(ert-deftest test-thread-last-dont-thread-last-one () - (with-temp-buffer - (insert "(->> (map square (filter even? (get-a-list))))") - (clojure-mode) - (clojure-thread) - (clojure-thread) - (clojure-thread) - (should - (equal - "(->> (get-a-list) + (clojure-thread) + (clojure-thread) + (clojure-thread)) + +(def-threading-test last-dont-thread-last-one + "(->> (map square (filter even? (get-a-list))))" + "(->> (get-a-list) (filter even?) (map square))" - (buffer-string))))) + (clojure-thread) + (clojure-thread) + (clojure-thread)) ;; unwind thread last -(ert-deftest test-unwind-last-one-step () - (with-temp-buffer - (insert "(->> [1 2 3 4 5] +(def-threading-test last-one-step + "(->> [1 2 3 4 5] (filter even?) - (map square))") - (clojure-mode) - (clojure-unwind) - (should - (equal - "(->> (filter even? [1 2 3 4 5]) (map square))" - (buffer-string))))) + "(->> (filter even? [1 2 3 4 5]) + (map square))" + (clojure-unwind)) -(ert-deftest test-unwind-last-two-steps () - (with-temp-buffer - (insert "(->> [1 2 3 4 5] +(def-threading-test last-two-steps + "(->> [1 2 3 4 5] (filter even?) - (map square))") - (clojure-mode) - (clojure-unwind) - (clojure-unwind) - (should - (equal - "(->> (map square (filter even? [1 2 3 4 5])))" - (buffer-string))))) - -(ert-deftest test-unwind-last-jump-out-of-threading () - (with-temp-buffer - (insert "(->> [1 2 3 4 5] + (map square))" + "(->> (map square (filter even? [1 2 3 4 5])))" + (clojure-unwind) + (clojure-unwind)) + +(def-threading-test last-jump-out-of-threading + "(->> [1 2 3 4 5] (filter even?) - (map square))") - (clojure-mode) - (clojure-unwind) - (clojure-unwind) - (clojure-unwind) - (should - (equal - "(map square (filter even? [1 2 3 4 5]))" - (buffer-string))))) - -(ert-deftest test-unwind-function-name () - (with-temp-buffer - (insert "(->> [1 2 3 4 5] + (map square))" + "(map square (filter even? [1 2 3 4 5]))" + (clojure-unwind) + (clojure-unwind) + (clojure-unwind)) + +(def-threading-test function-name + "(->> [1 2 3 4 5] sum - square)") - (clojure-mode) - (clojure-unwind) - (should - (equal - "(->> (sum [1 2 3 4 5]) square)" - (buffer-string))))) + "(->> (sum [1 2 3 4 5]) + square)" + (clojure-unwind)) -(ert-deftest test-unwind-function-name-twice () - (with-temp-buffer - (insert "(-> [1 2 3 4 5] +(def-threading-test function-name-twice + "(-> [1 2 3 4 5] sum - square)") - (clojure-mode) - (clojure-unwind) - (clojure-unwind) - (should - (equal - "(-> (square (sum [1 2 3 4 5])))" - (buffer-string))))) - -(ert-deftest test-unwind-issue-6-1 () - (with-temp-buffer - (insert "(defn plus [a b] - (-> a (+ b)))") - (clojure-mode) - (clojure-unwind) - (should - (equal - "(defn plus [a b] + square)" + "(-> (square (sum [1 2 3 4 5])))" + (clojure-unwind) + (clojure-unwind)) + +(def-threading-test issue-6-1 + "(defn plus [a b] + (-> a (+ b)))" + "(defn plus [a b] (-> (+ a b)))" - (buffer-string))))) - -(ert-deftest test-unwind-issue-6-2 () - (with-temp-buffer - (insert "(defn plus [a b] - (->> a (+ b)))") - (clojure-mode) - (clojure-unwind) - (should - (equal - "(defn plus [a b] + (clojure-unwind)) + +(def-threading-test issue-6-2 + "(defn plus [a b] + (->> a (+ b)))" + "(defn plus [a b] (->> (+ b a)))" - (buffer-string))))) - -(ert-deftest test-thread-first-some () - (with-temp-buffer - (insert "(some-> (+ (val (find {:a 1} :b)) 5))") - (clojure-mode) - (clojure-thread) - (clojure-thread) - (clojure-thread) - (should - (equal - "(some-> {:a 1} + (clojure-unwind)) + +(def-threading-test first-some + "(some-> (+ (val (find {:a 1} :b)) 5))" + "(some-> {:a 1} (find :b) val (+ 5))" - (buffer-string))))) - -(ert-deftest test-thread-last-some () - (with-temp-buffer - (insert "(some->> (+ 5 (val (find {:a 1} :b))))") - (clojure-mode) - (clojure-thread) - (clojure-thread) - (clojure-thread) - (should - (equal - "(some->> :b + (clojure-thread) + (clojure-thread) + (clojure-thread)) + +(def-threading-test last-some + "(some->> (+ 5 (val (find {:a 1} :b))))" + "(some->> :b (find {:a 1}) val (+ 5))" - (buffer-string))))) + (clojure-thread) + (clojure-thread) + (clojure-thread)) -(ert-deftest test-unwind-last-first-some () - (with-temp-buffer - (insert "(some-> {:a 1} +(def-threading-test last-first-some + "(some-> {:a 1} (find :b) val - (+ 5))") - (clojure-mode) - (clojure-unwind) - (clojure-unwind) - (clojure-unwind) - (should - (equal - "(some-> (+ (val (find {:a 1} :b)) 5))" - (buffer-string))))) - -(ert-deftest test-unwind-thread-last-some () - (with-temp-buffer - (insert "(some->> :b + (+ 5))" + "(some-> (+ (val (find {:a 1} :b)) 5))" + (clojure-unwind) + (clojure-unwind) + (clojure-unwind)) + +(def-threading-test thread-last-some + "(some->> :b (find {:a 1}) val - (+ 5))") - (clojure-mode) - (clojure-unwind) - (clojure-unwind) - (clojure-unwind) - (should - (equal - "(some->> (+ 5 (val (find {:a 1} :b))))" - (buffer-string))))) - -(ert-deftest test-thread-first-all () - (with-temp-buffer - (insert "(->map (assoc {} :key \"value\") :lock)") - (clojure-mode) - (beginning-of-buffer) - (clojure-thread-first-all nil) - (should - (equal - "(-> {} + (+ 5))" + "(some->> (+ 5 (val (find {:a 1} :b))))" + (clojure-unwind) + (clojure-unwind) + (clojure-unwind)) + +(def-threading-test first-all + "(->map (assoc {} :key \"value\") :lock)" + "(-> {} (assoc :key \"value\") (->map :lock))" - (buffer-string))))) - -(ert-deftest test-thread-first-all-but-last () - (with-temp-buffer - (insert "(->map (assoc {} :key \"value\") :lock)") - (clojure-mode) - (beginning-of-buffer) - (clojure-thread-first-all t) - (should - (equal - "(-> (assoc {} :key \"value\") + (beginning-of-buffer) + (clojure-thread-first-all nil)) + +(def-threading-test first-all-but-last + "(->map (assoc {} :key \"value\") :lock)" + "(-> (assoc {} :key \"value\") (->map :lock))" - (buffer-string))))) - -(ert-deftest test-thread-last-all () - (with-temp-buffer - (insert "(map square (filter even? (make-things)))") - (clojure-mode) - (beginning-of-buffer) - (clojure-thread-last-all nil) - (should - (equal - "(->> (make-things) + (beginning-of-buffer) + (clojure-thread-first-all t)) + +(def-threading-test last-all + "(map square (filter even? (make-things)))" + "(->> (make-things) (filter even?) (map square))" - (buffer-string))))) - -(ert-deftest test-thread-last-all-but-last () - (with-temp-buffer - (insert "(map square (filter even? (make-things)))") - (clojure-mode) - (beginning-of-buffer) - (clojure-thread-last-all t) - (should - (equal - "(->> (filter even? (make-things)) + (beginning-of-buffer) + (clojure-thread-last-all nil)) + +(def-threading-test last-all-but-last + "(map square (filter even? (make-things)))" + "(->> (filter even? (make-things)) (map square))" - (buffer-string))))) + (beginning-of-buffer) + (clojure-thread-last-all t)) -(ert-deftest test-unwind-all-thread-first () - (with-temp-buffer - (insert "(-> {} +(def-threading-test all-thread-first + "(-> {} (assoc :key \"value\") - (dissoc :lock))") - (clojure-mode) - (beginning-of-buffer) - (clojure-unwind-all) - (should - (equal - "(dissoc (assoc {} :key \"value\") :lock)" - (buffer-string))))) - -(ert-deftest test-unwind-all-thread-last () - (with-temp-buffer - (insert "(->> (make-things) + (dissoc :lock))" + "(dissoc (assoc {} :key \"value\") :lock)" + (beginning-of-buffer) + (clojure-unwind-all)) + +(def-threading-test all-thread-last + "(->> (make-things) (filter even?) - (map square))") - (clojure-mode) - (beginning-of-buffer) - (clojure-unwind-all) - (should - (equal - "(map square (filter even? (make-things)))" - (buffer-string))))) - -(ert-deftest test-thread-last-dangling-parens () - (with-temp-buffer - (insert "(map inc - (range))") - (clojure-mode) - (beginning-of-buffer) - (clojure-thread-last-all nil) - (should - (equal - "(->> (range) + (map square))" + "(map square (filter even? (make-things)))" + (beginning-of-buffer) + (clojure-unwind-all)) + +(def-threading-test last-dangling-parens + "(map inc + (range))" + "(->> (range) (map inc))" - (buffer-string))))) + (beginning-of-buffer) + (clojure-thread-last-all nil)) ;; fix for clojure-emacs/clj-refactor.el#259 -(ert-deftest test-unwind-last-leaves-multiline-sexp-alone () - (with-temp-buffer - (insert - "(->> [a b] +(def-threading-test last-leaves-multiline-sexp-alone + "(->> [a b] (some (fn [x] (when x - 10))))") - (clojure-mode) - (clojure-unwind-all) - (should - (equal - "(some (fn [x] + 10))))" + "(some (fn [x] (when x 10)) [a b])" - (buffer-string))))) + (clojure-unwind-all)) (provide 'clojure-mode-refactor-threading-test) From da449f6bdb0d87c95c04466fd3f8d17d235d9b70 Mon Sep 17 00:00:00 2001 From: Artur Malabarba Date: Wed, 11 May 2016 12:26:55 -0300 Subject: [PATCH 091/199] Fix dangling parens in more scenarios --- clojure-mode-refactor-threading-test.el | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/clojure-mode-refactor-threading-test.el b/clojure-mode-refactor-threading-test.el index 56bed59..af9233f 100644 --- a/clojure-mode-refactor-threading-test.el +++ b/clojure-mode-refactor-threading-test.el @@ -306,6 +306,16 @@ (beginning-of-buffer) (clojure-thread-last-all nil)) +(def-threading-test last-dangling-parens-2 + "(deftask dev [] + (comp (serve) + (cljs)))" + "(->> (cljs) + (comp (serve)) + (deftask dev []))" + (beginning-of-buffer) + (clojure-thread-last-all nil)) + ;; fix for clojure-emacs/clj-refactor.el#259 (def-threading-test last-leaves-multiline-sexp-alone "(->> [a b] From 203c18a213751595bea442627822de926c4721fa Mon Sep 17 00:00:00 2001 From: Artur Malabarba Date: Wed, 11 May 2016 19:58:33 -0300 Subject: [PATCH 092/199] Fix the test macro to support find-func --- clojure-mode-refactor-threading-test.el | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/clojure-mode-refactor-threading-test.el b/clojure-mode-refactor-threading-test.el index af9233f..0cf62b0 100644 --- a/clojure-mode-refactor-threading-test.el +++ b/clojure-mode-refactor-threading-test.el @@ -30,15 +30,18 @@ (defmacro def-threading-test (name before after &rest body) (declare (indent 3)) - `(ert-deftest ,(intern (format "test-thread-%s" name)) () - (let ((clojure-thread-all-but-last nil)) - (with-temp-buffer - (insert ,before) - (clojure-mode) - ,@body - (should (equal ,(concat "\n" after) - (concat "\n" (buffer-substring-no-properties - (point-min) (point-max))))))))) + (let ((sym (intern (format "test-thread-%s" name)))) + `(progn + (put ',sym 'definition-name ',name) + (ert-deftest ,sym () + (let ((clojure-thread-all-but-last nil)) + (with-temp-buffer + (insert ,before) + (clojure-mode) + ,@body + (should (equal ,(concat "\n" after) + (concat "\n" (buffer-substring-no-properties + (point-min) (point-max))))))))))) ;; thread first From 8fa3e1f9da40532a0c684aded99e34411b6672e4 Mon Sep 17 00:00:00 2001 From: Artur Malabarba Date: Wed, 11 May 2016 20:07:18 -0300 Subject: [PATCH 093/199] Preserve previously removed line-breaks when unwinding --- clojure-mode-refactor-threading-test.el | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/clojure-mode-refactor-threading-test.el b/clojure-mode-refactor-threading-test.el index 0cf62b0..840d600 100644 --- a/clojure-mode-refactor-threading-test.el +++ b/clojure-mode-refactor-threading-test.el @@ -331,6 +331,19 @@ [a b])" (clojure-unwind-all)) +(def-threading-test maybe-unjoin-lines + "(deftask dev [] + (comp (serve) + (cljs (lala) + 10)))" + "(deftask dev [] + (comp (serve) + (cljs (lala) + 10)))" + (goto-char (point-min)) + (clojure-thread-last-all nil) + (clojure-unwind-all)) + (provide 'clojure-mode-refactor-threading-test) ;;; clojure-mode-refactor-threading-test.el ends here From c8ec6e7f3a4c10b8ee19f6b6a09830b97653fc04 Mon Sep 17 00:00:00 2001 From: Artur Malabarba Date: Wed, 11 May 2016 20:59:43 -0300 Subject: [PATCH 094/199] Improve line-break handling with thread/unwind-first --- clojure-mode-refactor-threading-test.el | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/clojure-mode-refactor-threading-test.el b/clojure-mode-refactor-threading-test.el index 840d600..f86381a 100644 --- a/clojure-mode-refactor-threading-test.el +++ b/clojure-mode-refactor-threading-test.el @@ -331,7 +331,7 @@ [a b])" (clojure-unwind-all)) -(def-threading-test maybe-unjoin-lines +(def-threading-test last-maybe-unjoin-lines "(deftask dev [] (comp (serve) (cljs (lala) @@ -344,6 +344,27 @@ (clojure-thread-last-all nil) (clojure-unwind-all)) +(def-threading-test empty-first-line + "(map + inc + [1 2])" + "(-> inc + (map + [1 2]))" + (goto-char (point-min)) + (clojure-thread-first-all nil)) + +(def-threading-test first-maybe-unjoin-lines + "(map + inc + [1 2])" + "(map + inc + [1 2])" + (goto-char (point-min)) + (clojure-thread-first-all nil) + (clojure-unwind-all)) + (provide 'clojure-mode-refactor-threading-test) ;;; clojure-mode-refactor-threading-test.el ends here From 9c98734cb659363a73f9bb953c8f4213a5441fca Mon Sep 17 00:00:00 2001 From: Artur Malabarba Date: Fri, 13 May 2016 12:03:29 -0300 Subject: [PATCH 095/199] Add a test for ns-sort --- clojure-mode-util-test.el | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/clojure-mode-util-test.el b/clojure-mode-util-test.el index 5682d33..f118158 100644 --- a/clojure-mode-util-test.el +++ b/clojure-mode-util-test.el @@ -95,6 +95,40 @@ foo)")) (should (string-match clojure-namespace-name-regex ns)) (should (equal "foo+" (match-string 4 ns))))) +(ert-deftest test-sort-ns () + (with-temp-buffer + (insert "\n(ns my-app.core + (:require [my-app.views [front-page :as front-page]] + [my-app.state :refer [state]] ; Comments too. + ;; Some comments. + [rum.core :as rum] + [my-app.views [user-page :as user-page]] + my-app.util.api) + (:import java.io.Writer + [clojure.lang AFunction Atom MultiFn Namespace]))") + (clojure-mode) + (clojure-sort-ns) + (should (equal (buffer-string) + "\n(ns my-app.core + (:require [my-app.state :refer [state]] ; Comments too. + my-app.util.api + [my-app.views [front-page :as front-page]] + [my-app.views [user-page :as user-page]] + ;; Some comments. + [rum.core :as rum]) + (:import [clojure.lang AFunction Atom MultiFn Namespace] + java.io.Writer))"))) + (with-temp-buffer + (insert "(ns my-app.core + (:require [rum.core :as rum] ;comment + [my-app.views [user-page :as user-page]]))") + (clojure-mode) + (clojure-sort-ns) + (should (equal (buffer-string) + "(ns my-app.core + (:require [my-app.views [user-page :as user-page]] + [rum.core :as rum] ;comment\n))")))) + (provide 'clojure-mode-util-test) ;;; clojure-mode-util-test.el ends here From f937471437df014e5f89e1c3c242d9e8c9c6530a Mon Sep 17 00:00:00 2001 From: Benedek Fazekas Date: Sun, 15 May 2016 14:07:34 +0100 Subject: [PATCH 096/199] Add cycling privacy, collection type, if/if-not Migrate cycle privacy, cycle collection type and cycle if/if-not implementations from clj-refactor.el. Cycle collection type is reworked into convert collection with a dedicated defun/menu item/keybinding for every collection type. Quoted list is also added to the supported collection types. Additionally refactor `def-threading-test` macro to use it for testing cycling stuff too and fix duplicate test names in `clojure-mode-refactor-threading-test` --- clojure-mode-convert-collection-test.el | 75 +++++++++++++++ clojure-mode-cycling-test.el | 118 ++++++++++++++++++++++++ clojure-mode-refactor-threading-test.el | 89 ++++++++---------- test-helper.el | 16 ++++ 4 files changed, 246 insertions(+), 52 deletions(-) create mode 100644 clojure-mode-convert-collection-test.el create mode 100644 clojure-mode-cycling-test.el diff --git a/clojure-mode-convert-collection-test.el b/clojure-mode-convert-collection-test.el new file mode 100644 index 0000000..7b6dc02 --- /dev/null +++ b/clojure-mode-convert-collection-test.el @@ -0,0 +1,75 @@ +;;; clojure-mode-convert-collection-test.el --- Clojure Mode: convert collection type -*- lexical-binding: t; -*- + +;; Copyright (C) 2016 Benedek Fazekas + +;; This file is not part of GNU Emacs. + +;; This program is free software; you can redistribute it and/or modify +;; it under the terms of the GNU General Public License as published by +;; the Free Software Foundation, either version 3 of the License, or +;; (at your option) any later version. + +;; This program is distributed in the hope that it will be useful, +;; but WITHOUT ANY WARRANTY; without even the implied warranty of +;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +;; GNU General Public License for more details. + +;; You should have received a copy of the GNU General Public License +;; along with this program. If not, see . + +;;; Commentary: + +;; The convert collection code originally was implemented +;; as cycling collection type in clj-refactor.el and is the work +;; of the clj-reafctor.el team. + +;;; Code: + +(require 'clojure-mode) +(require 'ert) + +(def-refactor-test test-convert-collection-list-map + "(:a 1 :b 2)" + "{:a 1 :b 2}" + (backward-sexp) + (down-list) + (clojure-convert-collection-to-map)) + +(def-refactor-test test-convert-collection-map-vector + "{:a 1 :b 2}" + "[:a 1 :b 2]" + (backward-sexp) + (down-list) + (clojure-convert-collection-to-vector)) + +(def-refactor-test test-convert-collection-vector-set + "[1 2 3]" + "#{1 2 3}" + (backward-sexp) + (down-list) + (clojure-convert-collection-to-set)) + +(def-refactor-test test-convert-collection-set-list + "#{1 2 3}" + "(1 2 3)" + (backward-sexp) + (down-list) + (clojure-convert-collection-to-list)) + +(def-refactor-test test-convert-collection-set-quoted-list + "#{1 2 3}" + "'(1 2 3)" + (backward-sexp) + (down-list) + (clojure-convert-collection-to-quoted-list)) + +(def-refactor-test test-convert-collection-quoted-list-set + "'(1 2 3)" + "#{1 2 3}" + (backward-sexp) + (down-list) + (clojure-convert-collection-to-set)) + +(provide 'clojure-mode-convert-collection-test) + +;;; clojure-mode-convert-collection-test.el ends here diff --git a/clojure-mode-cycling-test.el b/clojure-mode-cycling-test.el new file mode 100644 index 0000000..5b2371d --- /dev/null +++ b/clojure-mode-cycling-test.el @@ -0,0 +1,118 @@ +;;; clojure-mode-cycling-test.el --- Clojure Mode: cycling things tests -*- lexical-binding: t; -*- + +;; Copyright (C) 2016 Benedek Fazekas + +;; This file is not part of GNU Emacs. + +;; This program is free software; you can redistribute it and/or modify +;; it under the terms of the GNU General Public License as published by +;; the Free Software Foundation, either version 3 of the License, or +;; (at your option) any later version. + +;; This program is distributed in the hope that it will be useful, +;; but WITHOUT ANY WARRANTY; without even the implied warranty of +;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +;; GNU General Public License for more details. + +;; You should have received a copy of the GNU General Public License +;; along with this program. If not, see . + +;;; Commentary: + +;; The cycling privacy and if/if-not code is ported from +;; clj-refactor.el and the work of the clj-reafctor.el team. + +;;; Code: + +(require 'clojure-mode) +(require 'ert) + +(def-refactor-test test-cycle-privacy-public-defn-private-defn + "(defn add [a b] + (+ a b))" + "(defn- add [a b] + (+ a b))" + (clojure-cycle-privacy)) + +(def-refactor-test test-cycle-privacy-from-sexp-beg + "(defn- add [a b] + (+ a b))" + "(defn add [a b] + (+ a b))" + (backward-sexp) + (clojure-cycle-privacy)) + +(def-refactor-test test-cycle-privacy-public-defn-private-defn-metadata + "(defn add [a b] + (+ a b))" + "(defn ^:private add [a b] + (+ a b))" + (let ((clojure-use-metadata-for-privacy t)) + (clojure-cycle-privacy))) + +(def-refactor-test test-cycle-privacy-private-defn-public-defn + "(defn- add [a b] + (+ a b))" + "(defn add [a b] + (+ a b))" + (clojure-cycle-privacy)) + +(def-refactor-test test-cycle-privacy-private-defn-public-defn-metadata + "(defn ^:private add [a b] + (+ a b))" + "(defn add [a b] + (+ a b))" + (let ((clojure-use-metadata-for-privacy t)) + (clojure-cycle-privacy))) + +(def-refactor-test test-cycle-privacy-public-def-private-def + "(def ^:dynamic config + \"docs\" + {:env \"staging\"})" + "(def ^:private ^:dynamic config + \"docs\" + {:env \"staging\"})" + (clojure-cycle-privacy)) + +(def-refactor-test test-cycle-privacy-private-def-public-def + "(def ^:private config + \"docs\" + {:env \"staging\"})" + "(def config + \"docs\" + {:env \"staging\"})" + (clojure-cycle-privacy)) + +(def-refactor-test test-cycle-if-inner-if + "(if this + (if that + (then AAA) + (else BBB)) + (otherwise CCC))" + "(if this + (if-not that + (else BBB) + (then AAA)) + (otherwise CCC))" + (beginning-of-buffer) + (search-forward "BBB)") + (clojure-cycle-if)) + +(def-refactor-test test-cycle-if-outer-if + "(if-not this + (if that + (then AAA) + (else BBB)) + (otherwise CCC))" + "(if this + (otherwise CCC) + (if that + (then AAA) + (else BBB)))" + (beginning-of-buffer) + (search-forward "BBB))") + (clojure-cycle-if)) + +(provide 'clojure-mode-cycling-test) + +;;; clojure-mode-cycling-test.el ends here diff --git a/clojure-mode-refactor-threading-test.el b/clojure-mode-refactor-threading-test.el index f86381a..03e896d 100644 --- a/clojure-mode-refactor-threading-test.el +++ b/clojure-mode-refactor-threading-test.el @@ -28,30 +28,15 @@ (require 'clojure-mode) (require 'ert) -(defmacro def-threading-test (name before after &rest body) - (declare (indent 3)) - (let ((sym (intern (format "test-thread-%s" name)))) - `(progn - (put ',sym 'definition-name ',name) - (ert-deftest ,sym () - (let ((clojure-thread-all-but-last nil)) - (with-temp-buffer - (insert ,before) - (clojure-mode) - ,@body - (should (equal ,(concat "\n" after) - (concat "\n" (buffer-substring-no-properties - (point-min) (point-max))))))))))) - ;; thread first -(def-threading-test first-one-step +(def-refactor-test test-thread-first-one-step "(-> (dissoc (assoc {} :key \"value\") :lock))" "(-> (assoc {} :key \"value\") (dissoc :lock))" (clojure-thread)) -(def-threading-test first-two-steps +(def-refactor-test test-thread-first-two-steps "(-> (dissoc (assoc {} :key \"value\") :lock))" "(-> {} (assoc :key \"value\") @@ -59,7 +44,7 @@ (clojure-thread) (clojure-thread)) -(def-threading-test first-dont-thread-maps +(def-refactor-test test-thread-first-dont-thread-maps "(-> (dissoc (assoc {} :key \"value\") :lock))" "(-> {} (assoc :key \"value\") @@ -68,7 +53,7 @@ (clojure-thread) (clojure-thread)) -(def-threading-test first-dont-thread-last-one +(def-refactor-test test-thread-first-dont-thread-last-one "(-> (dissoc (assoc (get-a-map) :key \"value\") :lock))" "(-> (get-a-map) (assoc :key \"value\") @@ -77,7 +62,7 @@ (clojure-thread) (clojure-thread)) -(def-threading-test first-easy-on-whitespace +(def-refactor-test test-thread-first-easy-on-whitespace "(-> (dissoc (assoc {} :key \"value\") :lock))" "(-> @@ -85,7 +70,7 @@ (dissoc :lock))" (clojure-thread)) -(def-threading-test first-remove-superfluous-parens +(def-refactor-test test-thread-first-remove-superfluous-parens "(-> (square (sum [1 2 3 4 5])))" "(-> [1 2 3 4 5] sum @@ -93,7 +78,7 @@ (clojure-thread) (clojure-thread)) -(def-threading-test first-cursor-before-threading +(def-refactor-test test-thread-first-cursor-before-threading "(-> (not (s-acc/mobile? session)))" "(-> (s-acc/mobile? session) not)" @@ -101,7 +86,7 @@ (clojure-thread)) ;; unwind thread first -(def-threading-test first-one-step +(def-refactor-test test-thread-unwind-first-one-step "(-> {} (assoc :key \"value\") (dissoc :lock))" @@ -109,7 +94,7 @@ (dissoc :lock))" (clojure-unwind)) -(def-threading-test first-two-steps +(def-refactor-test test-thread-unwind-first-two-steps "(-> {} (assoc :key \"value\") (dissoc :lock))" @@ -117,7 +102,7 @@ (clojure-unwind) (clojure-unwind)) -(def-threading-test first-jump-out-of-threading +(def-refactor-test test-thread-first-jump-out-of-threading "(-> {} (assoc :key \"value\") (dissoc :lock))" @@ -127,13 +112,13 @@ (clojure-unwind)) ;; thread last -(def-threading-test last-one-step +(def-refactor-test test-thread-last-one-step "(->> (map square (filter even? [1 2 3 4 5])))" "(->> (filter even? [1 2 3 4 5]) (map square))" (clojure-thread)) -(def-threading-test last-two-steps +(def-refactor-test test-thread-last-two-steps "(->> (map square (filter even? [1 2 3 4 5])))" "(->> [1 2 3 4 5] (filter even?) @@ -141,7 +126,7 @@ (clojure-thread) (clojure-thread)) -(def-threading-test last-dont-thread-vectors +(def-refactor-test test-thread-last-dont-thread-vectors "(->> (map square (filter even? [1 2 3 4 5])))" "(->> [1 2 3 4 5] (filter even?) @@ -150,7 +135,7 @@ (clojure-thread) (clojure-thread)) -(def-threading-test last-dont-thread-last-one +(def-refactor-test test-thread-last-dont-thread-last-one "(->> (map square (filter even? (get-a-list))))" "(->> (get-a-list) (filter even?) @@ -160,7 +145,7 @@ (clojure-thread)) ;; unwind thread last -(def-threading-test last-one-step +(def-refactor-test test-thread-last-one-step "(->> [1 2 3 4 5] (filter even?) (map square))" @@ -168,7 +153,7 @@ (map square))" (clojure-unwind)) -(def-threading-test last-two-steps +(def-refactor-test test-thread-last-two-steps "(->> [1 2 3 4 5] (filter even?) (map square))" @@ -176,7 +161,7 @@ (clojure-unwind) (clojure-unwind)) -(def-threading-test last-jump-out-of-threading +(def-refactor-test test-thread-last-jump-out-of-threading "(->> [1 2 3 4 5] (filter even?) (map square))" @@ -185,7 +170,7 @@ (clojure-unwind) (clojure-unwind)) -(def-threading-test function-name +(def-refactor-test test-thread-function-name "(->> [1 2 3 4 5] sum square)" @@ -193,7 +178,7 @@ square)" (clojure-unwind)) -(def-threading-test function-name-twice +(def-refactor-test test-thread-function-name-twice "(-> [1 2 3 4 5] sum square)" @@ -201,21 +186,21 @@ (clojure-unwind) (clojure-unwind)) -(def-threading-test issue-6-1 +(def-refactor-test test-thread-issue-6-1 "(defn plus [a b] (-> a (+ b)))" "(defn plus [a b] (-> (+ a b)))" (clojure-unwind)) -(def-threading-test issue-6-2 +(def-refactor-test test-thread-issue-6-2 "(defn plus [a b] (->> a (+ b)))" "(defn plus [a b] (->> (+ b a)))" (clojure-unwind)) -(def-threading-test first-some +(def-refactor-test test-thread-first-some "(some-> (+ (val (find {:a 1} :b)) 5))" "(some-> {:a 1} (find :b) @@ -225,7 +210,7 @@ (clojure-thread) (clojure-thread)) -(def-threading-test last-some +(def-refactor-test test-thread-last-some "(some->> (+ 5 (val (find {:a 1} :b))))" "(some->> :b (find {:a 1}) @@ -235,7 +220,7 @@ (clojure-thread) (clojure-thread)) -(def-threading-test last-first-some +(def-refactor-test test-thread-last-first-some "(some-> {:a 1} (find :b) val @@ -245,7 +230,7 @@ (clojure-unwind) (clojure-unwind)) -(def-threading-test thread-last-some +(def-refactor-test test-thread-thread-last-some "(some->> :b (find {:a 1}) val @@ -255,7 +240,7 @@ (clojure-unwind) (clojure-unwind)) -(def-threading-test first-all +(def-refactor-test test-thread-first-all "(->map (assoc {} :key \"value\") :lock)" "(-> {} (assoc :key \"value\") @@ -263,14 +248,14 @@ (beginning-of-buffer) (clojure-thread-first-all nil)) -(def-threading-test first-all-but-last +(def-refactor-test test-thread-first-all-but-last "(->map (assoc {} :key \"value\") :lock)" "(-> (assoc {} :key \"value\") (->map :lock))" (beginning-of-buffer) (clojure-thread-first-all t)) -(def-threading-test last-all +(def-refactor-test test-thread-last-all "(map square (filter even? (make-things)))" "(->> (make-things) (filter even?) @@ -278,14 +263,14 @@ (beginning-of-buffer) (clojure-thread-last-all nil)) -(def-threading-test last-all-but-last +(def-refactor-test test-thread-last-all-but-last "(map square (filter even? (make-things)))" "(->> (filter even? (make-things)) (map square))" (beginning-of-buffer) (clojure-thread-last-all t)) -(def-threading-test all-thread-first +(def-refactor-test test-thread-all-thread-first "(-> {} (assoc :key \"value\") (dissoc :lock))" @@ -293,7 +278,7 @@ (beginning-of-buffer) (clojure-unwind-all)) -(def-threading-test all-thread-last +(def-refactor-test test-thread-all-thread-last "(->> (make-things) (filter even?) (map square))" @@ -301,7 +286,7 @@ (beginning-of-buffer) (clojure-unwind-all)) -(def-threading-test last-dangling-parens +(def-refactor-test test-thread-last-dangling-parens "(map inc (range))" "(->> (range) @@ -309,7 +294,7 @@ (beginning-of-buffer) (clojure-thread-last-all nil)) -(def-threading-test last-dangling-parens-2 +(def-refactor-test test-thread-last-dangling-parens-2 "(deftask dev [] (comp (serve) (cljs)))" @@ -320,7 +305,7 @@ (clojure-thread-last-all nil)) ;; fix for clojure-emacs/clj-refactor.el#259 -(def-threading-test last-leaves-multiline-sexp-alone +(def-refactor-test test-thread-last-leaves-multiline-sexp-alone "(->> [a b] (some (fn [x] (when x @@ -331,7 +316,7 @@ [a b])" (clojure-unwind-all)) -(def-threading-test last-maybe-unjoin-lines +(def-refactor-test test-thread-last-maybe-unjoin-lines "(deftask dev [] (comp (serve) (cljs (lala) @@ -344,7 +329,7 @@ (clojure-thread-last-all nil) (clojure-unwind-all)) -(def-threading-test empty-first-line +(def-refactor-test test-thread-empty-first-line "(map inc [1 2])" @@ -354,7 +339,7 @@ (goto-char (point-min)) (clojure-thread-first-all nil)) -(def-threading-test first-maybe-unjoin-lines +(def-refactor-test test-thread-first-maybe-unjoin-lines "(map inc [1 2])" diff --git a/test-helper.el b/test-helper.el index 4846360..02a7402 100644 --- a/test-helper.el +++ b/test-helper.el @@ -32,4 +32,20 @@ ;; Load the file under test (load (expand-file-name "clojure-mode" source-directory))) +(defmacro def-refactor-test (name before after &rest body) + (declare (indent 3)) + `(progn + (put ',name 'definition-name ',name) + (ert-deftest ,name () + (let ((clojure-thread-all-but-last nil) + (clojure-use-metadata-for-privacy nil)) + (with-temp-buffer + (insert ,before) + (clojure-mode) + ,@body + (should (equal ,(concat "\n" after) + (concat "\n" (buffer-substring-no-properties + (point-min) (point-max)))))))))) + + ;;; test-helper.el ends here From 294714b89fcd5b8c9ac177782d77629d1a82d73b Mon Sep 17 00:00:00 2001 From: Andrea Richiardi Date: Wed, 15 Jun 2016 13:16:39 -0700 Subject: [PATCH 097/199] Fix bug when passing lambda to define-clojure-indent, closes #383 --- clojure-mode-indentation-test.el | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/clojure-mode-indentation-test.el b/clojure-mode-indentation-test.el index 30659fd..5c2171d 100644 --- a/clojure-mode-indentation-test.el +++ b/clojure-mode-indentation-test.el @@ -164,6 +164,17 @@ values of customisable variables." (ala/bala top |one)") +;; we can pass a lambda to explicitely set the column +(put-clojure-indent 'arsymbol (lambda (indent-point state) 0)) + +(check-indentation symbol-with-lambda + " +(arsymbol + |one)" + " +(arsymbol +|one)") + (check-indentation form-with-metadata " (ns ^:doc app.core From 71b21c3b8c545ef543b5ff2d38d6780d6fd31074 Mon Sep 17 00:00:00 2001 From: Ben Poweski Date: Mon, 27 Jun 2016 01:20:31 -0500 Subject: [PATCH 098/199] Fix multi-airty indention of deftype & defrecord (#389) (#390) --- clojure-mode-indentation-test.el | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/clojure-mode-indentation-test.el b/clojure-mode-indentation-test.el index 7fcc938..fbdb5f4 100644 --- a/clojure-mode-indentation-test.el +++ b/clojure-mode-indentation-test.el @@ -280,6 +280,15 @@ values of customisable variables." ([item a] (* a (:qty item)))))") +(def-full-indent-test deftype-allow-multiarity + "(deftype Banana [] + Fruit + (subtotal + ([item] + (* 158 (:qty item))) + ([item a] + (* a (:qty item)))))") + (def-full-indent-test defprotocol "(defprotocol IFoo (foo [this] @@ -326,6 +335,15 @@ values of customisable variables." SomeType (assoc [_ x] (.assoc pretty x 10)))") +(def-full-indent-test defrecord-allow-multiarity + "(defrecord Banana [] + Fruit + (subtotal + ([item] + (* 158 (:qty item))) + ([item a] + (* a (:qty item)))))") + (def-full-indent-test letfn "(letfn [(f [x] (* x 2)) From 4599b47b585db775dffb75876e4300059fba40e7 Mon Sep 17 00:00:00 2001 From: Ben Sima Date: Sat, 23 Jul 2016 05:02:28 -0700 Subject: [PATCH 099/199] Add indentation rule for definterface (#395) --- clojure-mode-indentation-test.el | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/clojure-mode-indentation-test.el b/clojure-mode-indentation-test.el index fbdb5f4..f74ad17 100644 --- a/clojure-mode-indentation-test.el +++ b/clojure-mode-indentation-test.el @@ -297,6 +297,15 @@ values of customisable variables." [this] \"Why is this over here?\"))") + +(def-full-indent-test definterface + "(definterface IFoo + (foo [this] + \"Why is this over here?\") + (foo-2 + [this] + \"Why is this over here?\"))") + (def-full-indent-test specify "(specify obj ISwap From 99b74128f2a242d8dbd0244d595c5954d76b9ed6 Mon Sep 17 00:00:00 2001 From: Vitalie Spinu Date: Sat, 23 Jul 2016 21:41:29 +0200 Subject: [PATCH 100/199] Add tests for correct treatment of prefix syntax --- clojure-mode-indentation-test.el | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/clojure-mode-indentation-test.el b/clojure-mode-indentation-test.el index f74ad17..b4f9ed0 100644 --- a/clojure-mode-indentation-test.el +++ b/clojure-mode-indentation-test.el @@ -637,6 +637,25 @@ x (should-not (non-func "^hint " form)) (should-not (non-func "#macro " form)))) +(ert-deftest clojure-syntax-prefixed-symbols () + (dolist (form '(("#?@aaa" . "aaa") + ("#?aaa" . "?aaa") + ("#aaa" . "aaa") + ("'aaa" . "aaa"))) + (with-temp-buffer + (clojure-mode) + (insert (car form)) + (equal (symbol-name (symbol-at-point)) (cdr form))))) + +(ert-deftest clojure-syntax-skip-prefixes () + (dolist (form '("#?@aaa" "#?aaa" "#aaa" "'aaa")) + (with-temp-buffer + (clojure-mode) + (insert form) + (backward-word) + (backward-prefix-chars) + (should (bobp))))) + (provide 'clojure-mode-indentation-test) ;;; clojure-mode-indentation-test.el ends here From ce815f99a39c556debeeaa59fde79eb5ef6b98ad Mon Sep 17 00:00:00 2001 From: Vitalie Spinu Date: Sat, 23 Jul 2016 21:43:39 +0200 Subject: [PATCH 101/199] Create separate clojure-mode-syntax-test suite --- clojure-mode-indentation-test.el | 53 --------------------- clojure-mode-syntax-test.el | 80 ++++++++++++++++++++++++++++++++ 2 files changed, 80 insertions(+), 53 deletions(-) create mode 100644 clojure-mode-syntax-test.el diff --git a/clojure-mode-indentation-test.el b/clojure-mode-indentation-test.el index b4f9ed0..892ceb8 100644 --- a/clojure-mode-indentation-test.el +++ b/clojure-mode-indentation-test.el @@ -602,59 +602,6 @@ x (insert "{:a 2, ,:c 4}") (call-interactively #'clojure-align) (should (string= (buffer-string) "{:a 2, :c 4}")))) - -;;; Misc - -(defun non-func (form-a form-b) - (with-temp-buffer - (clojure-mode) - (insert form-a) - (save-excursion (insert form-b)) - (clojure--not-function-form-p))) - -(ert-deftest non-function-form () - (dolist (form '(("#?@ " "(c d)") - ("#?@" "(c d)") - ("#? " "(c d)") - ("#?" "(c d)") - ("" "[asda]") - ("" "{a b}") - ("#" "{a b}") - ("" "(~)"))) - (should (apply #'non-func form))) - (dolist (form '("(c d)" - "(.c d)" - "(:c d)" - "(c/a d)" - "(.c/a d)" - "(:c/a d)" - "(c/a)" - "(:c/a)" - "(.c/a)")) - (should-not (non-func "" form)) - (should-not (non-func "^hint" form)) - (should-not (non-func "#macro" form)) - (should-not (non-func "^hint " form)) - (should-not (non-func "#macro " form)))) - -(ert-deftest clojure-syntax-prefixed-symbols () - (dolist (form '(("#?@aaa" . "aaa") - ("#?aaa" . "?aaa") - ("#aaa" . "aaa") - ("'aaa" . "aaa"))) - (with-temp-buffer - (clojure-mode) - (insert (car form)) - (equal (symbol-name (symbol-at-point)) (cdr form))))) - -(ert-deftest clojure-syntax-skip-prefixes () - (dolist (form '("#?@aaa" "#?aaa" "#aaa" "'aaa")) - (with-temp-buffer - (clojure-mode) - (insert form) - (backward-word) - (backward-prefix-chars) - (should (bobp))))) (provide 'clojure-mode-indentation-test) diff --git a/clojure-mode-syntax-test.el b/clojure-mode-syntax-test.el new file mode 100644 index 0000000..0ae5c09 --- /dev/null +++ b/clojure-mode-syntax-test.el @@ -0,0 +1,80 @@ +;;; clojure-mode-syntax-test.el --- Clojure Mode: syntax related tests -*- lexical-binding: t; -*- + +;; Copyright (C) 2015-2016 Bozhidar Batsov + +;; This file is not part of GNU Emacs. + +;; This program is free software; you can redistribute it and/or modify +;; it under the terms of the GNU General Public License as published by +;; the Free Software Foundation, either version 3 of the License, or +;; (at your option) any later version. + +;; This program is distributed in the hope that it will be useful, +;; but WITHOUT ANY WARRANTY; without even the implied warranty of +;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +;; GNU General Public License for more details. + +;; You should have received a copy of the GNU General Public License +;; along with this program. If not, see . + +;;; Commentary: + +;; The unit test suite of Clojure Mode + +;;; Code: + +(require 'clojure-mode) +(require 'ert) + +(defun non-func (form-a form-b) + (with-temp-buffer + (clojure-mode) + (insert form-a) + (save-excursion (insert form-b)) + (clojure--not-function-form-p))) + +(ert-deftest non-function-form () + (dolist (form '(("#?@ " "(c d)") + ("#?@" "(c d)") + ("#? " "(c d)") + ("#?" "(c d)") + ("" "[asda]") + ("" "{a b}") + ("#" "{a b}") + ("" "(~)"))) + (should (apply #'non-func form))) + (dolist (form '("(c d)" + "(.c d)" + "(:c d)" + "(c/a d)" + "(.c/a d)" + "(:c/a d)" + "(c/a)" + "(:c/a)" + "(.c/a)")) + (should-not (non-func "" form)) + (should-not (non-func "^hint" form)) + (should-not (non-func "#macro" form)) + (should-not (non-func "^hint " form)) + (should-not (non-func "#macro " form)))) + +(ert-deftest clojure-syntax-prefixed-symbols () + (dolist (form '(("#?@aaa" . "aaa") + ("#?aaa" . "?aaa") + ("#aaa" . "aaa") + ("'aaa" . "aaa"))) + (with-temp-buffer + (clojure-mode) + (insert (car form)) + (equal (symbol-name (symbol-at-point)) (cdr form))))) + +(ert-deftest clojure-syntax-skip-prefixes () + (dolist (form '("#?@aaa" "#?aaa" "#aaa" "'aaa")) + (with-temp-buffer + (clojure-mode) + (insert form) + (backward-word) + (backward-prefix-chars) + (should (bobp))))) + +(provide 'clojure-mode-syntax-test) From 29ba69e72dd99724ab0869c13f54f74f7e65f3df Mon Sep 17 00:00:00 2001 From: Vitalie Spinu Date: Tue, 2 Aug 2016 11:35:01 +0200 Subject: [PATCH 102/199] [Fix #399] Fix font-locking of prefix characters inside keywords (#401) - declare # with "_ p" syntax - no overwrite for #~@^ chars in font-lock syntax table --- clojure-mode-font-lock-test.el | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/clojure-mode-font-lock-test.el b/clojure-mode-font-lock-test.el index fac495f..f5fe4ca 100644 --- a/clojure-mode-font-lock-test.el +++ b/clojure-mode-font-lock-test.el @@ -298,6 +298,19 @@ POS." (should (eq (clojure-test-face-at 1 1) nil)) (should (equal (clojure-test-face-at 2 11) '(clojure-keyword-face))))) +(ert-deftest clojure-mode-syntax-table/keyword-allowed-chars () + :tags '(fontification syntax-table) + (should (equal (clojure-test-face-at 1 8 ":aaa#bbb") '(clojure-keyword-face)))) + +(ert-deftest clojure-mode-syntax-table/keyword-disallowed-chars () + :tags '(fontification syntax-table) + (should (eq (clojure-test-face-at 1 5 ":aaa@bbb") 'various-faces)) + (should (equal (clojure-test-face-at 1 4 ":aaa@bbb") '(clojure-keyword-face))) + (should (eq (clojure-test-face-at 1 5 ":aaa~bbb") 'various-faces)) + (should (equal (clojure-test-face-at 1 4 ":aaa~bbb") '(clojure-keyword-face))) + (should (eq (clojure-test-face-at 1 5 ":aaa@bbb") 'various-faces)) + (should (equal (clojure-test-face-at 1 4 ":aaa@bbb") '(clojure-keyword-face)))) + (ert-deftest clojure-mode-syntax-table/characters () :tags '(fontification syntax-table) (should (eq (clojure-test-face-at 1 2 "\\a") 'clojure-character-face)) From cbbf18a6a7205e425fb63f503b73f015797a8076 Mon Sep 17 00:00:00 2001 From: Benedek Fazekas Date: Mon, 17 Oct 2016 09:28:13 +0100 Subject: [PATCH 103/199] Port let related refactorings from clj-refactor.el Migrate introduce let, move to let from clj-refactor.el. Add introduce expanded let, forward slurp into let and backward slurp into let. Implementation follows the main outlines of the cljr code but is reworked at certain places. Major differences are as follows: - Expanded let is introduced: with a prefix argument let introduced N lists up with all the occurrences of bound form replaced at addition time. - New function: slurp function into let form forward and backward. Added value again is to replace bounded forms with their bound names in the slurped forms. prefix argument can be used again to slurp multiple forms into the let. - Expand let is not ported from cljr. Instead `paredit-convolute-sexp` is advised to replace forms with bound names when used on let like form. Further notes: - `string-trim` is moved upstream from cider (after merging this, cider can be refactored to use the trim fns from `clojure-mode`) Advice `paredit-convolute-sexp' when used on a let form as drop in replacement for `cljr-expand-let`. Depend on emacs 24.4 as `advice-add` is not available in 24.3 and also use `subr-x` for string trimming. --- clojure-mode-refactor-let-test.el | 213 ++++++++++++++++++++++++++++++ 1 file changed, 213 insertions(+) create mode 100644 clojure-mode-refactor-let-test.el diff --git a/clojure-mode-refactor-let-test.el b/clojure-mode-refactor-let-test.el new file mode 100644 index 0000000..d98347d --- /dev/null +++ b/clojure-mode-refactor-let-test.el @@ -0,0 +1,213 @@ +;;; clojure-mode-refactor-let-test.el --- Clojure Mode: refactor let -*- lexical-binding: t; -*- + +;; Copyright (C) 2016 Benedek Fazekas + +;; This file is not part of GNU Emacs. + +;; This program is free software; you can redistribute it and/or modify +;; it under the terms of the GNU General Public License as published by +;; the Free Software Foundation, either version 3 of the License, or +;; (at your option) any later version. + +;; This program is distributed in the hope that it will be useful, +;; but WITHOUT ANY WARRANTY; without even the implied warranty of +;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +;; GNU General Public License for more details. + +;; You should have received a copy of the GNU General Public License +;; along with this program. If not, see . + +;;; Commentary: + +;; The refactor-let code originally was implemented in clj-refactor.el +;; and is the work of the clj-reafctor.el team. + +;;; Code: + +(require 'clojure-mode) +(require 'ert) + +(def-refactor-test test-introduce-let + "{:status 200 + :body (find-body abc)}" + "{:status 200 + :body (let [body (find-body abc)] + body)}" + (search-backward "(find-body") + (clojure--introduce-let-internal "body")) + +(def-refactor-test test-introduce-expanded-let + "(defn handle-request [] + {:status 200 + :length (count (find-body abc)) + :body (find-body abc)})" + "(defn handle-request [] + (let [body (find-body abc)] + {:status 200 + :length (count body) + :body body}))" + (search-backward "(find-body") + (clojure--introduce-let-internal "body" 1)) + +(def-refactor-test test-let-replace-bindings-whitespace + "(defn handle-request [] + {:status 200 + :length (count + (find-body + abc)) + :body (find-body abc)})" + "(defn handle-request [] + (let [body (find-body abc)] + {:status 200 + :length (count + body) + :body body}))" + (search-backward "(find-body") + (clojure--introduce-let-internal "body" 1)) + +(def-refactor-test test-let-forward-slurp-sexp + "(defn handle-request [] + (let [body (find-body abc)] + {:status 200 + :length (count body) + :body body}) + (println (find-body abc)) + (println \"foobar\"))" + "(defn handle-request [] + (let [body (find-body abc)] + {:status 200 + :length (count body) + :body body} + (println body) + (println \"foobar\")))" + (search-backward "(count body") + (clojure-let-forward-slurp-sexp 2)) + +(def-refactor-test test-let-backward-slurp-sexp + "(defn handle-request [] + (println (find-body abc)) + (println \"foobar\") + (let [body (find-body abc)] + {:status 200 + :length (count body) + :body body}))" + "(defn handle-request [] + (let [body (find-body abc)] + (println body) + (println \"foobar\") + {:status 200 + :length (count body) + :body body}))" + (search-backward "(count body") + (clojure-let-backward-slurp-sexp 2)) + +(def-refactor-test test-move-sexp-to-let + "(defn handle-request + (let [body (find-body abc)] + {:status (or status 500) + :body body}))" + "(defn handle-request + (let [body (find-body abc) + status (or status 500)] + {:status status + :body body}))" + (search-backward "(or ") + (clojure--move-to-let-internal "status")) + +(def-refactor-test test-move-constant-to-when-let + "(defn handle-request + (when-let [body (find-body abc)] + {:status 42 + :body body}))" + "(defn handle-request + (when-let [body (find-body abc) + status 42] + {:status status + :body body}))" + (search-backward "42") + (clojure--move-to-let-internal "status")) + +(def-refactor-test test-move-to-empty-let + "(defn handle-request + (if-let [] + {:status (or status 500) + :body body}))" + "(defn handle-request + (if-let [status (or status 500)] + {:status status + :body body}))" + (search-backward "(or ") + (clojure--move-to-let-internal "status")) + +(def-refactor-test test-introduce-let-at-move-to-let-if-missing + "(defn handle-request + {:status (or status 500) + :body body})" + "(defn handle-request + {:status (let [status (or status 500)] + status) + :body body})" + (search-backward "(or ") + (clojure--move-to-let-internal "status")) + +(def-refactor-test test-move-to-let-multiple-occurrences + "(defn handle-request + (let [] + (println \"body: \" body \", params: \" \", status: \" (or status 500)) + {:status (or status 500) + :body body}))" + "(defn handle-request + (let [status (or status 500)] + (println \"body: \" body \", params: \" \", status: \" status) + {:status status + :body body}))" + (search-backward "(or ") + (clojure--move-to-let-internal "status")) + +;; clojure-emacs/clj-refactor.el#41 +(def-refactor-test test-move-to-let-nested-scope + "(defn foo [] + (let [x (range 10)] + (doseq [x (range 10)] + (let [x2 (* x x)])) + (+ 1 1)))" + "(defn foo [] + (let [x (range 10) + something (+ 1 1)] + (doseq [x x] + (let [x2 (* x x)])) + something))" + (search-backward "(+ 1 1") + (clojure--move-to-let-internal "something")) + +;; clojure-emacs/clj-refactor.el#30 +(def-refactor-test test-move-to-let-already-inside-let-binding-1 + "(deftest retrieve-order-body-test + (let [item (get-in (retrieve-order-body order-item-response-str))]))" + "(deftest retrieve-order-body-test + (let [something (retrieve-order-body order-item-response-str) + item (get-in something)]))" + (search-backward "(retrieve") + (clojure--move-to-let-internal "something")) + +;; clojure-emacs/clj-refactor.el#30 +(def-refactor-test test-move-to-let-already-inside-let-binding-2 + "(let [parent (.getParent (io/file root adrf)) + builder (string-builder) + normalize-path (comp (partial path/relative-to root) + path/->normalized + foobar)] + (do-something-spectacular parent builder))" + "(let [parent (.getParent (io/file root adrf)) + builder (string-builder) + something (partial path/relative-to root) + normalize-path (comp something + path/->normalized + foobar)] + (do-something-spectacular parent builder))" + (search-backward "(partial") + (clojure--move-to-let-internal "something")) + +(provide 'clojure-mode-refactor-let-test) + +;;; clojure-mode-refactor-let-test.el ends here From 02f027d8fe209ffeaad6e99221b87df0042f8bb4 Mon Sep 17 00:00:00 2001 From: Bozhidar Batsov Date: Sat, 21 Jan 2017 12:35:43 +0700 Subject: [PATCH 104/199] Add a command to toggle between when and when-not --- clojure-mode-cycling-test.el | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/clojure-mode-cycling-test.el b/clojure-mode-cycling-test.el index 5b2371d..8797596 100644 --- a/clojure-mode-cycling-test.el +++ b/clojure-mode-cycling-test.el @@ -113,6 +113,37 @@ (search-forward "BBB))") (clojure-cycle-if)) +(def-refactor-test test-cycle-when-inner-when + "(when this + (when that + (aaa) + (bbb)) + (ccc))" + "(when this + (when-not that + (aaa) + (bbb)) + (ccc))" + (beginning-of-buffer) + (search-forward "bbb)") + (clojure-cycle-when)) + +(def-refactor-test test-cycle-when-outer-when + "(when-not this + (when that + (aaa) + (bbb)) + (ccc))" + "(when this + (when that + (aaa) + (bbb)) + (ccc))" + (beginning-of-buffer) + (search-forward "bbb))") + (clojure-cycle-when)) + + (provide 'clojure-mode-cycling-test) ;;; clojure-mode-cycling-test.el ends here From 7e23196eb16921d80cde524c718e97d14d61f47d Mon Sep 17 00:00:00 2001 From: Bozhidar Batsov Date: Sat, 21 Jan 2017 13:39:37 +0700 Subject: [PATCH 105/199] Add a command to toggle negation for an expression --- clojure-mode-cycling-test.el | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/clojure-mode-cycling-test.el b/clojure-mode-cycling-test.el index 8797596..ae2eb71 100644 --- a/clojure-mode-cycling-test.el +++ b/clojure-mode-cycling-test.el @@ -143,6 +143,19 @@ (search-forward "bbb))") (clojure-cycle-when)) +(def-refactor-test test-cycle-not-add + "(ala bala portokala)" + "(not (ala bala portokala))" + (beginning-of-buffer) + (search-forward "bala") + (clojure-cycle-not)) + +(def-refactor-test test-cycle-not-remove + "(not (ala bala portokala))" + "(ala bala portokala)" + (beginning-of-buffer) + (search-forward "bala") + (clojure-cycle-not)) (provide 'clojure-mode-cycling-test) From c76435ba93b9946125b2677c3f201da54084d92a Mon Sep 17 00:00:00 2001 From: Bozhidar Batsov Date: Sat, 4 Mar 2017 09:10:56 +0200 Subject: [PATCH 106/199] Update the copyright years --- clojure-mode-convert-collection-test.el | 2 +- clojure-mode-cycling-test.el | 2 +- clojure-mode-font-lock-test.el | 2 +- clojure-mode-indentation-test.el | 2 +- clojure-mode-refactor-let-test.el | 2 +- clojure-mode-refactor-threading-test.el | 2 +- clojure-mode-sexp-test.el | 2 +- clojure-mode-syntax-test.el | 2 +- clojure-mode-util-test.el | 2 +- test-helper.el | 2 +- 10 files changed, 10 insertions(+), 10 deletions(-) diff --git a/clojure-mode-convert-collection-test.el b/clojure-mode-convert-collection-test.el index 7b6dc02..685536e 100644 --- a/clojure-mode-convert-collection-test.el +++ b/clojure-mode-convert-collection-test.el @@ -1,6 +1,6 @@ ;;; clojure-mode-convert-collection-test.el --- Clojure Mode: convert collection type -*- lexical-binding: t; -*- -;; Copyright (C) 2016 Benedek Fazekas +;; Copyright (C) 2016-2017 Benedek Fazekas ;; This file is not part of GNU Emacs. diff --git a/clojure-mode-cycling-test.el b/clojure-mode-cycling-test.el index ae2eb71..5e40885 100644 --- a/clojure-mode-cycling-test.el +++ b/clojure-mode-cycling-test.el @@ -1,6 +1,6 @@ ;;; clojure-mode-cycling-test.el --- Clojure Mode: cycling things tests -*- lexical-binding: t; -*- -;; Copyright (C) 2016 Benedek Fazekas +;; Copyright (C) 2016-2017 Benedek Fazekas ;; This file is not part of GNU Emacs. diff --git a/clojure-mode-font-lock-test.el b/clojure-mode-font-lock-test.el index f5fe4ca..8e5d0bd 100644 --- a/clojure-mode-font-lock-test.el +++ b/clojure-mode-font-lock-test.el @@ -1,6 +1,6 @@ ;;; clojure-mode-font-lock-test.el --- Clojure Mode: Font lock test suite -*- lexical-binding: t; -*- -;; Copyright (C) 2014-2016 Bozhidar Batsov +;; Copyright (C) 2014-2017 Bozhidar Batsov ;; This file is not part of GNU Emacs. diff --git a/clojure-mode-indentation-test.el b/clojure-mode-indentation-test.el index 892ceb8..936fc0b 100644 --- a/clojure-mode-indentation-test.el +++ b/clojure-mode-indentation-test.el @@ -1,6 +1,6 @@ ;;; clojure-mode-indentation-test.el --- Clojure Mode: indentation tests -*- lexical-binding: t; -*- -;; Copyright (C) 2015-2016 Bozhidar Batsov +;; Copyright (C) 2015-2017 Bozhidar Batsov ;; This file is not part of GNU Emacs. diff --git a/clojure-mode-refactor-let-test.el b/clojure-mode-refactor-let-test.el index d98347d..458ca5f 100644 --- a/clojure-mode-refactor-let-test.el +++ b/clojure-mode-refactor-let-test.el @@ -1,6 +1,6 @@ ;;; clojure-mode-refactor-let-test.el --- Clojure Mode: refactor let -*- lexical-binding: t; -*- -;; Copyright (C) 2016 Benedek Fazekas +;; Copyright (C) 2016-2017 Benedek Fazekas ;; This file is not part of GNU Emacs. diff --git a/clojure-mode-refactor-threading-test.el b/clojure-mode-refactor-threading-test.el index 03e896d..c54c300 100644 --- a/clojure-mode-refactor-threading-test.el +++ b/clojure-mode-refactor-threading-test.el @@ -1,6 +1,6 @@ ;;; clojure-mode-refactor-threading-test.el --- Clojure Mode: refactor threading tests -*- lexical-binding: t; -*- -;; Copyright (C) 2016 Benedek Fazekas +;; Copyright (C) 2016-2017 Benedek Fazekas ;; This file is not part of GNU Emacs. diff --git a/clojure-mode-sexp-test.el b/clojure-mode-sexp-test.el index bd18087..9e30ddc 100644 --- a/clojure-mode-sexp-test.el +++ b/clojure-mode-sexp-test.el @@ -1,6 +1,6 @@ ;;; clojure-mode-sexp-test.el --- Clojure Mode: sexp tests -*- lexical-binding: t; -*- -;; Copyright (C) 2015-2016 Artur Malabarba +;; Copyright (C) 2015-2017 Artur Malabarba ;; This file is not part of GNU Emacs. diff --git a/clojure-mode-syntax-test.el b/clojure-mode-syntax-test.el index 0ae5c09..b6eabf0 100644 --- a/clojure-mode-syntax-test.el +++ b/clojure-mode-syntax-test.el @@ -1,6 +1,6 @@ ;;; clojure-mode-syntax-test.el --- Clojure Mode: syntax related tests -*- lexical-binding: t; -*- -;; Copyright (C) 2015-2016 Bozhidar Batsov +;; Copyright (C) 2015-2017 Bozhidar Batsov ;; This file is not part of GNU Emacs. diff --git a/clojure-mode-util-test.el b/clojure-mode-util-test.el index f118158..32fd5a3 100644 --- a/clojure-mode-util-test.el +++ b/clojure-mode-util-test.el @@ -1,6 +1,6 @@ ;;; clojure-mode-util-test.el --- Clojure Mode: util test suite -*- lexical-binding: t; -*- -;; Copyright (C) 2014-2016 Bozhidar Batsov +;; Copyright (C) 2014-2017 Bozhidar Batsov ;; This file is not part of GNU Emacs. diff --git a/test-helper.el b/test-helper.el index 02a7402..d1173cc 100644 --- a/test-helper.el +++ b/test-helper.el @@ -1,6 +1,6 @@ ;;; test-helper.el --- Clojure Mode: Non-interactive unit-test setup -*- lexical-binding: t; -*- -;; Copyright (C) 2014-2016 Bozhidar Batsov +;; Copyright (C) 2014-2017 Bozhidar Batsov ;; This file is not part of GNU Emacs. From ef300cc8724d2b5f0606676becc79121edebce20 Mon Sep 17 00:00:00 2001 From: Benedek Fazekas Date: Fri, 7 Apr 2017 11:12:25 +0100 Subject: [PATCH 107/199] [Fix #429] Last occurrence sometimes not replaced for `move-to-let` (#430) In the following case: * there are more than one occurrences of an expression * and `move-to-let` is not initiated from the last occurrence * and the actual bound name is longer than the expression being moved to `let` the last expression won't be replaced. The solution: the end of the `let` expression is not cached before calling `clojure--replace-sexps-with-binding`. --- clojure-mode-refactor-let-test.el | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/clojure-mode-refactor-let-test.el b/clojure-mode-refactor-let-test.el index 458ca5f..6fe55b3 100644 --- a/clojure-mode-refactor-let-test.el +++ b/clojure-mode-refactor-let-test.el @@ -164,6 +164,21 @@ (search-backward "(or ") (clojure--move-to-let-internal "status")) +(def-refactor-test test-move-to-let-name-longer-than-expression + "(defn handle-request + (let [] + (println \"body: \" body \", params: \" \", status: \" 5) + {:body body + :status 5}))" + "(defn handle-request + (let [status 5] + (println \"body: \" body \", params: \" \", status: \" status) + {:body body + :status status}))" + (search-backward "5") + (search-backward "5") + (clojure--move-to-let-internal "status")) + ;; clojure-emacs/clj-refactor.el#41 (def-refactor-test test-move-to-let-nested-scope "(defn foo [] From 18d6f4f2ecdba0b62dfd74c7174aa8dde47f016c Mon Sep 17 00:00:00 2001 From: Vitalie Spinu Date: Fri, 9 Jun 2017 08:15:13 +0200 Subject: [PATCH 108/199] Remove ; from paragraph-start regexp during fill (#434) --- clojure-mode-syntax-test.el | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/clojure-mode-syntax-test.el b/clojure-mode-syntax-test.el index b6eabf0..4cf5f35 100644 --- a/clojure-mode-syntax-test.el +++ b/clojure-mode-syntax-test.el @@ -77,4 +77,32 @@ (backward-prefix-chars) (should (bobp))))) +(def-refactor-test test-paragraph-fill-within-comments + " +;; Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt +;; ut labore et dolore magna aliqua." + " +;; Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod +;; tempor incididunt ut labore et dolore magna aliqua." + (goto-char (point-min)) + (let ((fill-column 80)) + (fill-paragraph))) + +(def-refactor-test test-paragraph-fill-within-inner-comments + " +(let [a 1] + ;; Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt + ;; ut labore et dolore + ;; magna aliqua. + )" + " +(let [a 1] + ;; Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod + ;; tempor incididunt ut labore et dolore magna aliqua. + )" + (goto-char (point-min)) + (forward-line 2) + (let ((fill-column 80)) + (fill-paragraph))) + (provide 'clojure-mode-syntax-test) From 0dfbdcc3b541af47b939fb36b9eedf27d108c0b5 Mon Sep 17 00:00:00 2001 From: Tianxiang Xiong Date: Sun, 23 Jul 2017 14:53:37 -0700 Subject: [PATCH 109/199] Add byte-comp and `checkdoc` tests --- clojure-mode-bytecomp-warnings.el | 40 +++++++++++++++++++++++++++++++ test-checks.el | 30 +++++++++++++++++++++++ 2 files changed, 70 insertions(+) create mode 100644 clojure-mode-bytecomp-warnings.el create mode 100644 test-checks.el diff --git a/clojure-mode-bytecomp-warnings.el b/clojure-mode-bytecomp-warnings.el new file mode 100644 index 0000000..1096a53 --- /dev/null +++ b/clojure-mode-bytecomp-warnings.el @@ -0,0 +1,40 @@ +;;; clojure-mode-bytecomp-warnings.el --- Check for byte-compilation problems + +;; Copyright © 2012-2017 Bozhidar Batsov and contributors +;; +;; This program is free software: you can redistribute it and/or modify +;; it under the terms of the GNU General Public License as published by +;; the Free Software Foundation, either version 3 of the License, or +;; (at your option) any later version. + +;; This program is distributed in the hope that it will be useful, +;; but WITHOUT ANY WARRANTY; without even the implied warranty of +;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +;; GNU General Public License for more details. + +;; You should have received a copy of the GNU General Public License +;; along with this program. If not, see . + +;; This file is not part of GNU Emacs. + +;;; Commentary: + +;; This is a script to be loaded while visiting a `clojure-mode' source file. +;; It will prepare all requirements and then byte-compile the file and signal an +;; error on any warning. For example: +;; +;; emacs -Q --batch -l test/clojure-mode-bytecomp-warnings.el clojure-mode.el + +;; This assumes that all `clojure-mode' dependencies are already on the package +;; dir (probably from running `cask install'). + +(setq load-prefer-newer t) +(add-to-list 'load-path (expand-file-name "./")) +(require 'package) +(package-generate-autoloads 'clojure-mode default-directory) +(package-initialize) +(load-file "clojure-mode-autoloads.el") +(setq byte-compile-error-on-warn t) +(batch-byte-compile) + +;;; clojure-mode-bytecomp-warnings.el ends here diff --git a/test-checks.el b/test-checks.el new file mode 100644 index 0000000..ad23c36 --- /dev/null +++ b/test-checks.el @@ -0,0 +1,30 @@ +;; This is a script to be loaded from the root `clojure-mode' directory. It will +;; prepare all requirements and then run `check-declare-directory' on +;; `default-directory'. For example: emacs -Q --batch -l test/test-checkdoc.el + +;; This assumes that all `clojure-mode' dependencies are already on the package +;; dir (probably from running `cask install'). + +(add-to-list 'load-path (expand-file-name "./")) +(require 'package) +(require 'check-declare) +(package-initialize) + +;; disable some annoying (or non-applicable) checkdoc checks +(setq checkdoc-package-keywords-flag nil) +(setq checkdoc-arguments-in-order-flag nil) +(setq checkdoc-verb-check-experimental-flag nil) + +(let ((files (directory-files default-directory t + "\\`[^.].*\\.el\\'" t))) + + ;; `checkdoc-file' was introduced in Emacs 25 + (when (fboundp 'checkdoc-file) + (dolist (file files) + (checkdoc-file file)) + (when (get-buffer "*Warnings*") + (message "Failing due to checkdoc warnings...") + (kill-emacs 1))) + + (when (apply #'check-declare-files files) + (kill-emacs 1))) From f92e7a99a82610590d92c82d3344889c35a2c4c7 Mon Sep 17 00:00:00 2001 From: Vitalie Spinu Date: Sat, 5 Aug 2017 14:53:54 +0200 Subject: [PATCH 110/199] Add doc-string tests --- clojure-mode-syntax-test.el | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/clojure-mode-syntax-test.el b/clojure-mode-syntax-test.el index 4cf5f35..6a7f03b 100644 --- a/clojure-mode-syntax-test.el +++ b/clojure-mode-syntax-test.el @@ -68,6 +68,7 @@ (insert (car form)) (equal (symbol-name (symbol-at-point)) (cdr form))))) + (ert-deftest clojure-syntax-skip-prefixes () (dolist (form '("#?@aaa" "#?aaa" "#aaa" "'aaa")) (with-temp-buffer @@ -105,4 +106,32 @@ (let ((fill-column 80)) (fill-paragraph))) +(when (fboundp 'font-lock-ensure) + (def-refactor-test test-paragraph-fill-not-altering-surrounding-code + "(def my-example-variable + \"It has a very long docstring. So long, in fact, that it wraps onto multiple lines! This is to demonstrate what happens when the docstring wraps over three lines.\" + nil)" + "(def my-example-variable + \"It has a very long docstring. So long, in fact, that it wraps onto multiple + lines! This is to demonstrate what happens when the docstring wraps over three + lines.\" + nil)" + (font-lock-ensure) + (goto-char 40) + (let ((clojure-docstring-fill-column 80) + (fill-column 80)) + (fill-paragraph))) + + (ert-deftest test-clojure-in-docstring-p () + (with-temp-buffer + (insert "(def my-example-variable + \"Doc here and `doc-here`\" + nil)") + (clojure-mode) + (font-lock-ensure) + (goto-char 32) + (should (clojure-in-docstring-p)) + (goto-char 46) + (should (clojure-in-docstring-p))))) + (provide 'clojure-mode-syntax-test) From fb88b3b3c8a48c62bcc43f2793c0595cf0a6ad7a Mon Sep 17 00:00:00 2001 From: Tianxiang Xiong Date: Tue, 31 Oct 2017 02:16:32 -0700 Subject: [PATCH 111/199] Move to top-level before `re-search-backward` in `clojure-find-ns` Moving to top level avoids improper matching behavior due to being in middle of match. Fix clojure-emacs/cider#2100 --- clojure-mode-sexp-test.el | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/clojure-mode-sexp-test.el b/clojure-mode-sexp-test.el index 9e30ddc..dec29f4 100644 --- a/clojure-mode-sexp-test.el +++ b/clojure-mode-sexp-test.el @@ -75,6 +75,26 @@ (insert "(+ 10") (newline-and-indent))) +(ert-deftest clojure-find-ns-test () + (with-temp-buffer + (insert "(ns ^{:doc \"Some docs\"}\nfoo-bar)") + (newline) + (newline) + (insert "(in-ns 'baz-quux)") + (clojure-mode) + + ;; From inside docstring of first ns + (goto-char 18) + (should (equal "foo-bar" (clojure-find-ns))) + + ;; From inside first ns's name, on its own line + (goto-char 29) + (should (equal "foo-bar" (clojure-find-ns))) + + ;; From inside second ns's name + (goto-char 42) + (should (equal "baz-quux" (clojure-find-ns))))) + (provide 'clojure-mode-sexp-test) ;;; clojure-mode-sexp-test.el ends here From 5e5dbef03ece60dd143fdc7974e5b22a69dd0de1 Mon Sep 17 00:00:00 2001 From: Bozhidar Batsov Date: Sun, 14 Jan 2018 19:11:15 +0200 Subject: [PATCH 112/199] Bump the copyright years --- clojure-mode-bytecomp-warnings.el | 2 +- clojure-mode-convert-collection-test.el | 2 +- clojure-mode-cycling-test.el | 2 +- clojure-mode-font-lock-test.el | 2 +- clojure-mode-indentation-test.el | 2 +- clojure-mode-refactor-let-test.el | 2 +- clojure-mode-refactor-threading-test.el | 2 +- clojure-mode-sexp-test.el | 2 +- clojure-mode-syntax-test.el | 2 +- clojure-mode-util-test.el | 2 +- test-helper.el | 2 +- 11 files changed, 11 insertions(+), 11 deletions(-) diff --git a/clojure-mode-bytecomp-warnings.el b/clojure-mode-bytecomp-warnings.el index 1096a53..67c5a03 100644 --- a/clojure-mode-bytecomp-warnings.el +++ b/clojure-mode-bytecomp-warnings.el @@ -1,6 +1,6 @@ ;;; clojure-mode-bytecomp-warnings.el --- Check for byte-compilation problems -;; Copyright © 2012-2017 Bozhidar Batsov and contributors +;; Copyright © 2012-2018 Bozhidar Batsov and contributors ;; ;; This program is free software: you can redistribute it and/or modify ;; it under the terms of the GNU General Public License as published by diff --git a/clojure-mode-convert-collection-test.el b/clojure-mode-convert-collection-test.el index 685536e..790b6b6 100644 --- a/clojure-mode-convert-collection-test.el +++ b/clojure-mode-convert-collection-test.el @@ -1,6 +1,6 @@ ;;; clojure-mode-convert-collection-test.el --- Clojure Mode: convert collection type -*- lexical-binding: t; -*- -;; Copyright (C) 2016-2017 Benedek Fazekas +;; Copyright (C) 2016-2018 Benedek Fazekas ;; This file is not part of GNU Emacs. diff --git a/clojure-mode-cycling-test.el b/clojure-mode-cycling-test.el index 5e40885..bf3e0ef 100644 --- a/clojure-mode-cycling-test.el +++ b/clojure-mode-cycling-test.el @@ -1,6 +1,6 @@ ;;; clojure-mode-cycling-test.el --- Clojure Mode: cycling things tests -*- lexical-binding: t; -*- -;; Copyright (C) 2016-2017 Benedek Fazekas +;; Copyright (C) 2016-2018 Benedek Fazekas ;; This file is not part of GNU Emacs. diff --git a/clojure-mode-font-lock-test.el b/clojure-mode-font-lock-test.el index 8e5d0bd..ad84fd0 100644 --- a/clojure-mode-font-lock-test.el +++ b/clojure-mode-font-lock-test.el @@ -1,6 +1,6 @@ ;;; clojure-mode-font-lock-test.el --- Clojure Mode: Font lock test suite -*- lexical-binding: t; -*- -;; Copyright (C) 2014-2017 Bozhidar Batsov +;; Copyright (C) 2014-2018 Bozhidar Batsov ;; This file is not part of GNU Emacs. diff --git a/clojure-mode-indentation-test.el b/clojure-mode-indentation-test.el index 936fc0b..71e4ab5 100644 --- a/clojure-mode-indentation-test.el +++ b/clojure-mode-indentation-test.el @@ -1,6 +1,6 @@ ;;; clojure-mode-indentation-test.el --- Clojure Mode: indentation tests -*- lexical-binding: t; -*- -;; Copyright (C) 2015-2017 Bozhidar Batsov +;; Copyright (C) 2015-2018 Bozhidar Batsov ;; This file is not part of GNU Emacs. diff --git a/clojure-mode-refactor-let-test.el b/clojure-mode-refactor-let-test.el index 6fe55b3..8aec3d2 100644 --- a/clojure-mode-refactor-let-test.el +++ b/clojure-mode-refactor-let-test.el @@ -1,6 +1,6 @@ ;;; clojure-mode-refactor-let-test.el --- Clojure Mode: refactor let -*- lexical-binding: t; -*- -;; Copyright (C) 2016-2017 Benedek Fazekas +;; Copyright (C) 2016-2018 Benedek Fazekas ;; This file is not part of GNU Emacs. diff --git a/clojure-mode-refactor-threading-test.el b/clojure-mode-refactor-threading-test.el index c54c300..95e675b 100644 --- a/clojure-mode-refactor-threading-test.el +++ b/clojure-mode-refactor-threading-test.el @@ -1,6 +1,6 @@ ;;; clojure-mode-refactor-threading-test.el --- Clojure Mode: refactor threading tests -*- lexical-binding: t; -*- -;; Copyright (C) 2016-2017 Benedek Fazekas +;; Copyright (C) 2016-2018 Benedek Fazekas ;; This file is not part of GNU Emacs. diff --git a/clojure-mode-sexp-test.el b/clojure-mode-sexp-test.el index dec29f4..a9a5425 100644 --- a/clojure-mode-sexp-test.el +++ b/clojure-mode-sexp-test.el @@ -1,6 +1,6 @@ ;;; clojure-mode-sexp-test.el --- Clojure Mode: sexp tests -*- lexical-binding: t; -*- -;; Copyright (C) 2015-2017 Artur Malabarba +;; Copyright (C) 2015-2018 Artur Malabarba ;; This file is not part of GNU Emacs. diff --git a/clojure-mode-syntax-test.el b/clojure-mode-syntax-test.el index 6a7f03b..2ea590c 100644 --- a/clojure-mode-syntax-test.el +++ b/clojure-mode-syntax-test.el @@ -1,6 +1,6 @@ ;;; clojure-mode-syntax-test.el --- Clojure Mode: syntax related tests -*- lexical-binding: t; -*- -;; Copyright (C) 2015-2017 Bozhidar Batsov +;; Copyright (C) 2015-2018 Bozhidar Batsov ;; This file is not part of GNU Emacs. diff --git a/clojure-mode-util-test.el b/clojure-mode-util-test.el index 32fd5a3..b028d30 100644 --- a/clojure-mode-util-test.el +++ b/clojure-mode-util-test.el @@ -1,6 +1,6 @@ ;;; clojure-mode-util-test.el --- Clojure Mode: util test suite -*- lexical-binding: t; -*- -;; Copyright (C) 2014-2017 Bozhidar Batsov +;; Copyright (C) 2014-2018 Bozhidar Batsov ;; This file is not part of GNU Emacs. diff --git a/test-helper.el b/test-helper.el index d1173cc..1c98eb3 100644 --- a/test-helper.el +++ b/test-helper.el @@ -1,6 +1,6 @@ ;;; test-helper.el --- Clojure Mode: Non-interactive unit-test setup -*- lexical-binding: t; -*- -;; Copyright (C) 2014-2017 Bozhidar Batsov +;; Copyright (C) 2014-2018 Bozhidar Batsov ;; This file is not part of GNU Emacs. From 8cb977506ab326245a98d95e142672c27f13bca1 Mon Sep 17 00:00:00 2001 From: Bozhidar Batsov Date: Sun, 21 Jan 2018 20:11:48 +0200 Subject: [PATCH 113/199] Drop support for cljx Clojure 1.7 has been around for 3 years now and it's pretty safe to assume almost no one is still using cljx at this point. --- clojure-mode-font-lock-test.el | 26 -------------------------- 1 file changed, 26 deletions(-) diff --git a/clojure-mode-font-lock-test.el b/clojure-mode-font-lock-test.el index ad84fd0..9716d15 100644 --- a/clojure-mode-font-lock-test.el +++ b/clojure-mode-font-lock-test.el @@ -41,17 +41,6 @@ (goto-char (point-min)) ,@body)) -(defmacro clojurex-test-with-temp-buffer (content &rest body) - "Evaluate BODY in a temporary buffer with CONTENTS." - (declare (debug t) - (indent 1)) - `(with-temp-buffer - (insert ,content) - (clojurex-mode) - (font-lock-fontify-buffer) - (goto-char (point-min)) - ,@body)) - (defun clojure-get-face-at-range (start end) (let ((start-face (get-text-property start 'face)) (all-faces (cl-loop for i from start to end collect (get-text-property i 'face)))) @@ -69,16 +58,6 @@ buffer." (clojure-get-face-at-range start end)) (clojure-get-face-at-range start end))) -(defun clojurex-test-face-at (start end &optional content) - "Get the face between START and END in CONTENT. - -If CONTENT is not given, return the face at the specified range in the current -buffer." - (if content - (clojurex-test-with-temp-buffer content - (clojure-get-face-at-range start end)) - (clojure-get-face-at-range start end))) - (defconst clojure-test-syntax-classes [whitespace punctuation word symbol open-paren close-paren expression-prefix string-quote paired-delim escape character-quote comment-start @@ -322,11 +301,6 @@ POS." (should (eq (clojure-test-face-at 1 2 "\\,") 'clojure-character-face)) (should (eq (clojure-test-face-at 1 2 "\\;") 'clojure-character-face))) -(ert-deftest clojurex-mode-syntax-table/cljx () - :tags '(fontification syntax-table) - (should (eq (clojurex-test-face-at 1 5 "#+clj x") 'font-lock-preprocessor-face)) - (should (eq (clojurex-test-face-at 1 6 "#+cljs x") 'font-lock-preprocessor-face))) - (ert-deftest clojure-mode-syntax-table/refer-ns () :tags '(fontification syntax-table) (should (eq (clojure-test-face-at 1 3 "foo/var") 'font-lock-type-face)) From c0c74f61e079a79840193a4eac116ccc59600efe Mon Sep 17 00:00:00 2001 From: Evan Moses Date: Mon, 12 Mar 2018 10:37:04 -0700 Subject: [PATCH 114/199] [Fix #471] Add support for tagged maps (#472) --- clojure-mode-syntax-test.el | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/clojure-mode-syntax-test.el b/clojure-mode-syntax-test.el index 2ea590c..829dfba 100644 --- a/clojure-mode-syntax-test.el +++ b/clojure-mode-syntax-test.el @@ -78,6 +78,20 @@ (backward-prefix-chars) (should (bobp))))) + +(ert-deftest clojure-allowed-collection-tags () + (dolist (tag '("#::ns" "#:ns" "#ns" "#:f.q/ns" "#f.q/ns" "#::")) + (with-temp-buffer + (clojure-mode) + (insert tag) + (should-not (clojure-no-space-after-tag nil ?{)))) + (dolist (tag '("#$:" "#/f" "#:/f" "#::f.q/ns" "::ns" "::" "#f:ns")) + (with-temp-buffer + (clojure-mode) + (insert tag) + (should (clojure-no-space-after-tag nil ?{))))) + + (def-refactor-test test-paragraph-fill-within-comments " ;; Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt From b2f207f09d2e5f8415baabdcedb7b7740e0a48d2 Mon Sep 17 00:00:00 2001 From: Rostislav Svoboda Date: Sun, 19 Nov 2017 17:09:06 +0100 Subject: [PATCH 115/199] Comment out failing tests --- clojure-mode-font-lock-test.el | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/clojure-mode-font-lock-test.el b/clojure-mode-font-lock-test.el index 9716d15..e9ec147 100644 --- a/clojure-mode-font-lock-test.el +++ b/clojure-mode-font-lock-test.el @@ -121,7 +121,8 @@ POS." (ert-deftest clojure-mode-syntax-table/comment-macros () :tags '(fontification syntax-table) (should (not (clojure-test-face-at 1 2 "#_ \n;; some crap\n (lala 0101\n lao\n\n 0 0i)"))) - (should (equal (clojure-test-face-at 5 41 "#_ \n;; some crap\n (lala 0101\n lao\n\n 0 0i)") 'font-lock-comment-face))) + ;; (should (equal (clojure-test-face-at 5 41 "#_ \n;; some crap\n (lala 0101\n lao\n\n 0 0i)") 'font-lock-comment-face)) ; TODO failing test + ) (ert-deftest clojure-mode-syntax-table/type () :tags '(fontification syntax-table) @@ -247,7 +248,7 @@ POS." (ert-deftest clojure-mode-syntax-table/fn () :tags '(fontification syntax-table) (clojure-test-with-temp-buffer "(fn foo [x] x)" - (should (eq (clojure-test-face-at 2 3) 'font-lock-keyword-face)) + ;; (should (eq (clojure-test-face-at 2 3) 'font-lock-keyword-face)) ; TODO failing test (should (eq (clojure-test-face-at 5 7) 'font-lock-function-name-face)))) (ert-deftest clojure-mode-syntax-table/lambda-params () @@ -294,7 +295,7 @@ POS." :tags '(fontification syntax-table) (should (eq (clojure-test-face-at 1 2 "\\a") 'clojure-character-face)) (should (eq (clojure-test-face-at 1 8 "\\newline") 'clojure-character-face)) - (should (eq (clojure-test-face-at 1 2 "\\1") 'clojure-character-face)) + ;; (should (eq (clojure-test-face-at 1 2 "\\1") 'clojure-character-face)) ; TODO failing test (should (eq (clojure-test-face-at 1 6 "\\u0032") 'clojure-character-face)) (should (eq (clojure-test-face-at 1 2 "\\+") 'clojure-character-face)) (should (eq (clojure-test-face-at 1 2 "\\.") 'clojure-character-face)) @@ -316,7 +317,8 @@ POS." :tags '(fontification syntax-table) (should (eq (clojure-test-face-at 5 8 "(ns name)") 'font-lock-type-face)) (should (eq (clojure-test-face-at 5 13 "(ns name.name)") 'font-lock-type-face)) - (should (eq (clojure-test-face-at 1 10 "[ns name]") nil))) + ;; (should (eq (clojure-test-face-at 1 10 "[ns name]") nil)) ; TODO failing test + ) (provide 'clojure-mode-font-lock-test) From 32694c2d01d7bd6994e2e447a4a6b1d5b25a5e52 Mon Sep 17 00:00:00 2001 From: Rostislav Svoboda Date: Mon, 6 Nov 2017 18:10:27 +0100 Subject: [PATCH 116/199] Numerous font-locking fixes and improvements * s/clojure-interop-method-face/font-lock-type-face * keyword font-locking * visual examples w/ ert tests * fix failing ert tests --- clojure-mode-font-lock-test.el | 696 +++++++++++++++++++++++++++------ 1 file changed, 566 insertions(+), 130 deletions(-) diff --git a/clojure-mode-font-lock-test.el b/clojure-mode-font-lock-test.el index e9ec147..6e36ebd 100644 --- a/clojure-mode-font-lock-test.el +++ b/clojure-mode-font-lock-test.el @@ -1,4 +1,5 @@ -;;; clojure-mode-font-lock-test.el --- Clojure Mode: Font lock test suite -*- lexical-binding: t; -*- +;;; clojure-mode-font-lock-test.el --- Clojure Mode: Font lock test suite +;; -*- lexical-binding: t; -*- ;; Copyright (C) 2014-2018 Bozhidar Batsov @@ -43,7 +44,8 @@ (defun clojure-get-face-at-range (start end) (let ((start-face (get-text-property start 'face)) - (all-faces (cl-loop for i from start to end collect (get-text-property i 'face)))) + (all-faces (cl-loop for i from start to end collect (get-text-property + i 'face)))) (if (cl-every (lambda (face) (eq face start-face)) all-faces) start-face 'various-faces))) @@ -78,123 +80,555 @@ POS." ;;;; Font locking -(ert-deftest clojure-mode-syntax-table/fontify-clojure-keyword () - :tags '(fontification syntax-table) - (should (equal (clojure-test-face-at 2 11 "{:something 20}") '(clojure-keyword-face)))) - (ert-deftest clojure-mode-syntax-table/stuff-in-backticks () :tags '(fontification syntax-table) - (should (equal (clojure-test-face-at 1 2 "\"`#'s/trim`\"") font-lock-string-face)) - (should (equal (clojure-test-face-at 3 10 "\"`#'s/trim`\"") '(font-lock-constant-face font-lock-string-face))) - (should (equal (clojure-test-face-at 11 12 "\"`#'s/trim`\"") font-lock-string-face)) - (should (equal (clojure-test-face-at 1 1 ";`#'s/trim`") font-lock-comment-delimiter-face)) - (should (equal (clojure-test-face-at 2 2 ";`#'s/trim`") font-lock-comment-face)) - (should (equal (clojure-test-face-at 3 10 ";`#'s/trim`") '(font-lock-constant-face font-lock-comment-face))) - (should (equal (clojure-test-face-at 11 11 ";`#'s/trim`") font-lock-comment-face))) + (should (equal (clojure-test-face-at 1 2 "\"`#'s/trim`\"") + font-lock-string-face)) + (should (equal (clojure-test-face-at 3 10 "\"`#'s/trim`\"") + '(font-lock-constant-face font-lock-string-face))) + (should (equal (clojure-test-face-at 11 12 "\"`#'s/trim`\"") + font-lock-string-face)) + (should (equal (clojure-test-face-at 1 1 ";`#'s/trim`") + font-lock-comment-delimiter-face)) + (should (equal (clojure-test-face-at 2 2 ";`#'s/trim`") + font-lock-comment-face)) + (should (equal (clojure-test-face-at 3 10 ";`#'s/trim`") + '(font-lock-constant-face font-lock-comment-face))) + (should (equal (clojure-test-face-at 11 11 ";`#'s/trim`") + font-lock-comment-face))) (ert-deftest clojure-mode-syntax-table/stuff-in-backticks () :tags '(fontification syntax-table) - (should (equal (clojure-test-face-at 1 2 "\"a\\bc\\n\"") font-lock-string-face)) - (should (equal (clojure-test-face-at 3 4 "\"a\\bc\\n\"") '(bold font-lock-string-face))) - (should (equal (clojure-test-face-at 5 5 "\"a\\bc\\n\"") font-lock-string-face)) - (should (equal (clojure-test-face-at 6 7 "\"a\\bc\\n\"") '(bold font-lock-string-face))) - (should (equal (clojure-test-face-at 4 5 "#\"a\\bc\\n\"") '(bold font-lock-string-face)))) - -(ert-deftest clojure-mode-syntax-table/fontify-namespaced-keyword () - :tags '(fontification syntax-table) - (should (equal (clojure-test-face-at 9 11 "(:alias/def x 10)") '(clojure-keyword-face))) - (should (equal (clojure-test-face-at 2 2 "{:alias/some 20}") '(clojure-keyword-face))) - (should (equal (clojure-test-face-at 3 7 "{:alias/some 20}") '(font-lock-type-face clojure-keyword-face))) - (should (equal (clojure-test-face-at 8 8 "{:alias/some 20}") '(default clojure-keyword-face))) - (should (equal (clojure-test-face-at 9 12 "{:alias/some 20}") '(clojure-keyword-face))) - (should (equal (clojure-test-face-at 2 2 "{:a.ias/some 20}") '(clojure-keyword-face))) - (should (equal (clojure-test-face-at 3 7 "{:a.ias/some 20}") '(font-lock-type-face clojure-keyword-face))) - (should (equal (clojure-test-face-at 8 8 "{:a.ias/some 20}") '(default clojure-keyword-face))) - (should (equal (clojure-test-face-at 9 12 "{:a.ias/some 20}") '(clojure-keyword-face)))) + (should (equal (clojure-test-face-at 1 2 "\"a\\bc\\n\"") + font-lock-string-face)) + (should (equal (clojure-test-face-at 3 4 "\"a\\bc\\n\"") + '(bold font-lock-string-face))) + (should (equal (clojure-test-face-at 5 5 "\"a\\bc\\n\"") + font-lock-string-face)) + (should (equal (clojure-test-face-at 6 7 "\"a\\bc\\n\"") + '(bold font-lock-string-face))) + (should (equal (clojure-test-face-at 4 5 "#\"a\\bc\\n\"") + '(bold font-lock-string-face)))) (ert-deftest clojure-mode-syntax-table/fontify-let-when-while-type-forms () :tags '(fontification syntax-table) - (should (equal (clojure-test-face-at 2 11 "(when-alist [x 1]\n ())") 'font-lock-keyword-face)) - (should (equal (clojure-test-face-at 2 12 "(while-alist [x 1]\n ())") 'font-lock-keyword-face)) - (should (equal (clojure-test-face-at 2 10 "(let-alist [x 1]\n ())") 'font-lock-keyword-face))) + (should (equal (clojure-test-face-at 2 11 "(when-alist [x 1]\n ())") + 'font-lock-keyword-face)) + (should (equal (clojure-test-face-at 2 12 "(while-alist [x 1]\n ())") + 'font-lock-keyword-face)) + (should (equal (clojure-test-face-at 2 10 "(let-alist [x 1]\n ())") + 'font-lock-keyword-face))) (ert-deftest clojure-mode-syntax-table/comment-macros () :tags '(fontification syntax-table) - (should (not (clojure-test-face-at 1 2 "#_ \n;; some crap\n (lala 0101\n lao\n\n 0 0i)"))) - ;; (should (equal (clojure-test-face-at 5 41 "#_ \n;; some crap\n (lala 0101\n lao\n\n 0 0i)") 'font-lock-comment-face)) ; TODO failing test - ) - -(ert-deftest clojure-mode-syntax-table/type () - :tags '(fontification syntax-table) - (should (eq (clojure-test-face-at 1 9 "SomeClass") 'font-lock-type-face))) - -(ert-deftest clojure-mode-syntax-table/type-hint () - :tags '(fontification syntax-table) - (clojure-test-with-temp-buffer "#^SomeClass" - (should (eq (clojure-test-face-at 3 11) 'font-lock-type-face)) - (should (eq (clojure-test-face-at 1 2) nil)))) - -(ert-deftest clojure-mode-syntax-table/constructor () - :tags '(fontification syntax-table) - (should (eq (clojure-test-face-at 2 11 "(SomeClass.)") 'font-lock-type-face)) - (clojure-test-with-temp-buffer "(ns/SomeClass.)" - (should (eq (clojure-test-face-at 2 3) 'font-lock-type-face)) - (should (eq (clojure-test-face-at 5 14) 'font-lock-type-face)))) + (should (equal (clojure-test-face-at + 1 2 "#_") + 'default)) + (should (equal (clojure-test-face-at + 1 2 "#_ \n;; some crap\n (lala 0101\n lao\n\n 0 0i)") + 'default)) + (should (equal (clojure-test-face-at + 5 41 "#_ \n;; some crap\n (lala 0101\n lao\n\n 0 0i)") + 'font-lock-comment-face))) (ert-deftest clojure-mode-syntax-table/namespace () :tags '(fontification syntax-table) - (should (eq (clojure-test-face-at 1 5 "one.p") 'font-lock-type-face)) - (should (eq (clojure-test-face-at 1 11 "one.p.top13") 'font-lock-type-face)) - (should (eq (clojure-test-face-at 2 12 "^one.p.top13") 'font-lock-type-face))) - -(ert-deftest clojure-mode-syntax-table/namespaced-symbol () - :tags '(fontification syntax-table) - (clojure-test-with-temp-buffer "clo.core/something" - (should (eq (clojure-test-face-at 9 9) 'default)) - (should (eq (clojure-test-face-at 1 8) 'font-lock-type-face)) - (should (eq (clojure-test-face-at 10 18) nil))) - (clojure-test-with-temp-buffer "a/something" - (should (eq (clojure-test-face-at 1 1) 'font-lock-type-face)) - (should (eq (clojure-test-face-at 3 12) 'nil)) - (should (eq (clojure-test-face-at 2 2) 'default))) - (clojure-test-with-temp-buffer "abc/something" - (should (eq (clojure-test-face-at 1 3) 'font-lock-type-face)) - (should (eq (clojure-test-face-at 5 14) 'nil)) - (should (eq (clojure-test-face-at 4 4) 'default)))) - -(ert-deftest clojure-mode-syntax-table/static-method () - :tags '(fontification syntax-table) - (clojure-test-with-temp-buffer "Class/methodName" - (should (eq (clojure-test-face-at 1 5) 'font-lock-type-face)) - (should (eq (clojure-test-face-at 6 6) 'default)) - (should (eq (clojure-test-face-at 7 16) 'clojure-interop-method-face))) - (clojure-test-with-temp-buffer "SomeClass/methodName" - (should (eq (clojure-test-face-at 1 9) 'font-lock-type-face)) - (should (eq (clojure-test-face-at 10 10) 'default)) - (should (eq (clojure-test-face-at 11 20) 'clojure-interop-method-face))) - (clojure-test-with-temp-buffer "clojure.lang.Var/someMethod" - (should (eq (clojure-test-face-at 1 16) 'font-lock-type-face)) - (should (eq (clojure-test-face-at 17 17) 'default)) - (should (eq (clojure-test-face-at 18 27) 'clojure-interop-method-face)))) - -(ert-deftest clojure-mode-syntax-table/interop-method () - :tags '(fontification syntax-table) - (should (eq (clojure-test-face-at 1 11 ".someMethod") 'clojure-interop-method-face)) - (should (eq (clojure-test-face-at 1 10 "someMethod") 'clojure-interop-method-face)) - (should (eq (clojure-test-face-at 1 11 "topHttpTest") 'clojure-interop-method-face)) - (should (eq (clojure-test-face-at 1 4 "getX") 'clojure-interop-method-face))) - -(ert-deftest clojure-mode-syntax-table/constant () - :tags '(fontification syntax-table) - (should (eq (clojure-test-face-at 1 5 "CONST") 'font-lock-constant-face)) - (should (eq (clojure-test-face-at 1 10 "CONST_NAME") 'font-lock-constant-face))) - -(ert-deftest clojure-mode-syntax-table/class-constant () - :tags '(fontification syntax-table) - (clojure-test-with-temp-buffer "Class/CONST_NAME" - (should (eq (clojure-test-face-at 6 6) 'default)) - (should (eq (clojure-test-face-at 1 5) 'font-lock-type-face)) - (should (eq (clojure-test-face-at 7 16) 'font-lock-constant-face)))) + (should (eq (clojure-test-face-at 5 12 "(ns .validns)") 'font-lock-type-face)) + (should (eq (clojure-test-face-at 5 12 "(ns =validns)") 'font-lock-type-face)) + (should (eq (clojure-test-face-at 5 21 "(ns .ValidNs=<>?+|?*.)") + 'font-lock-type-face)) + (should (eq (clojure-test-face-at 5 28 "(ns ValidNs<>?+|?*.b*ar.ba*z)") + 'font-lock-type-face)) + (should (eq (clojure-test-face-at 5 18 "(ns other.valid.ns)") + 'font-lock-type-face)) + (should (eq (clojure-test-face-at 5 11 "(ns oneword)") 'font-lock-type-face)) + (should (eq (clojure-test-face-at 5 11 "(ns foo.bar)") 'font-lock-type-face)) + (should (eq (clojure-test-face-at 5 11 "(ns Foo.bar)") 'font-lock-type-face)) + (should (eq (clojure-test-face-at 5 11 "(ns Foo.Bar)") 'font-lock-type-face)) + (should (eq (clojure-test-face-at 5 11 "(ns foo.Bar)") 'font-lock-type-face)) + (should (eq (clojure-test-face-at 5 11 "(ns Foo-bar)") 'font-lock-type-face)) + (should (eq (clojure-test-face-at 5 11 "(ns Foo-Bar)") 'font-lock-type-face)) + (should (eq (clojure-test-face-at 5 11 "(ns foo-Bar)") 'font-lock-type-face)) + (should (eq (clojure-test-face-at 5 9 "(ns one.X)") 'font-lock-type-face))) + +(ert-deftest clojure-mode-syntax-table/oneword () + :tags '(fontification syntax-table) + (should (eq (clojure-test-face-at 2 8 " oneword") 'default)) + (should (eq (clojure-test-face-at 2 8 "@oneword") 'default)) + (should (eq (clojure-test-face-at 2 8 "#oneword") 'default)) + (should (eq (clojure-test-face-at 2 8 ".oneword") 'default)) + (should (eq (clojure-test-face-at 3 9 "#^oneword") + 'font-lock-type-face)) ;; type-hint + (should (eq (clojure-test-face-at 2 8 "(oneword)") 'default)) + + (should (eq (clojure-test-face-at 2 8 "(oneword/oneword)") + 'font-lock-type-face)) + (should (eq (clojure-test-face-at 9 10 "(oneword/oneword)") 'default)) + (should (eq (clojure-test-face-at 11 16 "(oneword/oneword)") 'default)) + + (should (eq (clojure-test-face-at 2 8 "(oneword/seg.mnt)") + 'font-lock-type-face)) + (should (eq (clojure-test-face-at 9 10 "(oneword/seg.mnt)") 'default)) + (should (eq (clojure-test-face-at 11 16 "(oneword/seg.mnt)") 'default)) + + (should (eq (clojure-test-face-at 2 8 "(oneword/mxdCase)") + 'font-lock-type-face)) + (should (eq (clojure-test-face-at 9 10 "(oneword/mxdCase)") 'default)) + (should (eq (clojure-test-face-at 11 16 "(oneword/mxdCase)") 'default)) + + (should (eq (clojure-test-face-at 2 8 "(oneword/CmlCase)") + 'font-lock-type-face)) + (should (eq (clojure-test-face-at 9 10 "(oneword/CmlCase)") 'default)) + (should (eq (clojure-test-face-at 11 16 "(oneword/CmlCase)") 'default)) + + (should (eq (clojure-test-face-at 2 8 "(oneword/veryCom|pLex.stu-ff)") + 'font-lock-type-face)) + (should (eq (clojure-test-face-at 9 10 "(oneword/veryCom|pLex.stu-ff)") + 'default)) + (should (eq (clojure-test-face-at 11 28 "(oneword/veryCom|pLex.stu-ff)") + 'default)) + + (should (eq (clojure-test-face-at 2 8 "(oneword/.veryCom|pLex.stu-ff)") + 'font-lock-type-face)) + (should (eq (clojure-test-face-at 9 10 "(oneword/.veryCom|pLex.stu-ff)") + 'default)) + (should (eq (clojure-test-face-at 12 29 "(oneword/.veryCom|pLex.stu-ff)") + 'default))) + +(ert-deftest clojure-mode-syntax-table/segment () + :tags '(fontification syntax-table) + (should (eq (clojure-test-face-at 2 8 " seg.mnt") 'default)) + (should (eq (clojure-test-face-at 2 8 "@seg.mnt") 'default)) + (should (eq (clojure-test-face-at 2 8 "#seg.mnt") 'default)) + (should (eq (clojure-test-face-at 2 8 ".seg.mnt") 'default)) + (should (eq (clojure-test-face-at 3 9 "#^seg.mnt") + 'font-lock-type-face)) ;; type-hint + (should (eq (clojure-test-face-at 2 8 "(seg.mnt)") 'default)) + (should (eq (clojure-test-face-at 2 8 "(seg.mnt/oneword)") + 'font-lock-type-face)) + (should (eq (clojure-test-face-at 9 10 "(seg.mnt/oneword)") 'default)) + (should (eq (clojure-test-face-at 11 16 "(seg.mnt/oneword)") 'default)) + + (should (eq (clojure-test-face-at 2 8 "(seg.mnt/seg.mnt)") + 'font-lock-type-face)) + (should (eq (clojure-test-face-at 9 10 "(seg.mnt/seg.mnt)") 'default)) + (should (eq (clojure-test-face-at 11 16 "(seg.mnt/seg.mnt)") 'default)) + + (should (eq (clojure-test-face-at 2 8 "(seg.mnt/mxdCase)") + 'font-lock-type-face)) + (should (eq (clojure-test-face-at 9 10 "(seg.mnt/mxdCase)") 'default)) + (should (eq (clojure-test-face-at 11 16 "(seg.mnt/mxdCase)") 'default)) + + (should (eq (clojure-test-face-at 2 8 "(seg.mnt/CmlCase)") + 'font-lock-type-face)) + (should (eq (clojure-test-face-at 9 10 "(seg.mnt/CmlCase)") 'default)) + (should (eq (clojure-test-face-at 11 16 "(seg.mnt/CmlCase)") 'default)) + + (should (eq (clojure-test-face-at 2 8 "(seg.mnt/veryCom|pLex.stu-ff)") + 'font-lock-type-face)) + (should (eq (clojure-test-face-at 9 10 "(seg.mnt/veryCom|pLex.stu-ff)") + 'default)) + (should (eq (clojure-test-face-at 11 28 "(seg.mnt/veryCom|pLex.stu-ff)") + 'default)) + + (should (eq (clojure-test-face-at 2 8 "(seg.mnt/.veryCom|pLex.stu-ff)") + 'font-lock-type-face)) + (should (eq (clojure-test-face-at 9 10 "(seg.mnt/.veryCom|pLex.stu-ff)") + 'default)) + (should (eq (clojure-test-face-at 12 29 "(seg.mnt/.veryCom|pLex.stu-ff)") + 'default))) + +(ert-deftest clojure-mode-syntax-table/camelcase () + :tags '(fontification syntax-table) + (should (eq (clojure-test-face-at 2 8 " CmlCase") 'default)) + (should (eq (clojure-test-face-at 2 8 "@CmlCase") 'default)) + (should (eq (clojure-test-face-at 2 8 "#CmlCase") 'default)) + (should (eq (clojure-test-face-at 2 8 ".CmlCase") 'default)) + (should (eq (clojure-test-face-at 3 9 "#^CmlCase") + 'font-lock-type-face)) ;; type-hint + (should (eq (clojure-test-face-at 2 8 "(CmlCase)") 'default)) + + (should (eq (clojure-test-face-at 2 8 "(CmlCase/oneword)") + 'font-lock-type-face)) + (should (eq (clojure-test-face-at 9 10 "(CmlCase/oneword)") 'default)) + (should (eq (clojure-test-face-at 11 16 "(CmlCase/oneword)") 'default)) + + (should (eq (clojure-test-face-at 2 8 "(CmlCase/seg.mnt)") + 'font-lock-type-face)) + (should (eq (clojure-test-face-at 9 10 "(CmlCase/seg.mnt)") 'default)) + (should (eq (clojure-test-face-at 11 16 "(CmlCase/seg.mnt)") 'default)) + + (should (eq (clojure-test-face-at 2 8 "(CmlCase/mxdCase)") + 'font-lock-type-face)) + (should (eq (clojure-test-face-at 9 10 "(CmlCase/mxdCase)") 'default)) + (should (eq (clojure-test-face-at 11 16 "(CmlCase/mxdCase)") 'default)) + + (should (eq (clojure-test-face-at 2 8 "(CmlCase/CmlCase)") + 'font-lock-type-face)) + (should (eq (clojure-test-face-at 9 10 "(CmlCase/CmlCase)") 'default)) + (should (eq (clojure-test-face-at 11 16 "(CmlCase/CmlCase)") 'default)) + + (should (eq (clojure-test-face-at 2 8 "(CmlCase/veryCom|pLex.stu-ff)") + 'font-lock-type-face)) + (should (eq (clojure-test-face-at 9 10 "(CmlCase/veryCom|pLex.stu-ff)") + 'default)) + (should (eq (clojure-test-face-at 11 28 "(CmlCase/veryCom|pLex.stu-ff)") + 'default)) + + (should (eq (clojure-test-face-at 2 8 "(CmlCase/.veryCom|pLex.stu-ff)") + 'font-lock-type-face)) + (should (eq (clojure-test-face-at 9 10 "(CmlCase/.veryCom|pLex.stu-ff)") + 'default)) + (should (eq (clojure-test-face-at 12 29 "(CmlCase/.veryCom|pLex.stu-ff)") + 'default))) + +(ert-deftest clojure-mode-syntax-table/mixedcase () + :tags '(fontification syntax-table) + (should (eq (clojure-test-face-at 2 8 " mxdCase") 'default)) + (should (eq (clojure-test-face-at 2 8 "@mxdCase") 'default)) + (should (eq (clojure-test-face-at 2 8 "#mxdCase") 'default)) + (should (eq (clojure-test-face-at 2 8 ".mxdCase") 'default)) + (should (eq (clojure-test-face-at 3 9 "#^mxdCase") + 'font-lock-type-face)) ;; type-hint + (should (eq (clojure-test-face-at 2 8 "(mxdCase)") 'default)) + + (should (eq (clojure-test-face-at 2 8 "(mxdCase/oneword)") + 'font-lock-type-face)) + (should (eq (clojure-test-face-at 9 10 "(mxdCase/oneword)") 'default)) + (should (eq (clojure-test-face-at 11 16 "(mxdCase/oneword)") 'default)) + + (should (eq (clojure-test-face-at 2 8 "(mxdCase/seg.mnt)") + 'font-lock-type-face)) + (should (eq (clojure-test-face-at 9 10 "(mxdCase/seg.mnt)") 'default)) + (should (eq (clojure-test-face-at 11 16 "(mxdCase/seg.mnt)") 'default)) + + (should (eq (clojure-test-face-at 2 8 "(mxdCase/mxdCase)") + 'font-lock-type-face)) + (should (eq (clojure-test-face-at 9 10 "(mxdCase/mxdCase)") 'default)) + (should (eq (clojure-test-face-at 11 16 "(mxdCase/mxdCase)") 'default)) + + (should (eq (clojure-test-face-at 2 8 "(mxdCase/CmlCase)") + 'font-lock-type-face)) + (should (eq (clojure-test-face-at 9 10 "(mxdCase/CmlCase)") 'default)) + (should (eq (clojure-test-face-at 11 16 "(mxdCase/CmlCase)") 'default)) + + (should (eq (clojure-test-face-at 2 8 "(mxdCase/veryCom|pLex.stu-ff)") + 'font-lock-type-face)) + (should (eq (clojure-test-face-at 9 10 "(mxdCase/veryCom|pLex.stu-ff)") + 'default)) + (should (eq (clojure-test-face-at 11 28 "(mxdCase/veryCom|pLex.stu-ff)") + 'default)) + + (should (eq (clojure-test-face-at 2 8 "(mxdCase/.veryCom|pLex.stu-ff)") + 'font-lock-type-face)) + (should (eq (clojure-test-face-at 9 10 "(mxdCase/.veryCom|pLex.stu-ff)") + 'default)) + (should (eq (clojure-test-face-at 12 29 "(mxdCase/.veryCom|pLex.stu-ff)") + 'default))) + +(ert-deftest clojure-mode-syntax-table/verycomplex () + :tags '(fontification syntax-table) + (should (eq (clojure-test-face-at 3 21 " veryCom|pLex.stu-ff") 'default)) + (should (eq (clojure-test-face-at 3 21 " @veryCom|pLex.stu-ff") 'default)) + (should (eq (clojure-test-face-at 3 21 " #veryCom|pLex.stu-ff") 'default)) + (should (eq (clojure-test-face-at 3 21 " .veryCom|pLex.stu-ff") 'default)) + (should (eq (clojure-test-face-at 3 21 "#^veryCom|pLex.stu-ff") + 'font-lock-type-face)) ;; type-hint + (should (eq (clojure-test-face-at 3 21 " (veryCom|pLex.stu-ff)") 'default)) + + (should (eq (clojure-test-face-at 3 21 " (veryCom|pLex.stu-ff/oneword)") + 'font-lock-type-face)) + (should (eq (clojure-test-face-at 22 22 " (veryCom|pLex.stu-ff/oneword)") + 'default)) + (should (eq (clojure-test-face-at 23 29 " (veryCom|pLex.stu-ff/oneword)") + 'default)) + + (should (eq (clojure-test-face-at 3 21 " (veryCom|pLex.stu-ff/seg.mnt)") + 'font-lock-type-face)) + (should (eq (clojure-test-face-at 22 22 " (veryCom|pLex.stu-ff/seg.mnt)") + 'default)) + (should (eq (clojure-test-face-at 22 29 " (veryCom|pLex.stu-ff/seg.mnt)") + 'default)) + + (should (eq (clojure-test-face-at 3 21 " (veryCom|pLex.stu-ff/mxdCase)") + 'font-lock-type-face)) + (should (eq (clojure-test-face-at 22 22 " (veryCom|pLex.stu-ff/mxdCase)") + 'default)) + (should (eq (clojure-test-face-at 22 29 " (veryCom|pLex.stu-ff/mxdCase)") + 'default)) + + (should (eq (clojure-test-face-at 3 21 " (veryCom|pLex.stu-ff/CmlCase)") + 'font-lock-type-face)) + (should (eq (clojure-test-face-at 22 22 " (veryCom|pLex.stu-ff/CmlCase)") + 'default)) + (should (eq (clojure-test-face-at 22 29 " (veryCom|pLex.stu-ff/CmlCase)") + 'default)) + + (should (eq (clojure-test-face-at + 3 21 " (veryCom|pLex.stu-ff/veryCom|pLex.stu-ff)") + 'font-lock-type-face)) + (should (eq (clojure-test-face-at + 22 22 " (veryCom|pLex.stu-ff/veryCom|pLex.stu-ff)") + 'default)) + (should (eq (clojure-test-face-at + 23 41 " (veryCom|pLex.stu-ff/veryCom|pLex.stu-ff)") + 'default)) + + (should (eq (clojure-test-face-at + 3 21 " (veryCom|pLex.stu-ff/.veryCom|pLex.stu-ff)") + 'font-lock-type-face)) + (should (eq (clojure-test-face-at + 22 22 " (veryCom|pLex.stu-ff/.veryCom|pLex.stu-ff)") + 'default)) + (should (eq (clojure-test-face-at + 23 42 " (veryCom|pLex.stu-ff/.veryCom|pLex.stu-ff)") + 'default))) + +(ert-deftest clojure-mode-syntax-table/kw-oneword () + :tags '(fontification syntax-table) + (should (eq (clojure-test-face-at 3 9 " :oneword") 'clojure-keyword-face)) + (should (eq (clojure-test-face-at 3 9 "{:oneword 0}") + 'clojure-keyword-face)) + (should (eq (clojure-test-face-at 3 10 "{:#oneword 0}") + 'clojure-keyword-face)) + (should (eq (clojure-test-face-at 3 10 "{:.oneword 0}") + 'clojure-keyword-face)) + + (should (eq (clojure-test-face-at 3 9 "{:oneword/oneword 0}") + 'font-lock-type-face)) + (should (eq (clojure-test-face-at 10 10 "{:oneword/oneword 0}") 'default)) + (should (eq (clojure-test-face-at 11 17 "{:oneword/oneword 0}") + 'clojure-keyword-face)) + + (should (eq (clojure-test-face-at 3 9 "{:oneword/seg.mnt 0}") + 'font-lock-type-face)) + (should (eq (clojure-test-face-at 10 10 "{:oneword/seg.mnt 0}") 'default)) + (should (eq (clojure-test-face-at 11 17 "{:oneword/seg.mnt 0}") + 'clojure-keyword-face)) + + (should (eq (clojure-test-face-at 3 9 "{:oneword/CmlCase 0}") + 'font-lock-type-face)) + (should (eq (clojure-test-face-at 10 10 "{:oneword/CmlCase 0}") 'default)) + (should (eq (clojure-test-face-at 11 17 "{:oneword/CmlCase 0}") + 'clojure-keyword-face)) + + (should (eq (clojure-test-face-at 3 9 "{:oneword/mxdCase 0}") + 'font-lock-type-face)) + (should (eq (clojure-test-face-at 10 10 "{:oneword/mxdCase 0}") 'default)) + (should (eq (clojure-test-face-at 11 17 "{:oneword/mxdCase 0}") + 'clojure-keyword-face)) + + (should (eq (clojure-test-face-at 3 9 "{:oneword/veryCom|pLex.stu-ff 0}") + 'font-lock-type-face)) + (should (eq (clojure-test-face-at 10 10 "{:oneword/veryCom|pLex.stu-ff 0}") + 'default)) + (should (eq (clojure-test-face-at 11 29 "{:oneword/veryCom|pLex.stu-ff 0}") + 'clojure-keyword-face)) + + (should (eq (clojure-test-face-at 3 9 "{:oneword/.veryCom|pLex.stu-ff 0}") + 'font-lock-type-face)) + (should (eq (clojure-test-face-at 10 10 "{:oneword/.veryCom|pLex.stu-ff 0}") + 'default)) + (should (eq (clojure-test-face-at 11 30 "{:oneword/.veryCom|pLex.stu-ff 0}") + 'clojure-keyword-face))) + +(ert-deftest clojure-mode-syntax-table/kw-segment () + :tags '(fontification syntax-table) + (should (eq (clojure-test-face-at 3 9 " :seg.mnt") 'clojure-keyword-face)) + (should (eq (clojure-test-face-at 3 9 "{:seg.mnt 0}") + 'clojure-keyword-face)) + (should (eq (clojure-test-face-at 3 10 "{:#seg.mnt 0}") + 'clojure-keyword-face)) + (should (eq (clojure-test-face-at 3 10 "{:.seg.mnt 0}") + 'clojure-keyword-face)) + + (should (eq (clojure-test-face-at 3 9 "{:seg.mnt/oneword 0}") + 'font-lock-type-face)) + (should (eq (clojure-test-face-at 10 10 "{:seg.mnt/oneword 0}") 'default)) + (should (eq (clojure-test-face-at 11 17 "{:seg.mnt/oneword 0}") + 'clojure-keyword-face)) + + (should (eq (clojure-test-face-at 3 9 "{:seg.mnt/seg.mnt 0}") + 'font-lock-type-face)) + (should (eq (clojure-test-face-at 10 10 "{:seg.mnt/seg.mnt 0}") 'default)) + (should (eq (clojure-test-face-at 11 17 "{:seg.mnt/seg.mnt 0}") + 'clojure-keyword-face)) + + (should (eq (clojure-test-face-at 3 9 "{:seg.mnt/CmlCase 0}") + 'font-lock-type-face)) + (should (eq (clojure-test-face-at 10 10 "{:seg.mnt/CmlCase 0}") 'default)) + (should (eq (clojure-test-face-at 11 17 "{:seg.mnt/CmlCase 0}") + 'clojure-keyword-face)) + + (should (eq (clojure-test-face-at 3 9 "{:seg.mnt/mxdCase 0}") + 'font-lock-type-face)) + (should (eq (clojure-test-face-at 10 10 "{:seg.mnt/mxdCase 0}") 'default)) + (should (eq (clojure-test-face-at 11 17 "{:seg.mnt/mxdCase 0}") + 'clojure-keyword-face)) + + (should (eq (clojure-test-face-at 3 9 "{:seg.mnt/veryCom|pLex.stu-ff 0}") + 'font-lock-type-face)) + (should (eq (clojure-test-face-at 10 10 "{:seg.mnt/veryCom|pLex.stu-ff 0}") + 'default)) + (should (eq (clojure-test-face-at 11 29 "{:seg.mnt/veryCom|pLex.stu-ff 0}") + 'clojure-keyword-face)) + + (should (eq (clojure-test-face-at 3 9 "{:seg.mnt/.veryCom|pLex.stu-ff 0}") + 'font-lock-type-face)) + (should (eq (clojure-test-face-at 10 10 "{:seg.mnt/.veryCom|pLex.stu-ff 0}") + 'default)) + (should (eq (clojure-test-face-at 11 30 "{:seg.mnt/.veryCom|pLex.stu-ff 0}") + 'clojure-keyword-face))) + +(ert-deftest clojure-mode-syntax-table/kw-camelcase () + :tags '(fontification syntax-table) + (should (eq (clojure-test-face-at 3 9 " :CmlCase") 'clojure-keyword-face)) + (should (eq (clojure-test-face-at 3 9 "{:CmlCase 0}") + 'clojure-keyword-face)) + (should (eq (clojure-test-face-at 3 10 "{:#CmlCase 0}") + 'clojure-keyword-face)) + (should (eq (clojure-test-face-at 3 10 "{:.CmlCase 0}") + 'clojure-keyword-face)) + (should (eq (clojure-test-face-at 3 9 "{:CmlCase/oneword 0}") + 'font-lock-type-face)) + (should (eq (clojure-test-face-at 10 10 "{:CmlCase/oneword 0}") 'default)) + (should (eq (clojure-test-face-at 11 17 "{:CmlCase/oneword 0}") + 'clojure-keyword-face)) + (should (eq (clojure-test-face-at 3 9 "{:CmlCase/seg.mnt 0}") + 'font-lock-type-face)) + (should (eq (clojure-test-face-at 10 10 "{:CmlCase/seg.mnt 0}") 'default)) + (should (eq (clojure-test-face-at 11 17 "{:CmlCase/seg.mnt 0}") + 'clojure-keyword-face)) + (should (eq (clojure-test-face-at 3 9 "{:CmlCase/CmlCase 0}") + 'font-lock-type-face)) + (should (eq (clojure-test-face-at 10 10 "{:CmlCase/CmlCase 0}") 'default)) + (should (eq (clojure-test-face-at 11 17 "{:CmlCase/CmlCase 0}") + 'clojure-keyword-face)) + (should (eq (clojure-test-face-at 3 9 "{:CmlCase/mxdCase 0}") + 'font-lock-type-face)) + (should (eq (clojure-test-face-at 10 10 "{:CmlCase/mxdCase 0}") 'default)) + (should (eq (clojure-test-face-at 11 17 "{:CmlCase/mxdCase 0}") + 'clojure-keyword-face)) + (should (eq (clojure-test-face-at 3 9 "{:CmlCase/veryCom|pLex.stu-ff 0}") + 'font-lock-type-face)) + (should (eq (clojure-test-face-at 10 10 "{:CmlCase/veryCom|pLex.stu-ff 0}") + 'default)) + (should (eq (clojure-test-face-at 11 29 "{:CmlCase/veryCom|pLex.stu-ff 0}") + 'clojure-keyword-face)) + + (should (eq (clojure-test-face-at 3 9 "{:CmlCase/.veryCom|pLex.stu-ff 0}") + 'font-lock-type-face)) + (should (eq (clojure-test-face-at 10 10 "{:CmlCase/.veryCom|pLex.stu-ff 0}") + 'default)) + (should (eq (clojure-test-face-at 11 30 "{:CmlCase/.veryCom|pLex.stu-ff 0}") + 'clojure-keyword-face))) + +(ert-deftest clojure-mode-syntax-table/kw-mixedcase () + :tags '(fontification syntax-table) + (should (eq (clojure-test-face-at 3 9 " :mxdCase") 'clojure-keyword-face)) + (should (eq (clojure-test-face-at 3 9 "{:mxdCase 0}") + 'clojure-keyword-face)) + (should (eq (clojure-test-face-at 3 10 "{:#mxdCase 0}") + 'clojure-keyword-face)) + (should (eq (clojure-test-face-at 3 10 "{:.mxdCase 0}") + 'clojure-keyword-face)) + + (should (eq (clojure-test-face-at 3 9 "{:mxdCase/oneword 0}") + 'font-lock-type-face)) + (should (eq (clojure-test-face-at 10 10 "{:mxdCase/oneword 0}") 'default)) + (should (eq (clojure-test-face-at 11 17 "{:mxdCase/oneword 0}") + 'clojure-keyword-face)) + + (should (eq (clojure-test-face-at 3 9 "{:mxdCase/seg.mnt 0}") + 'font-lock-type-face)) + (should (eq (clojure-test-face-at 10 10 "{:mxdCase/seg.mnt 0}") 'default)) + (should (eq (clojure-test-face-at 11 17 "{:mxdCase/seg.mnt 0}") + 'clojure-keyword-face)) + + (should (eq (clojure-test-face-at 3 9 "{:mxdCase/CmlCase 0}") + 'font-lock-type-face)) + (should (eq (clojure-test-face-at 10 10 "{:mxdCase/CmlCase 0}") 'default)) + (should (eq (clojure-test-face-at 11 17 "{:mxdCase/CmlCase 0}") + 'clojure-keyword-face)) + + (should (eq (clojure-test-face-at 3 9 "{:mxdCase/mxdCase 0}") + 'font-lock-type-face)) + (should (eq (clojure-test-face-at 10 10 "{:mxdCase/mxdCase 0}") 'default)) + (should (eq (clojure-test-face-at 11 17 "{:mxdCase/mxdCase 0}") + 'clojure-keyword-face)) + + (should (eq (clojure-test-face-at 3 9 "{:mxdCase/veryCom|pLex.stu-ff 0}") + 'font-lock-type-face)) + (should (eq (clojure-test-face-at 10 10 "{:mxdCase/veryCom|pLex.stu-ff 0}") + 'default)) + (should (eq (clojure-test-face-at 11 29 "{:mxdCase/veryCom|pLex.stu-ff 0}") + 'clojure-keyword-face)) + + (should (eq (clojure-test-face-at 3 9 "{:mxdCase/.veryCom|pLex.stu-ff 0}") + 'font-lock-type-face)) + (should (eq (clojure-test-face-at 10 10 "{:mxdCase/.veryCom|pLex.stu-ff 0}") + 'default)) + (should (eq (clojure-test-face-at 11 30 "{:mxdCase/.veryCom|pLex.stu-ff 0}") + 'clojure-keyword-face))) + +(ert-deftest clojure-mode-syntax-table/kw-verycomplex () + :tags '(fontification syntax-table) + (should (eq (clojure-test-face-at 3 9 " :veryCom|pLex.stu-ff") + 'clojure-keyword-face)) + (should (eq (clojure-test-face-at 3 9 "{:veryCom|pLex.stu-ff 0}") + 'clojure-keyword-face)) + (should (eq (clojure-test-face-at 3 9 "{:#veryCom|pLex.stu-ff 0}") + 'clojure-keyword-face)) + (should (eq (clojure-test-face-at 3 9 "{:.veryCom|pLex.stu-ff 0}") + 'clojure-keyword-face)) + + (should (eq (clojure-test-face-at 3 21 "{:veryCom|pLex.stu-ff/oneword 0}") + 'font-lock-type-face)) + (should (eq (clojure-test-face-at 22 22 "{:veryCom|pLex.stu-ff/oneword 0}") + 'default)) + (should (eq (clojure-test-face-at 23 29 "{:veryCom|pLex.stu-ff/oneword 0}") + 'clojure-keyword-face)) + + (should (eq (clojure-test-face-at 3 9 "{:veryCom|pLex.stu-ff/seg.mnt 0}") + 'font-lock-type-face)) + (should (eq (clojure-test-face-at 22 22 "{:veryCom|pLex.stu-ff/seg.mnt 0}") + 'default)) + (should (eq (clojure-test-face-at 23 29 "{:veryCom|pLex.stu-ff/seg.mnt 0}") + 'clojure-keyword-face)) + + (should (eq (clojure-test-face-at 3 9 "{:veryCom|pLex.stu-ff/CmlCase 0}") + 'font-lock-type-face)) + (should (eq (clojure-test-face-at 22 22 "{:veryCom|pLex.stu-ff/CmlCase 0}") + 'default)) + (should (eq (clojure-test-face-at 23 29 "{:veryCom|pLex.stu-ff/CmlCase 0}") + 'clojure-keyword-face)) + + (should (eq (clojure-test-face-at 3 9 "{:veryCom|pLex.stu-ff/mxdCase 0}") + 'font-lock-type-face)) + (should (eq (clojure-test-face-at 22 22 "{:veryCom|pLex.stu-ff/mxdCase 0}") + 'default)) + (should (eq (clojure-test-face-at 23 29 "{:veryCom|pLex.stu-ff/mxdCase 0}") + 'clojure-keyword-face)) + + (should (eq (clojure-test-face-at + 3 21 "{:veryCom|pLex.stu-ff/veryCom|pLex.stu-ff 0}") + 'font-lock-type-face)) + (should (eq (clojure-test-face-at + 22 22 "{:veryCom|pLex.stu-ff/veryCom|pLex.stu-ff 0}") + 'default)) + (should (eq (clojure-test-face-at + 23 41 "{:veryCom|pLex.stu-ff/veryCom|pLex.stu-ff 0}") + 'clojure-keyword-face)) + + (should (eq (clojure-test-face-at + 3 21 "{:veryCom|pLex.stu-ff/.veryCom|pLex.stu-ff 0}") + 'font-lock-type-face)) + (should (eq (clojure-test-face-at + 22 22 "{:veryCom|pLex.stu-ff/.veryCom|pLex.stu-ff 0}") + 'default)) + (should (eq (clojure-test-face-at + 23 42 "{:veryCom|pLex.stu-ff/.veryCom|pLex.stu-ff 0}") + 'clojure-keyword-face))) (ert-deftest clojure-mode-syntax-table/namespaced-def () :tags '(fontification syntax-table) @@ -211,9 +645,10 @@ POS." (ert-deftest clojure-mode-syntax-table/variable-def () :tags '(fontification syntax-table) - (clojure-test-with-temp-buffer "(def foo 10)" - (should (eq (clojure-test-face-at 2 4) 'font-lock-keyword-face)) - (should (eq (clojure-test-face-at 6 8) 'font-lock-variable-name-face)))) + (should (eq (clojure-test-face-at 2 4 "(def foo 10)") + 'font-lock-keyword-face)) + (should (eq (clojure-test-face-at 6 8 "(def foo 10)") + 'font-lock-variable-name-face))) (ert-deftest clojure-mode-syntax-table/type-def () :tags '(fontification syntax-table) @@ -247,9 +682,11 @@ POS." (ert-deftest clojure-mode-syntax-table/fn () :tags '(fontification syntax-table) - (clojure-test-with-temp-buffer "(fn foo [x] x)" - ;; (should (eq (clojure-test-face-at 2 3) 'font-lock-keyword-face)) ; TODO failing test - (should (eq (clojure-test-face-at 5 7) 'font-lock-function-name-face)))) + ;; try to byte-recompile the clojure-mode.el when the face of 'fn' is 't' + (should (eq (clojure-test-face-at 2 3 "(fn foo [x] x)") + 'font-lock-keyword-face)) + (should (eq (clojure-test-face-at 5 7 "(fn foo [x] x)") + 'font-lock-function-name-face))) (ert-deftest clojure-mode-syntax-table/lambda-params () :tags '(fontification syntax-table) @@ -262,40 +699,43 @@ POS." (ert-deftest clojure-mode-syntax-table/nil () :tags '(fontification syntax-table) (should (eq (clojure-test-face-at 4 6 "(= nil x)") 'font-lock-constant-face)) - (should-not (eq (clojure-test-face-at 3 5 "(fnil x)") 'font-lock-constant-face))) + (should-not (eq (clojure-test-face-at 3 5 "(fnil x)") + 'font-lock-constant-face))) (ert-deftest clojure-mode-syntax-table/true () :tags '(fontification syntax-table) - (should (eq (clojure-test-face-at 4 7 "(= true x)") 'font-lock-constant-face))) + (should (eq (clojure-test-face-at 4 7 "(= true x)") + 'font-lock-constant-face))) (ert-deftest clojure-mode-syntax-table/false () :tags '(fontification syntax-table) - (should (eq (clojure-test-face-at 4 8 "(= false x)") 'font-lock-constant-face))) + (should (eq (clojure-test-face-at 4 8 "(= false x)") + 'font-lock-constant-face))) (ert-deftest clojure-mode-syntax-table/keyword-meta () :tags '(fontification syntax-table) (clojure-test-with-temp-buffer "^:meta-data" (should (eq (clojure-test-face-at 1 1) nil)) - (should (equal (clojure-test-face-at 2 11) '(clojure-keyword-face))))) + (should (equal (clojure-test-face-at 2 11) 'clojure-keyword-face)))) (ert-deftest clojure-mode-syntax-table/keyword-allowed-chars () :tags '(fontification syntax-table) - (should (equal (clojure-test-face-at 1 8 ":aaa#bbb") '(clojure-keyword-face)))) + (should (equal (clojure-test-face-at 1 8 ":aaa#bbb") 'clojure-keyword-face))) (ert-deftest clojure-mode-syntax-table/keyword-disallowed-chars () :tags '(fontification syntax-table) (should (eq (clojure-test-face-at 1 5 ":aaa@bbb") 'various-faces)) - (should (equal (clojure-test-face-at 1 4 ":aaa@bbb") '(clojure-keyword-face))) + (should (equal (clojure-test-face-at 1 4 ":aaa@bbb") 'clojure-keyword-face)) (should (eq (clojure-test-face-at 1 5 ":aaa~bbb") 'various-faces)) - (should (equal (clojure-test-face-at 1 4 ":aaa~bbb") '(clojure-keyword-face))) + (should (equal (clojure-test-face-at 1 4 ":aaa~bbb") 'clojure-keyword-face)) (should (eq (clojure-test-face-at 1 5 ":aaa@bbb") 'various-faces)) - (should (equal (clojure-test-face-at 1 4 ":aaa@bbb") '(clojure-keyword-face)))) + (should (equal (clojure-test-face-at 1 4 ":aaa@bbb") 'clojure-keyword-face))) (ert-deftest clojure-mode-syntax-table/characters () :tags '(fontification syntax-table) (should (eq (clojure-test-face-at 1 2 "\\a") 'clojure-character-face)) (should (eq (clojure-test-face-at 1 8 "\\newline") 'clojure-character-face)) - ;; (should (eq (clojure-test-face-at 1 2 "\\1") 'clojure-character-face)) ; TODO failing test + (should (eq (clojure-test-face-at 1 2 "\\1") 'clojure-character-face)) (should (eq (clojure-test-face-at 1 6 "\\u0032") 'clojure-character-face)) (should (eq (clojure-test-face-at 1 2 "\\+") 'clojure-character-face)) (should (eq (clojure-test-face-at 1 2 "\\.") 'clojure-character-face)) @@ -309,16 +749,12 @@ POS." (ert-deftest clojure-mode-syntax-table/dynamic-var () :tags '(fontification syntax-table) - (should (eq (clojure-test-face-at 1 10 "*some-var*") 'font-lock-variable-name-face)) - (should (eq (clojure-test-face-at 2 11 "@*some-var*") 'font-lock-variable-name-face)) - (should (eq (clojure-test-face-at 9 13 "some.ns/*var*") 'font-lock-variable-name-face))) - -(ert-deftest clojure-mode-syntax-table/ns-macro () - :tags '(fontification syntax-table) - (should (eq (clojure-test-face-at 5 8 "(ns name)") 'font-lock-type-face)) - (should (eq (clojure-test-face-at 5 13 "(ns name.name)") 'font-lock-type-face)) - ;; (should (eq (clojure-test-face-at 1 10 "[ns name]") nil)) ; TODO failing test - ) + (should (eq (clojure-test-face-at 1 10 "*some-var*") + 'font-lock-variable-name-face)) + (should (eq (clojure-test-face-at 2 11 "@*some-var*") + 'font-lock-variable-name-face)) + (should (eq (clojure-test-face-at 9 13 "some.ns/*var*") + 'font-lock-variable-name-face))) (provide 'clojure-mode-font-lock-test) From 6aa5c4f1a4a6f64f23ce6d31b7f1159f114b0754 Mon Sep 17 00:00:00 2001 From: Rostislav Svoboda Date: Sat, 17 Mar 2018 15:33:44 +0100 Subject: [PATCH 117/199] Fix font-locking of namespaced keywords See #474 --- clojure-mode-font-lock-test.el | 273 ++++++++++++++++++++------------- 1 file changed, 170 insertions(+), 103 deletions(-) diff --git a/clojure-mode-font-lock-test.el b/clojure-mode-font-lock-test.el index 6e36ebd..a2a8155 100644 --- a/clojure-mode-font-lock-test.el +++ b/clojure-mode-font-lock-test.el @@ -181,18 +181,18 @@ POS." (should (eq (clojure-test-face-at 9 10 "(oneword/CmlCase)") 'default)) (should (eq (clojure-test-face-at 11 16 "(oneword/CmlCase)") 'default)) - (should (eq (clojure-test-face-at 2 8 "(oneword/veryCom|pLex.stu-ff)") + (should (eq (clojure-test-face-at 2 8 "(oneword/ve/yCom|pLex.stu-ff)") 'font-lock-type-face)) - (should (eq (clojure-test-face-at 9 10 "(oneword/veryCom|pLex.stu-ff)") + (should (eq (clojure-test-face-at 9 10 "(oneword/ve/yCom|pLex.stu-ff)") 'default)) - (should (eq (clojure-test-face-at 11 28 "(oneword/veryCom|pLex.stu-ff)") + (should (eq (clojure-test-face-at 11 28 "(oneword/ve/yCom|pLex.stu-ff)") 'default)) - (should (eq (clojure-test-face-at 2 8 "(oneword/.veryCom|pLex.stu-ff)") + (should (eq (clojure-test-face-at 2 8 "(oneword/.ve/yCom|pLex.stu-ff)") 'font-lock-type-face)) - (should (eq (clojure-test-face-at 9 10 "(oneword/.veryCom|pLex.stu-ff)") + (should (eq (clojure-test-face-at 9 10 "(oneword/.ve/yCom|pLex.stu-ff)") 'default)) - (should (eq (clojure-test-face-at 12 29 "(oneword/.veryCom|pLex.stu-ff)") + (should (eq (clojure-test-face-at 12 29 "(oneword/.ve/yCom|pLex.stu-ff)") 'default))) (ert-deftest clojure-mode-syntax-table/segment () @@ -224,18 +224,18 @@ POS." (should (eq (clojure-test-face-at 9 10 "(seg.mnt/CmlCase)") 'default)) (should (eq (clojure-test-face-at 11 16 "(seg.mnt/CmlCase)") 'default)) - (should (eq (clojure-test-face-at 2 8 "(seg.mnt/veryCom|pLex.stu-ff)") + (should (eq (clojure-test-face-at 2 8 "(seg.mnt/ve/yCom|pLex.stu-ff)") 'font-lock-type-face)) - (should (eq (clojure-test-face-at 9 10 "(seg.mnt/veryCom|pLex.stu-ff)") + (should (eq (clojure-test-face-at 9 10 "(seg.mnt/ve/yCom|pLex.stu-ff)") 'default)) - (should (eq (clojure-test-face-at 11 28 "(seg.mnt/veryCom|pLex.stu-ff)") + (should (eq (clojure-test-face-at 11 28 "(seg.mnt/ve/yCom|pLex.stu-ff)") 'default)) - (should (eq (clojure-test-face-at 2 8 "(seg.mnt/.veryCom|pLex.stu-ff)") + (should (eq (clojure-test-face-at 2 8 "(seg.mnt/.ve/yCom|pLex.stu-ff)") 'font-lock-type-face)) - (should (eq (clojure-test-face-at 9 10 "(seg.mnt/.veryCom|pLex.stu-ff)") + (should (eq (clojure-test-face-at 9 10 "(seg.mnt/.ve/yCom|pLex.stu-ff)") 'default)) - (should (eq (clojure-test-face-at 12 29 "(seg.mnt/.veryCom|pLex.stu-ff)") + (should (eq (clojure-test-face-at 12 29 "(seg.mnt/.ve/yCom|pLex.stu-ff)") 'default))) (ert-deftest clojure-mode-syntax-table/camelcase () @@ -268,18 +268,18 @@ POS." (should (eq (clojure-test-face-at 9 10 "(CmlCase/CmlCase)") 'default)) (should (eq (clojure-test-face-at 11 16 "(CmlCase/CmlCase)") 'default)) - (should (eq (clojure-test-face-at 2 8 "(CmlCase/veryCom|pLex.stu-ff)") + (should (eq (clojure-test-face-at 2 8 "(CmlCase/ve/yCom|pLex.stu-ff)") 'font-lock-type-face)) - (should (eq (clojure-test-face-at 9 10 "(CmlCase/veryCom|pLex.stu-ff)") + (should (eq (clojure-test-face-at 9 10 "(CmlCase/ve/yCom|pLex.stu-ff)") 'default)) - (should (eq (clojure-test-face-at 11 28 "(CmlCase/veryCom|pLex.stu-ff)") + (should (eq (clojure-test-face-at 11 28 "(CmlCase/ve/yCom|pLex.stu-ff)") 'default)) - (should (eq (clojure-test-face-at 2 8 "(CmlCase/.veryCom|pLex.stu-ff)") + (should (eq (clojure-test-face-at 2 8 "(CmlCase/.ve/yCom|pLex.stu-ff)") 'font-lock-type-face)) - (should (eq (clojure-test-face-at 9 10 "(CmlCase/.veryCom|pLex.stu-ff)") + (should (eq (clojure-test-face-at 9 10 "(CmlCase/.ve/yCom|pLex.stu-ff)") 'default)) - (should (eq (clojure-test-face-at 12 29 "(CmlCase/.veryCom|pLex.stu-ff)") + (should (eq (clojure-test-face-at 12 29 "(CmlCase/.ve/yCom|pLex.stu-ff)") 'default))) (ert-deftest clojure-mode-syntax-table/mixedcase () @@ -312,76 +312,81 @@ POS." (should (eq (clojure-test-face-at 9 10 "(mxdCase/CmlCase)") 'default)) (should (eq (clojure-test-face-at 11 16 "(mxdCase/CmlCase)") 'default)) - (should (eq (clojure-test-face-at 2 8 "(mxdCase/veryCom|pLex.stu-ff)") + (should (eq (clojure-test-face-at 2 8 "(mxdCase/ve/yCom|pLex.stu-ff)") 'font-lock-type-face)) - (should (eq (clojure-test-face-at 9 10 "(mxdCase/veryCom|pLex.stu-ff)") + (should (eq (clojure-test-face-at 9 10 "(mxdCase/ve/yCom|pLex.stu-ff)") 'default)) - (should (eq (clojure-test-face-at 11 28 "(mxdCase/veryCom|pLex.stu-ff)") + (should (eq (clojure-test-face-at 11 28 "(mxdCase/ve/yCom|pLex.stu-ff)") 'default)) - (should (eq (clojure-test-face-at 2 8 "(mxdCase/.veryCom|pLex.stu-ff)") + (should (eq (clojure-test-face-at 2 8 "(mxdCase/.ve/yCom|pLex.stu-ff)") 'font-lock-type-face)) - (should (eq (clojure-test-face-at 9 10 "(mxdCase/.veryCom|pLex.stu-ff)") + (should (eq (clojure-test-face-at 9 10 "(mxdCase/.ve/yCom|pLex.stu-ff)") 'default)) - (should (eq (clojure-test-face-at 12 29 "(mxdCase/.veryCom|pLex.stu-ff)") + (should (eq (clojure-test-face-at 12 29 "(mxdCase/.ve/yCom|pLex.stu-ff)") 'default))) (ert-deftest clojure-mode-syntax-table/verycomplex () :tags '(fontification syntax-table) - (should (eq (clojure-test-face-at 3 21 " veryCom|pLex.stu-ff") 'default)) - (should (eq (clojure-test-face-at 3 21 " @veryCom|pLex.stu-ff") 'default)) - (should (eq (clojure-test-face-at 3 21 " #veryCom|pLex.stu-ff") 'default)) - (should (eq (clojure-test-face-at 3 21 " .veryCom|pLex.stu-ff") 'default)) - (should (eq (clojure-test-face-at 3 21 "#^veryCom|pLex.stu-ff") - 'font-lock-type-face)) ;; type-hint - (should (eq (clojure-test-face-at 3 21 " (veryCom|pLex.stu-ff)") 'default)) + (should (eq (clojure-test-face-at 3 4 " ve/yCom|pLex.stu-ff") + 'font-lock-type-face)) + (should (eq (clojure-test-face-at 5 21 " ve/yCom|pLex.stu-ff") 'default)) - (should (eq (clojure-test-face-at 3 21 " (veryCom|pLex.stu-ff/oneword)") + (should (eq (clojure-test-face-at 2 2 " @ve/yCom|pLex.stu-ff") 'nil)) + (should (eq (clojure-test-face-at 3 4 " @ve/yCom|pLex.stu-ff") 'font-lock-type-face)) - (should (eq (clojure-test-face-at 22 22 " (veryCom|pLex.stu-ff/oneword)") - 'default)) - (should (eq (clojure-test-face-at 23 29 " (veryCom|pLex.stu-ff/oneword)") - 'default)) + (should (eq (clojure-test-face-at 5 21 " @ve/yCom|pLex.stu-ff") 'default)) - (should (eq (clojure-test-face-at 3 21 " (veryCom|pLex.stu-ff/seg.mnt)") + (should (eq (clojure-test-face-at 2 4 " #ve/yCom|pLex.stu-ff") 'font-lock-type-face)) - (should (eq (clojure-test-face-at 22 22 " (veryCom|pLex.stu-ff/seg.mnt)") - 'default)) - (should (eq (clojure-test-face-at 22 29 " (veryCom|pLex.stu-ff/seg.mnt)") - 'default)) + (should (eq (clojure-test-face-at 5 21 " #ve/yCom|pLex.stu-ff") 'default)) - (should (eq (clojure-test-face-at 3 21 " (veryCom|pLex.stu-ff/mxdCase)") + (should (eq (clojure-test-face-at 2 4 " .ve/yCom|pLex.stu-ff") 'font-lock-type-face)) - (should (eq (clojure-test-face-at 22 22 " (veryCom|pLex.stu-ff/mxdCase)") + (should (eq (clojure-test-face-at 5 21 " .ve/yCom|pLex.stu-ff") 'default)) + + ;; type-hint + (should (eq (clojure-test-face-at 1 2 "#^ve/yCom|pLex.stu-ff") 'default)) + (should (eq (clojure-test-face-at 3 4 "#^ve/yCom|pLex.stu-ff") + 'font-lock-type-face)) + (should (eq (clojure-test-face-at 5 21 "#^ve/yCom|pLex.stu-ff") 'default)) + + (should (eq (clojure-test-face-at 3 4 " (ve/yCom|pLex.stu-ff)") + 'font-lock-type-face)) + (should (eq (clojure-test-face-at 5 21 " (ve/yCom|pLex.stu-ff)") 'default)) + + (should (eq (clojure-test-face-at 3 4 " (ve/yCom|pLex.stu-ff/oneword)") + 'font-lock-type-face)) + (should (eq (clojure-test-face-at 5 29 " (ve/yCom|pLex.stu-ff/oneword)") 'default)) - (should (eq (clojure-test-face-at 22 29 " (veryCom|pLex.stu-ff/mxdCase)") + + (should (eq (clojure-test-face-at 3 4 " (ve/yCom|pLex.stu-ff/seg.mnt)") + 'font-lock-type-face)) + (should (eq (clojure-test-face-at 5 29 " (ve/yCom|pLex.stu-ff/seg.mnt)") 'default)) - (should (eq (clojure-test-face-at 3 21 " (veryCom|pLex.stu-ff/CmlCase)") + (should (eq (clojure-test-face-at 3 4 " (ve/yCom|pLex.stu-ff/mxdCase)") 'font-lock-type-face)) - (should (eq (clojure-test-face-at 22 22 " (veryCom|pLex.stu-ff/CmlCase)") + (should (eq (clojure-test-face-at 5 29 " (ve/yCom|pLex.stu-ff/mxdCase)") 'default)) - (should (eq (clojure-test-face-at 22 29 " (veryCom|pLex.stu-ff/CmlCase)") + + (should (eq (clojure-test-face-at 3 4 " (ve/yCom|pLex.stu-ff/CmlCase)") + 'font-lock-type-face)) + (should (eq (clojure-test-face-at 5 29 " (ve/yCom|pLex.stu-ff/CmlCase)") 'default)) (should (eq (clojure-test-face-at - 3 21 " (veryCom|pLex.stu-ff/veryCom|pLex.stu-ff)") + 3 4 " (ve/yCom|pLex.stu-ff/ve/yCom|pLex.stu-ff)") 'font-lock-type-face)) (should (eq (clojure-test-face-at - 22 22 " (veryCom|pLex.stu-ff/veryCom|pLex.stu-ff)") - 'default)) - (should (eq (clojure-test-face-at - 23 41 " (veryCom|pLex.stu-ff/veryCom|pLex.stu-ff)") + 5 41 " (ve/yCom|pLex.stu-ff/ve/yCom|pLex.stu-ff)") 'default)) (should (eq (clojure-test-face-at - 3 21 " (veryCom|pLex.stu-ff/.veryCom|pLex.stu-ff)") + 3 4 " (ve/yCom|pLex.stu-ff/.ve/yCom|pLex.stu-ff)") 'font-lock-type-face)) (should (eq (clojure-test-face-at - 22 22 " (veryCom|pLex.stu-ff/.veryCom|pLex.stu-ff)") - 'default)) - (should (eq (clojure-test-face-at - 23 42 " (veryCom|pLex.stu-ff/.veryCom|pLex.stu-ff)") + 5 42 " (ve/yCom|pLex.stu-ff/.ve/yCom|pLex.stu-ff)") 'default))) (ert-deftest clojure-mode-syntax-table/kw-oneword () @@ -418,18 +423,41 @@ POS." (should (eq (clojure-test-face-at 11 17 "{:oneword/mxdCase 0}") 'clojure-keyword-face)) - (should (eq (clojure-test-face-at 3 9 "{:oneword/veryCom|pLex.stu-ff 0}") + (should (eq (clojure-test-face-at 3 9 "{:oneword/ve/yCom|pLex.stu-ff 0}") 'font-lock-type-face)) - (should (eq (clojure-test-face-at 10 10 "{:oneword/veryCom|pLex.stu-ff 0}") + (should (eq (clojure-test-face-at 10 10 "{:oneword/ve/yCom|pLex.stu-ff 0}") 'default)) - (should (eq (clojure-test-face-at 11 29 "{:oneword/veryCom|pLex.stu-ff 0}") + (should (eq (clojure-test-face-at 11 29 "{:oneword/ve/yCom|pLex.stu-ff 0}") 'clojure-keyword-face)) - (should (eq (clojure-test-face-at 3 9 "{:oneword/.veryCom|pLex.stu-ff 0}") + (should (eq (clojure-test-face-at 3 9 "{:oneword/.ve/yCom|pLex.stu-ff 0}") 'font-lock-type-face)) - (should (eq (clojure-test-face-at 10 10 "{:oneword/.veryCom|pLex.stu-ff 0}") + (should (eq (clojure-test-face-at 10 10 "{:oneword/.ve/yCom|pLex.stu-ff 0}") 'default)) - (should (eq (clojure-test-face-at 11 30 "{:oneword/.veryCom|pLex.stu-ff 0}") + (should (eq (clojure-test-face-at 11 30 "{:oneword/.ve/yCom|pLex.stu-ff 0}") + 'clojure-keyword-face))) + +(ert-deftest clojure-mode-syntax-table/kw-namespaced () + :tags '(fontification syntax-table) + (should (eq (clojure-test-face-at 1 5 "::foo") 'clojure-keyword-face)) + (should (eq (clojure-test-face-at 1 9 ":_::_:foo") 'clojure-keyword-face)) + (should (eq (clojure-test-face-at 1 8 ":_:_:foo") 'clojure-keyword-face)) + (should (eq (clojure-test-face-at 1 9 ":foo/:bar") 'clojure-keyword-face)) + (should (eq (clojure-test-face-at 1 7 "::_:foo") 'clojure-keyword-face)) + (should (eq (clojure-test-face-at 1 9 "::_:_:foo") 'clojure-keyword-face)) + + (should (eq (clojure-test-face-at 1 1 ":_:_:foo/_") 'clojure-keyword-face)) + (should (eq (clojure-test-face-at 2 8 ":_:_:foo/_") 'font-lock-type-face)) + (should (eq (clojure-test-face-at 9 9 ":_:_:foo/_") 'default)) + (should (eq (clojure-test-face-at 10 10 ":_:_:foo/_") 'clojure-keyword-face)) + + (should (eq (clojure-test-face-at 10 12 ":_:_:foo/bar") + 'clojure-keyword-face)) + (should (eq (clojure-test-face-at 10 16 ":_:_:foo/bar/eee") + 'clojure-keyword-face)) + (should (eq (clojure-test-face-at 10 17 ":_:_:foo/bar_:foo") + 'clojure-keyword-face)) + (should (eq (clojure-test-face-at 10 19 ":_:_:foo/bar_:_:foo") 'clojure-keyword-face))) (ert-deftest clojure-mode-syntax-table/kw-segment () @@ -466,18 +494,18 @@ POS." (should (eq (clojure-test-face-at 11 17 "{:seg.mnt/mxdCase 0}") 'clojure-keyword-face)) - (should (eq (clojure-test-face-at 3 9 "{:seg.mnt/veryCom|pLex.stu-ff 0}") + (should (eq (clojure-test-face-at 3 9 "{:seg.mnt/ve/yCom|pLex.stu-ff 0}") 'font-lock-type-face)) - (should (eq (clojure-test-face-at 10 10 "{:seg.mnt/veryCom|pLex.stu-ff 0}") + (should (eq (clojure-test-face-at 10 10 "{:seg.mnt/ve/yCom|pLex.stu-ff 0}") 'default)) - (should (eq (clojure-test-face-at 11 29 "{:seg.mnt/veryCom|pLex.stu-ff 0}") + (should (eq (clojure-test-face-at 11 29 "{:seg.mnt/ve/yCom|pLex.stu-ff 0}") 'clojure-keyword-face)) - (should (eq (clojure-test-face-at 3 9 "{:seg.mnt/.veryCom|pLex.stu-ff 0}") + (should (eq (clojure-test-face-at 3 9 "{:seg.mnt/.ve/yCom|pLex.stu-ff 0}") 'font-lock-type-face)) - (should (eq (clojure-test-face-at 10 10 "{:seg.mnt/.veryCom|pLex.stu-ff 0}") + (should (eq (clojure-test-face-at 10 10 "{:seg.mnt/.ve/yCom|pLex.stu-ff 0}") 'default)) - (should (eq (clojure-test-face-at 11 30 "{:seg.mnt/.veryCom|pLex.stu-ff 0}") + (should (eq (clojure-test-face-at 11 30 "{:seg.mnt/.ve/yCom|pLex.stu-ff 0}") 'clojure-keyword-face))) (ert-deftest clojure-mode-syntax-table/kw-camelcase () @@ -509,18 +537,18 @@ POS." (should (eq (clojure-test-face-at 10 10 "{:CmlCase/mxdCase 0}") 'default)) (should (eq (clojure-test-face-at 11 17 "{:CmlCase/mxdCase 0}") 'clojure-keyword-face)) - (should (eq (clojure-test-face-at 3 9 "{:CmlCase/veryCom|pLex.stu-ff 0}") + (should (eq (clojure-test-face-at 3 9 "{:CmlCase/ve/yCom|pLex.stu-ff 0}") 'font-lock-type-face)) - (should (eq (clojure-test-face-at 10 10 "{:CmlCase/veryCom|pLex.stu-ff 0}") + (should (eq (clojure-test-face-at 10 10 "{:CmlCase/ve/yCom|pLex.stu-ff 0}") 'default)) - (should (eq (clojure-test-face-at 11 29 "{:CmlCase/veryCom|pLex.stu-ff 0}") + (should (eq (clojure-test-face-at 11 29 "{:CmlCase/ve/yCom|pLex.stu-ff 0}") 'clojure-keyword-face)) - (should (eq (clojure-test-face-at 3 9 "{:CmlCase/.veryCom|pLex.stu-ff 0}") + (should (eq (clojure-test-face-at 3 9 "{:CmlCase/.ve/yCom|pLex.stu-ff 0}") 'font-lock-type-face)) - (should (eq (clojure-test-face-at 10 10 "{:CmlCase/.veryCom|pLex.stu-ff 0}") + (should (eq (clojure-test-face-at 10 10 "{:CmlCase/.ve/yCom|pLex.stu-ff 0}") 'default)) - (should (eq (clojure-test-face-at 11 30 "{:CmlCase/.veryCom|pLex.stu-ff 0}") + (should (eq (clojure-test-face-at 11 30 "{:CmlCase/.ve/yCom|pLex.stu-ff 0}") 'clojure-keyword-face))) (ert-deftest clojure-mode-syntax-table/kw-mixedcase () @@ -557,77 +585,116 @@ POS." (should (eq (clojure-test-face-at 11 17 "{:mxdCase/mxdCase 0}") 'clojure-keyword-face)) - (should (eq (clojure-test-face-at 3 9 "{:mxdCase/veryCom|pLex.stu-ff 0}") + (should (eq (clojure-test-face-at 3 9 "{:mxdCase/ve/yCom|pLex.stu-ff 0}") 'font-lock-type-face)) - (should (eq (clojure-test-face-at 10 10 "{:mxdCase/veryCom|pLex.stu-ff 0}") + (should (eq (clojure-test-face-at 10 10 "{:mxdCase/ve/yCom|pLex.stu-ff 0}") 'default)) - (should (eq (clojure-test-face-at 11 29 "{:mxdCase/veryCom|pLex.stu-ff 0}") + (should (eq (clojure-test-face-at 11 29 "{:mxdCase/ve/yCom|pLex.stu-ff 0}") 'clojure-keyword-face)) - (should (eq (clojure-test-face-at 3 9 "{:mxdCase/.veryCom|pLex.stu-ff 0}") + (should (eq (clojure-test-face-at 3 9 "{:mxdCase/.ve/yCom|pLex.stu-ff 0}") 'font-lock-type-face)) - (should (eq (clojure-test-face-at 10 10 "{:mxdCase/.veryCom|pLex.stu-ff 0}") + (should (eq (clojure-test-face-at 10 10 "{:mxdCase/.ve/yCom|pLex.stu-ff 0}") 'default)) - (should (eq (clojure-test-face-at 11 30 "{:mxdCase/.veryCom|pLex.stu-ff 0}") + (should (eq (clojure-test-face-at 11 30 "{:mxdCase/.ve/yCom|pLex.stu-ff 0}") 'clojure-keyword-face))) (ert-deftest clojure-mode-syntax-table/kw-verycomplex () :tags '(fontification syntax-table) - (should (eq (clojure-test-face-at 3 9 " :veryCom|pLex.stu-ff") + (should (eq (clojure-test-face-at 3 4 " :ve/yCom|pLex.stu-ff") + 'font-lock-type-face)) + (should (eq (clojure-test-face-at 5 5 " :ve/yCom|pLex.stu-ff") + 'default)) + (should (eq (clojure-test-face-at 6 21 " :ve/yCom|pLex.stu-ff") 'clojure-keyword-face)) - (should (eq (clojure-test-face-at 3 9 "{:veryCom|pLex.stu-ff 0}") + + (should (eq (clojure-test-face-at 2 2 "{:ve/yCom|pLex.stu-ff 0}") 'clojure-keyword-face)) - (should (eq (clojure-test-face-at 3 9 "{:#veryCom|pLex.stu-ff 0}") + (should (eq (clojure-test-face-at 3 4 "{:ve/yCom|pLex.stu-ff 0}") + 'font-lock-type-face)) + (should (eq (clojure-test-face-at 5 5 "{:ve/yCom|pLex.stu-ff 0}") + 'default)) + (should (eq (clojure-test-face-at 6 21 "{:ve/yCom|pLex.stu-ff 0}") + 'clojure-keyword-face)) + + (should (eq (clojure-test-face-at 2 2 "{:#ve/yCom|pLex.stu-ff 0}") 'clojure-keyword-face)) - (should (eq (clojure-test-face-at 3 9 "{:.veryCom|pLex.stu-ff 0}") + (should (eq (clojure-test-face-at 3 5 "{:#ve/yCom|pLex.stu-ff 0}") + 'font-lock-type-face)) + (should (eq (clojure-test-face-at 6 6 "{:#ve/yCom|pLex.stu-ff 0}") + 'default)) + (should (eq (clojure-test-face-at 7 22 "{:#ve/yCom|pLex.stu-ff 0}") 'clojure-keyword-face)) - (should (eq (clojure-test-face-at 3 21 "{:veryCom|pLex.stu-ff/oneword 0}") + (should (eq (clojure-test-face-at 2 2 "{:.ve/yCom|pLex.stu-ff 0}") + 'clojure-keyword-face)) + (should (eq (clojure-test-face-at 3 5 "{:.ve/yCom|pLex.stu-ff 0}") 'font-lock-type-face)) - (should (eq (clojure-test-face-at 22 22 "{:veryCom|pLex.stu-ff/oneword 0}") + (should (eq (clojure-test-face-at 6 6 "{:.ve/yCom|pLex.stu-ff 0}") 'default)) - (should (eq (clojure-test-face-at 23 29 "{:veryCom|pLex.stu-ff/oneword 0}") + (should (eq (clojure-test-face-at 7 22 "{:.ve/yCom|pLex.stu-ff 0}") 'clojure-keyword-face)) - (should (eq (clojure-test-face-at 3 9 "{:veryCom|pLex.stu-ff/seg.mnt 0}") + (should (eq (clojure-test-face-at 2 2 "{:ve/yCom|pLex.stu-ff/oneword 0}") + 'clojure-keyword-face)) + (should (eq (clojure-test-face-at 3 4 "{:ve/yCom|pLex.stu-ff/oneword 0}") + 'font-lock-type-face)) + (should (eq (clojure-test-face-at 5 5 "{:ve/yCom|pLex.stu-ff/oneword 0}") + 'default)) + (should (eq (clojure-test-face-at 6 29 "{:ve/yCom|pLex.stu-ff/oneword 0}") + 'clojure-keyword-face)) + + (should (eq (clojure-test-face-at 2 2 "{:ve/yCom|pLex.stu-ff/seg.mnt 0}") + 'clojure-keyword-face)) + (should (eq (clojure-test-face-at 3 4 "{:ve/yCom|pLex.stu-ff/seg.mnt 0}") 'font-lock-type-face)) - (should (eq (clojure-test-face-at 22 22 "{:veryCom|pLex.stu-ff/seg.mnt 0}") + (should (eq (clojure-test-face-at 5 5 "{:ve/yCom|pLex.stu-ff/seg.mnt 0}") 'default)) - (should (eq (clojure-test-face-at 23 29 "{:veryCom|pLex.stu-ff/seg.mnt 0}") + (should (eq (clojure-test-face-at 6 29 "{:ve/yCom|pLex.stu-ff/seg.mnt 0}") 'clojure-keyword-face)) - (should (eq (clojure-test-face-at 3 9 "{:veryCom|pLex.stu-ff/CmlCase 0}") + (should (eq (clojure-test-face-at 2 2 "{:ve/yCom|pLex.stu-ff/ClmCase 0}") + 'clojure-keyword-face)) + (should (eq (clojure-test-face-at 3 4 "{:ve/yCom|pLex.stu-ff/ClmCase 0}") 'font-lock-type-face)) - (should (eq (clojure-test-face-at 22 22 "{:veryCom|pLex.stu-ff/CmlCase 0}") + (should (eq (clojure-test-face-at 5 5 "{:ve/yCom|pLex.stu-ff/ClmCase 0}") 'default)) - (should (eq (clojure-test-face-at 23 29 "{:veryCom|pLex.stu-ff/CmlCase 0}") + (should (eq (clojure-test-face-at 6 29 "{:ve/yCom|pLex.stu-ff/ClmCase 0}") 'clojure-keyword-face)) - (should (eq (clojure-test-face-at 3 9 "{:veryCom|pLex.stu-ff/mxdCase 0}") + (should (eq (clojure-test-face-at 2 2 "{:ve/yCom|pLex.stu-ff/mxdCase 0}") + 'clojure-keyword-face)) + (should (eq (clojure-test-face-at 3 4 "{:ve/yCom|pLex.stu-ff/mxdCase 0}") 'font-lock-type-face)) - (should (eq (clojure-test-face-at 22 22 "{:veryCom|pLex.stu-ff/mxdCase 0}") + (should (eq (clojure-test-face-at 5 5 "{:ve/yCom|pLex.stu-ff/mxdCase 0}") 'default)) - (should (eq (clojure-test-face-at 23 29 "{:veryCom|pLex.stu-ff/mxdCase 0}") + (should (eq (clojure-test-face-at 6 29 "{:ve/yCom|pLex.stu-ff/mxdCase 0}") 'clojure-keyword-face)) (should (eq (clojure-test-face-at - 3 21 "{:veryCom|pLex.stu-ff/veryCom|pLex.stu-ff 0}") + 2 2 "{:ve/yCom|pLex.stu-ff/ve/yCom|pLex.stu-ff 0}") + 'clojure-keyword-face)) + (should (eq (clojure-test-face-at + 3 4 "{:ve/yCom|pLex.stu-ff/ve/yCom|pLex.stu-ff 0}") 'font-lock-type-face)) (should (eq (clojure-test-face-at - 22 22 "{:veryCom|pLex.stu-ff/veryCom|pLex.stu-ff 0}") + 5 5 "{:ve/yCom|pLex.stu-ff/ve/yCom|pLex.stu-ff 0}") 'default)) (should (eq (clojure-test-face-at - 23 41 "{:veryCom|pLex.stu-ff/veryCom|pLex.stu-ff 0}") + 6 41 "{:ve/yCom|pLex.stu-ff/ve/yCom|pLex.stu-ff 0}") 'clojure-keyword-face)) (should (eq (clojure-test-face-at - 3 21 "{:veryCom|pLex.stu-ff/.veryCom|pLex.stu-ff 0}") + 2 2 "{:ve/yCom|pLex.stu-ff/.ve/yCom|pLex.stu-ff 0}") + 'clojure-keyword-face)) + (should (eq (clojure-test-face-at + 3 4 "{:ve/yCom|pLex.stu-ff/.ve/yCom|pLex.stu-ff 0}") 'font-lock-type-face)) (should (eq (clojure-test-face-at - 22 22 "{:veryCom|pLex.stu-ff/.veryCom|pLex.stu-ff 0}") + 5 5 "{:ve/yCom|pLex.stu-ff/.ve/yCom|pLex.stu-ff 0}") 'default)) (should (eq (clojure-test-face-at - 23 42 "{:veryCom|pLex.stu-ff/.veryCom|pLex.stu-ff 0}") + 6 42 "{:ve/yCom|pLex.stu-ff/.ve/yCom|pLex.stu-ff 0}") 'clojure-keyword-face))) (ert-deftest clojure-mode-syntax-table/namespaced-def () From 078cd1e5f9d27009ca2b5a9f8467f20f970c742e Mon Sep 17 00:00:00 2001 From: Bost Date: Mon, 26 Mar 2018 17:58:58 +0200 Subject: [PATCH 118/199] Fix regression to CIDER's dynamic syntax highlighting #474 --- clojure-mode-font-lock-test.el | 168 ++++++++++++++++----------------- 1 file changed, 84 insertions(+), 84 deletions(-) diff --git a/clojure-mode-font-lock-test.el b/clojure-mode-font-lock-test.el index a2a8155..69f5bf6 100644 --- a/clojure-mode-font-lock-test.el +++ b/clojure-mode-font-lock-test.el @@ -123,10 +123,10 @@ POS." :tags '(fontification syntax-table) (should (equal (clojure-test-face-at 1 2 "#_") - 'default)) + nil)) (should (equal (clojure-test-face-at 1 2 "#_ \n;; some crap\n (lala 0101\n lao\n\n 0 0i)") - 'default)) + nil)) (should (equal (clojure-test-face-at 5 41 "#_ \n;; some crap\n (lala 0101\n lao\n\n 0 0i)") 'font-lock-comment-face))) @@ -153,197 +153,197 @@ POS." (ert-deftest clojure-mode-syntax-table/oneword () :tags '(fontification syntax-table) - (should (eq (clojure-test-face-at 2 8 " oneword") 'default)) - (should (eq (clojure-test-face-at 2 8 "@oneword") 'default)) - (should (eq (clojure-test-face-at 2 8 "#oneword") 'default)) - (should (eq (clojure-test-face-at 2 8 ".oneword") 'default)) + (should (eq (clojure-test-face-at 2 8 " oneword") nil)) + (should (eq (clojure-test-face-at 2 8 "@oneword") nil)) + (should (eq (clojure-test-face-at 2 8 "#oneword") nil)) + (should (eq (clojure-test-face-at 2 8 ".oneword") nil)) (should (eq (clojure-test-face-at 3 9 "#^oneword") 'font-lock-type-face)) ;; type-hint - (should (eq (clojure-test-face-at 2 8 "(oneword)") 'default)) + (should (eq (clojure-test-face-at 2 8 "(oneword)") nil)) (should (eq (clojure-test-face-at 2 8 "(oneword/oneword)") 'font-lock-type-face)) - (should (eq (clojure-test-face-at 9 10 "(oneword/oneword)") 'default)) - (should (eq (clojure-test-face-at 11 16 "(oneword/oneword)") 'default)) + (should (eq (clojure-test-face-at 9 10 "(oneword/oneword)") nil)) + (should (eq (clojure-test-face-at 11 16 "(oneword/oneword)") nil)) (should (eq (clojure-test-face-at 2 8 "(oneword/seg.mnt)") 'font-lock-type-face)) - (should (eq (clojure-test-face-at 9 10 "(oneword/seg.mnt)") 'default)) - (should (eq (clojure-test-face-at 11 16 "(oneword/seg.mnt)") 'default)) + (should (eq (clojure-test-face-at 9 10 "(oneword/seg.mnt)") nil)) + (should (eq (clojure-test-face-at 11 16 "(oneword/seg.mnt)") nil)) (should (eq (clojure-test-face-at 2 8 "(oneword/mxdCase)") 'font-lock-type-face)) - (should (eq (clojure-test-face-at 9 10 "(oneword/mxdCase)") 'default)) - (should (eq (clojure-test-face-at 11 16 "(oneword/mxdCase)") 'default)) + (should (eq (clojure-test-face-at 9 10 "(oneword/mxdCase)") nil)) + (should (eq (clojure-test-face-at 11 16 "(oneword/mxdCase)") nil)) (should (eq (clojure-test-face-at 2 8 "(oneword/CmlCase)") 'font-lock-type-face)) - (should (eq (clojure-test-face-at 9 10 "(oneword/CmlCase)") 'default)) - (should (eq (clojure-test-face-at 11 16 "(oneword/CmlCase)") 'default)) + (should (eq (clojure-test-face-at 9 10 "(oneword/CmlCase)") nil)) + (should (eq (clojure-test-face-at 11 16 "(oneword/CmlCase)") nil)) (should (eq (clojure-test-face-at 2 8 "(oneword/ve/yCom|pLex.stu-ff)") 'font-lock-type-face)) (should (eq (clojure-test-face-at 9 10 "(oneword/ve/yCom|pLex.stu-ff)") - 'default)) + nil)) (should (eq (clojure-test-face-at 11 28 "(oneword/ve/yCom|pLex.stu-ff)") - 'default)) + nil)) (should (eq (clojure-test-face-at 2 8 "(oneword/.ve/yCom|pLex.stu-ff)") 'font-lock-type-face)) (should (eq (clojure-test-face-at 9 10 "(oneword/.ve/yCom|pLex.stu-ff)") - 'default)) + nil)) (should (eq (clojure-test-face-at 12 29 "(oneword/.ve/yCom|pLex.stu-ff)") - 'default))) + nil))) (ert-deftest clojure-mode-syntax-table/segment () :tags '(fontification syntax-table) - (should (eq (clojure-test-face-at 2 8 " seg.mnt") 'default)) - (should (eq (clojure-test-face-at 2 8 "@seg.mnt") 'default)) - (should (eq (clojure-test-face-at 2 8 "#seg.mnt") 'default)) - (should (eq (clojure-test-face-at 2 8 ".seg.mnt") 'default)) + (should (eq (clojure-test-face-at 2 8 " seg.mnt") nil)) + (should (eq (clojure-test-face-at 2 8 "@seg.mnt") nil)) + (should (eq (clojure-test-face-at 2 8 "#seg.mnt") nil)) + (should (eq (clojure-test-face-at 2 8 ".seg.mnt") nil)) (should (eq (clojure-test-face-at 3 9 "#^seg.mnt") 'font-lock-type-face)) ;; type-hint - (should (eq (clojure-test-face-at 2 8 "(seg.mnt)") 'default)) + (should (eq (clojure-test-face-at 2 8 "(seg.mnt)") nil)) (should (eq (clojure-test-face-at 2 8 "(seg.mnt/oneword)") 'font-lock-type-face)) - (should (eq (clojure-test-face-at 9 10 "(seg.mnt/oneword)") 'default)) - (should (eq (clojure-test-face-at 11 16 "(seg.mnt/oneword)") 'default)) + (should (eq (clojure-test-face-at 9 10 "(seg.mnt/oneword)") nil)) + (should (eq (clojure-test-face-at 11 16 "(seg.mnt/oneword)") nil)) (should (eq (clojure-test-face-at 2 8 "(seg.mnt/seg.mnt)") 'font-lock-type-face)) - (should (eq (clojure-test-face-at 9 10 "(seg.mnt/seg.mnt)") 'default)) - (should (eq (clojure-test-face-at 11 16 "(seg.mnt/seg.mnt)") 'default)) + (should (eq (clojure-test-face-at 9 10 "(seg.mnt/seg.mnt)") nil)) + (should (eq (clojure-test-face-at 11 16 "(seg.mnt/seg.mnt)") nil)) (should (eq (clojure-test-face-at 2 8 "(seg.mnt/mxdCase)") 'font-lock-type-face)) - (should (eq (clojure-test-face-at 9 10 "(seg.mnt/mxdCase)") 'default)) - (should (eq (clojure-test-face-at 11 16 "(seg.mnt/mxdCase)") 'default)) + (should (eq (clojure-test-face-at 9 10 "(seg.mnt/mxdCase)") nil)) + (should (eq (clojure-test-face-at 11 16 "(seg.mnt/mxdCase)") nil)) (should (eq (clojure-test-face-at 2 8 "(seg.mnt/CmlCase)") 'font-lock-type-face)) - (should (eq (clojure-test-face-at 9 10 "(seg.mnt/CmlCase)") 'default)) - (should (eq (clojure-test-face-at 11 16 "(seg.mnt/CmlCase)") 'default)) + (should (eq (clojure-test-face-at 9 10 "(seg.mnt/CmlCase)") nil)) + (should (eq (clojure-test-face-at 11 16 "(seg.mnt/CmlCase)") nil)) (should (eq (clojure-test-face-at 2 8 "(seg.mnt/ve/yCom|pLex.stu-ff)") 'font-lock-type-face)) (should (eq (clojure-test-face-at 9 10 "(seg.mnt/ve/yCom|pLex.stu-ff)") - 'default)) + nil)) (should (eq (clojure-test-face-at 11 28 "(seg.mnt/ve/yCom|pLex.stu-ff)") - 'default)) + nil)) (should (eq (clojure-test-face-at 2 8 "(seg.mnt/.ve/yCom|pLex.stu-ff)") 'font-lock-type-face)) (should (eq (clojure-test-face-at 9 10 "(seg.mnt/.ve/yCom|pLex.stu-ff)") - 'default)) + nil)) (should (eq (clojure-test-face-at 12 29 "(seg.mnt/.ve/yCom|pLex.stu-ff)") - 'default))) + nil))) (ert-deftest clojure-mode-syntax-table/camelcase () :tags '(fontification syntax-table) - (should (eq (clojure-test-face-at 2 8 " CmlCase") 'default)) - (should (eq (clojure-test-face-at 2 8 "@CmlCase") 'default)) - (should (eq (clojure-test-face-at 2 8 "#CmlCase") 'default)) - (should (eq (clojure-test-face-at 2 8 ".CmlCase") 'default)) + (should (eq (clojure-test-face-at 2 8 " CmlCase") nil)) + (should (eq (clojure-test-face-at 2 8 "@CmlCase") nil)) + (should (eq (clojure-test-face-at 2 8 "#CmlCase") nil)) + (should (eq (clojure-test-face-at 2 8 ".CmlCase") nil)) (should (eq (clojure-test-face-at 3 9 "#^CmlCase") 'font-lock-type-face)) ;; type-hint - (should (eq (clojure-test-face-at 2 8 "(CmlCase)") 'default)) + (should (eq (clojure-test-face-at 2 8 "(CmlCase)") nil)) (should (eq (clojure-test-face-at 2 8 "(CmlCase/oneword)") 'font-lock-type-face)) - (should (eq (clojure-test-face-at 9 10 "(CmlCase/oneword)") 'default)) - (should (eq (clojure-test-face-at 11 16 "(CmlCase/oneword)") 'default)) + (should (eq (clojure-test-face-at 9 10 "(CmlCase/oneword)") nil)) + (should (eq (clojure-test-face-at 11 16 "(CmlCase/oneword)") nil)) (should (eq (clojure-test-face-at 2 8 "(CmlCase/seg.mnt)") 'font-lock-type-face)) - (should (eq (clojure-test-face-at 9 10 "(CmlCase/seg.mnt)") 'default)) - (should (eq (clojure-test-face-at 11 16 "(CmlCase/seg.mnt)") 'default)) + (should (eq (clojure-test-face-at 9 10 "(CmlCase/seg.mnt)") nil)) + (should (eq (clojure-test-face-at 11 16 "(CmlCase/seg.mnt)") nil)) (should (eq (clojure-test-face-at 2 8 "(CmlCase/mxdCase)") 'font-lock-type-face)) - (should (eq (clojure-test-face-at 9 10 "(CmlCase/mxdCase)") 'default)) - (should (eq (clojure-test-face-at 11 16 "(CmlCase/mxdCase)") 'default)) + (should (eq (clojure-test-face-at 9 10 "(CmlCase/mxdCase)") nil)) + (should (eq (clojure-test-face-at 11 16 "(CmlCase/mxdCase)") nil)) (should (eq (clojure-test-face-at 2 8 "(CmlCase/CmlCase)") 'font-lock-type-face)) - (should (eq (clojure-test-face-at 9 10 "(CmlCase/CmlCase)") 'default)) - (should (eq (clojure-test-face-at 11 16 "(CmlCase/CmlCase)") 'default)) + (should (eq (clojure-test-face-at 9 10 "(CmlCase/CmlCase)") nil)) + (should (eq (clojure-test-face-at 11 16 "(CmlCase/CmlCase)") nil)) (should (eq (clojure-test-face-at 2 8 "(CmlCase/ve/yCom|pLex.stu-ff)") 'font-lock-type-face)) (should (eq (clojure-test-face-at 9 10 "(CmlCase/ve/yCom|pLex.stu-ff)") - 'default)) + nil)) (should (eq (clojure-test-face-at 11 28 "(CmlCase/ve/yCom|pLex.stu-ff)") - 'default)) + nil)) (should (eq (clojure-test-face-at 2 8 "(CmlCase/.ve/yCom|pLex.stu-ff)") 'font-lock-type-face)) (should (eq (clojure-test-face-at 9 10 "(CmlCase/.ve/yCom|pLex.stu-ff)") - 'default)) + nil)) (should (eq (clojure-test-face-at 12 29 "(CmlCase/.ve/yCom|pLex.stu-ff)") - 'default))) + nil))) (ert-deftest clojure-mode-syntax-table/mixedcase () :tags '(fontification syntax-table) - (should (eq (clojure-test-face-at 2 8 " mxdCase") 'default)) - (should (eq (clojure-test-face-at 2 8 "@mxdCase") 'default)) - (should (eq (clojure-test-face-at 2 8 "#mxdCase") 'default)) - (should (eq (clojure-test-face-at 2 8 ".mxdCase") 'default)) + (should (eq (clojure-test-face-at 2 8 " mxdCase") nil)) + (should (eq (clojure-test-face-at 2 8 "@mxdCase") nil)) + (should (eq (clojure-test-face-at 2 8 "#mxdCase") nil)) + (should (eq (clojure-test-face-at 2 8 ".mxdCase") nil)) (should (eq (clojure-test-face-at 3 9 "#^mxdCase") 'font-lock-type-face)) ;; type-hint - (should (eq (clojure-test-face-at 2 8 "(mxdCase)") 'default)) + (should (eq (clojure-test-face-at 2 8 "(mxdCase)") nil)) (should (eq (clojure-test-face-at 2 8 "(mxdCase/oneword)") 'font-lock-type-face)) - (should (eq (clojure-test-face-at 9 10 "(mxdCase/oneword)") 'default)) - (should (eq (clojure-test-face-at 11 16 "(mxdCase/oneword)") 'default)) + (should (eq (clojure-test-face-at 9 10 "(mxdCase/oneword)") nil)) + (should (eq (clojure-test-face-at 11 16 "(mxdCase/oneword)") nil)) (should (eq (clojure-test-face-at 2 8 "(mxdCase/seg.mnt)") 'font-lock-type-face)) - (should (eq (clojure-test-face-at 9 10 "(mxdCase/seg.mnt)") 'default)) - (should (eq (clojure-test-face-at 11 16 "(mxdCase/seg.mnt)") 'default)) + (should (eq (clojure-test-face-at 9 10 "(mxdCase/seg.mnt)") nil)) + (should (eq (clojure-test-face-at 11 16 "(mxdCase/seg.mnt)") nil)) (should (eq (clojure-test-face-at 2 8 "(mxdCase/mxdCase)") 'font-lock-type-face)) - (should (eq (clojure-test-face-at 9 10 "(mxdCase/mxdCase)") 'default)) - (should (eq (clojure-test-face-at 11 16 "(mxdCase/mxdCase)") 'default)) + (should (eq (clojure-test-face-at 9 10 "(mxdCase/mxdCase)") nil)) + (should (eq (clojure-test-face-at 11 16 "(mxdCase/mxdCase)") nil)) (should (eq (clojure-test-face-at 2 8 "(mxdCase/CmlCase)") 'font-lock-type-face)) - (should (eq (clojure-test-face-at 9 10 "(mxdCase/CmlCase)") 'default)) - (should (eq (clojure-test-face-at 11 16 "(mxdCase/CmlCase)") 'default)) + (should (eq (clojure-test-face-at 9 10 "(mxdCase/CmlCase)") nil)) + (should (eq (clojure-test-face-at 11 16 "(mxdCase/CmlCase)") nil)) (should (eq (clojure-test-face-at 2 8 "(mxdCase/ve/yCom|pLex.stu-ff)") 'font-lock-type-face)) (should (eq (clojure-test-face-at 9 10 "(mxdCase/ve/yCom|pLex.stu-ff)") - 'default)) + nil)) (should (eq (clojure-test-face-at 11 28 "(mxdCase/ve/yCom|pLex.stu-ff)") - 'default)) + nil)) (should (eq (clojure-test-face-at 2 8 "(mxdCase/.ve/yCom|pLex.stu-ff)") 'font-lock-type-face)) (should (eq (clojure-test-face-at 9 10 "(mxdCase/.ve/yCom|pLex.stu-ff)") - 'default)) + nil)) (should (eq (clojure-test-face-at 12 29 "(mxdCase/.ve/yCom|pLex.stu-ff)") - 'default))) + nil))) (ert-deftest clojure-mode-syntax-table/verycomplex () :tags '(fontification syntax-table) (should (eq (clojure-test-face-at 3 4 " ve/yCom|pLex.stu-ff") 'font-lock-type-face)) - (should (eq (clojure-test-face-at 5 21 " ve/yCom|pLex.stu-ff") 'default)) + (should (eq (clojure-test-face-at 5 21 " ve/yCom|pLex.stu-ff") nil)) - (should (eq (clojure-test-face-at 2 2 " @ve/yCom|pLex.stu-ff") 'nil)) + (should (eq (clojure-test-face-at 2 2 " @ve/yCom|pLex.stu-ff") nil)) (should (eq (clojure-test-face-at 3 4 " @ve/yCom|pLex.stu-ff") 'font-lock-type-face)) - (should (eq (clojure-test-face-at 5 21 " @ve/yCom|pLex.stu-ff") 'default)) + (should (eq (clojure-test-face-at 5 21 " @ve/yCom|pLex.stu-ff") nil)) (should (eq (clojure-test-face-at 2 4 " #ve/yCom|pLex.stu-ff") 'font-lock-type-face)) - (should (eq (clojure-test-face-at 5 21 " #ve/yCom|pLex.stu-ff") 'default)) + (should (eq (clojure-test-face-at 5 21 " #ve/yCom|pLex.stu-ff") nil)) (should (eq (clojure-test-face-at 2 4 " .ve/yCom|pLex.stu-ff") 'font-lock-type-face)) - (should (eq (clojure-test-face-at 5 21 " .ve/yCom|pLex.stu-ff") 'default)) + (should (eq (clojure-test-face-at 5 21 " .ve/yCom|pLex.stu-ff") nil)) ;; type-hint (should (eq (clojure-test-face-at 1 2 "#^ve/yCom|pLex.stu-ff") 'default)) @@ -353,41 +353,41 @@ POS." (should (eq (clojure-test-face-at 3 4 " (ve/yCom|pLex.stu-ff)") 'font-lock-type-face)) - (should (eq (clojure-test-face-at 5 21 " (ve/yCom|pLex.stu-ff)") 'default)) + (should (eq (clojure-test-face-at 5 21 " (ve/yCom|pLex.stu-ff)") nil)) (should (eq (clojure-test-face-at 3 4 " (ve/yCom|pLex.stu-ff/oneword)") 'font-lock-type-face)) (should (eq (clojure-test-face-at 5 29 " (ve/yCom|pLex.stu-ff/oneword)") - 'default)) + nil)) (should (eq (clojure-test-face-at 3 4 " (ve/yCom|pLex.stu-ff/seg.mnt)") 'font-lock-type-face)) (should (eq (clojure-test-face-at 5 29 " (ve/yCom|pLex.stu-ff/seg.mnt)") - 'default)) + nil)) (should (eq (clojure-test-face-at 3 4 " (ve/yCom|pLex.stu-ff/mxdCase)") 'font-lock-type-face)) (should (eq (clojure-test-face-at 5 29 " (ve/yCom|pLex.stu-ff/mxdCase)") - 'default)) + nil)) (should (eq (clojure-test-face-at 3 4 " (ve/yCom|pLex.stu-ff/CmlCase)") 'font-lock-type-face)) (should (eq (clojure-test-face-at 5 29 " (ve/yCom|pLex.stu-ff/CmlCase)") - 'default)) + nil)) (should (eq (clojure-test-face-at 3 4 " (ve/yCom|pLex.stu-ff/ve/yCom|pLex.stu-ff)") 'font-lock-type-face)) (should (eq (clojure-test-face-at 5 41 " (ve/yCom|pLex.stu-ff/ve/yCom|pLex.stu-ff)") - 'default)) + nil)) (should (eq (clojure-test-face-at 3 4 " (ve/yCom|pLex.stu-ff/.ve/yCom|pLex.stu-ff)") 'font-lock-type-face)) (should (eq (clojure-test-face-at 5 42 " (ve/yCom|pLex.stu-ff/.ve/yCom|pLex.stu-ff)") - 'default))) + nil))) (ert-deftest clojure-mode-syntax-table/kw-oneword () :tags '(fontification syntax-table) @@ -701,12 +701,12 @@ POS." :tags '(fontification syntax-table) (clojure-test-with-temp-buffer "(_c4/defconstrainedfn bar [] nil)" (should (eq (clojure-test-face-at 2 4) 'font-lock-type-face)) - (should (eq (clojure-test-face-at 5 5) 'default)) + (should (eq (clojure-test-face-at 5 5) nil)) (should (eq (clojure-test-face-at 6 18) 'font-lock-keyword-face)) (should (eq (clojure-test-face-at 23 25) 'font-lock-function-name-face))) (clojure-test-with-temp-buffer "(clo/defbar foo nil)" (should (eq (clojure-test-face-at 2 4) 'font-lock-type-face)) - (should (eq (clojure-test-face-at 5 5) 'default)) + (should (eq (clojure-test-face-at 5 5) nil)) (should (eq (clojure-test-face-at 6 11) 'font-lock-keyword-face)) (should (eq (clojure-test-face-at 13 15) 'font-lock-function-name-face)))) From d473dc10b2469a14e42d28be5ec67b80ec049b06 Mon Sep 17 00:00:00 2001 From: Bozhidar Batsov Date: Sat, 26 May 2018 12:25:48 +0300 Subject: [PATCH 119/199] [clojure-emacs/cider#2281] Cache the results of clojure-project-dir --- clojure-mode-util-test.el | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/clojure-mode-util-test.el b/clojure-mode-util-test.el index b028d30..09ffb41 100644 --- a/clojure-mode-util-test.el +++ b/clojure-mode-util-test.el @@ -29,7 +29,8 @@ (let ((project-dir "/home/user/projects/my-project/") (clj-file-path "/home/user/projects/my-project/src/clj/my_project/my_ns/my_file.clj") (project-relative-clj-file-path "src/clj/my_project/my_ns/my_file.clj") - (clj-file-ns "my-project.my-ns.my-file")) + (clj-file-ns "my-project.my-ns.my-file") + (clojure-cache-project nil)) (ert-deftest project-relative-path () :tags '(utils) From 17238f94e6f9a73128b98a6b155d58c13afe5786 Mon Sep 17 00:00:00 2001 From: Bozhidar Batsov Date: Tue, 26 Jun 2018 14:41:56 +0300 Subject: [PATCH 120/199] Don't cache ns in the test for clojure-find-ns The test uses a file with two namespaces in one source file, which doesn't work properly with ns caching. --- clojure-mode-sexp-test.el | 38 ++++++++++++++++++++------------------ 1 file changed, 20 insertions(+), 18 deletions(-) diff --git a/clojure-mode-sexp-test.el b/clojure-mode-sexp-test.el index a9a5425..f8c555b 100644 --- a/clojure-mode-sexp-test.el +++ b/clojure-mode-sexp-test.el @@ -76,24 +76,26 @@ (newline-and-indent))) (ert-deftest clojure-find-ns-test () - (with-temp-buffer - (insert "(ns ^{:doc \"Some docs\"}\nfoo-bar)") - (newline) - (newline) - (insert "(in-ns 'baz-quux)") - (clojure-mode) - - ;; From inside docstring of first ns - (goto-char 18) - (should (equal "foo-bar" (clojure-find-ns))) - - ;; From inside first ns's name, on its own line - (goto-char 29) - (should (equal "foo-bar" (clojure-find-ns))) - - ;; From inside second ns's name - (goto-char 42) - (should (equal "baz-quux" (clojure-find-ns))))) + ;; we should not cache the results of `clojure-find-ns' here + (let ((clojure-cache-ns nil)) + (with-temp-buffer + (insert "(ns ^{:doc \"Some docs\"}\nfoo-bar)") + (newline) + (newline) + (insert "(in-ns 'baz-quux)") + (clojure-mode) + + ;; From inside docstring of first ns + (goto-char 18) + (should (equal "foo-bar" (clojure-find-ns))) + + ;; From inside first ns's name, on its own line + (goto-char 29) + (should (equal "foo-bar" (clojure-find-ns))) + + ;; From inside second ns's name + (goto-char 42) + (should (equal "baz-quux" (clojure-find-ns)))))) (provide 'clojure-mode-sexp-test) From 07d9cf75f828e2f07862b4fce6b50af3ab604dab Mon Sep 17 00:00:00 2001 From: dan sutton Date: Sun, 12 Aug 2018 15:35:12 -0500 Subject: [PATCH 121/199] Make `beginning-of-defun` aware of clojure comment form Remove seq-find usage Move initialization of beginning-of-defun-function to correct spot Use new function name in tests Docstring for checkdoc --- clojure-mode-sexp-test.el | 45 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) diff --git a/clojure-mode-sexp-test.el b/clojure-mode-sexp-test.el index f8c555b..1faf103 100644 --- a/clojure-mode-sexp-test.el +++ b/clojure-mode-sexp-test.el @@ -22,6 +22,51 @@ (require 'clojure-mode) (require 'ert) +(defmacro clojure-buffer-with-text (text &rest body) + "Run body in a temporary clojure buffer with TEXT. +TEXT is a string with a | indicating where point is. The | will be erased +and point left there." + (declare (indent 2)) + `(progn + (with-temp-buffer + (erase-buffer) + (clojure-mode) + (insert ,text) + (goto-char (point-min)) + (re-search-forward "|") + (delete-char -1) + ,@body))) + +(ert-deftest test-clojure-top-level-form-p () + (clojure-buffer-with-text + "(comment + (wrong) + (rig|ht) + (wrong))" + ;; make this use the native beginning of defun since this is used to + ;; determine whether to use the comment aware version or not. + (should (let ((beginning-of-defun-function nil)) + (clojure-top-level-form-p "comment"))))) + +(ert-deftest test-clojure-beginning-of-defun-function () + (clojure-buffer-with-text + "(comment + (wrong) + (wrong) + (rig|ht) + (wrong))" + (beginning-of-defun) + (should (looking-at-p "(comment"))) + (clojure-buffer-with-text + "(comment + (wrong) + (wrong) + (rig|ht) + (wrong))" + (let ((clojure-toplevel-inside-comment-form t)) + (beginning-of-defun)) + (should (looking-at-p "(right)")))) + (ert-deftest test-sexp-with-commas () (with-temp-buffer (insert "[], {}, :a, 2") From 2a8e78618baecfe5ca9fd3332af500d6d7da06f7 Mon Sep 17 00:00:00 2001 From: dan sutton Date: Fri, 24 Aug 2018 08:09:38 -0500 Subject: [PATCH 122/199] Fix bug in end-of-defun Going to end of defun would skip over two forms. Needed to pass on the negative prefix that was used by the generic parts of this mechanism. Also fixed an issue with paredit would not insert parens in an empty buffer by handling the `end-of-buffer` condition. --- clojure-mode-sexp-test.el | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/clojure-mode-sexp-test.el b/clojure-mode-sexp-test.el index 1faf103..40f861c 100644 --- a/clojure-mode-sexp-test.el +++ b/clojure-mode-sexp-test.el @@ -65,7 +65,21 @@ and point left there." (wrong))" (let ((clojure-toplevel-inside-comment-form t)) (beginning-of-defun)) - (should (looking-at-p "(right)")))) + (should (looking-at-p "[[:space:]]*(right)")))) + +(ert-deftest test-clojure-end-of-defun-function () + (clojure-buffer-with-text + " +(first form) +| +(second form) + +(third form)" + + (end-of-defun) + (backward-char) + (should (looking-back "(second form)")))) + (ert-deftest test-sexp-with-commas () (with-temp-buffer From 7ad641e20c693abc355d9d8871fd46002ca1f9de Mon Sep 17 00:00:00 2001 From: vemv Date: Mon, 27 Aug 2018 20:26:22 +0200 Subject: [PATCH 123/199] [Fix #483] Support alignment for reader conditionals (#486) --- clojure-mode-indentation-test.el | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/clojure-mode-indentation-test.el b/clojure-mode-indentation-test.el index 71e4ab5..6f22503 100644 --- a/clojure-mode-indentation-test.el +++ b/clojure-mode-indentation-test.el @@ -485,7 +485,8 @@ x "Verify that all FORMs correspond to a properly indented sexps." (declare (indent defun)) `(ert-deftest ,(intern (format "test-align-%s" name)) () - (let ((clojure-align-forms-automatically t)) + (let ((clojure-align-forms-automatically t) + (clojure-align-reader-conditionals t)) ,@(mapcar (lambda (form) `(with-temp-buffer (clojure-mode) @@ -596,6 +597,28 @@ x :b {:a :a, :aa :a}}") +(def-full-align-test reader-conditional + "#?(:clj 2 + :cljs 2)") + +(def-full-align-test reader-conditional-splicing + "#?@(:clj [2] + :cljs [2])") + +(ert-deftest reader-conditional-alignment-disabled-by-default () + (let ((content "#?(:clj 2\n :cljs 2)")) + (with-temp-buffer + (clojure-mode) + (insert content) + (call-interactively #'clojure-align) + (should (string= (buffer-string) content))) + (with-temp-buffer + (clojure-mode) + (setq-local clojure-align-reader-conditionals t) + (insert content) + (call-interactively #'clojure-align) + (should-not (string= (buffer-string) content))))) + (ert-deftest clojure-align-remove-extra-commas () (with-temp-buffer (clojure-mode) From 5e4ec40f4d2b6e4acbcabcb2064dad9832a3aeaa Mon Sep 17 00:00:00 2001 From: dpsutton Date: Mon, 1 Oct 2018 14:01:40 -0500 Subject: [PATCH 124/199] [Fix #489] Inserting parens before comment form doesn't move point (#490) In a form like ``` | (comment (stuff)) ``` Entering parens with paredit would put the parens right before the comment block. Paredit determines if it is in a comment to insert parens so it doesn't automatically enter a closing when in a comment or a string. Part of this called beginning-of-defun which we have modified. The error here was that rater than just going to the beginning of the form, we went to the end and then back one logical form to be at the beginning. This is identical behavior _unless_ you are between two forms. Going straight to the beginning put you in the first form, going to the end and then the beginning puts you in the second form. I.e., ``` (formA) | (formB) ``` Our beginning of form went to formB but it should go to formA. --- clojure-mode-sexp-test.el | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/clojure-mode-sexp-test.el b/clojure-mode-sexp-test.el index 40f861c..a15a319 100644 --- a/clojure-mode-sexp-test.el +++ b/clojure-mode-sexp-test.el @@ -65,7 +65,15 @@ and point left there." (wrong))" (let ((clojure-toplevel-inside-comment-form t)) (beginning-of-defun)) - (should (looking-at-p "[[:space:]]*(right)")))) + (should (looking-at-p "[[:space:]]*(right)"))) + (clojure-buffer-with-text + " +(formA) +| +(formB)" + (let ((clojure-toplevel-inside-comment-form t)) + (beginning-of-defun) + (should (looking-at-p "(formA)"))))) (ert-deftest test-clojure-end-of-defun-function () (clojure-buffer-with-text From 037baeb77ab6b34982a85c4ff66de31038bb6e89 Mon Sep 17 00:00:00 2001 From: Vitalie Spinu Date: Wed, 24 Oct 2018 20:38:01 +0200 Subject: [PATCH 125/199] Fix font-lock of type hints #462 --- clojure-mode-font-lock-test.el | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/clojure-mode-font-lock-test.el b/clojure-mode-font-lock-test.el index 69f5bf6..f97c30f 100644 --- a/clojure-mode-font-lock-test.el +++ b/clojure-mode-font-lock-test.el @@ -347,9 +347,10 @@ POS." ;; type-hint (should (eq (clojure-test-face-at 1 2 "#^ve/yCom|pLex.stu-ff") 'default)) - (should (eq (clojure-test-face-at 3 4 "#^ve/yCom|pLex.stu-ff") - 'font-lock-type-face)) + (should (eq (clojure-test-face-at 3 4 "#^ve/yCom|pLex.stu-ff") 'font-lock-type-face)) (should (eq (clojure-test-face-at 5 21 "#^ve/yCom|pLex.stu-ff") 'default)) + (should (eq (clojure-test-face-at 2 3 "^ve/yCom|pLex.stu-ff") 'font-lock-type-face)) + (should (eq (clojure-test-face-at 5 20 "^ve/yCom|pLex.stu-ff") 'default)) (should (eq (clojure-test-face-at 3 4 " (ve/yCom|pLex.stu-ff)") 'font-lock-type-face)) From ec97912ae6a97cbb5ad3b0cd8ee34282cc2ed4e4 Mon Sep 17 00:00:00 2001 From: Markku Rontu Date: Sat, 5 Jan 2019 10:53:19 +0200 Subject: [PATCH 126/199] Indent "let", "when" and "while" as function form if not at start (#497) "let", "when" and "while" are considered to be a macro form normally: (when foo bar) Also you can introduce macros that start with "let", "when" or "while" that will be indented like macro forms: (when-foo-bar 1 2 3) But when "let", "when" and "while" are not in the beginning of a symbol they are now treated as function forms: (foo-when-bar 1 2 3) --- clojure-mode-indentation-test.el | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/clojure-mode-indentation-test.el b/clojure-mode-indentation-test.el index 6f22503..51af55c 100644 --- a/clojure-mode-indentation-test.el +++ b/clojure-mode-indentation-test.el @@ -421,7 +421,9 @@ values of customisable variables." (def-full-indent-test let-when-while-forms "(let-alist [x 1]\n ())" "(while-alist [x 1]\n ())" - "(when-alist [x 1]\n ())") + "(when-alist [x 1]\n ())" + "(if-alist [x 1]\n ())" + "(indents-like-fn-when-let-while-if-are-not-the-start [x 1]\n ())") (defun indent-cond (indent-point state) (goto-char (elt state 1)) From 855bc2c80d105e12bf8cf3be61205d1eaaa63c9d Mon Sep 17 00:00:00 2001 From: Bozhidar Batsov Date: Sat, 5 Jan 2019 12:43:13 +0200 Subject: [PATCH 127/199] Clean up the indentation config logic * Converted the type of `clojure-indent-style` to symbol for consistency with Emacs configuration practices. * Removed some legacy code related to clojure-defun-style-default-indent. --- clojure-mode-indentation-test.el | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/clojure-mode-indentation-test.el b/clojure-mode-indentation-test.el index 51af55c..613e692 100644 --- a/clojure-mode-indentation-test.el +++ b/clojure-mode-indentation-test.el @@ -58,7 +58,7 @@ values of customisable variables." (let ((fname (intern (format "indentation/%s" description)))) `(ert-deftest ,fname () (let* ((after ,after) - (clojure-indent-style :always-align) + (clojure-indent-style 'always-align) (expected-cursor-pos (1+ (s-index-of "|" after))) (expected-state (delete ?| after)) ,@var-bindings) @@ -238,14 +238,14 @@ values of customisable variables." (declare (indent 1)) (when (stringp style) (setq forms (cons style forms)) - (setq style :always-align)) + (setq style 'always-align)) `(ert-deftest ,(intern (format "test-backtracking-%s" name)) () (progn ,@(mapcar (lambda (form) `(with-temp-buffer (clojure-mode) (insert "\n" ,(replace-regexp-in-string "\n +" "\n " form)) - (let ((clojure-indent-style ,style)) + (let ((clojure-indent-style (quote ,style))) (indent-region (point-min) (point-max))) (should (equal (buffer-string) ,(concat "\n" form))))) @@ -463,7 +463,7 @@ x 3))") (def-full-indent-test align-arguments - :align-arguments + 'align-arguments "(some-function 10 1 @@ -473,7 +473,7 @@ x 2)") (def-full-indent-test always-indent - :always-indent + 'always-indent "(some-function 10 1 From f88c05a5b23a253b1066730e688d7a23473d4bdc Mon Sep 17 00:00:00 2001 From: Bozhidar Batsov Date: Sat, 5 Jan 2019 13:18:09 +0200 Subject: [PATCH 128/199] Fix the broken build --- clojure-mode-indentation-test.el | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/clojure-mode-indentation-test.el b/clojure-mode-indentation-test.el index 613e692..7c71f11 100644 --- a/clojure-mode-indentation-test.el +++ b/clojure-mode-indentation-test.el @@ -238,14 +238,14 @@ values of customisable variables." (declare (indent 1)) (when (stringp style) (setq forms (cons style forms)) - (setq style 'always-align)) + (setq style '(quote always-align))) `(ert-deftest ,(intern (format "test-backtracking-%s" name)) () (progn ,@(mapcar (lambda (form) `(with-temp-buffer (clojure-mode) (insert "\n" ,(replace-regexp-in-string "\n +" "\n " form)) - (let ((clojure-indent-style (quote ,style))) + (let ((clojure-indent-style ,style)) (indent-region (point-min) (point-max))) (should (equal (buffer-string) ,(concat "\n" form))))) From 2cf589c952e85c1d0a9b71ecbdaaa755f5efdd6c Mon Sep 17 00:00:00 2001 From: Michael Griffiths Date: Sat, 16 Feb 2019 23:19:11 +0000 Subject: [PATCH 129/199] Fix font locking for non-alphanumeric chars in dynamic var names --- clojure-mode-font-lock-test.el | 2 ++ 1 file changed, 2 insertions(+) diff --git a/clojure-mode-font-lock-test.el b/clojure-mode-font-lock-test.el index f97c30f..2eb1fa1 100644 --- a/clojure-mode-font-lock-test.el +++ b/clojure-mode-font-lock-test.el @@ -822,6 +822,8 @@ POS." (should (eq (clojure-test-face-at 2 11 "@*some-var*") 'font-lock-variable-name-face)) (should (eq (clojure-test-face-at 9 13 "some.ns/*var*") + 'font-lock-variable-name-face)) + (should (eq (clojure-test-face-at 1 11 "*some-var?*") 'font-lock-variable-name-face))) (provide 'clojure-mode-font-lock-test) From 002a82decbaedc1ae2d349f7ce69b386afc4f736 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Carlos=20Requena=20L=C3=B3pez?= Date: Mon, 25 Feb 2019 22:02:32 +0100 Subject: [PATCH 130/199] [Fix #506] Makes display version command return the actual version `clojure-mode-display-version` displays the correct version (was displaying nil) also added some tests --- clojure-mode-util-test.el | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/clojure-mode-util-test.el b/clojure-mode-util-test.el index 09ffb41..3d5e0ac 100644 --- a/clojure-mode-util-test.el +++ b/clojure-mode-util-test.el @@ -26,6 +26,10 @@ (require 'cl-lib) (require 'ert) + +(ert-deftest clojure-mode-version-should-be-non-nil () + (should (not (eq clojure-mode-version nil)))) + (let ((project-dir "/home/user/projects/my-project/") (clj-file-path "/home/user/projects/my-project/src/clj/my_project/my_ns/my_file.clj") (project-relative-clj-file-path "src/clj/my_project/my_ns/my_file.clj") From 58d2421d164739df335fa8279c3531a581c519c4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Carlos=20Requena=20L=C3=B3pez?= Date: Mon, 25 Feb 2019 22:06:22 +0100 Subject: [PATCH 131/199] [Fix comment in #445] Proper font lock for (s/def ::keyword) forms added tests as well --- clojure-mode-font-lock-test.el | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/clojure-mode-font-lock-test.el b/clojure-mode-font-lock-test.el index 2eb1fa1..17548b4 100644 --- a/clojure-mode-font-lock-test.el +++ b/clojure-mode-font-lock-test.el @@ -709,7 +709,13 @@ POS." (should (eq (clojure-test-face-at 2 4) 'font-lock-type-face)) (should (eq (clojure-test-face-at 5 5) nil)) (should (eq (clojure-test-face-at 6 11) 'font-lock-keyword-face)) - (should (eq (clojure-test-face-at 13 15) 'font-lock-function-name-face)))) + (should (eq (clojure-test-face-at 13 15) 'font-lock-function-name-face))) + (clojure-test-with-temp-buffer "(s/def ::keyword)" + (should (eq (clojure-test-face-at 2 2) 'font-lock-type-face)) + (should (eq (clojure-test-face-at 3 3) nil)) + (should (eq (clojure-test-face-at 4 6) 'font-lock-keyword-face)) + (should (eq (clojure-test-face-at 8 16) 'clojure-keyword-face)))) + (ert-deftest clojure-mode-syntax-table/variable-def () :tags '(fontification syntax-table) From 4e4b03e2de1ef09d1ec506948ed318311e601dce Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Carlos=20Requena=20L=C3=B3pez?= Date: Mon, 25 Feb 2019 23:44:44 +0100 Subject: [PATCH 132/199] [Fix #508] Correct font-lock for namespaces namespace metadata prevented the namespace name to be highlighted as such add font-lock tests as well. --- clojure-mode-font-lock-test.el | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/clojure-mode-font-lock-test.el b/clojure-mode-font-lock-test.el index 2eb1fa1..8eb187c 100644 --- a/clojure-mode-font-lock-test.el +++ b/clojure-mode-font-lock-test.el @@ -149,7 +149,14 @@ POS." (should (eq (clojure-test-face-at 5 11 "(ns Foo-bar)") 'font-lock-type-face)) (should (eq (clojure-test-face-at 5 11 "(ns Foo-Bar)") 'font-lock-type-face)) (should (eq (clojure-test-face-at 5 11 "(ns foo-Bar)") 'font-lock-type-face)) - (should (eq (clojure-test-face-at 5 9 "(ns one.X)") 'font-lock-type-face))) + (should (eq (clojure-test-face-at 5 9 "(ns one.X)") 'font-lock-type-face)) + (should (eq (clojure-test-face-at 10 16 "(ns ^:md ns-name)") 'font-lock-type-face)) + (should (eq (clojure-test-face-at 13 19 "(ns ^:md \n ns-name)") 'font-lock-type-face)) + (should (eq (clojure-test-face-at 17 23 "(ns ^:md1 ^:md2 ns-name)") 'font-lock-type-face)) + (should (eq (clojure-test-face-at 24 30 "(ns ^:md1 ^{:md2 true} ns-name)") 'font-lock-type-face)) + (should (eq (clojure-test-face-at 24 30 "(ns ^{:md2 true} ^:md1 ns-name)") 'font-lock-type-face)) + (should (eq (clojure-test-face-at 27 33 "(ns ^:md1 ^{:md2 true} \n ns-name)") 'font-lock-type-face)) + (should (eq (clojure-test-face-at 27 33 "(ns ^{:md2 true} ^:md1 \n ns-name)") 'font-lock-type-face))) (ert-deftest clojure-mode-syntax-table/oneword () :tags '(fontification syntax-table) From 49b6a480e826551c550e9037fe2b2db1ac84e63a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Carlos=20Requena=20L=C3=B3pez?= Date: Tue, 26 Feb 2019 00:52:27 +0100 Subject: [PATCH 133/199] [Fix #445] More accurate font locking for strings in def forms - def forms can now have docstrings and strings properly font-locked - they will not be incorrectly indented added tests as well --- clojure-mode-font-lock-test.el | 28 ++++++++++++++++++++++++++++ clojure-mode-indentation-test.el | 5 +++++ 2 files changed, 33 insertions(+) diff --git a/clojure-mode-font-lock-test.el b/clojure-mode-font-lock-test.el index 2eb1fa1..ac202b4 100644 --- a/clojure-mode-font-lock-test.el +++ b/clojure-mode-font-lock-test.el @@ -718,6 +718,34 @@ POS." (should (eq (clojure-test-face-at 6 8 "(def foo 10)") 'font-lock-variable-name-face))) +(ert-deftest clojure-mode-syntax-table/variable-def-string () + :tags '(fontification syntax-table) + (should (eq (clojure-test-face-at 10 16 "(def foo \"hello\")") + 'font-lock-string-face)) + (should (eq (clojure-test-face-at 10 16 "(def foo \"hello\" )") + 'font-lock-string-face)) + (should (eq (clojure-test-face-at 13 19 "(def foo \n \"hello\")") + 'font-lock-string-face)) + (should (eq (clojure-test-face-at 13 19 "(def foo \n \"hello\"\n)") + 'font-lock-string-face))) + +(ert-deftest clojure-mode-syntax-table/variable-def-string-with-docstring () + :tags '(fontification syntax-table) + (should (eq (clojure-test-face-at 10 16 "(def foo \"usage\" \"hello\")") + 'font-lock-doc-face)) + (should (eq (clojure-test-face-at 18 24 "(def foo \"usage\" \"hello\")") + 'font-lock-string-face)) + (should (eq (clojure-test-face-at 18 24 "(def foo \"usage\" \"hello\" )") + 'font-lock-string-face)) + (should (eq (clojure-test-face-at 21 27 "(def foo \"usage\" \n \"hello\")") + 'font-lock-string-face)) + (should (eq (clojure-test-face-at 13 19 "(def foo \n \"usage\" \"hello\")") + 'font-lock-doc-face)) + (should (eq (clojure-test-face-at 13 19 "(def foo \n \"usage\" \n \"hello\")") + 'font-lock-doc-face)) + (should (eq (clojure-test-face-at 24 30 "(def foo \n \"usage\" \n \"hello\")") + 'font-lock-string-face))) + (ert-deftest clojure-mode-syntax-table/type-def () :tags '(fontification syntax-table) (clojure-test-with-temp-buffer "(deftype Foo)" diff --git a/clojure-mode-indentation-test.el b/clojure-mode-indentation-test.el index 7c71f11..7afa3ff 100644 --- a/clojure-mode-indentation-test.el +++ b/clojure-mode-indentation-test.el @@ -68,6 +68,7 @@ values of customisable variables." (search-forward "|") (delete-char -1) (clojure-mode) + (font-lock-ensure) (indent-according-to-mode) (should (equal expected-state (buffer-string))) @@ -118,6 +119,10 @@ values of customisable variables." (->> |expr)") +(check-indentation no-indent-for-def-string + "(def foo \"hello|\")" + "(def foo \"hello|\")") + (check-indentation doc-strings-without-indent-specified " (defn some-fn From 5c594aeb18f052035e60ee270229878484e5450b Mon Sep 17 00:00:00 2001 From: Artur Malabarba Date: Mon, 25 Mar 2019 03:28:59 -0300 Subject: [PATCH 134/199] [Fix #518] Ignore ns forms inside strings in clojure-find-ns (#519) --- clojure-mode-sexp-test.el | 49 +++++++++++++++++++++++++-------------- 1 file changed, 32 insertions(+), 17 deletions(-) diff --git a/clojure-mode-sexp-test.el b/clojure-mode-sexp-test.el index a15a319..f8a97e3 100644 --- a/clojure-mode-sexp-test.el +++ b/clojure-mode-sexp-test.el @@ -146,23 +146,38 @@ and point left there." ;; we should not cache the results of `clojure-find-ns' here (let ((clojure-cache-ns nil)) (with-temp-buffer - (insert "(ns ^{:doc \"Some docs\"}\nfoo-bar)") - (newline) - (newline) - (insert "(in-ns 'baz-quux)") - (clojure-mode) - - ;; From inside docstring of first ns - (goto-char 18) - (should (equal "foo-bar" (clojure-find-ns))) - - ;; From inside first ns's name, on its own line - (goto-char 29) - (should (equal "foo-bar" (clojure-find-ns))) - - ;; From inside second ns's name - (goto-char 42) - (should (equal "baz-quux" (clojure-find-ns)))))) + (insert "(ns ^{:doc \"Some docs\"}\nfoo-bar)") + (newline) + (newline) + (insert "(in-ns 'baz-quux)") + (clojure-mode) + + ;; From inside docstring of first ns + (goto-char 18) + (should (equal "foo-bar" (clojure-find-ns))) + + ;; From inside first ns's name, on its own line + (goto-char 29) + (should (equal "foo-bar" (clojure-find-ns))) + + ;; From inside second ns's name + (goto-char 42) + (should (equal "baz-quux" (clojure-find-ns)))) + (let ((data + '(("\"\n(ns foo-bar)\"\n" "(in-ns 'baz-quux)" "baz-quux") + (";(ns foo-bar)\n" "(in-ns 'baz-quux)" "baz-quux") + ("(ns foo-bar)\n" "\"\n(in-ns 'baz-quux)\"" "foo-bar") + ("(ns foo-bar)\n" ";(in-ns 'baz-quux)" "foo-bar")))) + (pcase-dolist (`(,form1 ,form2 ,expected) data) + (with-temp-buffer + (insert form1) + (save-excursion (insert form2)) + (clojure-mode) + ;; Between the two namespaces + (should (equal expected (clojure-find-ns))) + ;; After both namespaces + (goto-char (point-max)) + (should (equal expected (clojure-find-ns)))))))) (provide 'clojure-mode-sexp-test) From b111dfc54e33ef63b019f389227038f935cb820f Mon Sep 17 00:00:00 2001 From: Robin Karlsson Date: Tue, 9 Apr 2019 20:29:30 +0200 Subject: [PATCH 135/199] [Fix #496] Highlight [[var]] style comments --- clojure-mode-font-lock-test.el | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/clojure-mode-font-lock-test.el b/clojure-mode-font-lock-test.el index 48e9b4c..52fa601 100644 --- a/clojure-mode-font-lock-test.el +++ b/clojure-mode-font-lock-test.el @@ -110,6 +110,23 @@ POS." (should (equal (clojure-test-face-at 4 5 "#\"a\\bc\\n\"") '(bold font-lock-string-face)))) +(ert-deftest clojure-mode-syntax-table/stuff-in-double-brackets () + :tags '(fontification syntax-table) + (should (equal (clojure-test-face-at 1 3 "\"[[#'s/trim]]\"") + font-lock-string-face)) + (should (equal (clojure-test-face-at 4 11 "\"[[#'s/trim]]\"") + '(font-lock-constant-face font-lock-string-face))) + (should (equal (clojure-test-face-at 12 14 "\"[[#'s/trim]]\"") + font-lock-string-face)) + (should (equal (clojure-test-face-at 1 1 ";[[#'s/trim]]") + font-lock-comment-delimiter-face)) + (should (equal (clojure-test-face-at 2 3 ";[[#'s/trim]]") + font-lock-comment-face)) + (should (equal (clojure-test-face-at 4 11 ";[[#'s/trim]]") + '(font-lock-constant-face font-lock-comment-face))) + (should (equal (clojure-test-face-at 12 13 ";[[#'s/trim]]") + font-lock-comment-face))) + (ert-deftest clojure-mode-syntax-table/fontify-let-when-while-type-forms () :tags '(fontification syntax-table) (should (equal (clojure-test-face-at 2 11 "(when-alist [x 1]\n ())") From b2d6d39476f4f339736c76ad958bc0c01e4d0859 Mon Sep 17 00:00:00 2001 From: Anthony Galea Date: Mon, 1 Jul 2019 14:39:58 +0200 Subject: [PATCH 136/199] Add refactoring command `clojure-rename-ns-alias` (#529) Originally requested in clj-refactor: https://github.com/clojure-emacs/clj-refactor.el/issues/366. --- clojure-mode-refactor-rename-ns-alias-test.el | 55 +++++++++++++++++++ 1 file changed, 55 insertions(+) create mode 100644 clojure-mode-refactor-rename-ns-alias-test.el diff --git a/clojure-mode-refactor-rename-ns-alias-test.el b/clojure-mode-refactor-rename-ns-alias-test.el new file mode 100644 index 0000000..8e7f8d8 --- /dev/null +++ b/clojure-mode-refactor-rename-ns-alias-test.el @@ -0,0 +1,55 @@ +;;; clojure-mode-refactor-rename-ns-alias-test.el --- Clojure Mode: refactor rename ns alias -*- lexical-binding: t; -*- + +;; This file is not part of GNU Emacs. + +;; This program is free software; you can redistribute it and/or modify +;; it under the terms of the GNU General Public License as published by +;; the Free Software Foundation, either version 3 of the License, or +;; (at your option) any later version. + +;; This program is distributed in the hope that it will be useful, +;; but WITHOUT ANY WARRANTY; without even the implied warranty of +;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +;; GNU General Public License for more details. + +;; You should have received a copy of the GNU General Public License +;; along with this program. If not, see . + +;;; Code: + +(require 'clojure-mode) +(require 'ert) + +(def-refactor-test test-rename-ns-alias + "(ns cljr.core + (:require [my.lib :as lib])) + + (def m #::lib{:kw 1, :n/kw 2, :_/bare 3, 0 4}) + + (+ (lib/a 1) (b 2))" + "(ns cljr.core + (:require [my.lib :as foo])) + + (def m #::foo{:kw 1, :n/kw 2, :_/bare 3, 0 4}) + + (+ (foo/a 1) (b 2))" + (clojure--rename-ns-alias-internal "lib" "foo")) + +(def-refactor-test test-rename-ns-alias-with-missing-as + "(ns cljr.core + (:require [my.lib :as lib])) + + (def m #::lib{:kw 1, :n/kw 2, :_/bare 3, 0 4}) + + (+ (lib/a 1) (b 2))" + "(ns cljr.core + (:require [my.lib :as lib])) + + (def m #::lib{:kw 1, :n/kw 2, :_/bare 3, 0 4}) + + (+ (lib/a 1) (b 2))" + (clojure--rename-ns-alias-internal "foo" "bar")) + +(provide 'clojure-mode-refactor-rename-ns-alias-test) + +;;; clojure-mode-refactor-rename-ns-alias-test.el ends here From a126773966263f6723f65d84aa90acf2ec82cddf Mon Sep 17 00:00:00 2001 From: Anthony Galea Date: Tue, 9 Jul 2019 08:07:27 +0200 Subject: [PATCH 137/199] [#422] Split def-refactor-test macro into 2 separate macros. --- test-helper.el | 36 +++++++++++++++++++++--------------- 1 file changed, 21 insertions(+), 15 deletions(-) diff --git a/test-helper.el b/test-helper.el index 1c98eb3..840cfc9 100644 --- a/test-helper.el +++ b/test-helper.el @@ -19,7 +19,7 @@ ;;; Commentary: -;; Non-interactive test suite setup for ERT Runner. +;; Non-interactive test suite setup. ;;; Code: @@ -32,20 +32,26 @@ ;; Load the file under test (load (expand-file-name "clojure-mode" source-directory))) -(defmacro def-refactor-test (name before after &rest body) - (declare (indent 3)) - `(progn - (put ',name 'definition-name ',name) - (ert-deftest ,name () - (let ((clojure-thread-all-but-last nil) - (clojure-use-metadata-for-privacy nil)) - (with-temp-buffer - (insert ,before) - (clojure-mode) - ,@body - (should (equal ,(concat "\n" after) - (concat "\n" (buffer-substring-no-properties - (point-min) (point-max)))))))))) +(defmacro with-clojure-buffer (text &rest body) + "Create a temporary buffer, insert TEXT, switch to clojure-mode and evaluate BODY." + `(with-temp-buffer + (erase-buffer) + (insert ,text) + (clojure-mode) + ,@body)) +(defmacro when-refactoring-it (description before after &rest body) + "Return a buttercup spec. + +Insert BEFORE into a buffer, evaluate BODY and compare the resulting buffer to +AFTER. + +BODY should contain the refactoring that transforms BEFORE into AFTER. + +DESCRIPTION is the description of the spec." + `(it ,description + (with-clojure-buffer ,before + ,@body + (expect (buffer-string) :to-equal ,after)))) ;;; test-helper.el ends here From 9c82c7834b9711f099a44b49b313e5ff4e43780e Mon Sep 17 00:00:00 2001 From: Anthony Galea Date: Tue, 9 Jul 2019 08:08:36 +0200 Subject: [PATCH 138/199] [#422] Convert tests to buttercup. --- clojure-mode-convert-collection-test.el | 93 +- clojure-mode-cycling-test.el | 171 +- clojure-mode-font-lock-test.el | 1680 +++++++++-------- clojure-mode-indentation-test.el | 715 +++---- clojure-mode-refactor-let-test.el | 180 +- clojure-mode-refactor-rename-ns-alias-test.el | 23 +- clojure-mode-refactor-threading-test.el | 400 ++-- clojure-mode-sexp-test.el | 244 ++- clojure-mode-syntax-test.el | 193 +- clojure-mode-util-test.el | 180 +- test-helper.el | 2 + 11 files changed, 2041 insertions(+), 1840 deletions(-) diff --git a/clojure-mode-convert-collection-test.el b/clojure-mode-convert-collection-test.el index 790b6b6..545b2ef 100644 --- a/clojure-mode-convert-collection-test.el +++ b/clojure-mode-convert-collection-test.el @@ -26,49 +26,56 @@ ;;; Code: (require 'clojure-mode) -(require 'ert) - -(def-refactor-test test-convert-collection-list-map - "(:a 1 :b 2)" - "{:a 1 :b 2}" - (backward-sexp) - (down-list) - (clojure-convert-collection-to-map)) - -(def-refactor-test test-convert-collection-map-vector - "{:a 1 :b 2}" - "[:a 1 :b 2]" - (backward-sexp) - (down-list) - (clojure-convert-collection-to-vector)) - -(def-refactor-test test-convert-collection-vector-set - "[1 2 3]" - "#{1 2 3}" - (backward-sexp) - (down-list) - (clojure-convert-collection-to-set)) - -(def-refactor-test test-convert-collection-set-list - "#{1 2 3}" - "(1 2 3)" - (backward-sexp) - (down-list) - (clojure-convert-collection-to-list)) - -(def-refactor-test test-convert-collection-set-quoted-list - "#{1 2 3}" - "'(1 2 3)" - (backward-sexp) - (down-list) - (clojure-convert-collection-to-quoted-list)) - -(def-refactor-test test-convert-collection-quoted-list-set - "'(1 2 3)" - "#{1 2 3}" - (backward-sexp) - (down-list) - (clojure-convert-collection-to-set)) +(require 'test-helper) +(require 'buttercup) + +(describe "clojure-convert-collection-to-map" + (when-refactoring-it "should convert a list to a map" + "(:a 1 :b 2)" + "{:a 1 :b 2}" + (backward-sexp) + (down-list) + (clojure-convert-collection-to-map))) + +(describe "clojure-convert-collection-to-vector" + (when-refactoring-it "should convert a map to a vector" + "{:a 1 :b 2}" + "[:a 1 :b 2]" + (backward-sexp) + (down-list) + (clojure-convert-collection-to-vector))) + +(describe "clojure-convert-collection-to-set" + (when-refactoring-it "should convert a vector to a set" + "[1 2 3]" + "#{1 2 3}" + (backward-sexp) + (down-list) + (clojure-convert-collection-to-set))) + +(describe "clojure-convert-collection-to-list" + (when-refactoring-it "should convert a set to a list" + "#{1 2 3}" + "(1 2 3)" + (backward-sexp) + (down-list) + (clojure-convert-collection-to-list))) + +(describe "clojure-convert-collection-to-quoted-list" + (when-refactoring-it "should convert a set to a quoted list" + "#{1 2 3}" + "'(1 2 3)" + (backward-sexp) + (down-list) + (clojure-convert-collection-to-quoted-list))) + +(describe "clojure-convert-collection-to-set" + (when-refactoring-it "should convert a quoted list to a set" + "'(1 2 3)" + "#{1 2 3}" + (backward-sexp) + (down-list) + (clojure-convert-collection-to-set))) (provide 'clojure-mode-convert-collection-test) diff --git a/clojure-mode-cycling-test.el b/clojure-mode-cycling-test.el index bf3e0ef..40754a9 100644 --- a/clojure-mode-cycling-test.el +++ b/clojure-mode-cycling-test.el @@ -25,137 +25,170 @@ ;;; Code: (require 'clojure-mode) -(require 'ert) +(require 'test-helper) +(require 'buttercup) -(def-refactor-test test-cycle-privacy-public-defn-private-defn - "(defn add [a b] +(describe "clojure-cycle-privacy" + + (when-refactoring-it "should turn a public defn into a private defn" + "(defn add [a b] (+ a b))" - "(defn- add [a b] + + "(defn- add [a b] (+ a b))" - (clojure-cycle-privacy)) -(def-refactor-test test-cycle-privacy-from-sexp-beg - "(defn- add [a b] + (clojure-cycle-privacy)) + + (when-refactoring-it "should also work from the beginning of a sexp" + "(defn- add [a b] (+ a b))" - "(defn add [a b] + + "(defn add [a b] (+ a b))" - (backward-sexp) - (clojure-cycle-privacy)) -(def-refactor-test test-cycle-privacy-public-defn-private-defn-metadata - "(defn add [a b] + (backward-sexp) + (clojure-cycle-privacy)) + + (when-refactoring-it "should use metadata when clojure-use-metadata-for-privacy is set to true" + "(defn add [a b] (+ a b))" - "(defn ^:private add [a b] + + "(defn ^:private add [a b] (+ a b))" - (let ((clojure-use-metadata-for-privacy t)) + + (let ((clojure-use-metadata-for-privacy t)) (clojure-cycle-privacy))) -(def-refactor-test test-cycle-privacy-private-defn-public-defn - "(defn- add [a b] + (when-refactoring-it "should turn a private defn into a public defn" + "(defn- add [a b] (+ a b))" - "(defn add [a b] + + "(defn add [a b] (+ a b))" - (clojure-cycle-privacy)) -(def-refactor-test test-cycle-privacy-private-defn-public-defn-metadata - "(defn ^:private add [a b] + (clojure-cycle-privacy)) + + (when-refactoring-it "should turn a private defn with metadata into a public defn" + "(defn ^:private add [a b] (+ a b))" - "(defn add [a b] + + "(defn add [a b] (+ a b))" - (let ((clojure-use-metadata-for-privacy t)) - (clojure-cycle-privacy))) -(def-refactor-test test-cycle-privacy-public-def-private-def - "(def ^:dynamic config + (let ((clojure-use-metadata-for-privacy t)) + (clojure-cycle-privacy))) + + (when-refactoring-it "should also work with pre-existing metadata" + "(def ^:dynamic config \"docs\" {:env \"staging\"})" - "(def ^:private ^:dynamic config + + "(def ^:private ^:dynamic config \"docs\" {:env \"staging\"})" - (clojure-cycle-privacy)) -(def-refactor-test test-cycle-privacy-private-def-public-def - "(def ^:private config + (clojure-cycle-privacy)) + + (when-refactoring-it "should turn a private def with metadata into a public def" + "(def ^:private config \"docs\" {:env \"staging\"})" - "(def config + + "(def config \"docs\" {:env \"staging\"})" - (clojure-cycle-privacy)) -(def-refactor-test test-cycle-if-inner-if - "(if this + (clojure-cycle-privacy))) + +(describe "clojure-cycle-if" + + (when-refactoring-it "should cycle inner if" + "(if this (if that (then AAA) (else BBB)) (otherwise CCC))" - "(if this + + "(if this (if-not that (else BBB) (then AAA)) (otherwise CCC))" - (beginning-of-buffer) - (search-forward "BBB)") - (clojure-cycle-if)) -(def-refactor-test test-cycle-if-outer-if - "(if-not this + (beginning-of-buffer) + (search-forward "BBB)") + (clojure-cycle-if)) + + (when-refactoring-it "should cycle outer if" + "(if-not this (if that (then AAA) (else BBB)) (otherwise CCC))" - "(if this + + "(if this (otherwise CCC) (if that (then AAA) (else BBB)))" - (beginning-of-buffer) - (search-forward "BBB))") - (clojure-cycle-if)) -(def-refactor-test test-cycle-when-inner-when - "(when this + (beginning-of-buffer) + (search-forward "BBB))") + (clojure-cycle-if))) + +(describe "clojure-cycle-when" + + (when-refactoring-it "should cycle inner when" + "(when this (when that (aaa) (bbb)) (ccc))" - "(when this + + "(when this (when-not that (aaa) (bbb)) (ccc))" - (beginning-of-buffer) - (search-forward "bbb)") - (clojure-cycle-when)) -(def-refactor-test test-cycle-when-outer-when - "(when-not this + (beginning-of-buffer) + (search-forward "bbb)") + (clojure-cycle-when)) + + (when-refactoring-it "should cycle outer when" + "(when-not this (when that (aaa) (bbb)) (ccc))" - "(when this + + "(when this (when that (aaa) (bbb)) (ccc))" - (beginning-of-buffer) - (search-forward "bbb))") - (clojure-cycle-when)) - -(def-refactor-test test-cycle-not-add - "(ala bala portokala)" - "(not (ala bala portokala))" - (beginning-of-buffer) - (search-forward "bala") - (clojure-cycle-not)) - -(def-refactor-test test-cycle-not-remove - "(not (ala bala portokala))" - "(ala bala portokala)" - (beginning-of-buffer) - (search-forward "bala") - (clojure-cycle-not)) + + (beginning-of-buffer) + (search-forward "bbb))") + (clojure-cycle-when))) + +(describe "clojure-cycle-not" + + (when-refactoring-it "should add a not when missing" + "(ala bala portokala)" + "(not (ala bala portokala))" + + (beginning-of-buffer) + (search-forward "bala") + (clojure-cycle-not)) + + (when-refactoring-it "should remove a not when present" + "(not (ala bala portokala))" + "(ala bala portokala)" + + (beginning-of-buffer) + (search-forward "bala") + (clojure-cycle-not))) (provide 'clojure-mode-cycling-test) diff --git a/clojure-mode-font-lock-test.el b/clojure-mode-font-lock-test.el index 52fa601..10ebd38 100644 --- a/clojure-mode-font-lock-test.el +++ b/clojure-mode-font-lock-test.el @@ -25,40 +25,42 @@ ;;; Code: (require 'clojure-mode) +(require 'test-helper) (require 'cl-lib) -(require 'ert) +(require 'buttercup) ;;;; Utilities -(defmacro clojure-test-with-temp-buffer (content &rest body) - "Evaluate BODY in a temporary buffer with CONTENTS." +(defmacro with-fontified-clojure-buffer (content &rest body) + "Evaluate BODY in a temporary buffer with CONTENT." (declare (debug t) (indent 1)) - `(with-temp-buffer - (insert ,content) - (clojure-mode) + `(with-clojure-buffer ,content (font-lock-fontify-buffer) (goto-char (point-min)) ,@body)) -(defun clojure-get-face-at-range (start end) - (let ((start-face (get-text-property start 'face)) - (all-faces (cl-loop for i from start to end collect (get-text-property - i 'face)))) - (if (cl-every (lambda (face) (eq face start-face)) all-faces) - start-face - 'various-faces))) +(defun clojure-get-face-at (start end content) + "Get the face between START and END in CONTENT." + (with-fontified-clojure-buffer content + (let ((start-face (get-text-property start 'face)) + (all-faces (cl-loop for i from start to end collect (get-text-property + i 'face)))) + (if (cl-every (lambda (face) (eq face start-face)) all-faces) + start-face + 'various-faces)))) -(defun clojure-test-face-at (start end &optional content) - "Get the face between START and END in CONTENT. +(defun expect-face-at (content start end face) + "Expect face in CONTENT between START and END to be equal to FACE." + (expect (clojure-get-face-at start end content) :to-equal face)) -If CONTENT is not given, return the face at the specified range in the current -buffer." - (if content - (clojure-test-with-temp-buffer content - (clojure-get-face-at-range start end)) - (clojure-get-face-at-range start end))) +(defun expect-faces-at (content &rest faces) + "Expect FACES in CONTENT. + +FACES is a list of the form (content (start end expected-face)*)" + (dolist (face faces) + (apply (apply-partially #'expect-face-at content) face))) (defconst clojure-test-syntax-classes [whitespace punctuation word symbol open-paren close-paren expression-prefix @@ -69,820 +71,836 @@ buffer." Each symbol in this vector corresponding to the syntax code of its index.") -(defun clojure-test-syntax-at (pos) - "Get the syntax at POS. +(defmacro when-fontifying-it (description &rest tests) + "Return a buttercup spec. -Get the syntax class symbol at POS, or nil if there is no syntax a -POS." - (let ((code (syntax-class (syntax-after pos)))) - (aref clojure-test-syntax-classes code))) +TESTS are lists of the form (content (start end expected-face)*). For each test +check that each `expected-face` is found in `content` between `start` and `end`. + +DESCRIPTION is the description of the spec." + `(it ,description + (dolist (test (quote ,tests)) + (apply #'expect-faces-at test)))) - ;;;; Font locking -(ert-deftest clojure-mode-syntax-table/stuff-in-backticks () - :tags '(fontification syntax-table) - (should (equal (clojure-test-face-at 1 2 "\"`#'s/trim`\"") - font-lock-string-face)) - (should (equal (clojure-test-face-at 3 10 "\"`#'s/trim`\"") - '(font-lock-constant-face font-lock-string-face))) - (should (equal (clojure-test-face-at 11 12 "\"`#'s/trim`\"") - font-lock-string-face)) - (should (equal (clojure-test-face-at 1 1 ";`#'s/trim`") - font-lock-comment-delimiter-face)) - (should (equal (clojure-test-face-at 2 2 ";`#'s/trim`") - font-lock-comment-face)) - (should (equal (clojure-test-face-at 3 10 ";`#'s/trim`") - '(font-lock-constant-face font-lock-comment-face))) - (should (equal (clojure-test-face-at 11 11 ";`#'s/trim`") - font-lock-comment-face))) - -(ert-deftest clojure-mode-syntax-table/stuff-in-backticks () - :tags '(fontification syntax-table) - (should (equal (clojure-test-face-at 1 2 "\"a\\bc\\n\"") - font-lock-string-face)) - (should (equal (clojure-test-face-at 3 4 "\"a\\bc\\n\"") - '(bold font-lock-string-face))) - (should (equal (clojure-test-face-at 5 5 "\"a\\bc\\n\"") - font-lock-string-face)) - (should (equal (clojure-test-face-at 6 7 "\"a\\bc\\n\"") - '(bold font-lock-string-face))) - (should (equal (clojure-test-face-at 4 5 "#\"a\\bc\\n\"") - '(bold font-lock-string-face)))) - -(ert-deftest clojure-mode-syntax-table/stuff-in-double-brackets () - :tags '(fontification syntax-table) - (should (equal (clojure-test-face-at 1 3 "\"[[#'s/trim]]\"") - font-lock-string-face)) - (should (equal (clojure-test-face-at 4 11 "\"[[#'s/trim]]\"") - '(font-lock-constant-face font-lock-string-face))) - (should (equal (clojure-test-face-at 12 14 "\"[[#'s/trim]]\"") - font-lock-string-face)) - (should (equal (clojure-test-face-at 1 1 ";[[#'s/trim]]") - font-lock-comment-delimiter-face)) - (should (equal (clojure-test-face-at 2 3 ";[[#'s/trim]]") - font-lock-comment-face)) - (should (equal (clojure-test-face-at 4 11 ";[[#'s/trim]]") - '(font-lock-constant-face font-lock-comment-face))) - (should (equal (clojure-test-face-at 12 13 ";[[#'s/trim]]") - font-lock-comment-face))) - -(ert-deftest clojure-mode-syntax-table/fontify-let-when-while-type-forms () - :tags '(fontification syntax-table) - (should (equal (clojure-test-face-at 2 11 "(when-alist [x 1]\n ())") - 'font-lock-keyword-face)) - (should (equal (clojure-test-face-at 2 12 "(while-alist [x 1]\n ())") - 'font-lock-keyword-face)) - (should (equal (clojure-test-face-at 2 10 "(let-alist [x 1]\n ())") - 'font-lock-keyword-face))) - -(ert-deftest clojure-mode-syntax-table/comment-macros () - :tags '(fontification syntax-table) - (should (equal (clojure-test-face-at - 1 2 "#_") - nil)) - (should (equal (clojure-test-face-at - 1 2 "#_ \n;; some crap\n (lala 0101\n lao\n\n 0 0i)") - nil)) - (should (equal (clojure-test-face-at - 5 41 "#_ \n;; some crap\n (lala 0101\n lao\n\n 0 0i)") - 'font-lock-comment-face))) - -(ert-deftest clojure-mode-syntax-table/namespace () - :tags '(fontification syntax-table) - (should (eq (clojure-test-face-at 5 12 "(ns .validns)") 'font-lock-type-face)) - (should (eq (clojure-test-face-at 5 12 "(ns =validns)") 'font-lock-type-face)) - (should (eq (clojure-test-face-at 5 21 "(ns .ValidNs=<>?+|?*.)") - 'font-lock-type-face)) - (should (eq (clojure-test-face-at 5 28 "(ns ValidNs<>?+|?*.b*ar.ba*z)") - 'font-lock-type-face)) - (should (eq (clojure-test-face-at 5 18 "(ns other.valid.ns)") - 'font-lock-type-face)) - (should (eq (clojure-test-face-at 5 11 "(ns oneword)") 'font-lock-type-face)) - (should (eq (clojure-test-face-at 5 11 "(ns foo.bar)") 'font-lock-type-face)) - (should (eq (clojure-test-face-at 5 11 "(ns Foo.bar)") 'font-lock-type-face)) - (should (eq (clojure-test-face-at 5 11 "(ns Foo.Bar)") 'font-lock-type-face)) - (should (eq (clojure-test-face-at 5 11 "(ns foo.Bar)") 'font-lock-type-face)) - (should (eq (clojure-test-face-at 5 11 "(ns Foo-bar)") 'font-lock-type-face)) - (should (eq (clojure-test-face-at 5 11 "(ns Foo-Bar)") 'font-lock-type-face)) - (should (eq (clojure-test-face-at 5 11 "(ns foo-Bar)") 'font-lock-type-face)) - (should (eq (clojure-test-face-at 5 9 "(ns one.X)") 'font-lock-type-face)) - (should (eq (clojure-test-face-at 10 16 "(ns ^:md ns-name)") 'font-lock-type-face)) - (should (eq (clojure-test-face-at 13 19 "(ns ^:md \n ns-name)") 'font-lock-type-face)) - (should (eq (clojure-test-face-at 17 23 "(ns ^:md1 ^:md2 ns-name)") 'font-lock-type-face)) - (should (eq (clojure-test-face-at 24 30 "(ns ^:md1 ^{:md2 true} ns-name)") 'font-lock-type-face)) - (should (eq (clojure-test-face-at 24 30 "(ns ^{:md2 true} ^:md1 ns-name)") 'font-lock-type-face)) - (should (eq (clojure-test-face-at 27 33 "(ns ^:md1 ^{:md2 true} \n ns-name)") 'font-lock-type-face)) - (should (eq (clojure-test-face-at 27 33 "(ns ^{:md2 true} ^:md1 \n ns-name)") 'font-lock-type-face))) - -(ert-deftest clojure-mode-syntax-table/oneword () - :tags '(fontification syntax-table) - (should (eq (clojure-test-face-at 2 8 " oneword") nil)) - (should (eq (clojure-test-face-at 2 8 "@oneword") nil)) - (should (eq (clojure-test-face-at 2 8 "#oneword") nil)) - (should (eq (clojure-test-face-at 2 8 ".oneword") nil)) - (should (eq (clojure-test-face-at 3 9 "#^oneword") - 'font-lock-type-face)) ;; type-hint - (should (eq (clojure-test-face-at 2 8 "(oneword)") nil)) - - (should (eq (clojure-test-face-at 2 8 "(oneword/oneword)") - 'font-lock-type-face)) - (should (eq (clojure-test-face-at 9 10 "(oneword/oneword)") nil)) - (should (eq (clojure-test-face-at 11 16 "(oneword/oneword)") nil)) - - (should (eq (clojure-test-face-at 2 8 "(oneword/seg.mnt)") - 'font-lock-type-face)) - (should (eq (clojure-test-face-at 9 10 "(oneword/seg.mnt)") nil)) - (should (eq (clojure-test-face-at 11 16 "(oneword/seg.mnt)") nil)) - - (should (eq (clojure-test-face-at 2 8 "(oneword/mxdCase)") - 'font-lock-type-face)) - (should (eq (clojure-test-face-at 9 10 "(oneword/mxdCase)") nil)) - (should (eq (clojure-test-face-at 11 16 "(oneword/mxdCase)") nil)) - - (should (eq (clojure-test-face-at 2 8 "(oneword/CmlCase)") - 'font-lock-type-face)) - (should (eq (clojure-test-face-at 9 10 "(oneword/CmlCase)") nil)) - (should (eq (clojure-test-face-at 11 16 "(oneword/CmlCase)") nil)) - - (should (eq (clojure-test-face-at 2 8 "(oneword/ve/yCom|pLex.stu-ff)") - 'font-lock-type-face)) - (should (eq (clojure-test-face-at 9 10 "(oneword/ve/yCom|pLex.stu-ff)") - nil)) - (should (eq (clojure-test-face-at 11 28 "(oneword/ve/yCom|pLex.stu-ff)") - nil)) - - (should (eq (clojure-test-face-at 2 8 "(oneword/.ve/yCom|pLex.stu-ff)") - 'font-lock-type-face)) - (should (eq (clojure-test-face-at 9 10 "(oneword/.ve/yCom|pLex.stu-ff)") - nil)) - (should (eq (clojure-test-face-at 12 29 "(oneword/.ve/yCom|pLex.stu-ff)") - nil))) - -(ert-deftest clojure-mode-syntax-table/segment () - :tags '(fontification syntax-table) - (should (eq (clojure-test-face-at 2 8 " seg.mnt") nil)) - (should (eq (clojure-test-face-at 2 8 "@seg.mnt") nil)) - (should (eq (clojure-test-face-at 2 8 "#seg.mnt") nil)) - (should (eq (clojure-test-face-at 2 8 ".seg.mnt") nil)) - (should (eq (clojure-test-face-at 3 9 "#^seg.mnt") - 'font-lock-type-face)) ;; type-hint - (should (eq (clojure-test-face-at 2 8 "(seg.mnt)") nil)) - (should (eq (clojure-test-face-at 2 8 "(seg.mnt/oneword)") - 'font-lock-type-face)) - (should (eq (clojure-test-face-at 9 10 "(seg.mnt/oneword)") nil)) - (should (eq (clojure-test-face-at 11 16 "(seg.mnt/oneword)") nil)) - - (should (eq (clojure-test-face-at 2 8 "(seg.mnt/seg.mnt)") - 'font-lock-type-face)) - (should (eq (clojure-test-face-at 9 10 "(seg.mnt/seg.mnt)") nil)) - (should (eq (clojure-test-face-at 11 16 "(seg.mnt/seg.mnt)") nil)) - - (should (eq (clojure-test-face-at 2 8 "(seg.mnt/mxdCase)") - 'font-lock-type-face)) - (should (eq (clojure-test-face-at 9 10 "(seg.mnt/mxdCase)") nil)) - (should (eq (clojure-test-face-at 11 16 "(seg.mnt/mxdCase)") nil)) - - (should (eq (clojure-test-face-at 2 8 "(seg.mnt/CmlCase)") - 'font-lock-type-face)) - (should (eq (clojure-test-face-at 9 10 "(seg.mnt/CmlCase)") nil)) - (should (eq (clojure-test-face-at 11 16 "(seg.mnt/CmlCase)") nil)) - - (should (eq (clojure-test-face-at 2 8 "(seg.mnt/ve/yCom|pLex.stu-ff)") - 'font-lock-type-face)) - (should (eq (clojure-test-face-at 9 10 "(seg.mnt/ve/yCom|pLex.stu-ff)") - nil)) - (should (eq (clojure-test-face-at 11 28 "(seg.mnt/ve/yCom|pLex.stu-ff)") - nil)) - - (should (eq (clojure-test-face-at 2 8 "(seg.mnt/.ve/yCom|pLex.stu-ff)") - 'font-lock-type-face)) - (should (eq (clojure-test-face-at 9 10 "(seg.mnt/.ve/yCom|pLex.stu-ff)") - nil)) - (should (eq (clojure-test-face-at 12 29 "(seg.mnt/.ve/yCom|pLex.stu-ff)") - nil))) - -(ert-deftest clojure-mode-syntax-table/camelcase () - :tags '(fontification syntax-table) - (should (eq (clojure-test-face-at 2 8 " CmlCase") nil)) - (should (eq (clojure-test-face-at 2 8 "@CmlCase") nil)) - (should (eq (clojure-test-face-at 2 8 "#CmlCase") nil)) - (should (eq (clojure-test-face-at 2 8 ".CmlCase") nil)) - (should (eq (clojure-test-face-at 3 9 "#^CmlCase") - 'font-lock-type-face)) ;; type-hint - (should (eq (clojure-test-face-at 2 8 "(CmlCase)") nil)) - - (should (eq (clojure-test-face-at 2 8 "(CmlCase/oneword)") - 'font-lock-type-face)) - (should (eq (clojure-test-face-at 9 10 "(CmlCase/oneword)") nil)) - (should (eq (clojure-test-face-at 11 16 "(CmlCase/oneword)") nil)) - - (should (eq (clojure-test-face-at 2 8 "(CmlCase/seg.mnt)") - 'font-lock-type-face)) - (should (eq (clojure-test-face-at 9 10 "(CmlCase/seg.mnt)") nil)) - (should (eq (clojure-test-face-at 11 16 "(CmlCase/seg.mnt)") nil)) - - (should (eq (clojure-test-face-at 2 8 "(CmlCase/mxdCase)") - 'font-lock-type-face)) - (should (eq (clojure-test-face-at 9 10 "(CmlCase/mxdCase)") nil)) - (should (eq (clojure-test-face-at 11 16 "(CmlCase/mxdCase)") nil)) - - (should (eq (clojure-test-face-at 2 8 "(CmlCase/CmlCase)") - 'font-lock-type-face)) - (should (eq (clojure-test-face-at 9 10 "(CmlCase/CmlCase)") nil)) - (should (eq (clojure-test-face-at 11 16 "(CmlCase/CmlCase)") nil)) - - (should (eq (clojure-test-face-at 2 8 "(CmlCase/ve/yCom|pLex.stu-ff)") - 'font-lock-type-face)) - (should (eq (clojure-test-face-at 9 10 "(CmlCase/ve/yCom|pLex.stu-ff)") - nil)) - (should (eq (clojure-test-face-at 11 28 "(CmlCase/ve/yCom|pLex.stu-ff)") - nil)) - - (should (eq (clojure-test-face-at 2 8 "(CmlCase/.ve/yCom|pLex.stu-ff)") - 'font-lock-type-face)) - (should (eq (clojure-test-face-at 9 10 "(CmlCase/.ve/yCom|pLex.stu-ff)") - nil)) - (should (eq (clojure-test-face-at 12 29 "(CmlCase/.ve/yCom|pLex.stu-ff)") - nil))) - -(ert-deftest clojure-mode-syntax-table/mixedcase () - :tags '(fontification syntax-table) - (should (eq (clojure-test-face-at 2 8 " mxdCase") nil)) - (should (eq (clojure-test-face-at 2 8 "@mxdCase") nil)) - (should (eq (clojure-test-face-at 2 8 "#mxdCase") nil)) - (should (eq (clojure-test-face-at 2 8 ".mxdCase") nil)) - (should (eq (clojure-test-face-at 3 9 "#^mxdCase") - 'font-lock-type-face)) ;; type-hint - (should (eq (clojure-test-face-at 2 8 "(mxdCase)") nil)) - - (should (eq (clojure-test-face-at 2 8 "(mxdCase/oneword)") - 'font-lock-type-face)) - (should (eq (clojure-test-face-at 9 10 "(mxdCase/oneword)") nil)) - (should (eq (clojure-test-face-at 11 16 "(mxdCase/oneword)") nil)) - - (should (eq (clojure-test-face-at 2 8 "(mxdCase/seg.mnt)") - 'font-lock-type-face)) - (should (eq (clojure-test-face-at 9 10 "(mxdCase/seg.mnt)") nil)) - (should (eq (clojure-test-face-at 11 16 "(mxdCase/seg.mnt)") nil)) - - (should (eq (clojure-test-face-at 2 8 "(mxdCase/mxdCase)") - 'font-lock-type-face)) - (should (eq (clojure-test-face-at 9 10 "(mxdCase/mxdCase)") nil)) - (should (eq (clojure-test-face-at 11 16 "(mxdCase/mxdCase)") nil)) - - (should (eq (clojure-test-face-at 2 8 "(mxdCase/CmlCase)") - 'font-lock-type-face)) - (should (eq (clojure-test-face-at 9 10 "(mxdCase/CmlCase)") nil)) - (should (eq (clojure-test-face-at 11 16 "(mxdCase/CmlCase)") nil)) - - (should (eq (clojure-test-face-at 2 8 "(mxdCase/ve/yCom|pLex.stu-ff)") - 'font-lock-type-face)) - (should (eq (clojure-test-face-at 9 10 "(mxdCase/ve/yCom|pLex.stu-ff)") - nil)) - (should (eq (clojure-test-face-at 11 28 "(mxdCase/ve/yCom|pLex.stu-ff)") - nil)) - - (should (eq (clojure-test-face-at 2 8 "(mxdCase/.ve/yCom|pLex.stu-ff)") - 'font-lock-type-face)) - (should (eq (clojure-test-face-at 9 10 "(mxdCase/.ve/yCom|pLex.stu-ff)") - nil)) - (should (eq (clojure-test-face-at 12 29 "(mxdCase/.ve/yCom|pLex.stu-ff)") - nil))) - -(ert-deftest clojure-mode-syntax-table/verycomplex () - :tags '(fontification syntax-table) - (should (eq (clojure-test-face-at 3 4 " ve/yCom|pLex.stu-ff") - 'font-lock-type-face)) - (should (eq (clojure-test-face-at 5 21 " ve/yCom|pLex.stu-ff") nil)) - - (should (eq (clojure-test-face-at 2 2 " @ve/yCom|pLex.stu-ff") nil)) - (should (eq (clojure-test-face-at 3 4 " @ve/yCom|pLex.stu-ff") - 'font-lock-type-face)) - (should (eq (clojure-test-face-at 5 21 " @ve/yCom|pLex.stu-ff") nil)) - - (should (eq (clojure-test-face-at 2 4 " #ve/yCom|pLex.stu-ff") - 'font-lock-type-face)) - (should (eq (clojure-test-face-at 5 21 " #ve/yCom|pLex.stu-ff") nil)) - - (should (eq (clojure-test-face-at 2 4 " .ve/yCom|pLex.stu-ff") - 'font-lock-type-face)) - (should (eq (clojure-test-face-at 5 21 " .ve/yCom|pLex.stu-ff") nil)) - - ;; type-hint - (should (eq (clojure-test-face-at 1 2 "#^ve/yCom|pLex.stu-ff") 'default)) - (should (eq (clojure-test-face-at 3 4 "#^ve/yCom|pLex.stu-ff") 'font-lock-type-face)) - (should (eq (clojure-test-face-at 5 21 "#^ve/yCom|pLex.stu-ff") 'default)) - (should (eq (clojure-test-face-at 2 3 "^ve/yCom|pLex.stu-ff") 'font-lock-type-face)) - (should (eq (clojure-test-face-at 5 20 "^ve/yCom|pLex.stu-ff") 'default)) - - (should (eq (clojure-test-face-at 3 4 " (ve/yCom|pLex.stu-ff)") - 'font-lock-type-face)) - (should (eq (clojure-test-face-at 5 21 " (ve/yCom|pLex.stu-ff)") nil)) - - (should (eq (clojure-test-face-at 3 4 " (ve/yCom|pLex.stu-ff/oneword)") - 'font-lock-type-face)) - (should (eq (clojure-test-face-at 5 29 " (ve/yCom|pLex.stu-ff/oneword)") - nil)) - - (should (eq (clojure-test-face-at 3 4 " (ve/yCom|pLex.stu-ff/seg.mnt)") - 'font-lock-type-face)) - (should (eq (clojure-test-face-at 5 29 " (ve/yCom|pLex.stu-ff/seg.mnt)") - nil)) - - (should (eq (clojure-test-face-at 3 4 " (ve/yCom|pLex.stu-ff/mxdCase)") - 'font-lock-type-face)) - (should (eq (clojure-test-face-at 5 29 " (ve/yCom|pLex.stu-ff/mxdCase)") - nil)) - - (should (eq (clojure-test-face-at 3 4 " (ve/yCom|pLex.stu-ff/CmlCase)") - 'font-lock-type-face)) - (should (eq (clojure-test-face-at 5 29 " (ve/yCom|pLex.stu-ff/CmlCase)") - nil)) - - (should (eq (clojure-test-face-at - 3 4 " (ve/yCom|pLex.stu-ff/ve/yCom|pLex.stu-ff)") - 'font-lock-type-face)) - (should (eq (clojure-test-face-at - 5 41 " (ve/yCom|pLex.stu-ff/ve/yCom|pLex.stu-ff)") - nil)) - - (should (eq (clojure-test-face-at - 3 4 " (ve/yCom|pLex.stu-ff/.ve/yCom|pLex.stu-ff)") - 'font-lock-type-face)) - (should (eq (clojure-test-face-at - 5 42 " (ve/yCom|pLex.stu-ff/.ve/yCom|pLex.stu-ff)") - nil))) - -(ert-deftest clojure-mode-syntax-table/kw-oneword () - :tags '(fontification syntax-table) - (should (eq (clojure-test-face-at 3 9 " :oneword") 'clojure-keyword-face)) - (should (eq (clojure-test-face-at 3 9 "{:oneword 0}") - 'clojure-keyword-face)) - (should (eq (clojure-test-face-at 3 10 "{:#oneword 0}") - 'clojure-keyword-face)) - (should (eq (clojure-test-face-at 3 10 "{:.oneword 0}") - 'clojure-keyword-face)) - - (should (eq (clojure-test-face-at 3 9 "{:oneword/oneword 0}") - 'font-lock-type-face)) - (should (eq (clojure-test-face-at 10 10 "{:oneword/oneword 0}") 'default)) - (should (eq (clojure-test-face-at 11 17 "{:oneword/oneword 0}") - 'clojure-keyword-face)) - - (should (eq (clojure-test-face-at 3 9 "{:oneword/seg.mnt 0}") - 'font-lock-type-face)) - (should (eq (clojure-test-face-at 10 10 "{:oneword/seg.mnt 0}") 'default)) - (should (eq (clojure-test-face-at 11 17 "{:oneword/seg.mnt 0}") - 'clojure-keyword-face)) - - (should (eq (clojure-test-face-at 3 9 "{:oneword/CmlCase 0}") - 'font-lock-type-face)) - (should (eq (clojure-test-face-at 10 10 "{:oneword/CmlCase 0}") 'default)) - (should (eq (clojure-test-face-at 11 17 "{:oneword/CmlCase 0}") - 'clojure-keyword-face)) - - (should (eq (clojure-test-face-at 3 9 "{:oneword/mxdCase 0}") - 'font-lock-type-face)) - (should (eq (clojure-test-face-at 10 10 "{:oneword/mxdCase 0}") 'default)) - (should (eq (clojure-test-face-at 11 17 "{:oneword/mxdCase 0}") - 'clojure-keyword-face)) - - (should (eq (clojure-test-face-at 3 9 "{:oneword/ve/yCom|pLex.stu-ff 0}") - 'font-lock-type-face)) - (should (eq (clojure-test-face-at 10 10 "{:oneword/ve/yCom|pLex.stu-ff 0}") - 'default)) - (should (eq (clojure-test-face-at 11 29 "{:oneword/ve/yCom|pLex.stu-ff 0}") - 'clojure-keyword-face)) - - (should (eq (clojure-test-face-at 3 9 "{:oneword/.ve/yCom|pLex.stu-ff 0}") - 'font-lock-type-face)) - (should (eq (clojure-test-face-at 10 10 "{:oneword/.ve/yCom|pLex.stu-ff 0}") - 'default)) - (should (eq (clojure-test-face-at 11 30 "{:oneword/.ve/yCom|pLex.stu-ff 0}") - 'clojure-keyword-face))) - -(ert-deftest clojure-mode-syntax-table/kw-namespaced () - :tags '(fontification syntax-table) - (should (eq (clojure-test-face-at 1 5 "::foo") 'clojure-keyword-face)) - (should (eq (clojure-test-face-at 1 9 ":_::_:foo") 'clojure-keyword-face)) - (should (eq (clojure-test-face-at 1 8 ":_:_:foo") 'clojure-keyword-face)) - (should (eq (clojure-test-face-at 1 9 ":foo/:bar") 'clojure-keyword-face)) - (should (eq (clojure-test-face-at 1 7 "::_:foo") 'clojure-keyword-face)) - (should (eq (clojure-test-face-at 1 9 "::_:_:foo") 'clojure-keyword-face)) - - (should (eq (clojure-test-face-at 1 1 ":_:_:foo/_") 'clojure-keyword-face)) - (should (eq (clojure-test-face-at 2 8 ":_:_:foo/_") 'font-lock-type-face)) - (should (eq (clojure-test-face-at 9 9 ":_:_:foo/_") 'default)) - (should (eq (clojure-test-face-at 10 10 ":_:_:foo/_") 'clojure-keyword-face)) - - (should (eq (clojure-test-face-at 10 12 ":_:_:foo/bar") - 'clojure-keyword-face)) - (should (eq (clojure-test-face-at 10 16 ":_:_:foo/bar/eee") - 'clojure-keyword-face)) - (should (eq (clojure-test-face-at 10 17 ":_:_:foo/bar_:foo") - 'clojure-keyword-face)) - (should (eq (clojure-test-face-at 10 19 ":_:_:foo/bar_:_:foo") - 'clojure-keyword-face))) - -(ert-deftest clojure-mode-syntax-table/kw-segment () - :tags '(fontification syntax-table) - (should (eq (clojure-test-face-at 3 9 " :seg.mnt") 'clojure-keyword-face)) - (should (eq (clojure-test-face-at 3 9 "{:seg.mnt 0}") - 'clojure-keyword-face)) - (should (eq (clojure-test-face-at 3 10 "{:#seg.mnt 0}") - 'clojure-keyword-face)) - (should (eq (clojure-test-face-at 3 10 "{:.seg.mnt 0}") - 'clojure-keyword-face)) - - (should (eq (clojure-test-face-at 3 9 "{:seg.mnt/oneword 0}") - 'font-lock-type-face)) - (should (eq (clojure-test-face-at 10 10 "{:seg.mnt/oneword 0}") 'default)) - (should (eq (clojure-test-face-at 11 17 "{:seg.mnt/oneword 0}") - 'clojure-keyword-face)) - - (should (eq (clojure-test-face-at 3 9 "{:seg.mnt/seg.mnt 0}") - 'font-lock-type-face)) - (should (eq (clojure-test-face-at 10 10 "{:seg.mnt/seg.mnt 0}") 'default)) - (should (eq (clojure-test-face-at 11 17 "{:seg.mnt/seg.mnt 0}") - 'clojure-keyword-face)) - - (should (eq (clojure-test-face-at 3 9 "{:seg.mnt/CmlCase 0}") - 'font-lock-type-face)) - (should (eq (clojure-test-face-at 10 10 "{:seg.mnt/CmlCase 0}") 'default)) - (should (eq (clojure-test-face-at 11 17 "{:seg.mnt/CmlCase 0}") - 'clojure-keyword-face)) - - (should (eq (clojure-test-face-at 3 9 "{:seg.mnt/mxdCase 0}") - 'font-lock-type-face)) - (should (eq (clojure-test-face-at 10 10 "{:seg.mnt/mxdCase 0}") 'default)) - (should (eq (clojure-test-face-at 11 17 "{:seg.mnt/mxdCase 0}") - 'clojure-keyword-face)) - - (should (eq (clojure-test-face-at 3 9 "{:seg.mnt/ve/yCom|pLex.stu-ff 0}") - 'font-lock-type-face)) - (should (eq (clojure-test-face-at 10 10 "{:seg.mnt/ve/yCom|pLex.stu-ff 0}") - 'default)) - (should (eq (clojure-test-face-at 11 29 "{:seg.mnt/ve/yCom|pLex.stu-ff 0}") - 'clojure-keyword-face)) - - (should (eq (clojure-test-face-at 3 9 "{:seg.mnt/.ve/yCom|pLex.stu-ff 0}") - 'font-lock-type-face)) - (should (eq (clojure-test-face-at 10 10 "{:seg.mnt/.ve/yCom|pLex.stu-ff 0}") - 'default)) - (should (eq (clojure-test-face-at 11 30 "{:seg.mnt/.ve/yCom|pLex.stu-ff 0}") - 'clojure-keyword-face))) - -(ert-deftest clojure-mode-syntax-table/kw-camelcase () - :tags '(fontification syntax-table) - (should (eq (clojure-test-face-at 3 9 " :CmlCase") 'clojure-keyword-face)) - (should (eq (clojure-test-face-at 3 9 "{:CmlCase 0}") - 'clojure-keyword-face)) - (should (eq (clojure-test-face-at 3 10 "{:#CmlCase 0}") - 'clojure-keyword-face)) - (should (eq (clojure-test-face-at 3 10 "{:.CmlCase 0}") - 'clojure-keyword-face)) - (should (eq (clojure-test-face-at 3 9 "{:CmlCase/oneword 0}") - 'font-lock-type-face)) - (should (eq (clojure-test-face-at 10 10 "{:CmlCase/oneword 0}") 'default)) - (should (eq (clojure-test-face-at 11 17 "{:CmlCase/oneword 0}") - 'clojure-keyword-face)) - (should (eq (clojure-test-face-at 3 9 "{:CmlCase/seg.mnt 0}") - 'font-lock-type-face)) - (should (eq (clojure-test-face-at 10 10 "{:CmlCase/seg.mnt 0}") 'default)) - (should (eq (clojure-test-face-at 11 17 "{:CmlCase/seg.mnt 0}") - 'clojure-keyword-face)) - (should (eq (clojure-test-face-at 3 9 "{:CmlCase/CmlCase 0}") - 'font-lock-type-face)) - (should (eq (clojure-test-face-at 10 10 "{:CmlCase/CmlCase 0}") 'default)) - (should (eq (clojure-test-face-at 11 17 "{:CmlCase/CmlCase 0}") - 'clojure-keyword-face)) - (should (eq (clojure-test-face-at 3 9 "{:CmlCase/mxdCase 0}") - 'font-lock-type-face)) - (should (eq (clojure-test-face-at 10 10 "{:CmlCase/mxdCase 0}") 'default)) - (should (eq (clojure-test-face-at 11 17 "{:CmlCase/mxdCase 0}") - 'clojure-keyword-face)) - (should (eq (clojure-test-face-at 3 9 "{:CmlCase/ve/yCom|pLex.stu-ff 0}") - 'font-lock-type-face)) - (should (eq (clojure-test-face-at 10 10 "{:CmlCase/ve/yCom|pLex.stu-ff 0}") - 'default)) - (should (eq (clojure-test-face-at 11 29 "{:CmlCase/ve/yCom|pLex.stu-ff 0}") - 'clojure-keyword-face)) - - (should (eq (clojure-test-face-at 3 9 "{:CmlCase/.ve/yCom|pLex.stu-ff 0}") - 'font-lock-type-face)) - (should (eq (clojure-test-face-at 10 10 "{:CmlCase/.ve/yCom|pLex.stu-ff 0}") - 'default)) - (should (eq (clojure-test-face-at 11 30 "{:CmlCase/.ve/yCom|pLex.stu-ff 0}") - 'clojure-keyword-face))) - -(ert-deftest clojure-mode-syntax-table/kw-mixedcase () - :tags '(fontification syntax-table) - (should (eq (clojure-test-face-at 3 9 " :mxdCase") 'clojure-keyword-face)) - (should (eq (clojure-test-face-at 3 9 "{:mxdCase 0}") - 'clojure-keyword-face)) - (should (eq (clojure-test-face-at 3 10 "{:#mxdCase 0}") - 'clojure-keyword-face)) - (should (eq (clojure-test-face-at 3 10 "{:.mxdCase 0}") - 'clojure-keyword-face)) - - (should (eq (clojure-test-face-at 3 9 "{:mxdCase/oneword 0}") - 'font-lock-type-face)) - (should (eq (clojure-test-face-at 10 10 "{:mxdCase/oneword 0}") 'default)) - (should (eq (clojure-test-face-at 11 17 "{:mxdCase/oneword 0}") - 'clojure-keyword-face)) - - (should (eq (clojure-test-face-at 3 9 "{:mxdCase/seg.mnt 0}") - 'font-lock-type-face)) - (should (eq (clojure-test-face-at 10 10 "{:mxdCase/seg.mnt 0}") 'default)) - (should (eq (clojure-test-face-at 11 17 "{:mxdCase/seg.mnt 0}") - 'clojure-keyword-face)) - - (should (eq (clojure-test-face-at 3 9 "{:mxdCase/CmlCase 0}") - 'font-lock-type-face)) - (should (eq (clojure-test-face-at 10 10 "{:mxdCase/CmlCase 0}") 'default)) - (should (eq (clojure-test-face-at 11 17 "{:mxdCase/CmlCase 0}") - 'clojure-keyword-face)) - - (should (eq (clojure-test-face-at 3 9 "{:mxdCase/mxdCase 0}") - 'font-lock-type-face)) - (should (eq (clojure-test-face-at 10 10 "{:mxdCase/mxdCase 0}") 'default)) - (should (eq (clojure-test-face-at 11 17 "{:mxdCase/mxdCase 0}") - 'clojure-keyword-face)) - - (should (eq (clojure-test-face-at 3 9 "{:mxdCase/ve/yCom|pLex.stu-ff 0}") - 'font-lock-type-face)) - (should (eq (clojure-test-face-at 10 10 "{:mxdCase/ve/yCom|pLex.stu-ff 0}") - 'default)) - (should (eq (clojure-test-face-at 11 29 "{:mxdCase/ve/yCom|pLex.stu-ff 0}") - 'clojure-keyword-face)) - - (should (eq (clojure-test-face-at 3 9 "{:mxdCase/.ve/yCom|pLex.stu-ff 0}") - 'font-lock-type-face)) - (should (eq (clojure-test-face-at 10 10 "{:mxdCase/.ve/yCom|pLex.stu-ff 0}") - 'default)) - (should (eq (clojure-test-face-at 11 30 "{:mxdCase/.ve/yCom|pLex.stu-ff 0}") - 'clojure-keyword-face))) - -(ert-deftest clojure-mode-syntax-table/kw-verycomplex () - :tags '(fontification syntax-table) - (should (eq (clojure-test-face-at 3 4 " :ve/yCom|pLex.stu-ff") - 'font-lock-type-face)) - (should (eq (clojure-test-face-at 5 5 " :ve/yCom|pLex.stu-ff") - 'default)) - (should (eq (clojure-test-face-at 6 21 " :ve/yCom|pLex.stu-ff") - 'clojure-keyword-face)) - - (should (eq (clojure-test-face-at 2 2 "{:ve/yCom|pLex.stu-ff 0}") - 'clojure-keyword-face)) - (should (eq (clojure-test-face-at 3 4 "{:ve/yCom|pLex.stu-ff 0}") - 'font-lock-type-face)) - (should (eq (clojure-test-face-at 5 5 "{:ve/yCom|pLex.stu-ff 0}") - 'default)) - (should (eq (clojure-test-face-at 6 21 "{:ve/yCom|pLex.stu-ff 0}") - 'clojure-keyword-face)) - - (should (eq (clojure-test-face-at 2 2 "{:#ve/yCom|pLex.stu-ff 0}") - 'clojure-keyword-face)) - (should (eq (clojure-test-face-at 3 5 "{:#ve/yCom|pLex.stu-ff 0}") - 'font-lock-type-face)) - (should (eq (clojure-test-face-at 6 6 "{:#ve/yCom|pLex.stu-ff 0}") - 'default)) - (should (eq (clojure-test-face-at 7 22 "{:#ve/yCom|pLex.stu-ff 0}") - 'clojure-keyword-face)) - - (should (eq (clojure-test-face-at 2 2 "{:.ve/yCom|pLex.stu-ff 0}") - 'clojure-keyword-face)) - (should (eq (clojure-test-face-at 3 5 "{:.ve/yCom|pLex.stu-ff 0}") - 'font-lock-type-face)) - (should (eq (clojure-test-face-at 6 6 "{:.ve/yCom|pLex.stu-ff 0}") - 'default)) - (should (eq (clojure-test-face-at 7 22 "{:.ve/yCom|pLex.stu-ff 0}") - 'clojure-keyword-face)) - - (should (eq (clojure-test-face-at 2 2 "{:ve/yCom|pLex.stu-ff/oneword 0}") - 'clojure-keyword-face)) - (should (eq (clojure-test-face-at 3 4 "{:ve/yCom|pLex.stu-ff/oneword 0}") - 'font-lock-type-face)) - (should (eq (clojure-test-face-at 5 5 "{:ve/yCom|pLex.stu-ff/oneword 0}") - 'default)) - (should (eq (clojure-test-face-at 6 29 "{:ve/yCom|pLex.stu-ff/oneword 0}") - 'clojure-keyword-face)) - - (should (eq (clojure-test-face-at 2 2 "{:ve/yCom|pLex.stu-ff/seg.mnt 0}") - 'clojure-keyword-face)) - (should (eq (clojure-test-face-at 3 4 "{:ve/yCom|pLex.stu-ff/seg.mnt 0}") - 'font-lock-type-face)) - (should (eq (clojure-test-face-at 5 5 "{:ve/yCom|pLex.stu-ff/seg.mnt 0}") - 'default)) - (should (eq (clojure-test-face-at 6 29 "{:ve/yCom|pLex.stu-ff/seg.mnt 0}") - 'clojure-keyword-face)) - - (should (eq (clojure-test-face-at 2 2 "{:ve/yCom|pLex.stu-ff/ClmCase 0}") - 'clojure-keyword-face)) - (should (eq (clojure-test-face-at 3 4 "{:ve/yCom|pLex.stu-ff/ClmCase 0}") - 'font-lock-type-face)) - (should (eq (clojure-test-face-at 5 5 "{:ve/yCom|pLex.stu-ff/ClmCase 0}") - 'default)) - (should (eq (clojure-test-face-at 6 29 "{:ve/yCom|pLex.stu-ff/ClmCase 0}") - 'clojure-keyword-face)) - - (should (eq (clojure-test-face-at 2 2 "{:ve/yCom|pLex.stu-ff/mxdCase 0}") - 'clojure-keyword-face)) - (should (eq (clojure-test-face-at 3 4 "{:ve/yCom|pLex.stu-ff/mxdCase 0}") - 'font-lock-type-face)) - (should (eq (clojure-test-face-at 5 5 "{:ve/yCom|pLex.stu-ff/mxdCase 0}") - 'default)) - (should (eq (clojure-test-face-at 6 29 "{:ve/yCom|pLex.stu-ff/mxdCase 0}") - 'clojure-keyword-face)) - - (should (eq (clojure-test-face-at - 2 2 "{:ve/yCom|pLex.stu-ff/ve/yCom|pLex.stu-ff 0}") - 'clojure-keyword-face)) - (should (eq (clojure-test-face-at - 3 4 "{:ve/yCom|pLex.stu-ff/ve/yCom|pLex.stu-ff 0}") - 'font-lock-type-face)) - (should (eq (clojure-test-face-at - 5 5 "{:ve/yCom|pLex.stu-ff/ve/yCom|pLex.stu-ff 0}") - 'default)) - (should (eq (clojure-test-face-at - 6 41 "{:ve/yCom|pLex.stu-ff/ve/yCom|pLex.stu-ff 0}") - 'clojure-keyword-face)) - - (should (eq (clojure-test-face-at - 2 2 "{:ve/yCom|pLex.stu-ff/.ve/yCom|pLex.stu-ff 0}") - 'clojure-keyword-face)) - (should (eq (clojure-test-face-at - 3 4 "{:ve/yCom|pLex.stu-ff/.ve/yCom|pLex.stu-ff 0}") - 'font-lock-type-face)) - (should (eq (clojure-test-face-at - 5 5 "{:ve/yCom|pLex.stu-ff/.ve/yCom|pLex.stu-ff 0}") - 'default)) - (should (eq (clojure-test-face-at - 6 42 "{:ve/yCom|pLex.stu-ff/.ve/yCom|pLex.stu-ff 0}") - 'clojure-keyword-face))) - -(ert-deftest clojure-mode-syntax-table/namespaced-def () - :tags '(fontification syntax-table) - (clojure-test-with-temp-buffer "(_c4/defconstrainedfn bar [] nil)" - (should (eq (clojure-test-face-at 2 4) 'font-lock-type-face)) - (should (eq (clojure-test-face-at 5 5) nil)) - (should (eq (clojure-test-face-at 6 18) 'font-lock-keyword-face)) - (should (eq (clojure-test-face-at 23 25) 'font-lock-function-name-face))) - (clojure-test-with-temp-buffer "(clo/defbar foo nil)" - (should (eq (clojure-test-face-at 2 4) 'font-lock-type-face)) - (should (eq (clojure-test-face-at 5 5) nil)) - (should (eq (clojure-test-face-at 6 11) 'font-lock-keyword-face)) - (should (eq (clojure-test-face-at 13 15) 'font-lock-function-name-face))) - (clojure-test-with-temp-buffer "(s/def ::keyword)" - (should (eq (clojure-test-face-at 2 2) 'font-lock-type-face)) - (should (eq (clojure-test-face-at 3 3) nil)) - (should (eq (clojure-test-face-at 4 6) 'font-lock-keyword-face)) - (should (eq (clojure-test-face-at 8 16) 'clojure-keyword-face)))) - - -(ert-deftest clojure-mode-syntax-table/variable-def () - :tags '(fontification syntax-table) - (should (eq (clojure-test-face-at 2 4 "(def foo 10)") - 'font-lock-keyword-face)) - (should (eq (clojure-test-face-at 6 8 "(def foo 10)") - 'font-lock-variable-name-face))) - -(ert-deftest clojure-mode-syntax-table/variable-def-string () - :tags '(fontification syntax-table) - (should (eq (clojure-test-face-at 10 16 "(def foo \"hello\")") - 'font-lock-string-face)) - (should (eq (clojure-test-face-at 10 16 "(def foo \"hello\" )") - 'font-lock-string-face)) - (should (eq (clojure-test-face-at 13 19 "(def foo \n \"hello\")") - 'font-lock-string-face)) - (should (eq (clojure-test-face-at 13 19 "(def foo \n \"hello\"\n)") - 'font-lock-string-face))) - -(ert-deftest clojure-mode-syntax-table/variable-def-string-with-docstring () - :tags '(fontification syntax-table) - (should (eq (clojure-test-face-at 10 16 "(def foo \"usage\" \"hello\")") - 'font-lock-doc-face)) - (should (eq (clojure-test-face-at 18 24 "(def foo \"usage\" \"hello\")") - 'font-lock-string-face)) - (should (eq (clojure-test-face-at 18 24 "(def foo \"usage\" \"hello\" )") - 'font-lock-string-face)) - (should (eq (clojure-test-face-at 21 27 "(def foo \"usage\" \n \"hello\")") - 'font-lock-string-face)) - (should (eq (clojure-test-face-at 13 19 "(def foo \n \"usage\" \"hello\")") - 'font-lock-doc-face)) - (should (eq (clojure-test-face-at 13 19 "(def foo \n \"usage\" \n \"hello\")") - 'font-lock-doc-face)) - (should (eq (clojure-test-face-at 24 30 "(def foo \n \"usage\" \n \"hello\")") - 'font-lock-string-face))) - -(ert-deftest clojure-mode-syntax-table/type-def () - :tags '(fontification syntax-table) - (clojure-test-with-temp-buffer "(deftype Foo)" - (should (eq (clojure-test-face-at 2 8) 'font-lock-keyword-face)) - (should (eq (clojure-test-face-at 10 12) 'font-lock-type-face)))) - -(ert-deftest clojure-mode-syntax-table/function-def () - :tags '(fontification syntax-table) - (clojure-test-with-temp-buffer "(defn foo [x] x)" - (should (eq (clojure-test-face-at 2 5) 'font-lock-keyword-face)) - (should (eq (clojure-test-face-at 7 9) 'font-lock-function-name-face)))) - -(ert-deftest clojure-mode-syntax-table/custom-def-with-special-chars1 () - :tags '(fontification syntax-table) - (clojure-test-with-temp-buffer "(defn* foo [x] x)" - (should (eq (clojure-test-face-at 2 6) 'font-lock-keyword-face)) - (should (eq (clojure-test-face-at 8 10) 'font-lock-function-name-face)))) - -(ert-deftest clojure-mode-syntax-table/custom-def-with-special-chars2 () - :tags '(fontification syntax-table) - (clojure-test-with-temp-buffer "(defsomething! foo [x] x)" - (should (eq (clojure-test-face-at 2 14) 'font-lock-keyword-face)) - (should (eq (clojure-test-face-at 16 18) 'font-lock-function-name-face)))) - -(ert-deftest clojure-mode-syntax-table/custom-def-with-special-chars3 () - :tags '(fontification syntax-table) - (clojure-test-with-temp-buffer "(def-something foo [x] x)" - (should (eq (clojure-test-face-at 2 14) 'font-lock-keyword-face)) - (should (eq (clojure-test-face-at 16 18) 'font-lock-function-name-face)))) - -(ert-deftest clojure-mode-syntax-table/fn () - :tags '(fontification syntax-table) - ;; try to byte-recompile the clojure-mode.el when the face of 'fn' is 't' - (should (eq (clojure-test-face-at 2 3 "(fn foo [x] x)") - 'font-lock-keyword-face)) - (should (eq (clojure-test-face-at 5 7 "(fn foo [x] x)") - 'font-lock-function-name-face))) - -(ert-deftest clojure-mode-syntax-table/lambda-params () - :tags '(fontification syntax-table) - (clojure-test-with-temp-buffer "#(+ % %2 %3 %&)" - (should (eq (clojure-test-face-at 5 5) 'font-lock-variable-name-face)) - (should (eq (clojure-test-face-at 7 8) 'font-lock-variable-name-face)) - (should (eq (clojure-test-face-at 10 11) 'font-lock-variable-name-face)) - (should (eq (clojure-test-face-at 13 14) 'font-lock-variable-name-face)))) - -(ert-deftest clojure-mode-syntax-table/nil () - :tags '(fontification syntax-table) - (should (eq (clojure-test-face-at 4 6 "(= nil x)") 'font-lock-constant-face)) - (should-not (eq (clojure-test-face-at 3 5 "(fnil x)") - 'font-lock-constant-face))) - -(ert-deftest clojure-mode-syntax-table/true () - :tags '(fontification syntax-table) - (should (eq (clojure-test-face-at 4 7 "(= true x)") - 'font-lock-constant-face))) - -(ert-deftest clojure-mode-syntax-table/false () - :tags '(fontification syntax-table) - (should (eq (clojure-test-face-at 4 8 "(= false x)") - 'font-lock-constant-face))) - -(ert-deftest clojure-mode-syntax-table/keyword-meta () - :tags '(fontification syntax-table) - (clojure-test-with-temp-buffer "^:meta-data" - (should (eq (clojure-test-face-at 1 1) nil)) - (should (equal (clojure-test-face-at 2 11) 'clojure-keyword-face)))) - -(ert-deftest clojure-mode-syntax-table/keyword-allowed-chars () - :tags '(fontification syntax-table) - (should (equal (clojure-test-face-at 1 8 ":aaa#bbb") 'clojure-keyword-face))) - -(ert-deftest clojure-mode-syntax-table/keyword-disallowed-chars () - :tags '(fontification syntax-table) - (should (eq (clojure-test-face-at 1 5 ":aaa@bbb") 'various-faces)) - (should (equal (clojure-test-face-at 1 4 ":aaa@bbb") 'clojure-keyword-face)) - (should (eq (clojure-test-face-at 1 5 ":aaa~bbb") 'various-faces)) - (should (equal (clojure-test-face-at 1 4 ":aaa~bbb") 'clojure-keyword-face)) - (should (eq (clojure-test-face-at 1 5 ":aaa@bbb") 'various-faces)) - (should (equal (clojure-test-face-at 1 4 ":aaa@bbb") 'clojure-keyword-face))) - -(ert-deftest clojure-mode-syntax-table/characters () - :tags '(fontification syntax-table) - (should (eq (clojure-test-face-at 1 2 "\\a") 'clojure-character-face)) - (should (eq (clojure-test-face-at 1 8 "\\newline") 'clojure-character-face)) - (should (eq (clojure-test-face-at 1 2 "\\1") 'clojure-character-face)) - (should (eq (clojure-test-face-at 1 6 "\\u0032") 'clojure-character-face)) - (should (eq (clojure-test-face-at 1 2 "\\+") 'clojure-character-face)) - (should (eq (clojure-test-face-at 1 2 "\\.") 'clojure-character-face)) - (should (eq (clojure-test-face-at 1 2 "\\,") 'clojure-character-face)) - (should (eq (clojure-test-face-at 1 2 "\\;") 'clojure-character-face))) - -(ert-deftest clojure-mode-syntax-table/refer-ns () - :tags '(fontification syntax-table) - (should (eq (clojure-test-face-at 1 3 "foo/var") 'font-lock-type-face)) - (should (eq (clojure-test-face-at 2 4 "@foo/var") 'font-lock-type-face))) - -(ert-deftest clojure-mode-syntax-table/dynamic-var () - :tags '(fontification syntax-table) - (should (eq (clojure-test-face-at 1 10 "*some-var*") - 'font-lock-variable-name-face)) - (should (eq (clojure-test-face-at 2 11 "@*some-var*") - 'font-lock-variable-name-face)) - (should (eq (clojure-test-face-at 9 13 "some.ns/*var*") - 'font-lock-variable-name-face)) - (should (eq (clojure-test-face-at 1 11 "*some-var?*") - 'font-lock-variable-name-face))) +(describe "clojure-mode-syntax-table" + + (when-fontifying-it "should handle stuff in backticks" + ("\"`#'s/trim`\"" + (1 2 font-lock-string-face) + (3 10 (font-lock-constant-face font-lock-string-face)) + (11 12 font-lock-string-face)) + + (";`#'s/trim`" + (1 1 font-lock-comment-delimiter-face) + (2 2 font-lock-comment-face) + (3 10 (font-lock-constant-face font-lock-comment-face)) + (11 11 font-lock-comment-face))) + + (when-fontifying-it "should handle stuff in strings" + ("\"a\\bc\\n\"" + (1 2 font-lock-string-face) + (3 4 (bold font-lock-string-face)) + (5 5 font-lock-string-face) + (6 7 (bold font-lock-string-face))) + + ("#\"a\\bc\\n\"" + (4 5 (bold font-lock-string-face)))) + + (when-fontifying-it "should handle stuff in double brackets" + ("\"[[#'s/trim]]\"" + (1 3 font-lock-string-face) + (4 11 (font-lock-constant-face font-lock-string-face)) + (12 14 font-lock-string-face)) + + (";[[#'s/trim]]" + (1 1 font-lock-comment-delimiter-face) + (2 3 font-lock-comment-face) + (4 11 (font-lock-constant-face font-lock-comment-face)) + (12 13 font-lock-comment-face))) + + (when-fontifying-it "should fontify let, when, and while type forms" + ("(when-alist [x 1]\n ())" + (2 11 font-lock-keyword-face)) + + ("(while-alist [x 1]\n ())" + (2 12 font-lock-keyword-face)) + + ("(let-alist [x 1]\n ())" + (2 10 font-lock-keyword-face))) + + (when-fontifying-it "should handle comment macros" + ("#_" + (1 2 nil)) + + ("#_ \n;; some crap\n (lala 0101\n lao\n\n 0 0i)" + (1 2 nil)) + + ("#_ \n;; some crap\n (lala 0101\n lao\n\n 0 0i)" + (5 41 font-lock-comment-face))) + + (when-fontifying-it "should handle namespace declarations" + ("(ns .validns)" + (5 12 font-lock-type-face)) + + ("(ns =validns)" + (5 12 font-lock-type-face)) + + ("(ns .ValidNs=<>?+|?*.)" + (5 21 font-lock-type-face)) + + ("(ns ValidNs<>?+|?*.b*ar.ba*z)" + (5 28 font-lock-type-face)) + + ("(ns other.valid.ns)" + (5 18 font-lock-type-face)) + + ("(ns oneword)" + (5 11 font-lock-type-face)) + + ("(ns foo.bar)" + (5 11 font-lock-type-face)) + + ("(ns Foo.bar)" + (5 11 font-lock-type-face) + (5 11 font-lock-type-face) + (5 11 font-lock-type-face)) + + ("(ns Foo-bar)" + (5 11 font-lock-type-face) + (5 11 font-lock-type-face)) + + ("(ns foo-Bar)" + (5 11 font-lock-type-face)) + + ("(ns one.X)" + (5 9 font-lock-type-face)) + + ("(ns ^:md ns-name)" + (10 16 font-lock-type-face)) + + ("(ns ^:md \n ns-name)" + (13 19 font-lock-type-face)) + + ("(ns ^:md1 ^:md2 ns-name)" + (17 23 font-lock-type-face)) + + ("(ns ^:md1 ^{:md2 true} ns-name)" + (24 30 font-lock-type-face)) + + ("(ns ^{:md2 true} ^:md1 ns-name)" + (24 30 font-lock-type-face)) + + ("(ns ^:md1 ^{:md2 true} \n ns-name)" + (27 33 font-lock-type-face)) + + ("(ns ^{:md2 true} ^:md1 \n ns-name)" + (27 33 font-lock-type-face))) + + (when-fontifying-it "should handle one word" + (" oneword" + (2 8 nil)) + + ("@oneword" + (2 8 nil)) + + ("#oneword" + (2 8 nil)) + + (".oneword" + (2 8 nil)) + + ("#^oneword" + (3 9 font-lock-type-face)) ;; type-hint + + ("(oneword)" + (2 8 nil)) + + ("(oneword/oneword)" + (2 8 font-lock-type-face) + (9 10 nil) + (11 16 nil)) + + ("(oneword/seg.mnt)" + (2 8 font-lock-type-face) + (9 10 nil) + (11 16 nil)) + + ("(oneword/mxdCase)" + (2 8 font-lock-type-face) + (9 10 nil) + (11 16 nil)) + + ("(oneword/CmlCase)" + (2 8 font-lock-type-face) + (9 10 nil) + (11 16 nil)) + + ("(oneword/ve/yCom|pLex.stu-ff)" + (2 8 font-lock-type-face) + (9 10 nil) + (11 28 nil)) + + ("(oneword/.ve/yCom|pLex.stu-ff)" + (2 8 font-lock-type-face) + (9 10 nil) + (12 29 nil))) + + (when-fontifying-it "should handle a segment" + (" seg.mnt" + (2 8 nil)) + + ("@seg.mnt" + (2 8 nil)) + + ("#seg.mnt" + (2 8 nil)) + + (".seg.mnt" + (2 8 nil)) + + ("#^seg.mnt" + (3 9 font-lock-type-face)) ;; type-hint + + ("(seg.mnt)" + (2 8 nil)) + + ("(seg.mnt/oneword)" + (2 8 font-lock-type-face) + (9 10 nil) + (11 16 nil)) + + ("(seg.mnt/seg.mnt)" + (2 8 font-lock-type-face) + (9 10 nil) + (11 16 nil)) + + ("(seg.mnt/mxdCase)" + (2 8 font-lock-type-face) + (9 10 nil) + (11 16 nil)) + + ("(seg.mnt/CmlCase)" + (2 8 font-lock-type-face) + (9 10 nil) + (11 16 nil)) + + ("(seg.mnt/ve/yCom|pLex.stu-ff)" + (2 8 font-lock-type-face) + (9 10 nil) + (11 28 nil)) + + ("(seg.mnt/.ve/yCom|pLex.stu-ff)" + (2 8 font-lock-type-face) + (9 10 nil) + (12 29 nil))) + + (when-fontifying-it "should handle camelcase" + (" CmlCase" + (2 8 nil)) + + ("@CmlCase" + (2 8 nil)) + + ("#CmlCase" + (2 8 nil)) + + (".CmlCase" + (2 8 nil)) + + ("#^CmlCase" + (3 9 font-lock-type-face)) ;; type-hint + + ("(CmlCase)" + (2 8 nil)) + + ("(CmlCase/oneword)" + (2 8 font-lock-type-face) + (9 10 nil) + (11 16 nil)) + + ("(CmlCase/seg.mnt)" + (2 8 font-lock-type-face) + (9 10 nil) + (11 16 nil)) + + ("(CmlCase/mxdCase)" + (2 8 font-lock-type-face) + (9 10 nil) + (11 16 nil)) + + ("(CmlCase/CmlCase)" + (2 8 font-lock-type-face) + (9 10 nil) + (11 16 nil)) + + ("(CmlCase/ve/yCom|pLex.stu-ff)" + (2 8 font-lock-type-face) + (9 10 nil) + (11 28 nil)) + + ("(CmlCase/.ve/yCom|pLex.stu-ff)" + (2 8 font-lock-type-face) + (9 10 nil) + (12 29 nil))) + + (when-fontifying-it "should handle mixed case" + (" mxdCase" + (2 8 nil)) + + ("@mxdCase" + (2 8 nil)) + + ("#mxdCase" + (2 8 nil)) + + (".mxdCase" + (2 8 nil)) + + ("#^mxdCase" + (3 9 font-lock-type-face)) ;; type-hint + + ("(mxdCase)" + (2 8 nil)) + + ("(mxdCase/oneword)" + (2 8 font-lock-type-face) + (9 10 nil) + (11 16 nil)) + + ("(mxdCase/seg.mnt)" + (2 8 font-lock-type-face) + (9 10 nil) + (11 16 nil)) + + ("(mxdCase/mxdCase)" + (2 8 font-lock-type-face) + (9 10 nil) + (11 16 nil)) + + ("(mxdCase/CmlCase)" + (2 8 font-lock-type-face) + (9 10 nil) + (11 16 nil)) + + ("(mxdCase/ve/yCom|pLex.stu-ff)" + (2 8 font-lock-type-face) + (9 10 nil) + (11 28 nil)) + + ("(mxdCase/.ve/yCom|pLex.stu-ff)" + (2 8 font-lock-type-face) + (9 10 nil) + (12 29 nil))) + + (when-fontifying-it "should handle very complex stuff" + (" ve/yCom|pLex.stu-ff" + (3 4 font-lock-type-face) + (5 21 nil)) + + (" @ve/yCom|pLex.stu-ff" + (2 2 nil) + (3 4 font-lock-type-face) + (5 21 nil)) + + (" #ve/yCom|pLex.stu-ff" + (2 4 font-lock-type-face) + (5 21 nil)) + + (" .ve/yCom|pLex.stu-ff" + (2 4 font-lock-type-face) + (5 21 nil)) + + ;; type-hint + ("#^ve/yCom|pLex.stu-ff" + (1 2 default) + (3 4 font-lock-type-face) + (5 21 default)) + + ("^ve/yCom|pLex.stu-ff" + (2 3 font-lock-type-face) + (5 20 default)) + + (" (ve/yCom|pLex.stu-ff)" + (3 4 font-lock-type-face) + (5 21 nil)) + + (" (ve/yCom|pLex.stu-ff/oneword)" + (3 4 font-lock-type-face) + (5 29 nil)) + + (" (ve/yCom|pLex.stu-ff/seg.mnt)" + (3 4 font-lock-type-face) + (5 29 nil)) + + (" (ve/yCom|pLex.stu-ff/mxdCase)" + (3 4 font-lock-type-face) + (5 29 nil)) + + (" (ve/yCom|pLex.stu-ff/CmlCase)" + (3 4 font-lock-type-face) + (5 29 nil)) + + (" (ve/yCom|pLex.stu-ff/ve/yCom|pLex.stu-ff)" + (3 4 font-lock-type-face) + (5 41 nil)) + + (" (ve/yCom|pLex.stu-ff/.ve/yCom|pLex.stu-ff)" + (3 4 font-lock-type-face) + (5 42 nil))) + + (when-fontifying-it "should handle oneword keywords" + (" :oneword" + (3 9 clojure-keyword-face )) + + ("{:oneword 0}" + (3 9 clojure-keyword-face)) + + ("{:#oneword 0}" + (3 10 clojure-keyword-face)) + + ("{:.oneword 0}" + (3 10 clojure-keyword-face)) + + ("{:oneword/oneword 0}" + (3 9 font-lock-type-face) + (10 10 default) + (11 17 clojure-keyword-face)) + + ("{:oneword/seg.mnt 0}" + (3 9 font-lock-type-face) + (10 10 default) + (11 17 clojure-keyword-face)) + + ("{:oneword/CmlCase 0}" + (3 9 font-lock-type-face) + (10 10 default) + (11 17 clojure-keyword-face)) + + ("{:oneword/mxdCase 0}" + (3 9 font-lock-type-face) + (10 10 default) + (11 17 clojure-keyword-face)) + + ("{:oneword/ve/yCom|pLex.stu-ff 0}" + (3 9 font-lock-type-face) + (10 10 default) + (11 29 clojure-keyword-face)) + + ("{:oneword/.ve/yCom|pLex.stu-ff 0}" + (3 9 font-lock-type-face) + (10 10 default) + (11 30 clojure-keyword-face))) + + (when-fontifying-it "should handle namespaced keywords" + ("::foo" + (1 5 clojure-keyword-face)) + + (":_::_:foo" + (1 9 clojure-keyword-face)) + + (":_:_:foo" + (1 8 clojure-keyword-face)) + + (":foo/:bar" + (1 9 clojure-keyword-face)) + + ("::_:foo" + (1 7 clojure-keyword-face)) + + ("::_:_:foo" + (1 9 clojure-keyword-face)) + + (":_:_:foo/_" + (1 1 clojure-keyword-face) + (2 8 font-lock-type-face) + (9 9 default) + (10 10 clojure-keyword-face)) + + (":_:_:foo/bar" + (10 12 clojure-keyword-face)) + + (":_:_:foo/bar/eee" + (10 16 clojure-keyword-face)) + + (":_:_:foo/bar_:foo" + (10 17 clojure-keyword-face)) + + (":_:_:foo/bar_:_:foo" + (10 19 clojure-keyword-face))) + + (when-fontifying-it "should handle segment keywords" + (" :seg.mnt" + (3 9 clojure-keyword-face)) + + ("{:seg.mnt 0}" + (3 9 clojure-keyword-face)) + + ("{:#seg.mnt 0}" + (3 10 clojure-keyword-face)) + + ("{:.seg.mnt 0}" + (3 10 clojure-keyword-face)) + + ("{:seg.mnt/oneword 0}" + (3 9 font-lock-type-face) + (10 10 default) + (11 17 clojure-keyword-face)) + + ("{:seg.mnt/seg.mnt 0}" + (3 9 font-lock-type-face ) + (10 10 default) + (11 17 clojure-keyword-face)) + + ("{:seg.mnt/CmlCase 0}" + (3 9 font-lock-type-face) + (10 10 default) + (11 17 clojure-keyword-face)) + + ("{:seg.mnt/mxdCase 0}" + (3 9 font-lock-type-face) + (10 10 default) + (11 17 clojure-keyword-face)) + + ("{:seg.mnt/ve/yCom|pLex.stu-ff 0}" + (3 9 font-lock-type-face) + (10 10 default) + (11 29 clojure-keyword-face)) + + ("{:seg.mnt/.ve/yCom|pLex.stu-ff 0}" + (3 9 font-lock-type-face) + (10 10 default) + (11 30 clojure-keyword-face))) + + (when-fontifying-it "should handle camel case keywords" + (" :CmlCase" + (3 9 clojure-keyword-face)) + + ("{:CmlCase 0}" + (3 9 clojure-keyword-face)) + + ("{:#CmlCase 0}" + (3 10 clojure-keyword-face)) + + ("{:.CmlCase 0}" + (3 10 clojure-keyword-face)) + + ("{:CmlCase/oneword 0}" + (3 9 font-lock-type-face) + (10 10 default) + (11 17 clojure-keyword-face)) + + ("{:CmlCase/seg.mnt 0}" + (3 9 font-lock-type-face) + (10 10 default) + (11 17 clojure-keyword-face)) + + ("{:CmlCase/CmlCase 0}" + (3 9 font-lock-type-face) + (10 10 default) + (11 17 clojure-keyword-face)) + + ("{:CmlCase/mxdCase 0}" + (3 9 font-lock-type-face) + (10 10 default) + (11 17 clojure-keyword-face)) + + ("{:CmlCase/ve/yCom|pLex.stu-ff 0}" + (3 9 font-lock-type-face) + (10 10 default) + (11 29 clojure-keyword-face)) + + ("{:CmlCase/.ve/yCom|pLex.stu-ff 0}" + (3 9 font-lock-type-face) + (10 10 default) + (11 30 clojure-keyword-face))) + + (when-fontifying-it "should handle mixed case keywords" + (" :mxdCase" + (3 9 clojure-keyword-face)) + + ("{:mxdCase 0}" + (3 9 clojure-keyword-face)) + + ("{:#mxdCase 0}" + (3 10 clojure-keyword-face)) + + ("{:.mxdCase 0}" + (3 10 clojure-keyword-face)) + + ("{:mxdCase/oneword 0}" + (3 9 font-lock-type-face) + (10 10 default) + (11 17 clojure-keyword-face)) + + ("{:mxdCase/seg.mnt 0}" + (3 9 font-lock-type-face) + (10 10 default) + (11 17 clojure-keyword-face)) + + ("{:mxdCase/CmlCase 0}" + (3 9 font-lock-type-face) + (10 10 default) + (11 17 clojure-keyword-face)) + + ("{:mxdCase/mxdCase 0}" + (3 9 font-lock-type-face) + (10 10 default) + (11 17 clojure-keyword-face)) + + ("{:mxdCase/ve/yCom|pLex.stu-ff 0}" + (3 9 font-lock-type-face) + (10 10 default) + (11 29 clojure-keyword-face)) + + ("{:mxdCase/.ve/yCom|pLex.stu-ff 0}" + (3 9 font-lock-type-face) + (10 10 default) + (11 30 clojure-keyword-face))) + + (when-fontifying-it "should handle very complex keywords" + (" :ve/yCom|pLex.stu-ff" + (3 4 font-lock-type-face) + (5 5 default) + (6 21 clojure-keyword-face)) + + ("{:ve/yCom|pLex.stu-ff 0}" + (2 2 clojure-keyword-face) + (3 4 font-lock-type-face) + (5 5 default) + (6 21 clojure-keyword-face)) + + ("{:#ve/yCom|pLex.stu-ff 0}" + (2 2 clojure-keyword-face) + (3 5 font-lock-type-face) + (6 6 default) + (7 22 clojure-keyword-face)) + + ("{:.ve/yCom|pLex.stu-ff 0}" + (2 2 clojure-keyword-face) + (3 5 font-lock-type-face) + (6 6 default) + (7 22 clojure-keyword-face)) + + ("{:ve/yCom|pLex.stu-ff/oneword 0}" + (2 2 clojure-keyword-face) + (3 4 font-lock-type-face) + (5 5 default) + (6 29 clojure-keyword-face)) + + ("{:ve/yCom|pLex.stu-ff/seg.mnt 0}" + (2 2 clojure-keyword-face) + (3 4 font-lock-type-face) + (5 5 default) + (6 29 clojure-keyword-face)) + + ("{:ve/yCom|pLex.stu-ff/ClmCase 0}" + (2 2 clojure-keyword-face) + (3 4 font-lock-type-face) + (5 5 default) + (6 29 clojure-keyword-face)) + + ("{:ve/yCom|pLex.stu-ff/mxdCase 0}" + (2 2 clojure-keyword-face) + (3 4 font-lock-type-face) + (5 5 default) + (6 29 clojure-keyword-face)) + + ("{:ve/yCom|pLex.stu-ff/ve/yCom|pLex.stu-ff 0}" + (2 2 clojure-keyword-face) + (3 4 font-lock-type-face) + (5 5 default) + (6 41 clojure-keyword-face)) + + ("{:ve/yCom|pLex.stu-ff/.ve/yCom|pLex.stu-ff 0}" + (2 2 clojure-keyword-face) + (3 4 font-lock-type-face) + (5 5 default) + (6 42 clojure-keyword-face))) + + (when-fontifying-it "should handle namespaced defs" + ("(_c4/defconstrainedfn bar [] nil)" + (2 4 font-lock-type-face) + (5 5 nil) + (6 18 font-lock-keyword-face) + (23 25 font-lock-function-name-face)) + + ("(clo/defbar foo nil)" + (2 4 font-lock-type-face) + (5 5 nil) + (6 11 font-lock-keyword-face) + (13 15 font-lock-function-name-face)) + + ("(s/def ::keyword)" + (2 2 font-lock-type-face) + (3 3 nil) + (4 6 font-lock-keyword-face) + (8 16 clojure-keyword-face))) + + (when-fontifying-it "should handle variables defined with def" + ("(def foo 10)" + (2 4 font-lock-keyword-face) + (6 8 font-lock-variable-name-face))) + + (when-fontifying-it "should handle variables definitions of type string" + ("(def foo \"hello\")" + (10 16 font-lock-string-face)) + + ("(def foo \"hello\" )" + (10 16 font-lock-string-face)) + + ("(def foo \n \"hello\")" + (13 19 font-lock-string-face)) + + ("(def foo \n \"hello\"\n)" + (13 19 font-lock-string-face))) + + (when-fontifying-it "variable-def-string-with-docstring" + ("(def foo \"usage\" \"hello\")" + (10 16 font-lock-doc-face) + (18 24 font-lock-string-face)) + + ("(def foo \"usage\" \"hello\" )" + (18 24 font-lock-string-face)) + + ("(def foo \"usage\" \n \"hello\")" + (21 27 font-lock-string-face)) + + ("(def foo \n \"usage\" \"hello\")" + (13 19 font-lock-doc-face)) + + ("(def foo \n \"usage\" \n \"hello\")" + (13 19 font-lock-doc-face) + (24 30 font-lock-string-face))) + + (when-fontifying-it "should handle deftype" + ("(deftype Foo)" + (2 8 font-lock-keyword-face) + (10 12 font-lock-type-face))) + + (when-fontifying-it "should handle defn" + ("(defn foo [x] x)" + (2 5 font-lock-keyword-face) + (7 9 font-lock-function-name-face))) + + (when-fontifying-it "should handle a custom def with special chars 1" + ("(defn* foo [x] x)" + (2 6 font-lock-keyword-face) + (8 10 font-lock-function-name-face))) + + (when-fontifying-it "should handle a custom def with special chars 2" + ("(defsomething! foo [x] x)" + (2 14 font-lock-keyword-face) + (16 18 font-lock-function-name-face))) + + (when-fontifying-it "should handle a custom def with special chars 3" + ("(def-something foo [x] x)" + (2 14 font-lock-keyword-face)) + + ("(def-something foo [x] x)" + (16 18 font-lock-function-name-face))) + + (when-fontifying-it "should handle fn" + ;; try to byte-recompile the clojure-mode.el when the face of 'fn' is 't' + ("(fn foo [x] x)" + (2 3 font-lock-keyword-face) + ( 5 7 font-lock-function-name-face))) + + (when-fontifying-it "should handle lambda-params" + ("#(+ % %2 %3 %&)" + (5 5 font-lock-variable-name-face) + (7 8 font-lock-variable-name-face) + (10 11 font-lock-variable-name-face) + (13 14 font-lock-variable-name-face))) + + (when-fontifying-it "should handle nils" + ("(= nil x)" + (4 6 font-lock-constant-face)) + + ("(fnil x)" + (3 5 nil))) + + (when-fontifying-it "should handle true" + ("(= true x)" + (4 7 font-lock-constant-face))) + + (when-fontifying-it "should handle false" + ("(= false x)" + (4 8 font-lock-constant-face))) + + (when-fontifying-it "should handle keyword-meta" + ("^:meta-data" + (1 1 nil) + (2 11 clojure-keyword-face))) + + (when-fontifying-it "should handle a keyword with allowed characters" + (":aaa#bbb" + (1 8 clojure-keyword-face))) + + (when-fontifying-it "should handle a keyword with disallowed characters" + (":aaa@bbb" + (1 5 various-faces)) + + (":aaa@bbb" + (1 4 clojure-keyword-face)) + + (":aaa~bbb" + (1 5 various-faces)) + + (":aaa~bbb" + (1 4 clojure-keyword-face)) + + (":aaa@bbb" + (1 5 various-faces)) + + (":aaa@bbb" + (1 4 clojure-keyword-face))) + + (when-fontifying-it "should handle characters" + ("\\a" + (1 2 clojure-character-face)) + + ("\\newline" + (1 8 clojure-character-face)) + + ("\\1" + (1 2 clojure-character-face)) + + ("\\u0032" + (1 6 clojure-character-face)) + + ("\\+" + (1 2 clojure-character-face)) + + ("\\." + (1 2 clojure-character-face)) + + ("\\," + (1 2 clojure-character-face)) + + ("\\;" + (1 2 clojure-character-face))) + + (when-fontifying-it "should handle referred vars" + ("foo/var" + (1 3 font-lock-type-face)) + + ("@foo/var" + (2 4 font-lock-type-face))) + + (when-fontifying-it "should handle dynamic vars" + ("*some-var*" + (1 10 font-lock-variable-name-face)) + + ("@*some-var*" + (2 11 font-lock-variable-name-face)) + + ("some.ns/*var*" + (9 13 font-lock-variable-name-face)) + + ("*some-var?*" + (1 11 font-lock-variable-name-face)))) (provide 'clojure-mode-font-lock-test) diff --git a/clojure-mode-indentation-test.el b/clojure-mode-indentation-test.el index 7afa3ff..2ec7e26 100644 --- a/clojure-mode-indentation-test.el +++ b/clojure-mode-indentation-test.el @@ -24,27 +24,16 @@ ;;; Code: (require 'clojure-mode) +(require 'test-helper) (require 'cl-lib) -(require 'ert) +(require 'buttercup) (require 's) -(ert-deftest dont-hang-on-eob () - (with-temp-buffer - (insert "(let [a b]") - (clojure-mode) - (goto-char (point-max)) - (should - (with-timeout (2) - (newline-and-indent) - t)))) +(defmacro when-indenting-with-point-it (description before after) + "Return a buttercup spec. -(defmacro check-indentation (description before after &optional var-bindings) - "Declare an ert test for indentation behaviour. -The test will check that the swift indentation command changes the buffer -from one state to another. It will also test that point is moved to an -expected position. - -DESCRIPTION is a symbol describing the test. +Check whether the swift indentation command will correctly change the buffer. +Will also check whether point is moved to the expected position. BEFORE is the buffer string before indenting, where a pipe (|) represents point. @@ -52,232 +41,274 @@ point. AFTER is the expected buffer string after indenting, where a pipe (|) represents the expected position of point. -VAR-BINDINGS is an optional let-bindings list. It can be used to set the -values of customisable variables." +DESCRIPTION is a string with the description of the spec." + (declare (indent 1)) + `(it ,description + (let* ((after ,after) + (clojure-indent-style 'always-align) + (expected-cursor-pos (1+ (s-index-of "|" after))) + (expected-state (delete ?| after))) + (with-clojure-buffer ,before + (goto-char (point-min)) + (search-forward "|") + (delete-char -1) + (font-lock-ensure) + (indent-according-to-mode) + (expect (buffer-string) :to-equal expected-state) + (expect (point) :to-equal expected-cursor-pos))))) + +;; Backtracking indent +(defmacro when-indenting-it (description &optional style &rest forms) + "Return a buttercup spec. + +Check that all FORMS correspond to properly indented sexps. + +STYLE allows overriding the default clojure-indent-style 'always-align. + +DESCRIPTION is a string with the description of the spec." (declare (indent 1)) - (let ((fname (intern (format "indentation/%s" description)))) - `(ert-deftest ,fname () - (let* ((after ,after) - (clojure-indent-style 'always-align) - (expected-cursor-pos (1+ (s-index-of "|" after))) - (expected-state (delete ?| after)) - ,@var-bindings) - (with-temp-buffer - (insert ,before) - (goto-char (point-min)) - (search-forward "|") - (delete-char -1) - (clojure-mode) - (font-lock-ensure) - (indent-according-to-mode) - - (should (equal expected-state (buffer-string))) - (should (equal expected-cursor-pos (point)))))))) + (when (stringp style) + (setq forms (cons style forms)) + (setq style '(quote always-align))) + `(it ,description + (progn + ,@(mapcar (lambda (form) + `(with-temp-buffer + (clojure-mode) + (insert "\n" ,form);,(replace-regexp-in-string "\n +" "\n " form)) + (let ((clojure-indent-style ,style)) + (indent-region (point-min) (point-max))) + (expect (buffer-string) :to-equal ,(concat "\n" form)))) + forms)))) + +(defmacro when-aligning-it (description &rest forms) + "Return a buttercup spec. + +Check that all FORMS correspond to properly indented sexps. + +DESCRIPTION is a string with the description of the spec." + (declare (indent defun)) + `(it ,description + (let ((clojure-align-forms-automatically t) + (clojure-align-reader-conditionals t)) + ,@(mapcar (lambda (form) + `(with-temp-buffer + (clojure-mode) + (insert "\n" ,(replace-regexp-in-string " +" " " form)) + (indent-region (point-min) (point-max)) + (should (equal (buffer-substring-no-properties (point-min) (point-max)) + ,(concat "\n" form))))) + forms)) + (let ((clojure-align-forms-automatically nil)) + ,@(mapcar (lambda (form) + `(with-temp-buffer + (clojure-mode) + (insert "\n" ,(replace-regexp-in-string " +" " " form)) + ;; This is to check that we did NOT align anything. Run + ;; `indent-region' and then check that no extra spaces + ;; where inserted besides the start of the line. + (indent-region (point-min) (point-max)) + (goto-char (point-min)) + (should-not (search-forward-regexp "\\([^\s\n]\\) +" nil 'noerror)))) + forms)))) ;; Provide font locking for easier test editing. (font-lock-add-keywords 'emacs-lisp-mode - `((,(rx "(" (group "check-indentation") eow) + `((,(rx "(" (group "when-indenting-with-point-it") eow) (1 font-lock-keyword-face)) (,(rx "(" - (group "check-indentation") (+ space) + (group "when-indenting-with-point-it") (+ space) (group bow (+ (not space)) eow) ) (1 font-lock-keyword-face) (2 font-lock-function-name-face)))) - -;;; Tests - - -(check-indentation no-indentation-at-top-level - "|x" - "|x") - -(check-indentation cond-indentation - " -(cond -|x)" - " -(cond - |x)") - -(check-indentation threading-with-expression-on-first-line - " -(->> expr - |ala)" - " -(->> expr - |ala)") - -(check-indentation threading-with-expression-on-second-line - " -(->> -|expr)" - " -(->> - |expr)") - -(check-indentation no-indent-for-def-string - "(def foo \"hello|\")" - "(def foo \"hello|\")") - -(check-indentation doc-strings-without-indent-specified - " -(defn some-fn -|\"some doc string\")" - " -(defn some-fn - |\"some doc string\")") - -(check-indentation doc-strings-with-correct-indent-specified - " -(defn some-fn - |\"some doc string\")" - " -(defn some-fn - |\"some doc string\")") - -(check-indentation doc-strings-with-additional-indent-specified - " -(defn some-fn - |\"some doc string - - some note\")" - " -(defn some-fn - |\"some doc string - - some note\")") - -;; we can specify different indentation for symbol with some ns prefix -(put-clojure-indent 'bala 0) -(put-clojure-indent 'ala/bala 1) - -(check-indentation symbol-without-ns - " -(bala -|one)" - " -(bala - |one)") - -(check-indentation symbol-with-ns - " -(ala/bala top -|one)" - " -(ala/bala top - |one)") - -;; we can pass a lambda to explicitely set the column -(put-clojure-indent 'arsymbol (lambda (indent-point state) 0)) - -(check-indentation symbol-with-lambda - " +(describe "indentation" + (it "should not hang on end of buffer" + (with-clojure-buffer "(let [a b]" + (goto-char (point-max)) + (expect + (with-timeout (2) + (newline-and-indent) + t)))) + + (when-indenting-with-point-it "should have no indentation at top level" + "|x" + + "|x") + + (when-indenting-with-point-it "should indent cond" + " + (cond + |x)" + + " + (cond + |x)") + + (when-indenting-with-point-it "should indent threading macro with expression on first line" + " + (->> expr + |ala)" + + " + (->> expr + |ala)") + + (when-indenting-with-point-it "should indent threading macro with expression on second line" + " + (->> + |expr)" + + " + (->> + |expr)") + + (when-indenting-with-point-it "should not indent for def string" + "(def foo \"hello|\")" + "(def foo \"hello|\")") + + (when-indenting-with-point-it "should indent doc strings" + " + (defn some-fn + |\"some doc string\")" + " + (defn some-fn + |\"some doc string\")") + + (when-indenting-with-point-it "should not indent doc strings when correct indent already specified" + " + (defn some-fn + |\"some doc string\")" + " + (defn some-fn + |\"some doc string\")") + + (when-indenting-with-point-it "should handle doc strings with additional indent specified" + " + (defn some-fn + |\"some doc string + - some note\")" + " + (defn some-fn + |\"some doc string + - some note\")") + + (describe "specify different indentation for symbol with some ns prefix" + (put-clojure-indent 'bala 0) + (put-clojure-indent 'ala/bala 1) + + (when-indenting-with-point-it "should handle a symbol without ns" + " + (bala + |one)" + " + (bala + |one)") + + (when-indenting-with-point-it "should handle a symbol with ns" + " + (ala/bala top + |one)" + " + (ala/bala top + |one)")) + + (describe "we can pass a lambda to explicitly set the column" + (put-clojure-indent 'arsymbol (lambda (indent-point state) 0)) + + (when-indenting-with-point-it "should handle a symbol with lambda" + " (arsymbol - |one)" - " +|one)" + " (arsymbol -|one)") - -(check-indentation form-with-metadata - " -(ns ^:doc app.core -|(:gen-class))" -" -(ns ^:doc app.core - |(:gen-class))") - -(check-indentation multiline-sexps - " -[[ - 2] a -|x]" -" -[[ - 2] a - |x]") - -(check-indentation reader-conditionals - " -#?(:clj :foo -|:cljs :bar)" - " -#?(:clj :foo - |:cljs :bar)") - -(check-indentation backtracking-with-aliases - " -(clojure.core/letfn [(twice [x] -|(* x 2))] - :a)" - " -(clojure.core/letfn [(twice [x] - |(* x 2))] - :a)") - -(check-indentation fixed-normal-indent - "(cond - (or 1 - 2) 3 -|:else 4)" - "(cond - (or 1 - 2) 3 - |:else 4)") - -(check-indentation fixed-normal-indent-2 - "(fact {:spec-type +|one)")) + + (when-indenting-with-point-it "should indent a form with metadata" + " + (ns ^:doc app.core + |(:gen-class))" + " + (ns ^:doc app.core + |(:gen-class))") + + (when-indenting-with-point-it "should handle multiline sexps" + " + [[ + 2] a + |x]" + " + [[ + 2] a + |x]") + + (when-indenting-with-point-it "should indent reader conditionals" + " + #?(:clj :foo + |:cljs :bar)" + " + #?(:clj :foo + |:cljs :bar)") + + (when-indenting-with-point-it "should handle backtracking with aliases" + " + (clojure.core/letfn [(twice [x] + |(* x 2))] + :a)" + " + (clojure.core/letfn [(twice [x] + |(* x 2))] + :a)") + + (when-indenting-with-point-it "should handle fixed-normal-indent" + "(cond + (or 1 + 2) 3 + |:else 4)" + + "(cond + (or 1 + 2) 3 + |:else 4)") + + (when-indenting-with-point-it "should handle fixed-normal-indent-2" + "(fact {:spec-type :charnock-column-id} #{\"charnock\"} |{:spec-type :charnock-column-id} #{\"current_charnock\"})" - "(fact {:spec-type + + "(fact {:spec-type :charnock-column-id} #{\"charnock\"} |{:spec-type :charnock-column-id} #{\"current_charnock\"})") - -;;; Backtracking indent -(defmacro def-full-indent-test (name &optional style &rest forms) - "Verify that all FORMs correspond to a properly indented sexps." - (declare (indent 1)) - (when (stringp style) - (setq forms (cons style forms)) - (setq style '(quote always-align))) - `(ert-deftest ,(intern (format "test-backtracking-%s" name)) () - (progn - ,@(mapcar (lambda (form) - `(with-temp-buffer - (clojure-mode) - (insert "\n" ,(replace-regexp-in-string "\n +" "\n " form)) - (let ((clojure-indent-style ,style)) - (indent-region (point-min) (point-max))) - (should (equal (buffer-string) - ,(concat "\n" form))))) - forms)))) - -(def-full-indent-test closing-paren - "(ns ca + (when-indenting-it "closing-paren" + "(ns ca (:gen-class) )") -(def-full-indent-test default-is-not-a-define - "(default a + (when-indenting-it "default-is-not-a-define" + "(default a b b)" - "(some.namespace/default a + "(some.namespace/default a b b)") -(def-full-indent-test extend-type-allow-multiarity - "(extend-type Banana + + (when-indenting-it "should handle extend-type with multiarity" + "(extend-type Banana Fruit (subtotal ([item] (* 158 (:qty item))) ([item a] (* a (:qty item)))))" - "(extend-protocol Banana + + "(extend-protocol Banana Fruit (subtotal ([item] @@ -285,8 +316,9 @@ values of customisable variables." ([item a] (* a (:qty item)))))") -(def-full-indent-test deftype-allow-multiarity - "(deftype Banana [] + + (when-indenting-it "should handle deftype with multiarity" + "(deftype Banana [] Fruit (subtotal ([item] @@ -294,8 +326,8 @@ values of customisable variables." ([item a] (* a (:qty item)))))") -(def-full-indent-test defprotocol - "(defprotocol IFoo + (when-indenting-it "should handle defprotocol" + "(defprotocol IFoo (foo [this] \"Why is this over here?\") (foo-2 @@ -303,16 +335,16 @@ values of customisable variables." \"Why is this over here?\"))") -(def-full-indent-test definterface - "(definterface IFoo + (when-indenting-it "should handle definterface" + "(definterface IFoo (foo [this] \"Why is this over here?\") (foo-2 [this] \"Why is this over here?\"))") -(def-full-indent-test specify - "(specify obj + (when-indenting-it "should handle specify" + "(specify obj ISwap (-swap! ([this f] (reset! this (f @this))) @@ -320,8 +352,8 @@ values of customisable variables." ([this f a b] (reset! this (f @this a b))) ([this f a b xs] (reset! this (apply f @this a b xs)))))") -(def-full-indent-test specify! - "(specify! obj + (when-indenting-it "should handle specify!" + "(specify! obj ISwap (-swap! ([this f] (reset! this (f @this))) @@ -329,28 +361,28 @@ values of customisable variables." ([this f a b] (reset! this (f @this a b))) ([this f a b xs] (reset! this (apply f @this a b xs)))))") -(def-full-indent-test non-symbol-at-start - "{\"1\" 2 + (when-indenting-it "should handle non-symbol at start" + "{\"1\" 2 *3 4}") -(def-full-indent-test non-symbol-at-start-2 - "(\"1\" 2 + (when-indenting-it "should handle non-symbol at start 2" + "(\"1\" 2 *3 4)") -(def-full-indent-test defrecord - "(defrecord TheNameOfTheRecord + (when-indenting-it "should handle defrecord" + "(defrecord TheNameOfTheRecord [a pretty long argument list] SomeType (assoc [_ x] (.assoc pretty x 10)))") -(def-full-indent-test defrecord-2 - "(defrecord TheNameOfTheRecord [a pretty long argument list] + (when-indenting-it "should handle defrecord 2" + "(defrecord TheNameOfTheRecord [a pretty long argument list] SomeType (assoc [_ x] (.assoc pretty x 10)))") -(def-full-indent-test defrecord-allow-multiarity - "(defrecord Banana [] + (when-indenting-it "should handle defrecord with multiarity" + "(defrecord Banana [] Fruit (subtotal ([item] @@ -358,8 +390,8 @@ values of customisable variables." ([item a] (* a (:qty item)))))") -(def-full-indent-test letfn - "(letfn [(f [x] + (when-indenting-it "should handle letfn" + "(letfn [(f [x] (* x 2)) (f [x] (* x 2))] @@ -367,11 +399,12 @@ values of customisable variables." c) (d) e)") -(def-full-indent-test reify - "(reify Object + (when-indenting-it "should handle reify" + "(reify Object (x [_] 1))" - "(reify + + "(reify om/IRender (render [this] (let [indent-test :fail] @@ -381,8 +414,8 @@ values of customisable variables." (let [indent-test :fail] ...)))") -(def-full-indent-test proxy - "(proxy [Writer] [] + (when-indenting-it "proxy" + "(proxy [Writer] [] (close [] (.flush ^Writer this)) (write ([x] @@ -395,40 +428,42 @@ values of customisable variables." (with-out-binding [out messages] (.flush out))))") -(def-full-indent-test reader-conditionals - "#?@ (:clj [] + (when-indenting-it "should handle reader conditionals" + "#?@ (:clj [] :cljs [])") -(def-full-indent-test empty-close-paren - "(let [x] + (when-indenting-it "should handle an empty close paren" + "(let [x] )" - "(ns ok + "(ns ok )" - "(ns ^{:zen :dikar} + "(ns ^{:zen :dikar} ok )") -(def-full-indent-test unfinished-sexps - "(letfn [(tw [x] + (when-indenting-it "should handle unfinished sexps" + "(letfn [(tw [x] dd") -(def-full-indent-test symbols-ending-in-crap - "(msg? ExceptionInfo + (when-indenting-it "should handle symbols ending in crap" + "(msg? ExceptionInfo 10)" - "(thrown-with-msg? ExceptionInfo + + "(thrown-with-msg? ExceptionInfo #\"Storage must be initialized before use\" (f))" - "(msg' 1 + + "(msg' 1 10)") -(def-full-indent-test let-when-while-forms - "(let-alist [x 1]\n ())" - "(while-alist [x 1]\n ())" - "(when-alist [x 1]\n ())" - "(if-alist [x 1]\n ())" - "(indents-like-fn-when-let-while-if-are-not-the-start [x 1]\n ())") + (when-indenting-it "should handle let, when and while forms" + "(let-alist [x 1]\n ())" + "(while-alist [x 1]\n ())" + "(when-alist [x 1]\n ())" + "(if-alist [x 1]\n ())" + "(indents-like-fn-when-let-while-if-are-not-the-start [x 1]\n ())") (defun indent-cond (indent-point state) (goto-char (elt state 1)) @@ -453,101 +488,86 @@ values of customisable variables." (defun indent-cond-0 (_indent-point _state) 0) (put-clojure-indent 'test-cond-0 #'indent-cond-0) -(def-full-indent-test function-spec - "(when me + + (when-indenting-it "should handle function spec" + "(when me (test-cond x 1 2 3))" - "(when me + + "(when me (test-cond-0 x 1 2 3))") -(def-full-indent-test align-arguments - 'align-arguments - "(some-function + (when-indenting-it "should respect indent style 'align-arguments" + 'align-arguments + + "(some-function 10 1 2)" - "(some-function 10 + + "(some-function 10 1 2)") -(def-full-indent-test always-indent - 'always-indent - "(some-function + (when-indenting-it "should respect indent style 'always-indent" + 'always-indent + + "(some-function 10 1 2)" - "(some-function 10 + + "(some-function 10 1 2)") -;;; Alignment -(defmacro def-full-align-test (name &rest forms) - "Verify that all FORMs correspond to a properly indented sexps." - (declare (indent defun)) - `(ert-deftest ,(intern (format "test-align-%s" name)) () - (let ((clojure-align-forms-automatically t) - (clojure-align-reader-conditionals t)) - ,@(mapcar (lambda (form) - `(with-temp-buffer - (clojure-mode) - (insert "\n" ,(replace-regexp-in-string " +" " " form)) - (indent-region (point-min) (point-max)) - (should (equal (buffer-substring-no-properties (point-min) (point-max)) - ,(concat "\n" form))))) - forms)) - (let ((clojure-align-forms-automatically nil)) - ,@(mapcar (lambda (form) - `(with-temp-buffer - (clojure-mode) - (insert "\n" ,(replace-regexp-in-string " +" " " form)) - ;; This is to check that we did NOT align anything. Run - ;; `indent-region' and then check that no extra spaces - ;; where inserted besides the start of the line. - (indent-region (point-min) (point-max)) - (goto-char (point-min)) - (should-not (search-forward-regexp "\\([^\s\n]\\) +" nil 'noerror)))) - forms)))) - -(def-full-align-test basic - "{:this-is-a-form b + (when-aligning-it "should basic forms" + "{:this-is-a-form b c d}" - "{:this-is b + + "{:this-is b c d}" - "{:this b + + "{:this b c d}" - "{:a b + + "{:a b c d}" - "(let [this-is-a-form b + "(let [this-is-a-form b c d])" - "(let [this-is b + + "(let [this-is b c d])" - "(let [this b + + "(let [this b c d])" - "(let [a b + + "(let [a b c d])") -(def-full-align-test blank-line - "(let [this-is-a-form b + (when-aligning-it "should handle a blank line" + "(let [this-is-a-form b c d another form k g])" - "{:this-is-a-form b + + "{:this-is-a-form b c d :another form k g}") -(def-full-align-test basic-reversed - "{c d + (when-aligning-it "should handle basic forms (reversed)" + "{c d :this-is-a-form b}" "{c d :this-is b}" @@ -558,80 +578,87 @@ x "(let [c d this-is-a-form b])" + "(let [c d this-is b])" + "(let [c d this b])" + "(let [c d a b])") -(def-full-align-test incomplete-sexp - "(cond aa b + (when-aligning-it "should handle incomplete sexps" + "(cond aa b casodkas )" - "(cond aa b + + "(cond aa b casodkas)" - "(cond aa b + + "(cond aa b casodkas " - "(cond aa b + + "(cond aa b casodkas" - "(cond aa b + + "(cond aa b casodkas a)" - "(cond casodkas a + + "(cond casodkas a aa b)" - "(cond casodkas + + "(cond casodkas aa b)") -(def-full-align-test multiple-words - "(cond this is just + + (when-aligning-it "should handle multiple words" + "(cond this is just a test of how well multiple words will work)") -(def-full-align-test nested-maps - "{:a {:a :a + (when-aligning-it "should handle nested maps" + "{:a {:a :a :bbbb :b} :bbbb :b}") -(def-full-align-test end-is-a-marker - "{:a {:a :a + (when-aligning-it "should regard end as a marker" + "{:a {:a :a :aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa :a} :b {:a :a :aa :a}}") -(def-full-align-test trailing-commas - "{:a {:a :a, + (when-aligning-it "should handle trailing commas" + "{:a {:a :a, :aa :a}, :b {:a :a, :aa :a}}") -(def-full-align-test reader-conditional - "#?(:clj 2 + (when-aligning-it "should handle standard reader conditionals" + "#?(:clj 2 :cljs 2)") -(def-full-align-test reader-conditional-splicing - "#?@(:clj [2] + (when-aligning-it "should handle splicing reader conditional" + "#?@(:clj [2] :cljs [2])") -(ert-deftest reader-conditional-alignment-disabled-by-default () - (let ((content "#?(:clj 2\n :cljs 2)")) - (with-temp-buffer - (clojure-mode) - (insert content) - (call-interactively #'clojure-align) - (should (string= (buffer-string) content))) - (with-temp-buffer - (clojure-mode) - (setq-local clojure-align-reader-conditionals t) - (insert content) + (it "should not align reader conditionals by default" + (let ((content "#?(:clj 2\n :cljs 2)")) + (with-clojure-buffer content + (call-interactively #'clojure-align) + (expect (buffer-string) :to-equal content)))) + + (it "should align reader conditionals when clojure-align-reader-conditionals is true" + (let ((content "#?(:clj 2\n :cljs 2)")) + (with-clojure-buffer content + (setq-local clojure-align-reader-conditionals t) + (call-interactively #'clojure-align) + (expect (buffer-string) :not :to-equal content)))) + + (it "should remove extra commas" + (with-clojure-buffer "{:a 2, ,:c 4}" (call-interactively #'clojure-align) - (should-not (string= (buffer-string) content))))) - -(ert-deftest clojure-align-remove-extra-commas () - (with-temp-buffer - (clojure-mode) - (insert "{:a 2, ,:c 4}") - (call-interactively #'clojure-align) - (should (string= (buffer-string) "{:a 2, :c 4}")))) + (expect (string= (buffer-string) "{:a 2, :c 4}"))))) (provide 'clojure-mode-indentation-test) diff --git a/clojure-mode-refactor-let-test.el b/clojure-mode-refactor-let-test.el index 8aec3d2..e36654a 100644 --- a/clojure-mode-refactor-let-test.el +++ b/clojure-mode-refactor-let-test.el @@ -25,65 +25,76 @@ ;;; Code: (require 'clojure-mode) -(require 'ert) +(require 'test-helper) +(require 'buttercup) -(def-refactor-test test-introduce-let - "{:status 200 +(describe "clojure--introduce-let-internal" + (when-refactoring-it "should introduce a let form" + "{:status 200 :body (find-body abc)}" - "{:status 200 + + "{:status 200 :body (let [body (find-body abc)] body)}" - (search-backward "(find-body") - (clojure--introduce-let-internal "body")) -(def-refactor-test test-introduce-expanded-let - "(defn handle-request [] + (search-backward "(find-body") + (clojure--introduce-let-internal "body")) + + (when-refactoring-it "should introduce an expanded let form" + "(defn handle-request [] {:status 200 :length (count (find-body abc)) :body (find-body abc)})" - "(defn handle-request [] + + "(defn handle-request [] (let [body (find-body abc)] {:status 200 :length (count body) :body body}))" - (search-backward "(find-body") - (clojure--introduce-let-internal "body" 1)) -(def-refactor-test test-let-replace-bindings-whitespace - "(defn handle-request [] + (search-backward "(find-body") + (clojure--introduce-let-internal "body" 1)) + + (when-refactoring-it "should replace bindings whitespace" + "(defn handle-request [] {:status 200 :length (count (find-body abc)) :body (find-body abc)})" - "(defn handle-request [] + + "(defn handle-request [] (let [body (find-body abc)] {:status 200 :length (count body) :body body}))" - (search-backward "(find-body") - (clojure--introduce-let-internal "body" 1)) + (search-backward "(find-body") + (clojure--introduce-let-internal "body" 1))) -(def-refactor-test test-let-forward-slurp-sexp - "(defn handle-request [] +(describe "clojure-let-forward-slurp-sexp" + (when-refactoring-it "should slurp the next 2 sexps after the let into the let form" + "(defn handle-request [] (let [body (find-body abc)] {:status 200 :length (count body) :body body}) (println (find-body abc)) (println \"foobar\"))" - "(defn handle-request [] + + "(defn handle-request [] (let [body (find-body abc)] {:status 200 :length (count body) :body body} (println body) (println \"foobar\")))" - (search-backward "(count body") - (clojure-let-forward-slurp-sexp 2)) -(def-refactor-test test-let-backward-slurp-sexp + (search-backward "(count body") + (clojure-let-forward-slurp-sexp 2))) + +(describe "clojure-let-backward-slurp-sexp" + (when-refactoring-it "should slurp the previous 2 sexps before the let into the let form" "(defn handle-request [] (println (find-body abc)) (println \"foobar\") @@ -91,137 +102,158 @@ {:status 200 :length (count body) :body body}))" - "(defn handle-request [] + + "(defn handle-request [] (let [body (find-body abc)] (println body) (println \"foobar\") {:status 200 :length (count body) :body body}))" - (search-backward "(count body") - (clojure-let-backward-slurp-sexp 2)) -(def-refactor-test test-move-sexp-to-let - "(defn handle-request + (search-backward "(count body") + (clojure-let-backward-slurp-sexp 2))) + +(describe "clojure--move-to-let-internal" + (when-refactoring-it "should move sexp to let" + "(defn handle-request (let [body (find-body abc)] {:status (or status 500) :body body}))" - "(defn handle-request + + "(defn handle-request (let [body (find-body abc) status (or status 500)] {:status status :body body}))" - (search-backward "(or ") - (clojure--move-to-let-internal "status")) -(def-refactor-test test-move-constant-to-when-let - "(defn handle-request + (search-backward "(or ") + (clojure--move-to-let-internal "status")) + + (when-refactoring-it "should move constant to when let" + "(defn handle-request (when-let [body (find-body abc)] {:status 42 :body body}))" - "(defn handle-request + + "(defn handle-request (when-let [body (find-body abc) status 42] {:status status :body body}))" - (search-backward "42") - (clojure--move-to-let-internal "status")) -(def-refactor-test test-move-to-empty-let - "(defn handle-request + (search-backward "42") + (clojure--move-to-let-internal "status")) + + (when-refactoring-it "should move sexp to empty let" + "(defn handle-request (if-let [] {:status (or status 500) :body body}))" - "(defn handle-request + + "(defn handle-request (if-let [status (or status 500)] {:status status :body body}))" - (search-backward "(or ") - (clojure--move-to-let-internal "status")) -(def-refactor-test test-introduce-let-at-move-to-let-if-missing - "(defn handle-request + (search-backward "(or ") + (clojure--move-to-let-internal "status")) + + (when-refactoring-it "should introduce let if missing" + "(defn handle-request {:status (or status 500) :body body})" - "(defn handle-request + + "(defn handle-request {:status (let [status (or status 500)] status) :body body})" - (search-backward "(or ") - (clojure--move-to-let-internal "status")) -(def-refactor-test test-move-to-let-multiple-occurrences - "(defn handle-request + (search-backward "(or ") + (clojure--move-to-let-internal "status")) + + (when-refactoring-it "should move multiple occurrences of a sexp" + "(defn handle-request (let [] (println \"body: \" body \", params: \" \", status: \" (or status 500)) {:status (or status 500) :body body}))" - "(defn handle-request + + "(defn handle-request (let [status (or status 500)] (println \"body: \" body \", params: \" \", status: \" status) {:status status :body body}))" - (search-backward "(or ") - (clojure--move-to-let-internal "status")) -(def-refactor-test test-move-to-let-name-longer-than-expression - "(defn handle-request + (search-backward "(or ") + (clojure--move-to-let-internal "status")) + + (when-refactoring-it "should handle a name that is longer than the expression" + "(defn handle-request (let [] (println \"body: \" body \", params: \" \", status: \" 5) {:body body :status 5}))" - "(defn handle-request + + "(defn handle-request (let [status 5] (println \"body: \" body \", params: \" \", status: \" status) {:body body :status status}))" - (search-backward "5") - (search-backward "5") - (clojure--move-to-let-internal "status")) -;; clojure-emacs/clj-refactor.el#41 -(def-refactor-test test-move-to-let-nested-scope - "(defn foo [] + (search-backward "5") + (search-backward "5") + (clojure--move-to-let-internal "status")) + + ;; clojure-emacs/clj-refactor.el#41 + (when-refactoring-it "should not move to nested let" + "(defn foo [] (let [x (range 10)] (doseq [x (range 10)] (let [x2 (* x x)])) (+ 1 1)))" - "(defn foo [] + + "(defn foo [] (let [x (range 10) something (+ 1 1)] (doseq [x x] (let [x2 (* x x)])) something))" - (search-backward "(+ 1 1") - (clojure--move-to-let-internal "something")) -;; clojure-emacs/clj-refactor.el#30 -(def-refactor-test test-move-to-let-already-inside-let-binding-1 - "(deftest retrieve-order-body-test + (search-backward "(+ 1 1") + (clojure--move-to-let-internal "something")) + + ;; clojure-emacs/clj-refactor.el#30 + (when-refactoring-it "should move before current form when already inside let binding-1" + "(deftest retrieve-order-body-test (let [item (get-in (retrieve-order-body order-item-response-str))]))" - "(deftest retrieve-order-body-test + + "(deftest retrieve-order-body-test (let [something (retrieve-order-body order-item-response-str) item (get-in something)]))" - (search-backward "(retrieve") - (clojure--move-to-let-internal "something")) -;; clojure-emacs/clj-refactor.el#30 -(def-refactor-test test-move-to-let-already-inside-let-binding-2 - "(let [parent (.getParent (io/file root adrf)) + (search-backward "(retrieve") + (clojure--move-to-let-internal "something")) + + ;; clojure-emacs/clj-refactor.el#30 + (when-refactoring-it "should move before current form when already inside let binding-2" + "(let [parent (.getParent (io/file root adrf)) builder (string-builder) normalize-path (comp (partial path/relative-to root) path/->normalized foobar)] (do-something-spectacular parent builder))" - "(let [parent (.getParent (io/file root adrf)) + + "(let [parent (.getParent (io/file root adrf)) builder (string-builder) something (partial path/relative-to root) normalize-path (comp something path/->normalized foobar)] (do-something-spectacular parent builder))" - (search-backward "(partial") - (clojure--move-to-let-internal "something")) + + (search-backward "(partial") + (clojure--move-to-let-internal "something"))) (provide 'clojure-mode-refactor-let-test) diff --git a/clojure-mode-refactor-rename-ns-alias-test.el b/clojure-mode-refactor-rename-ns-alias-test.el index 8e7f8d8..a2875b4 100644 --- a/clojure-mode-refactor-rename-ns-alias-test.el +++ b/clojure-mode-refactor-rename-ns-alias-test.el @@ -18,37 +18,44 @@ ;;; Code: (require 'clojure-mode) +(require 'test-helper) (require 'ert) -(def-refactor-test test-rename-ns-alias - "(ns cljr.core +(describe "clojure--rename-ns-alias-internal" + + (when-refactoring-it "should rename an alias" + "(ns cljr.core (:require [my.lib :as lib])) (def m #::lib{:kw 1, :n/kw 2, :_/bare 3, 0 4}) (+ (lib/a 1) (b 2))" - "(ns cljr.core + + "(ns cljr.core (:require [my.lib :as foo])) (def m #::foo{:kw 1, :n/kw 2, :_/bare 3, 0 4}) (+ (foo/a 1) (b 2))" - (clojure--rename-ns-alias-internal "lib" "foo")) -(def-refactor-test test-rename-ns-alias-with-missing-as - "(ns cljr.core + (clojure--rename-ns-alias-internal "lib" "foo")) + + (when-refactoring-it "should handle ns declarations with missing as" + "(ns cljr.core (:require [my.lib :as lib])) (def m #::lib{:kw 1, :n/kw 2, :_/bare 3, 0 4}) (+ (lib/a 1) (b 2))" - "(ns cljr.core + + "(ns cljr.core (:require [my.lib :as lib])) (def m #::lib{:kw 1, :n/kw 2, :_/bare 3, 0 4}) (+ (lib/a 1) (b 2))" - (clojure--rename-ns-alias-internal "foo" "bar")) + + (clojure--rename-ns-alias-internal "foo" "bar"))) (provide 'clojure-mode-refactor-rename-ns-alias-test) diff --git a/clojure-mode-refactor-threading-test.el b/clojure-mode-refactor-threading-test.el index 95e675b..5e4b482 100644 --- a/clojure-mode-refactor-threading-test.el +++ b/clojure-mode-refactor-threading-test.el @@ -26,329 +26,411 @@ ;;; Code: (require 'clojure-mode) -(require 'ert) +(require 'test-helper) +(require 'buttercup) -;; thread first +(describe "clojure-thread" -(def-refactor-test test-thread-first-one-step + (when-refactoring-it "should work with -> when performed once" "(-> (dissoc (assoc {} :key \"value\") :lock))" + "(-> (assoc {} :key \"value\") (dissoc :lock))" - (clojure-thread)) -(def-refactor-test test-thread-first-two-steps + (clojure-thread)) + + (when-refactoring-it "should work with -> when performed twice" "(-> (dissoc (assoc {} :key \"value\") :lock))" + "(-> {} (assoc :key \"value\") (dissoc :lock))" - (clojure-thread) - (clojure-thread)) -(def-refactor-test test-thread-first-dont-thread-maps + (clojure-thread) + (clojure-thread)) + + (when-refactoring-it "should not thread maps" "(-> (dissoc (assoc {} :key \"value\") :lock))" + "(-> {} (assoc :key \"value\") (dissoc :lock))" - (clojure-thread) - (clojure-thread) - (clojure-thread)) -(def-refactor-test test-thread-first-dont-thread-last-one + (clojure-thread) + (clojure-thread) + (clojure-thread)) + + (when-refactoring-it "should not thread last sexp" "(-> (dissoc (assoc (get-a-map) :key \"value\") :lock))" + "(-> (get-a-map) (assoc :key \"value\") (dissoc :lock))" - (clojure-thread) - (clojure-thread) - (clojure-thread)) -(def-refactor-test test-thread-first-easy-on-whitespace + (clojure-thread) + (clojure-thread) + (clojure-thread)) + + (when-refactoring-it "should thread-first-easy-on-whitespace" "(-> (dissoc (assoc {} :key \"value\") :lock))" + "(-> (assoc {} :key \"value\") (dissoc :lock))" - (clojure-thread)) -(def-refactor-test test-thread-first-remove-superfluous-parens + (clojure-thread)) + + (when-refactoring-it "should remove superfluous parens" "(-> (square (sum [1 2 3 4 5])))" + "(-> [1 2 3 4 5] sum square)" - (clojure-thread) - (clojure-thread)) -(def-refactor-test test-thread-first-cursor-before-threading + (clojure-thread) + (clojure-thread)) + + (when-refactoring-it "should work with cursor before ->" "(-> (not (s-acc/mobile? session)))" + "(-> (s-acc/mobile? session) not)" - (beginning-of-buffer) - (clojure-thread)) -;; unwind thread first -(def-refactor-test test-thread-unwind-first-one-step - "(-> {} - (assoc :key \"value\") - (dissoc :lock))" - "(-> (assoc {} :key \"value\") - (dissoc :lock))" - (clojure-unwind)) + (beginning-of-buffer) + (clojure-thread)) -(def-refactor-test test-thread-unwind-first-two-steps - "(-> {} - (assoc :key \"value\") - (dissoc :lock))" - "(-> (dissoc (assoc {} :key \"value\") :lock))" - (clojure-unwind) - (clojure-unwind)) - -(def-refactor-test test-thread-first-jump-out-of-threading - "(-> {} - (assoc :key \"value\") - (dissoc :lock))" - "(dissoc (assoc {} :key \"value\") :lock)" - (clojure-unwind) - (clojure-unwind) - (clojure-unwind)) - -;; thread last -(def-refactor-test test-thread-last-one-step + (when-refactoring-it "should work with one step with ->>" "(->> (map square (filter even? [1 2 3 4 5])))" + "(->> (filter even? [1 2 3 4 5]) (map square))" - (clojure-thread)) -(def-refactor-test test-thread-last-two-steps + (clojure-thread)) + + (when-refactoring-it "should work with two steps with ->>" "(->> (map square (filter even? [1 2 3 4 5])))" + "(->> [1 2 3 4 5] (filter even?) (map square))" - (clojure-thread) - (clojure-thread)) -(def-refactor-test test-thread-last-dont-thread-vectors + (clojure-thread) + (clojure-thread)) + + (when-refactoring-it "should not thread vectors with ->>" "(->> (map square (filter even? [1 2 3 4 5])))" + "(->> [1 2 3 4 5] (filter even?) (map square))" - (clojure-thread) - (clojure-thread) - (clojure-thread)) -(def-refactor-test test-thread-last-dont-thread-last-one + (clojure-thread) + (clojure-thread) + (clojure-thread)) + + (when-refactoring-it "should not thread last sexp with ->>" "(->> (map square (filter even? (get-a-list))))" + "(->> (get-a-list) (filter even?) (map square))" - (clojure-thread) - (clojure-thread) - (clojure-thread)) -;; unwind thread last -(def-refactor-test test-thread-last-one-step + (clojure-thread) + (clojure-thread) + (clojure-thread)) + + (when-refactoring-it "should work with some->" + "(some-> (+ (val (find {:a 1} :b)) 5))" + + "(some-> {:a 1} + (find :b) + val + (+ 5))" + + (clojure-thread) + (clojure-thread) + (clojure-thread)) + + (when-refactoring-it "should work with some->>" + "(some->> (+ 5 (val (find {:a 1} :b))))" + + "(some->> :b + (find {:a 1}) + val + (+ 5))" + + (clojure-thread) + (clojure-thread) + (clojure-thread))) + +(describe "clojure-unwind" + + (when-refactoring-it "should unwind -> one step" + "(-> {} + (assoc :key \"value\") + (dissoc :lock))" + + "(-> (assoc {} :key \"value\") + (dissoc :lock))" + + (clojure-unwind)) + + (when-refactoring-it "should unwind -> two steps" + "(-> {} + (assoc :key \"value\") + (dissoc :lock))" + + "(-> (dissoc (assoc {} :key \"value\") :lock))" + + (clojure-unwind) + (clojure-unwind)) + + (when-refactoring-it "should unwind -> completely" + "(-> {} + (assoc :key \"value\") + (dissoc :lock))" + + "(dissoc (assoc {} :key \"value\") :lock)" + + (clojure-unwind) + (clojure-unwind) + (clojure-unwind)) + + (when-refactoring-it "should unwind ->> one step" "(->> [1 2 3 4 5] (filter even?) (map square))" + "(->> (filter even? [1 2 3 4 5]) (map square))" - (clojure-unwind)) -(def-refactor-test test-thread-last-two-steps + (clojure-unwind)) + + (when-refactoring-it "should unwind ->> two steps" "(->> [1 2 3 4 5] (filter even?) (map square))" + "(->> (map square (filter even? [1 2 3 4 5])))" - (clojure-unwind) - (clojure-unwind)) -(def-refactor-test test-thread-last-jump-out-of-threading + (clojure-unwind) + (clojure-unwind)) + + (when-refactoring-it "should unwind ->> completely" "(->> [1 2 3 4 5] (filter even?) (map square))" + "(map square (filter even? [1 2 3 4 5]))" - (clojure-unwind) - (clojure-unwind) - (clojure-unwind)) -(def-refactor-test test-thread-function-name + (clojure-unwind) + (clojure-unwind) + (clojure-unwind)) + + (when-refactoring-it "should unwind with function name" "(->> [1 2 3 4 5] sum square)" + "(->> (sum [1 2 3 4 5]) square)" - (clojure-unwind)) -(def-refactor-test test-thread-function-name-twice + (clojure-unwind)) + + (when-refactoring-it "should unwind with function name twice" "(-> [1 2 3 4 5] sum square)" + "(-> (square (sum [1 2 3 4 5])))" - (clojure-unwind) - (clojure-unwind)) -(def-refactor-test test-thread-issue-6-1 + (clojure-unwind) + (clojure-unwind)) + + (when-refactoring-it "should thread-issue-6-1" "(defn plus [a b] (-> a (+ b)))" + "(defn plus [a b] (-> (+ a b)))" - (clojure-unwind)) -(def-refactor-test test-thread-issue-6-2 + (clojure-unwind)) + + (when-refactoring-it "should thread-issue-6-2" "(defn plus [a b] (->> a (+ b)))" + "(defn plus [a b] (->> (+ b a)))" - (clojure-unwind)) -(def-refactor-test test-thread-first-some - "(some-> (+ (val (find {:a 1} :b)) 5))" - "(some-> {:a 1} - (find :b) - val - (+ 5))" - (clojure-thread) - (clojure-thread) - (clojure-thread)) + (clojure-unwind)) -(def-refactor-test test-thread-last-some - "(some->> (+ 5 (val (find {:a 1} :b))))" - "(some->> :b - (find {:a 1}) - val - (+ 5))" - (clojure-thread) - (clojure-thread) - (clojure-thread)) - -(def-refactor-test test-thread-last-first-some + (when-refactoring-it "should unwind some->" "(some-> {:a 1} (find :b) val (+ 5))" + "(some-> (+ (val (find {:a 1} :b)) 5))" - (clojure-unwind) - (clojure-unwind) - (clojure-unwind)) -(def-refactor-test test-thread-thread-last-some + (clojure-unwind) + (clojure-unwind) + (clojure-unwind)) + + (when-refactoring-it "should unwind some->>" "(some->> :b (find {:a 1}) val (+ 5))" + "(some->> (+ 5 (val (find {:a 1} :b))))" - (clojure-unwind) - (clojure-unwind) - (clojure-unwind)) -(def-refactor-test test-thread-first-all + (clojure-unwind) + (clojure-unwind) + (clojure-unwind))) + +(describe "clojure-thread-first-all" + + (when-refactoring-it "should thread first all sexps" "(->map (assoc {} :key \"value\") :lock)" + "(-> {} (assoc :key \"value\") (->map :lock))" - (beginning-of-buffer) - (clojure-thread-first-all nil)) -(def-refactor-test test-thread-first-all-but-last + (beginning-of-buffer) + (clojure-thread-first-all nil)) + + (when-refactoring-it "should thread a form except the last expression" "(->map (assoc {} :key \"value\") :lock)" + "(-> (assoc {} :key \"value\") (->map :lock))" - (beginning-of-buffer) - (clojure-thread-first-all t)) -(def-refactor-test test-thread-last-all + (beginning-of-buffer) + (clojure-thread-first-all t))) + +(describe "clojure-thread-last-all" + + (when-refactoring-it "should fully thread a form" "(map square (filter even? (make-things)))" + "(->> (make-things) (filter even?) (map square))" - (beginning-of-buffer) - (clojure-thread-last-all nil)) -(def-refactor-test test-thread-last-all-but-last + (beginning-of-buffer) + (clojure-thread-last-all nil)) + + (when-refactoring-it "should thread a form except the last expression" "(map square (filter even? (make-things)))" + "(->> (filter even? (make-things)) (map square))" - (beginning-of-buffer) - (clojure-thread-last-all t)) -(def-refactor-test test-thread-all-thread-first - "(-> {} - (assoc :key \"value\") - (dissoc :lock))" - "(dissoc (assoc {} :key \"value\") :lock)" - (beginning-of-buffer) - (clojure-unwind-all)) - -(def-refactor-test test-thread-all-thread-last - "(->> (make-things) - (filter even?) - (map square))" - "(map square (filter even? (make-things)))" - (beginning-of-buffer) - (clojure-unwind-all)) + (beginning-of-buffer) + (clojure-thread-last-all t)) -(def-refactor-test test-thread-last-dangling-parens + (when-refactoring-it "should handle dangling parens 1" "(map inc - (range))" + (range))" + "(->> (range) (map inc))" - (beginning-of-buffer) - (clojure-thread-last-all nil)) -(def-refactor-test test-thread-last-dangling-parens-2 + (beginning-of-buffer) + (clojure-thread-last-all nil)) + + (when-refactoring-it "should handle dangling parens 2" "(deftask dev [] (comp (serve) - (cljs)))" + (cljs)))" + "(->> (cljs) (comp (serve)) (deftask dev []))" - (beginning-of-buffer) - (clojure-thread-last-all nil)) -;; fix for clojure-emacs/clj-refactor.el#259 -(def-refactor-test test-thread-last-leaves-multiline-sexp-alone + (beginning-of-buffer) + (clojure-thread-last-all nil))) + +(describe "clojure-unwind-all" + + (when-refactoring-it "should unwind all in ->" + "(-> {} + (assoc :key \"value\") + (dissoc :lock))" + + "(dissoc (assoc {} :key \"value\") :lock)" + + (beginning-of-buffer) + (clojure-unwind-all)) + + (when-refactoring-it "should unwind all in ->>" + "(->> (make-things) + (filter even?) + (map square))" + + "(map square (filter even? (make-things)))" + + (beginning-of-buffer) + (clojure-unwind-all)) + + ;; fix for clojure-emacs/clj-refactor.el#259 + (when-refactoring-it "should leave multiline sexp alone" "(->> [a b] (some (fn [x] (when x 10))))" + "(some (fn [x] (when x 10)) [a b])" - (clojure-unwind-all)) -(def-refactor-test test-thread-last-maybe-unjoin-lines + (clojure-unwind-all)) + + (when-refactoring-it "should thread-last-maybe-unjoin-lines" "(deftask dev [] (comp (serve) (cljs (lala) 10)))" + "(deftask dev [] (comp (serve) (cljs (lala) 10)))" - (goto-char (point-min)) - (clojure-thread-last-all nil) - (clojure-unwind-all)) -(def-refactor-test test-thread-empty-first-line + (goto-char (point-min)) + (clojure-thread-last-all nil) + (clojure-unwind-all))) + +(describe "clojure-thread-first-all" + + (when-refactoring-it "should thread with an empty first line" "(map - inc - [1 2])" + inc + [1 2])" + "(-> inc (map [1 2]))" - (goto-char (point-min)) - (clojure-thread-first-all nil)) -(def-refactor-test test-thread-first-maybe-unjoin-lines + (goto-char (point-min)) + (clojure-thread-first-all nil)) + + (when-refactoring-it "should thread-first-maybe-unjoin-lines" "(map inc [1 2])" + "(map inc [1 2])" - (goto-char (point-min)) - (clojure-thread-first-all nil) - (clojure-unwind-all)) + + (goto-char (point-min)) + (clojure-thread-first-all nil) + (clojure-unwind-all))) (provide 'clojure-mode-refactor-threading-test) diff --git a/clojure-mode-sexp-test.el b/clojure-mode-sexp-test.el index f8a97e3..5574588 100644 --- a/clojure-mode-sexp-test.el +++ b/clojure-mode-sexp-test.el @@ -20,44 +20,47 @@ ;;; Code: (require 'clojure-mode) -(require 'ert) +(require 'test-helper) +(require 'buttercup) -(defmacro clojure-buffer-with-text (text &rest body) - "Run body in a temporary clojure buffer with TEXT. -TEXT is a string with a | indicating where point is. The | will be erased +(defmacro with-clojure-buffer-point (text &rest body) + "Run BODY in a temporary clojure buffer with TEXT. + +TEXT is a string with a | indicating where point is. The | will be erased and point left there." (declare (indent 2)) `(progn - (with-temp-buffer - (erase-buffer) - (clojure-mode) - (insert ,text) + (with-clojure-buffer ,text (goto-char (point-min)) (re-search-forward "|") (delete-char -1) ,@body))) -(ert-deftest test-clojure-top-level-form-p () - (clojure-buffer-with-text - "(comment - (wrong) - (rig|ht) - (wrong))" - ;; make this use the native beginning of defun since this is used to - ;; determine whether to use the comment aware version or not. - (should (let ((beginning-of-defun-function nil)) - (clojure-top-level-form-p "comment"))))) - -(ert-deftest test-clojure-beginning-of-defun-function () - (clojure-buffer-with-text +(describe "clojure-top-level-form-p" + (it "should return true when passed the correct form" + (with-clojure-buffer-point + "(comment + (wrong) + (rig|ht) + (wrong))" + ;; make this use the native beginning of defun since this is used to + ;; determine whether to use the comment aware version or not. + (expect (let ((beginning-of-defun-function nil)) + (clojure-top-level-form-p "comment")))))) + +(describe "clojure-beginning-of-defun-function" + (it "should go to top level form" + (with-clojure-buffer-point "(comment (wrong) (wrong) (rig|ht) (wrong))" (beginning-of-defun) - (should (looking-at-p "(comment"))) - (clojure-buffer-with-text + (expect (looking-at-p "(comment")))) + + (it "should eval top level forms inside comment forms when clojure-toplevel-inside-comment-form set to true" + (with-clojure-buffer-point "(comment (wrong) (wrong) @@ -65,119 +68,112 @@ and point left there." (wrong))" (let ((clojure-toplevel-inside-comment-form t)) (beginning-of-defun)) - (should (looking-at-p "[[:space:]]*(right)"))) - (clojure-buffer-with-text - " + (expect (looking-at-p "[[:space:]]*(right)")))) + + (it "should go to beginning of previous top level form" + (with-clojure-buffer-point + " (formA) | (formB)" - (let ((clojure-toplevel-inside-comment-form t)) - (beginning-of-defun) - (should (looking-at-p "(formA)"))))) + (let ((clojure-toplevel-inside-comment-form t)) + (beginning-of-defun) + (expect (looking-at-p "(formA)"))))) -(ert-deftest test-clojure-end-of-defun-function () - (clojure-buffer-with-text + (it "should move forward to next top level form" + (with-clojure-buffer-point " (first form) | (second form) (third form)" - + (end-of-defun) - (backward-char) - (should (looking-back "(second form)")))) - - -(ert-deftest test-sexp-with-commas () - (with-temp-buffer - (insert "[], {}, :a, 2") - (clojure-mode) - (goto-char (point-min)) - (clojure-forward-logical-sexp 1) - (should (looking-at-p " {}, :a, 2")) - (clojure-forward-logical-sexp 1) - (should (looking-at-p " :a, 2")))) - -(ert-deftest test-sexp () - (with-temp-buffer - (insert "^String #macro ^dynamic reverse") - (clojure-mode) - (clojure-backward-logical-sexp 1) - (should (looking-at-p "\\^String \\#macro \\^dynamic reverse")) - (clojure-forward-logical-sexp 1) - (should (looking-back "\\^String \\#macro \\^dynamic reverse")) - (insert " ^String biverse inverse") - (clojure-backward-logical-sexp 1) - (should (looking-at-p "inverse")) - (clojure-backward-logical-sexp 2) - (should (looking-at-p "\\^String \\#macro \\^dynamic reverse")) - (clojure-forward-logical-sexp 2) - (should (looking-back "\\^String biverse")) - (clojure-backward-logical-sexp 1) - (should (looking-at-p "\\^String biverse")))) - -(ert-deftest test-buffer-corners () - (with-temp-buffer - (insert "^String reverse") - (clojure-mode) - ;; Return nil and don't error - (should-not (clojure-backward-logical-sexp 100)) - (should (looking-at-p "\\^String reverse")) - (should-not (clojure-forward-logical-sexp 100)) - (should (looking-at-p "$"))) - (with-temp-buffer - (clojure-mode) - (insert "(+ 10") - (should-error (clojure-backward-logical-sexp 100)) - (goto-char (point-min)) - (should-error (clojure-forward-logical-sexp 100)) - ;; Just don't hang. - (goto-char (point-max)) - (should-not (clojure-forward-logical-sexp 1)) - (erase-buffer) - (insert "(+ 10") - (newline) - (erase-buffer) - (insert "(+ 10") - (newline-and-indent))) - -(ert-deftest clojure-find-ns-test () - ;; we should not cache the results of `clojure-find-ns' here - (let ((clojure-cache-ns nil)) - (with-temp-buffer - (insert "(ns ^{:doc \"Some docs\"}\nfoo-bar)") - (newline) + (backward-char) + (expect (looking-back "(second form)"))))) + +(describe "clojure-forward-logical-sexp" + (it "should work with commas" + (with-clojure-buffer "[], {}, :a, 2" + (goto-char (point-min)) + (clojure-forward-logical-sexp 1) + (expect (looking-at-p " {}, :a, 2")) + (clojure-forward-logical-sexp 1) + (expect (looking-at-p " :a, 2"))))) + +(describe "clojure-backward-logical-sexp" + (it "should work when used in conjunction with clojure-forward-logical-sexp" + (with-clojure-buffer "^String #macro ^dynamic reverse" + (clojure-backward-logical-sexp 1) + (expect (looking-at-p "\\^String \\#macro \\^dynamic reverse")) + (clojure-forward-logical-sexp 1) + (expect (looking-back "\\^String \\#macro \\^dynamic reverse")) + (insert " ^String biverse inverse") + (clojure-backward-logical-sexp 1) + (expect (looking-at-p "inverse")) + (clojure-backward-logical-sexp 2) + (expect (looking-at-p "\\^String \\#macro \\^dynamic reverse")) + (clojure-forward-logical-sexp 2) + (expect (looking-back "\\^String biverse")) + (clojure-backward-logical-sexp 1) + (expect (looking-at-p "\\^String biverse"))))) + +(describe "clojure-backward-logical-sexp" + (it "should work with buffer corners" + (with-clojure-buffer "^String reverse" + ;; Return nil and don't error + (expect (clojure-backward-logical-sexp 100) :to-be nil) + (expect (looking-at-p "\\^String reverse")) + (expect (clojure-forward-logical-sexp 100) :to-be nil) + (expect (looking-at-p "$"))) + (with-clojure-buffer "(+ 10" + (expect (clojure-backward-logical-sexp 100) :to-throw 'error) + (goto-char (point-min)) + (expect (clojure-forward-logical-sexp 100) :to-throw 'error) + ;; Just don't hang. + (goto-char (point-max)) + (expect (clojure-forward-logical-sexp 1) :to-be nil) + (erase-buffer) + (insert "(+ 10") (newline) - (insert "(in-ns 'baz-quux)") - (clojure-mode) - - ;; From inside docstring of first ns - (goto-char 18) - (should (equal "foo-bar" (clojure-find-ns))) - - ;; From inside first ns's name, on its own line - (goto-char 29) - (should (equal "foo-bar" (clojure-find-ns))) - - ;; From inside second ns's name - (goto-char 42) - (should (equal "baz-quux" (clojure-find-ns)))) - (let ((data - '(("\"\n(ns foo-bar)\"\n" "(in-ns 'baz-quux)" "baz-quux") - (";(ns foo-bar)\n" "(in-ns 'baz-quux)" "baz-quux") - ("(ns foo-bar)\n" "\"\n(in-ns 'baz-quux)\"" "foo-bar") - ("(ns foo-bar)\n" ";(in-ns 'baz-quux)" "foo-bar")))) - (pcase-dolist (`(,form1 ,form2 ,expected) data) - (with-temp-buffer - (insert form1) - (save-excursion (insert form2)) - (clojure-mode) - ;; Between the two namespaces - (should (equal expected (clojure-find-ns))) - ;; After both namespaces - (goto-char (point-max)) - (should (equal expected (clojure-find-ns)))))))) + (erase-buffer) + (insert "(+ 10") + (newline-and-indent)))) + +(describe "clojure-find-ns" + (it "should return the namespace from various locations in the buffer" + ;; we should not cache the results of `clojure-find-ns' here + (let ((clojure-cache-ns nil)) + (with-clojure-buffer "(ns ^{:doc \"Some docs\"}\nfoo-bar)" + (newline) + (newline) + (insert "(in-ns 'baz-quux)") + + ;; From inside docstring of first ns + (goto-char 18) + (expect (clojure-find-ns) :to-equal "foo-bar") + + ;; From inside first ns's name, on its own line + (goto-char 29) + (expect (clojure-find-ns) :to-equal "foo-bar") + + ;; From inside second ns's name + (goto-char 42) + (expect (equal "baz-quux" (clojure-find-ns)))) + (let ((data + '(("\"\n(ns foo-bar)\"\n" "(in-ns 'baz-quux)" "baz-quux") + (";(ns foo-bar)\n" "(in-ns 'baz-quux)" "baz-quux") + ("(ns foo-bar)\n" "\"\n(in-ns 'baz-quux)\"" "foo-bar") + ("(ns foo-bar)\n" ";(in-ns 'baz-quux)" "foo-bar")))) + (pcase-dolist (`(,form1 ,form2 ,expected) data) + (with-clojure-buffer form1 + (save-excursion (insert form2)) + ;; Between the two namespaces + (expect (clojure-find-ns) :to-equal expected) + ;; After both namespaces + (goto-char (point-max)) + (expect (clojure-find-ns) :to-equal expected))))))) (provide 'clojure-mode-sexp-test) diff --git a/clojure-mode-syntax-test.el b/clojure-mode-syntax-test.el index 829dfba..0370f1a 100644 --- a/clojure-mode-syntax-test.el +++ b/clojure-mode-syntax-test.el @@ -24,128 +24,125 @@ ;;; Code: (require 'clojure-mode) -(require 'ert) +(require 'test-helper) +(require 'buttercup) (defun non-func (form-a form-b) - (with-temp-buffer - (clojure-mode) - (insert form-a) + (with-clojure-buffer form-a (save-excursion (insert form-b)) (clojure--not-function-form-p))) -(ert-deftest non-function-form () - (dolist (form '(("#?@ " "(c d)") - ("#?@" "(c d)") - ("#? " "(c d)") - ("#?" "(c d)") - ("" "[asda]") - ("" "{a b}") - ("#" "{a b}") - ("" "(~)"))) - (should (apply #'non-func form))) - (dolist (form '("(c d)" - "(.c d)" - "(:c d)" - "(c/a d)" - "(.c/a d)" - "(:c/a d)" - "(c/a)" - "(:c/a)" - "(.c/a)")) - (should-not (non-func "" form)) - (should-not (non-func "^hint" form)) - (should-not (non-func "#macro" form)) - (should-not (non-func "^hint " form)) - (should-not (non-func "#macro " form)))) - -(ert-deftest clojure-syntax-prefixed-symbols () - (dolist (form '(("#?@aaa" . "aaa") - ("#?aaa" . "?aaa") - ("#aaa" . "aaa") - ("'aaa" . "aaa"))) - (with-temp-buffer - (clojure-mode) - (insert (car form)) - (equal (symbol-name (symbol-at-point)) (cdr form))))) - - -(ert-deftest clojure-syntax-skip-prefixes () - (dolist (form '("#?@aaa" "#?aaa" "#aaa" "'aaa")) - (with-temp-buffer - (clojure-mode) - (insert form) - (backward-word) - (backward-prefix-chars) - (should (bobp))))) - - -(ert-deftest clojure-allowed-collection-tags () - (dolist (tag '("#::ns" "#:ns" "#ns" "#:f.q/ns" "#f.q/ns" "#::")) - (with-temp-buffer - (clojure-mode) - (insert tag) - (should-not (clojure-no-space-after-tag nil ?{)))) - (dolist (tag '("#$:" "#/f" "#:/f" "#::f.q/ns" "::ns" "::" "#f:ns")) - (with-temp-buffer - (clojure-mode) - (insert tag) - (should (clojure-no-space-after-tag nil ?{))))) - - -(def-refactor-test test-paragraph-fill-within-comments - " +(describe "clojure--not-function-form-p" + (it "should handle forms that are not funcions" + (dolist (form '(("#?@ " "(c d)") + ("#?@" "(c d)") + ("#? " "(c d)") + ("#?" "(c d)") + ("" "[asda]") + ("" "{a b}") + ("#" "{a b}") + ("" "(~)"))) + (expect (apply #'non-func form)))) + + (it "should handle forms that are funcions" + (dolist (form '("(c d)" + "(.c d)" + "(:c d)" + "(c/a d)" + "(.c/a d)" + "(:c/a d)" + "(c/a)" + "(:c/a)" + "(.c/a)")) + (expect (non-func "" form) :to-be nil) + (expect (non-func "^hint" form) :to-be nil) + (expect (non-func "#macro" form) :to-be nil) + (expect (non-func "^hint " form) :to-be nil) + (expect (non-func "#macro " form) :to-be nil)))) + +(describe "clojure syntax" + (it "handles prefixed symbols" + (dolist (form '(("#?@aaa" . "aaa") + ("#?aaa" . "?aaa") + ("#aaa" . "aaa") + ("'aaa" . "aaa"))) + (with-clojure-buffer (car form) + (equal (symbol-name (symbol-at-point)) (cdr form))))) + + (it "skips prefixes" + (dolist (form '("#?@aaa" "#?aaa" "#aaa" "'aaa")) + (with-clojure-buffer form + (backward-word) + (backward-prefix-chars) + (expect (bobp)))))) + +(describe "clojure-no-space-after-tag" + (it "should allow allow collection tags" + (dolist (tag '("#::ns" "#:ns" "#ns" "#:f.q/ns" "#f.q/ns" "#::")) + (with-clojure-buffer tag + (expect (clojure-no-space-after-tag nil ?{) :to-be nil))) + (dolist (tag '("#$:" "#/f" "#:/f" "#::f.q/ns" "::ns" "::" "#f:ns")) + (with-clojure-buffer tag + (expect (clojure-no-space-after-tag nil ?{)))))) + +(describe "fill-paragraph" + + (it "should work within comments" + (with-clojure-buffer " ;; Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ;; ut labore et dolore magna aliqua." - " + (goto-char (point-min)) + (let ((fill-column 80)) + (fill-paragraph)) + (expect (buffer-string) :to-equal " ;; Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod -;; tempor incididunt ut labore et dolore magna aliqua." - (goto-char (point-min)) - (let ((fill-column 80)) - (fill-paragraph))) +;; tempor incididunt ut labore et dolore magna aliqua."))) -(def-refactor-test test-paragraph-fill-within-inner-comments - " + (it "should work within inner comments" + (with-clojure-buffer " (let [a 1] ;; Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ;; ut labore et dolore ;; magna aliqua. )" - " + (goto-char (point-min)) + (forward-line 2) + (let ((fill-column 80)) + (fill-paragraph)) + (expect (buffer-string) :to-equal " (let [a 1] ;; Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod ;; tempor incididunt ut labore et dolore magna aliqua. - )" - (goto-char (point-min)) - (forward-line 2) - (let ((fill-column 80)) - (fill-paragraph))) + )"))) (when (fboundp 'font-lock-ensure) - (def-refactor-test test-paragraph-fill-not-altering-surrounding-code - "(def my-example-variable + (it "should not alter surrounding code" + (with-clojure-buffer "(def my-example-variable \"It has a very long docstring. So long, in fact, that it wraps onto multiple lines! This is to demonstrate what happens when the docstring wraps over three lines.\" nil)" - "(def my-example-variable + (font-lock-ensure) + (goto-char 40) + (let ((clojure-docstring-fill-column 80) + (fill-column 80)) + (fill-paragraph)) + (expect (buffer-string) :to-equal "(def my-example-variable \"It has a very long docstring. So long, in fact, that it wraps onto multiple lines! This is to demonstrate what happens when the docstring wraps over three lines.\" - nil)" - (font-lock-ensure) - (goto-char 40) - (let ((clojure-docstring-fill-column 80) - (fill-column 80)) - (fill-paragraph))) - - (ert-deftest test-clojure-in-docstring-p () - (with-temp-buffer - (insert "(def my-example-variable + nil)"))))) + +(when (fboundp 'font-lock-ensure) + (describe "clojure-in-docstring-p" + (it "should handle def with docstring" + (with-clojure-buffer "(def my-example-variable \"Doc here and `doc-here`\" - nil)") - (clojure-mode) - (font-lock-ensure) - (goto-char 32) - (should (clojure-in-docstring-p)) - (goto-char 46) - (should (clojure-in-docstring-p))))) + nil)" + (font-lock-ensure) + (goto-char 32) + (expect (clojure-in-docstring-p)) + (goto-char 46) + (expect (clojure-in-docstring-p)))))) (provide 'clojure-mode-syntax-test) + +;;; clojure-mode-syntax-test.el ends here diff --git a/clojure-mode-util-test.el b/clojure-mode-util-test.el index 3d5e0ac..9dd6516 100644 --- a/clojure-mode-util-test.el +++ b/clojure-mode-util-test.el @@ -23,12 +23,14 @@ ;;; Code: (require 'clojure-mode) +(require 'test-helper) (require 'cl-lib) -(require 'ert) +(require 'buttercup) -(ert-deftest clojure-mode-version-should-be-non-nil () - (should (not (eq clojure-mode-version nil)))) +(describe "clojure-mode-version" + (it "should not be nil" + (expect clojure-mode-version))) (let ((project-dir "/home/user/projects/my-project/") (clj-file-path "/home/user/projects/my-project/src/clj/my_project/my_ns/my_file.clj") @@ -36,52 +38,50 @@ (clj-file-ns "my-project.my-ns.my-file") (clojure-cache-project nil)) - (ert-deftest project-relative-path () - :tags '(utils) + (describe "clojure-project-relative-path" (cl-letf (((symbol-function 'clojure-project-dir) (lambda () project-dir))) - (should (string= (clojure-project-relative-path clj-file-path) + (expect (string= (clojure-project-relative-path clj-file-path) project-relative-clj-file-path)))) - (ert-deftest expected-ns () - :tags '(utils) - (cl-letf (((symbol-function 'clojure-project-relative-path) - (lambda (&optional current-buffer-file-name) - project-relative-clj-file-path))) - (should (string= (clojure-expected-ns clj-file-path) clj-file-ns)))) - - (ert-deftest expected-ns-without-argument () - :tags '(utils) - (cl-letf (((symbol-function 'clojure-project-relative-path) - (lambda (&optional current-buffer-file-name) - project-relative-clj-file-path))) - (should (string= (let ((buffer-file-name clj-file-path)) - (clojure-expected-ns)) - clj-file-ns))))) - -(ert-deftest clojure-namespace-name-regex-test () - :tags '(regexp) - (let ((ns "(ns foo)")) - (should (string-match clojure-namespace-name-regex ns)) - (match-string 4 ns)) - (let ((ns "(ns -foo)")) - (should (string-match clojure-namespace-name-regex ns)) - (should (equal "foo" (match-string 4 ns)))) - (let ((ns "(ns foo.baz)")) - (should (string-match clojure-namespace-name-regex ns)) - (should (equal "foo.baz" (match-string 4 ns)))) - (let ((ns "(ns ^:bar foo)")) - (should (string-match clojure-namespace-name-regex ns)) - (should (equal "foo" (match-string 4 ns)))) - (let ((ns "(ns ^:bar ^:baz foo)")) - (should (string-match clojure-namespace-name-regex ns)) - (should (equal "foo" (match-string 4 ns)))) - (let ((ns "(ns ^{:bar true} foo)")) - (should (string-match clojure-namespace-name-regex ns)) - (should (equal "foo" (match-string 4 ns)))) - (let ((ns "(ns #^{:bar true} foo)")) - (should (string-match clojure-namespace-name-regex ns)) - (should (equal "foo" (match-string 4 ns)))) + (describe "clojure-expected-ns" + (it "should return the namespace matching a path" + (cl-letf (((symbol-function 'clojure-project-relative-path) + (lambda (&optional current-buffer-file-name) + project-relative-clj-file-path))) + (expect (string= (clojure-expected-ns clj-file-path) clj-file-ns)))) + + (it "should return the namespace even without a path" + (cl-letf (((symbol-function 'clojure-project-relative-path) + (lambda (&optional current-buffer-file-name) + project-relative-clj-file-path))) + (expect (string= (let ((buffer-file-name clj-file-path)) + (clojure-expected-ns)) + clj-file-ns)))))) + +(describe "clojure-namespace-name-regex" + (it "should match common namespace declarations" + (let ((ns "(ns foo)")) + (expect (string-match clojure-namespace-name-regex ns)) + (match-string 4 ns)) + (let ((ns "(ns + foo)")) + (expect (string-match clojure-namespace-name-regex ns)) + (expect (match-string 4 ns) :to-equal "foo")) + (let ((ns "(ns foo.baz)")) + (expect (string-match clojure-namespace-name-regex ns)) + (expect (match-string 4 ns) :to-equal "foo.baz")) + (let ((ns "(ns ^:bar foo)")) + (expect (string-match clojure-namespace-name-regex ns)) + (expect (match-string 4 ns) :to-equal "foo")) + (let ((ns "(ns ^:bar ^:baz foo)")) + (expect (string-match clojure-namespace-name-regex ns)) + (expect (match-string 4 ns) :to-equal "foo")) + (let ((ns "(ns ^{:bar true} foo)")) + (expect (string-match clojure-namespace-name-regex ns)) + (expect (match-string 4 ns) :to-equal "foo")) + (let ((ns "(ns #^{:bar true} foo)")) + (expect (string-match clojure-namespace-name-regex ns)) + (expect (match-string 4 ns) :to-equal "foo")) ;; TODO ;; (let ((ns "(ns #^{:fail {}} foo)")) ;; (should (string-match clojure-namespace-name-regex ns)) @@ -89,50 +89,50 @@ foo)")) ;; (let ((ns "(ns ^{:fail2 {}} foo.baz)")) ;; (should (string-match clojure-namespace-name-regex ns)) ;; (should (equal "foo.baz" (match-string 4 ns)))) - (let ((ns "(ns ^{} foo)")) - (should (string-match clojure-namespace-name-regex ns)) - (should (equal "foo" (match-string 4 ns)))) - (let ((ns "(ns ^{:skip-wiki true} - aleph.netty")) - (should (string-match clojure-namespace-name-regex ns)) - (should (equal "aleph.netty" (match-string 4 ns)))) - (let ((ns "(ns foo+)")) - (should (string-match clojure-namespace-name-regex ns)) - (should (equal "foo+" (match-string 4 ns))))) - -(ert-deftest test-sort-ns () - (with-temp-buffer - (insert "\n(ns my-app.core - (:require [my-app.views [front-page :as front-page]] - [my-app.state :refer [state]] ; Comments too. - ;; Some comments. - [rum.core :as rum] - [my-app.views [user-page :as user-page]] - my-app.util.api) - (:import java.io.Writer - [clojure.lang AFunction Atom MultiFn Namespace]))") - (clojure-mode) - (clojure-sort-ns) - (should (equal (buffer-string) - "\n(ns my-app.core - (:require [my-app.state :refer [state]] ; Comments too. - my-app.util.api - [my-app.views [front-page :as front-page]] - [my-app.views [user-page :as user-page]] - ;; Some comments. - [rum.core :as rum]) - (:import [clojure.lang AFunction Atom MultiFn Namespace] - java.io.Writer))"))) - (with-temp-buffer - (insert "(ns my-app.core - (:require [rum.core :as rum] ;comment - [my-app.views [user-page :as user-page]]))") - (clojure-mode) - (clojure-sort-ns) - (should (equal (buffer-string) - "(ns my-app.core - (:require [my-app.views [user-page :as user-page]] - [rum.core :as rum] ;comment\n))")))) + (let ((ns "(ns ^{} foo)")) + (expect (string-match clojure-namespace-name-regex ns)) + (expect (match-string 4 ns) :to-equal "foo")) + (let ((ns "(ns ^{:skip-wiki true} + aleph.netty")) + (expect (string-match clojure-namespace-name-regex ns)) + (expect (match-string 4 ns) :to-equal "aleph.netty")) + (let ((ns "(ns foo+)")) + (expect (string-match clojure-namespace-name-regex ns)) + (expect (match-string 4 ns) :to-equal "foo+")))) + +(describe "clojure-sort-ns" + (it "should sort requires in a basic ns" + (with-clojure-buffer "(ns my-app.core + (:require [rum.core :as rum] ;comment + [my-app.views [user-page :as user-page]]))" + (clojure-sort-ns) + (expect (buffer-string) :to-equal + "(ns my-app.core + (:require [my-app.views [user-page :as user-page]] + [rum.core :as rum] ;comment\n))"))) + + (it "should also sort imports in a ns" + (with-clojure-buffer "\n(ns my-app.core + (:require [my-app.views [front-page :as front-page]] + [my-app.state :refer [state]] ; Comments too. + ;; Some comments. + [rum.core :as rum] + [my-app.views [user-page :as user-page]] + my-app.util.api) + (:import java.io.Writer + [clojure.lang AFunction Atom MultiFn Namespace]))" + (clojure-mode) + (clojure-sort-ns) + (expect (buffer-string) :to-equal + "\n(ns my-app.core + (:require [my-app.state :refer [state]] ; Comments too. + my-app.util.api + [my-app.views [front-page :as front-page]] + [my-app.views [user-page :as user-page]] + ;; Some comments. + [rum.core :as rum]) + (:import [clojure.lang AFunction Atom MultiFn Namespace] + java.io.Writer))")))) (provide 'clojure-mode-util-test) diff --git a/test-helper.el b/test-helper.el index 840cfc9..332560d 100644 --- a/test-helper.el +++ b/test-helper.el @@ -54,4 +54,6 @@ DESCRIPTION is the description of the spec." ,@body (expect (buffer-string) :to-equal ,after)))) +(provide 'test-helper) + ;;; test-helper.el ends here From 4dcf6b712422658e59e2dfaa5e2748eabbca4c12 Mon Sep 17 00:00:00 2001 From: Anthony Galea Date: Tue, 9 Jul 2019 16:33:47 +0200 Subject: [PATCH 139/199] [Fix #511] Fix incorrect indentation of namespaced map (#533) --- clojure-mode-indentation-test.el | 18 ++++++++++++++++++ clojure-mode-sexp-test.el | 10 +++++++++- 2 files changed, 27 insertions(+), 1 deletion(-) diff --git a/clojure-mode-indentation-test.el b/clojure-mode-indentation-test.el index 2ec7e26..5e71877 100644 --- a/clojure-mode-indentation-test.el +++ b/clojure-mode-indentation-test.el @@ -148,6 +148,24 @@ DESCRIPTION is a string with the description of the spec." (cond |x)") + (when-indenting-with-point-it "should indent cond-> with a namespaced map" + " +(cond-> #:a{:b 1} +|x 1)" + + " +(cond-> #:a{:b 1} + |x 1)") + + (when-indenting-with-point-it "should indent cond-> with a namespaced map 2" + " +(cond-> #::a{:b 1} +|x 1)" + + " +(cond-> #::a{:b 1} + |x 1)") + (when-indenting-with-point-it "should indent threading macro with expression on first line" " (->> expr diff --git a/clojure-mode-sexp-test.el b/clojure-mode-sexp-test.el index 5574588..09494dd 100644 --- a/clojure-mode-sexp-test.el +++ b/clojure-mode-sexp-test.el @@ -117,7 +117,15 @@ and point left there." (clojure-forward-logical-sexp 2) (expect (looking-back "\\^String biverse")) (clojure-backward-logical-sexp 1) - (expect (looking-at-p "\\^String biverse"))))) + (expect (looking-at-p "\\^String biverse")))) + + (it "should handle a namespaced map" + (with-clojure-buffer "first #:name/space{:k v}" + (clojure-backward-logical-sexp 1) + (expect (looking-at-p "#:name/space{:k v}")) + (insert " #::ns {:k v}") + (clojure-backward-logical-sexp 1) + (expect (looking-at-p "#::ns {:k v}"))))) (describe "clojure-backward-logical-sexp" (it "should work with buffer corners" From c629593675abf1146acf9624f7c811cc5fd17a94 Mon Sep 17 00:00:00 2001 From: Anthony Galea Date: Wed, 10 Jul 2019 14:39:16 +0200 Subject: [PATCH 140/199] [Fix #531] Don't match strings when using `clojure-rename-ns-alias` (#534) --- clojure-mode-refactor-rename-ns-alias-test.el | 40 ++++++++++++++++++- 1 file changed, 38 insertions(+), 2 deletions(-) diff --git a/clojure-mode-refactor-rename-ns-alias-test.el b/clojure-mode-refactor-rename-ns-alias-test.el index a2875b4..eeb96d5 100644 --- a/clojure-mode-refactor-rename-ns-alias-test.el +++ b/clojure-mode-refactor-rename-ns-alias-test.el @@ -55,8 +55,44 @@ (+ (lib/a 1) (b 2))" - (clojure--rename-ns-alias-internal "foo" "bar"))) + (clojure--rename-ns-alias-internal "foo" "bar")) -(provide 'clojure-mode-refactor-rename-ns-alias-test) + (when-refactoring-it "should skip strings" + "(ns cljr.core + (:require [my.lib :as lib])) + + (def dirname \"/usr/local/lib/python3.6/site-packages\") + + (+ (lib/a 1) (b 2))" + + "(ns cljr.core + (:require [my.lib :as foo])) + + (def dirname \"/usr/local/lib/python3.6/site-packages\") + + (+ (foo/a 1) (b 2))" + + (clojure--rename-ns-alias-internal "lib" "foo")) + + (when-refactoring-it "should not skip comments" + "(ns cljr.core + (:require [my.lib :as lib])) + + (def dirname \"/usr/local/lib/python3.6/site-packages\") + + ;; TODO refactor using lib/foo + (+ (lib/a 1) (b 2))" + + "(ns cljr.core + (:require [my.lib :as new-lib])) + + (def dirname \"/usr/local/lib/python3.6/site-packages\") + + ;; TODO refactor using new-lib/foo + (+ (new-lib/a 1) (b 2))" + + (clojure--rename-ns-alias-internal "lib" "new-lib"))) + + (provide 'clojure-mode-refactor-rename-ns-alias-test) ;;; clojure-mode-refactor-rename-ns-alias-test.el ends here From e203f91ec58212e4f4249da1ec47ea85f17fbb48 Mon Sep 17 00:00:00 2001 From: Anthony Galea Date: Thu, 11 Jul 2019 09:18:22 +0200 Subject: [PATCH 141/199] Remove calls to provide and require for test-helper. The require/provide machinery is intended for things that are to be loaded for the benefit of end-users. Placing test-helper under utils is enough to get buttercup to load it before the tests. --- clojure-mode-convert-collection-test.el | 1 - clojure-mode-cycling-test.el | 1 - clojure-mode-font-lock-test.el | 1 - clojure-mode-indentation-test.el | 1 - clojure-mode-refactor-let-test.el | 1 - clojure-mode-refactor-rename-ns-alias-test.el | 1 - clojure-mode-refactor-threading-test.el | 1 - clojure-mode-sexp-test.el | 1 - clojure-mode-syntax-test.el | 1 - clojure-mode-util-test.el | 1 - test-helper.el => utils/test-helper.el | 2 -- 11 files changed, 12 deletions(-) rename test-helper.el => utils/test-helper.el (98%) diff --git a/clojure-mode-convert-collection-test.el b/clojure-mode-convert-collection-test.el index 545b2ef..220eb9d 100644 --- a/clojure-mode-convert-collection-test.el +++ b/clojure-mode-convert-collection-test.el @@ -26,7 +26,6 @@ ;;; Code: (require 'clojure-mode) -(require 'test-helper) (require 'buttercup) (describe "clojure-convert-collection-to-map" diff --git a/clojure-mode-cycling-test.el b/clojure-mode-cycling-test.el index 40754a9..21688e4 100644 --- a/clojure-mode-cycling-test.el +++ b/clojure-mode-cycling-test.el @@ -25,7 +25,6 @@ ;;; Code: (require 'clojure-mode) -(require 'test-helper) (require 'buttercup) (describe "clojure-cycle-privacy" diff --git a/clojure-mode-font-lock-test.el b/clojure-mode-font-lock-test.el index 10ebd38..0f7a50f 100644 --- a/clojure-mode-font-lock-test.el +++ b/clojure-mode-font-lock-test.el @@ -25,7 +25,6 @@ ;;; Code: (require 'clojure-mode) -(require 'test-helper) (require 'cl-lib) (require 'buttercup) diff --git a/clojure-mode-indentation-test.el b/clojure-mode-indentation-test.el index 5e71877..39ed8a4 100644 --- a/clojure-mode-indentation-test.el +++ b/clojure-mode-indentation-test.el @@ -24,7 +24,6 @@ ;;; Code: (require 'clojure-mode) -(require 'test-helper) (require 'cl-lib) (require 'buttercup) (require 's) diff --git a/clojure-mode-refactor-let-test.el b/clojure-mode-refactor-let-test.el index e36654a..e1dd0bd 100644 --- a/clojure-mode-refactor-let-test.el +++ b/clojure-mode-refactor-let-test.el @@ -25,7 +25,6 @@ ;;; Code: (require 'clojure-mode) -(require 'test-helper) (require 'buttercup) (describe "clojure--introduce-let-internal" diff --git a/clojure-mode-refactor-rename-ns-alias-test.el b/clojure-mode-refactor-rename-ns-alias-test.el index eeb96d5..0bfb546 100644 --- a/clojure-mode-refactor-rename-ns-alias-test.el +++ b/clojure-mode-refactor-rename-ns-alias-test.el @@ -18,7 +18,6 @@ ;;; Code: (require 'clojure-mode) -(require 'test-helper) (require 'ert) (describe "clojure--rename-ns-alias-internal" diff --git a/clojure-mode-refactor-threading-test.el b/clojure-mode-refactor-threading-test.el index 5e4b482..be86eb1 100644 --- a/clojure-mode-refactor-threading-test.el +++ b/clojure-mode-refactor-threading-test.el @@ -26,7 +26,6 @@ ;;; Code: (require 'clojure-mode) -(require 'test-helper) (require 'buttercup) (describe "clojure-thread" diff --git a/clojure-mode-sexp-test.el b/clojure-mode-sexp-test.el index 09494dd..cca4048 100644 --- a/clojure-mode-sexp-test.el +++ b/clojure-mode-sexp-test.el @@ -20,7 +20,6 @@ ;;; Code: (require 'clojure-mode) -(require 'test-helper) (require 'buttercup) (defmacro with-clojure-buffer-point (text &rest body) diff --git a/clojure-mode-syntax-test.el b/clojure-mode-syntax-test.el index 0370f1a..b8503a5 100644 --- a/clojure-mode-syntax-test.el +++ b/clojure-mode-syntax-test.el @@ -24,7 +24,6 @@ ;;; Code: (require 'clojure-mode) -(require 'test-helper) (require 'buttercup) (defun non-func (form-a form-b) diff --git a/clojure-mode-util-test.el b/clojure-mode-util-test.el index 9dd6516..fca0a6c 100644 --- a/clojure-mode-util-test.el +++ b/clojure-mode-util-test.el @@ -23,7 +23,6 @@ ;;; Code: (require 'clojure-mode) -(require 'test-helper) (require 'cl-lib) (require 'buttercup) diff --git a/test-helper.el b/utils/test-helper.el similarity index 98% rename from test-helper.el rename to utils/test-helper.el index 332560d..840cfc9 100644 --- a/test-helper.el +++ b/utils/test-helper.el @@ -54,6 +54,4 @@ DESCRIPTION is the description of the spec." ,@body (expect (buffer-string) :to-equal ,after)))) -(provide 'test-helper) - ;;; test-helper.el ends here From 35bdde40d983a37734fb590466e93f9530178e5e Mon Sep 17 00:00:00 2001 From: Anthony Galea Date: Thu, 11 Jul 2019 10:31:28 +0200 Subject: [PATCH 142/199] [Fix #410] Add refactoring: add an arity to a function. --- clojure-mode-refactor-add-arity-test.el | 156 ++++++++++++++++++ clojure-mode-refactor-rename-ns-alias-test.el | 5 + 2 files changed, 161 insertions(+) create mode 100644 clojure-mode-refactor-add-arity-test.el diff --git a/clojure-mode-refactor-add-arity-test.el b/clojure-mode-refactor-add-arity-test.el new file mode 100644 index 0000000..8bef9af --- /dev/null +++ b/clojure-mode-refactor-add-arity-test.el @@ -0,0 +1,156 @@ +;;; clojure-mode-refactor-add-arity.el --- Clojure Mode: refactor add arity -*- lexical-binding: t; -*- + +;; This file is not part of GNU Emacs. + +;; This program is free software; you can redistribute it and/or modify +;; it under the terms of the GNU General Public License as published by +;; the Free Software Foundation, either version 3 of the License, or +;; (at your option) any later version. + +;; This program is distributed in the hope that it will be useful, +;; but WITHOUT ANY WARRANTY; without even the implied warranty of +;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +;; GNU General Public License for more details. + +;; You should have received a copy of the GNU General Public License +;; along with this program. If not, see . + + +;;; Commentary: + +;; Tests for clojure-add-arity + +;;; Code: + +(require 'clojure-mode) +(require 'buttercup) + +(defmacro when-refactoring-with-point-it (description before after &rest body) + "Return a buttercup spec. + +Like when-refactor-it but also checks whether point is moved to the expected +position. + +BEFORE is the buffer string before refactoring, where a pipe (|) represents +point. + +AFTER is the expected buffer string after refactoring, where a pipe (|) +represents the expected position of point. + +DESCRIPTION is a string with the description of the spec." + `(it ,description + (let* ((after ,after) + (expected-cursor-pos (1+ (s-index-of "|" after))) + (expected-state (delete ?| after))) + (with-clojure-buffer ,before + (goto-char (point-min)) + (search-forward "|") + (delete-char -1) + ,@body + (expect (buffer-string) :to-equal expected-state) + (expect (point) :to-equal expected-cursor-pos))))) + +(describe "clojure-add-arity" + + (when-refactoring-with-point-it "should add an arity to a single-arity defn with args on same line" + "(defn foo [arg] + body|)" + + "(defn foo + ([|]) + ([arg] + body))" + + (clojure-add-arity)) + + (when-refactoring-with-point-it "should add an arity to a single-arity defn with args on next line" + "(defn foo + [arg] + bo|dy)" + + "(defn foo + ([|]) + ([arg] + body))" + + (clojure-add-arity)) + + (when-refactoring-with-point-it "should handle a single-arity defn with a docstring" + "(defn foo + \"some docst|ring\" + [arg] + body)" + + "(defn foo + \"some docstring\" + ([|]) + ([arg] + body))" + + (clojure-add-arity)) + + (when-refactoring-with-point-it "should handle a single-arity defn with metadata" + "(defn fo|o + ^{:bla \"meta\"} + [arg] + body)" + + "(defn foo + ^{:bla \"meta\"} + ([|]) + ([arg] + body))" + + (clojure-add-arity)) + + (when-refactoring-with-point-it "should add an arity to a multi-arity defn" + "(defn foo + ([arg1]) + ([ar|g1 arg2] + body))" + + "(defn foo + ([|]) + ([arg1]) + ([arg1 arg2] + body))" + + (clojure-add-arity)) + + (when-refactoring-with-point-it "should handle a multi-arity defn with a docstring" + "(defn foo + \"some docstring\" + ([]) + ([arg|] + body))" + + "(defn foo + \"some docstring\" + ([|]) + ([]) + ([arg] + body))" + + (clojure-add-arity)) + + (when-refactoring-with-point-it "should handle a multi-arity defn with metadata" + "(defn foo + \"some docstring\" + ^{:bla \"meta\"} + ([]) + |([arg] + body))" + + "(defn foo + \"some docstring\" + ^{:bla \"meta\"} + ([|]) + ([]) + ([arg] + body))" + + (clojure-add-arity))) + +(provide 'clojure-mode-refactor-add-arity-test) + +;;; clojure-mode-refactor-add-arity-test.el ends here diff --git a/clojure-mode-refactor-rename-ns-alias-test.el b/clojure-mode-refactor-rename-ns-alias-test.el index 0bfb546..aba75b3 100644 --- a/clojure-mode-refactor-rename-ns-alias-test.el +++ b/clojure-mode-refactor-rename-ns-alias-test.el @@ -15,6 +15,11 @@ ;; You should have received a copy of the GNU General Public License ;; along with this program. If not, see . + +;;; Commentary: + +;; Tests for clojure-rename-ns-alias + ;;; Code: (require 'clojure-mode) From 756d6941d839efade60945f178ce2aee3c8798f5 Mon Sep 17 00:00:00 2001 From: Bozhidar Batsov Date: Fri, 12 Jul 2019 09:39:30 +0300 Subject: [PATCH 143/199] Bump the copyright years --- clojure-mode-bytecomp-warnings.el | 2 +- clojure-mode-convert-collection-test.el | 2 +- clojure-mode-cycling-test.el | 2 +- clojure-mode-font-lock-test.el | 2 +- clojure-mode-indentation-test.el | 2 +- clojure-mode-refactor-let-test.el | 2 +- clojure-mode-refactor-threading-test.el | 2 +- clojure-mode-sexp-test.el | 2 +- clojure-mode-syntax-test.el | 2 +- clojure-mode-util-test.el | 2 +- utils/test-helper.el | 2 +- 11 files changed, 11 insertions(+), 11 deletions(-) diff --git a/clojure-mode-bytecomp-warnings.el b/clojure-mode-bytecomp-warnings.el index 67c5a03..c6fb344 100644 --- a/clojure-mode-bytecomp-warnings.el +++ b/clojure-mode-bytecomp-warnings.el @@ -1,6 +1,6 @@ ;;; clojure-mode-bytecomp-warnings.el --- Check for byte-compilation problems -;; Copyright © 2012-2018 Bozhidar Batsov and contributors +;; Copyright © 2012-2019 Bozhidar Batsov and contributors ;; ;; This program is free software: you can redistribute it and/or modify ;; it under the terms of the GNU General Public License as published by diff --git a/clojure-mode-convert-collection-test.el b/clojure-mode-convert-collection-test.el index 220eb9d..bf7a644 100644 --- a/clojure-mode-convert-collection-test.el +++ b/clojure-mode-convert-collection-test.el @@ -1,6 +1,6 @@ ;;; clojure-mode-convert-collection-test.el --- Clojure Mode: convert collection type -*- lexical-binding: t; -*- -;; Copyright (C) 2016-2018 Benedek Fazekas +;; Copyright (C) 2016-2019 Benedek Fazekas ;; This file is not part of GNU Emacs. diff --git a/clojure-mode-cycling-test.el b/clojure-mode-cycling-test.el index 21688e4..6acd047 100644 --- a/clojure-mode-cycling-test.el +++ b/clojure-mode-cycling-test.el @@ -1,6 +1,6 @@ ;;; clojure-mode-cycling-test.el --- Clojure Mode: cycling things tests -*- lexical-binding: t; -*- -;; Copyright (C) 2016-2018 Benedek Fazekas +;; Copyright (C) 2016-2019 Benedek Fazekas ;; This file is not part of GNU Emacs. diff --git a/clojure-mode-font-lock-test.el b/clojure-mode-font-lock-test.el index 0f7a50f..715fb2f 100644 --- a/clojure-mode-font-lock-test.el +++ b/clojure-mode-font-lock-test.el @@ -1,7 +1,7 @@ ;;; clojure-mode-font-lock-test.el --- Clojure Mode: Font lock test suite ;; -*- lexical-binding: t; -*- -;; Copyright (C) 2014-2018 Bozhidar Batsov +;; Copyright (C) 2014-2019 Bozhidar Batsov ;; This file is not part of GNU Emacs. diff --git a/clojure-mode-indentation-test.el b/clojure-mode-indentation-test.el index 39ed8a4..006d6f7 100644 --- a/clojure-mode-indentation-test.el +++ b/clojure-mode-indentation-test.el @@ -1,6 +1,6 @@ ;;; clojure-mode-indentation-test.el --- Clojure Mode: indentation tests -*- lexical-binding: t; -*- -;; Copyright (C) 2015-2018 Bozhidar Batsov +;; Copyright (C) 2015-2019 Bozhidar Batsov ;; This file is not part of GNU Emacs. diff --git a/clojure-mode-refactor-let-test.el b/clojure-mode-refactor-let-test.el index e1dd0bd..6b9df13 100644 --- a/clojure-mode-refactor-let-test.el +++ b/clojure-mode-refactor-let-test.el @@ -1,6 +1,6 @@ ;;; clojure-mode-refactor-let-test.el --- Clojure Mode: refactor let -*- lexical-binding: t; -*- -;; Copyright (C) 2016-2018 Benedek Fazekas +;; Copyright (C) 2016-2019 Benedek Fazekas ;; This file is not part of GNU Emacs. diff --git a/clojure-mode-refactor-threading-test.el b/clojure-mode-refactor-threading-test.el index be86eb1..61f4409 100644 --- a/clojure-mode-refactor-threading-test.el +++ b/clojure-mode-refactor-threading-test.el @@ -1,6 +1,6 @@ ;;; clojure-mode-refactor-threading-test.el --- Clojure Mode: refactor threading tests -*- lexical-binding: t; -*- -;; Copyright (C) 2016-2018 Benedek Fazekas +;; Copyright (C) 2016-2019 Benedek Fazekas ;; This file is not part of GNU Emacs. diff --git a/clojure-mode-sexp-test.el b/clojure-mode-sexp-test.el index cca4048..a7d5b85 100644 --- a/clojure-mode-sexp-test.el +++ b/clojure-mode-sexp-test.el @@ -1,6 +1,6 @@ ;;; clojure-mode-sexp-test.el --- Clojure Mode: sexp tests -*- lexical-binding: t; -*- -;; Copyright (C) 2015-2018 Artur Malabarba +;; Copyright (C) 2015-2019 Artur Malabarba ;; This file is not part of GNU Emacs. diff --git a/clojure-mode-syntax-test.el b/clojure-mode-syntax-test.el index b8503a5..60286d4 100644 --- a/clojure-mode-syntax-test.el +++ b/clojure-mode-syntax-test.el @@ -1,6 +1,6 @@ ;;; clojure-mode-syntax-test.el --- Clojure Mode: syntax related tests -*- lexical-binding: t; -*- -;; Copyright (C) 2015-2018 Bozhidar Batsov +;; Copyright (C) 2015-2019 Bozhidar Batsov ;; This file is not part of GNU Emacs. diff --git a/clojure-mode-util-test.el b/clojure-mode-util-test.el index fca0a6c..ee5591a 100644 --- a/clojure-mode-util-test.el +++ b/clojure-mode-util-test.el @@ -1,6 +1,6 @@ ;;; clojure-mode-util-test.el --- Clojure Mode: util test suite -*- lexical-binding: t; -*- -;; Copyright (C) 2014-2018 Bozhidar Batsov +;; Copyright (C) 2014-2019 Bozhidar Batsov ;; This file is not part of GNU Emacs. diff --git a/utils/test-helper.el b/utils/test-helper.el index 840cfc9..f16379b 100644 --- a/utils/test-helper.el +++ b/utils/test-helper.el @@ -1,6 +1,6 @@ ;;; test-helper.el --- Clojure Mode: Non-interactive unit-test setup -*- lexical-binding: t; -*- -;; Copyright (C) 2014-2018 Bozhidar Batsov +;; Copyright (C) 2014-2019 Bozhidar Batsov ;; This file is not part of GNU Emacs. From 9da2f8d716ecd9098808a0e45b4d7844cf2e61e0 Mon Sep 17 00:00:00 2001 From: yuhan0 Date: Tue, 16 Jul 2019 10:07:18 +0800 Subject: [PATCH 144/199] Update changelog and tests for clojure-unwind changes --- clojure-mode-refactor-threading-test.el | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/clojure-mode-refactor-threading-test.el b/clojure-mode-refactor-threading-test.el index 61f4409..6124634 100644 --- a/clojure-mode-refactor-threading-test.el +++ b/clojure-mode-refactor-threading-test.el @@ -227,6 +227,26 @@ (clojure-unwind) (clojure-unwind)) + (when-refactoring-it "should unwind N steps with numeric prefix arg" + "(->> [1 2 3 4 5] + (filter even?) + (map square) + sum)" + + "(->> (sum (map square (filter even? [1 2 3 4 5]))))" + + (clojure-unwind 3)) + + (when-refactoring-it "should unwind completely with universal prefix arg" + "(->> [1 2 3 4 5] + (filter even?) + (map square) + sum)" + + "(sum (map square (filter even? [1 2 3 4 5])))" + + (clojure-unwind '(4))) + (when-refactoring-it "should unwind with function name" "(->> [1 2 3 4 5] sum From 93b9e7e7f9e5f825676e25d3df237197cd3b07a8 Mon Sep 17 00:00:00 2001 From: Anthony Galea Date: Thu, 25 Jul 2019 08:54:23 +0200 Subject: [PATCH 145/199] Enhance add arity refactoring (#541) Support reader conditionals, letfn, fn, defmacro, defmethod, defprotocol, reify and proxy in addition to defn. --- clojure-mode-refactor-add-arity-test.el | 196 ++++++++++++++++++++++++ 1 file changed, 196 insertions(+) diff --git a/clojure-mode-refactor-add-arity-test.el b/clojure-mode-refactor-add-arity-test.el index 8bef9af..2b3cbc5 100644 --- a/clojure-mode-refactor-add-arity-test.el +++ b/clojure-mode-refactor-add-arity-test.el @@ -149,6 +149,202 @@ DESCRIPTION is a string with the description of the spec." ([arg] body))" + (clojure-add-arity)) + + (when-refactoring-with-point-it "should handle a single-arity fn" + "(fn foo [arg] + body|)" + + "(fn foo + ([|]) + ([arg] + body))" + + (clojure-add-arity)) + + (when-refactoring-with-point-it "should handle a multi-arity fn" + "(fn foo + ([x y] + body) + ([a|rg] + body))" + + "(fn foo + ([|]) + ([x y] + body) + ([arg] + body))" + + (clojure-add-arity)) + + (when-refactoring-with-point-it "should handle a single-arity defmacro" + "(defmacro foo [arg] + body|)" + + "(defmacro foo + ([|]) + ([arg] + body))" + + (clojure-add-arity)) + + (when-refactoring-with-point-it "should handle a multi-arity defmacro" + "(defmacro foo + ([x y] + body) + ([a|rg] + body))" + + "(defmacro foo + ([|]) + ([x y] + body) + ([arg] + body))" + + (clojure-add-arity)) + + (when-refactoring-with-point-it "should handle a single-arity defmethod" + "(defmethod foo :bar [arg] + body|)" + + "(defmethod foo :bar + ([|]) + ([arg] + body))" + + (clojure-add-arity)) + + (when-refactoring-with-point-it "should handle a multi-arity defmethod" + "(defmethod foo :bar + ([x y] + body) + ([a|rg] + body))" + + "(defmethod foo :bar + ([|]) + ([x y] + body) + ([arg] + body))" + + (clojure-add-arity)) + + (when-refactoring-with-point-it "should handle a defn inside a reader conditional" + "#?(:clj + (defn foo + \"some docstring\" + ^{:bla \"meta\"} + |([arg] + body)))" + + "#?(:clj + (defn foo + \"some docstring\" + ^{:bla \"meta\"} + ([|]) + ([arg] + body)))" + + (clojure-add-arity)) + + (when-refactoring-with-point-it "should handle a defn inside a reader conditional with 2 platform tags" + "#?(:clj + (defn foo + \"some docstring\" + ^{:bla \"meta\"} + |([arg] + body)) + :cljs + (defn foo + \"some docstring\" + ^{:bla \"meta\"} + ([arg] + body)))" + + "#?(:clj + (defn foo + \"some docstring\" + ^{:bla \"meta\"} + ([|]) + ([arg] + body)) + :cljs + (defn foo + \"some docstring\" + ^{:bla \"meta\"} + ([arg] + body)))" + + (clojure-add-arity)) + + (when-refactoring-with-point-it "should handle a single-arity fn inside a letfn" + "(letfn [(foo [x] + bo|dy)] + (foo 3))" + + "(letfn [(foo + ([|]) + ([x] + body))] + (foo 3))" + + (clojure-add-arity)) + + (when-refactoring-with-point-it "should handle a multi-arity fn inside a letfn" + "(letfn [(foo + ([x] + body) + |([x y] + body))] + (foo 3))" + + "(letfn [(foo + ([|]) + ([x] + body) + ([x y] + body))] + (foo 3))" + + (clojure-add-arity)) + + (when-refactoring-with-point-it "should handle a proxy" + "(proxy [Foo] [] + (bar [arg] + body|))" + + "(proxy [Foo] [] + (bar + ([|]) + ([arg] + body)))" + + (clojure-add-arity)) + + (when-refactoring-with-point-it "should handle a defprotocol" + "(defprotocol Foo + \"some docstring\" + (bar [arg] [x |y] \"some docstring\"))" + + "(defprotocol Foo + \"some docstring\" + (bar [|] [arg] [x y] \"some docstring\"))" + + (clojure-add-arity)) + + (when-refactoring-with-point-it "should handle a reify" + "(reify Foo + (bar [arg] body) + (blahs [arg]| body))" + + "(reify Foo + (bar [arg] body) + (blahs [|]) + (blahs [arg] body))" + (clojure-add-arity))) (provide 'clojure-mode-refactor-add-arity-test) From c933a4e2fe521a4556ac3098e5db6f90ffaf3dbd Mon Sep 17 00:00:00 2001 From: Robin Schroer Date: Tue, 1 Oct 2019 16:46:30 +0200 Subject: [PATCH 146/199] Support multiple consecutive reader comments (#_#_a b) Modified the default regexps and the heuristic to find the end of the region to comment out. Previously Emacs would treat the second `#_` as the commented form, and then highlight the following two forms as usual. Now it (mostly) matches what Clojure actually evaluates. Things get weird when you start mixing `#_` and forms, but this fixes the most common use cases, like key-value-pairs. --- clojure-mode-font-lock-test.el | 26 +++++++++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) diff --git a/clojure-mode-font-lock-test.el b/clojure-mode-font-lock-test.el index 715fb2f..484caa5 100644 --- a/clojure-mode-font-lock-test.el +++ b/clojure-mode-font-lock-test.el @@ -133,11 +133,35 @@ DESCRIPTION is the description of the spec." ("#_" (1 2 nil)) + ("#_#_" + (1 2 nil)) + + ("#_#_" + (3 2 font-lock-comment-face)) + + ("#_ #_" + (1 3 nil)) + + ("#_ #_" + (4 2 font-lock-comment-face)) + ("#_ \n;; some crap\n (lala 0101\n lao\n\n 0 0i)" (1 2 nil)) ("#_ \n;; some crap\n (lala 0101\n lao\n\n 0 0i)" - (5 41 font-lock-comment-face))) + (5 41 font-lock-comment-face)) + + ("#_#_ \n;; some crap\n (lala 0101\n lao\n\n 0 0i)\n;; more crap\n (foobar tnseriao)" + (1 4 nil)) + + ("#_ #_ \n;; some crap\n (lala 0101\n lao\n\n 0 0i)\n;; more crap\n (foobar tnseriao)" + (1 5 nil)) + + ("#_#_ \n;; some crap\n (lala 0101\n lao\n\n 0 0i)\n;; more crap\n (foobar tnseriao)" + (7 75 font-lock-comment-face)) + + ("#_ #_ \n;; some crap\n (lala 0101\n lao\n\n 0 0i)\n;; more crap\n (foobar tnseriao)" + (8 75 font-lock-comment-face))) (when-fontifying-it "should handle namespace declarations" ("(ns .validns)" From fad40cc55bcdb921f98ee25812d99306a56de7e3 Mon Sep 17 00:00:00 2001 From: Bozhidar Batsov Date: Fri, 20 Mar 2020 10:23:37 +0200 Subject: [PATCH 147/199] Update the copyright years --- clojure-mode-bytecomp-warnings.el | 2 +- clojure-mode-convert-collection-test.el | 2 +- clojure-mode-cycling-test.el | 2 +- clojure-mode-font-lock-test.el | 2 +- clojure-mode-indentation-test.el | 2 +- clojure-mode-refactor-let-test.el | 2 +- clojure-mode-refactor-threading-test.el | 2 +- clojure-mode-sexp-test.el | 2 +- clojure-mode-syntax-test.el | 2 +- clojure-mode-util-test.el | 2 +- utils/test-helper.el | 2 +- 11 files changed, 11 insertions(+), 11 deletions(-) diff --git a/clojure-mode-bytecomp-warnings.el b/clojure-mode-bytecomp-warnings.el index c6fb344..7c65dda 100644 --- a/clojure-mode-bytecomp-warnings.el +++ b/clojure-mode-bytecomp-warnings.el @@ -1,6 +1,6 @@ ;;; clojure-mode-bytecomp-warnings.el --- Check for byte-compilation problems -;; Copyright © 2012-2019 Bozhidar Batsov and contributors +;; Copyright © 2012-2020 Bozhidar Batsov and contributors ;; ;; This program is free software: you can redistribute it and/or modify ;; it under the terms of the GNU General Public License as published by diff --git a/clojure-mode-convert-collection-test.el b/clojure-mode-convert-collection-test.el index bf7a644..34d6b12 100644 --- a/clojure-mode-convert-collection-test.el +++ b/clojure-mode-convert-collection-test.el @@ -1,6 +1,6 @@ ;;; clojure-mode-convert-collection-test.el --- Clojure Mode: convert collection type -*- lexical-binding: t; -*- -;; Copyright (C) 2016-2019 Benedek Fazekas +;; Copyright (C) 2016-2020 Benedek Fazekas ;; This file is not part of GNU Emacs. diff --git a/clojure-mode-cycling-test.el b/clojure-mode-cycling-test.el index 6acd047..f4d6297 100644 --- a/clojure-mode-cycling-test.el +++ b/clojure-mode-cycling-test.el @@ -1,6 +1,6 @@ ;;; clojure-mode-cycling-test.el --- Clojure Mode: cycling things tests -*- lexical-binding: t; -*- -;; Copyright (C) 2016-2019 Benedek Fazekas +;; Copyright (C) 2016-2020 Benedek Fazekas ;; This file is not part of GNU Emacs. diff --git a/clojure-mode-font-lock-test.el b/clojure-mode-font-lock-test.el index 484caa5..a45e3de 100644 --- a/clojure-mode-font-lock-test.el +++ b/clojure-mode-font-lock-test.el @@ -1,7 +1,7 @@ ;;; clojure-mode-font-lock-test.el --- Clojure Mode: Font lock test suite ;; -*- lexical-binding: t; -*- -;; Copyright (C) 2014-2019 Bozhidar Batsov +;; Copyright (C) 2014-2020 Bozhidar Batsov ;; This file is not part of GNU Emacs. diff --git a/clojure-mode-indentation-test.el b/clojure-mode-indentation-test.el index 006d6f7..cb37941 100644 --- a/clojure-mode-indentation-test.el +++ b/clojure-mode-indentation-test.el @@ -1,6 +1,6 @@ ;;; clojure-mode-indentation-test.el --- Clojure Mode: indentation tests -*- lexical-binding: t; -*- -;; Copyright (C) 2015-2019 Bozhidar Batsov +;; Copyright (C) 2015-2020 Bozhidar Batsov ;; This file is not part of GNU Emacs. diff --git a/clojure-mode-refactor-let-test.el b/clojure-mode-refactor-let-test.el index 6b9df13..0e178f7 100644 --- a/clojure-mode-refactor-let-test.el +++ b/clojure-mode-refactor-let-test.el @@ -1,6 +1,6 @@ ;;; clojure-mode-refactor-let-test.el --- Clojure Mode: refactor let -*- lexical-binding: t; -*- -;; Copyright (C) 2016-2019 Benedek Fazekas +;; Copyright (C) 2016-2020 Benedek Fazekas ;; This file is not part of GNU Emacs. diff --git a/clojure-mode-refactor-threading-test.el b/clojure-mode-refactor-threading-test.el index 6124634..76e5810 100644 --- a/clojure-mode-refactor-threading-test.el +++ b/clojure-mode-refactor-threading-test.el @@ -1,6 +1,6 @@ ;;; clojure-mode-refactor-threading-test.el --- Clojure Mode: refactor threading tests -*- lexical-binding: t; -*- -;; Copyright (C) 2016-2019 Benedek Fazekas +;; Copyright (C) 2016-2020 Benedek Fazekas ;; This file is not part of GNU Emacs. diff --git a/clojure-mode-sexp-test.el b/clojure-mode-sexp-test.el index a7d5b85..da0c08f 100644 --- a/clojure-mode-sexp-test.el +++ b/clojure-mode-sexp-test.el @@ -1,6 +1,6 @@ ;;; clojure-mode-sexp-test.el --- Clojure Mode: sexp tests -*- lexical-binding: t; -*- -;; Copyright (C) 2015-2019 Artur Malabarba +;; Copyright (C) 2015-2020 Artur Malabarba ;; This file is not part of GNU Emacs. diff --git a/clojure-mode-syntax-test.el b/clojure-mode-syntax-test.el index 60286d4..af00c1a 100644 --- a/clojure-mode-syntax-test.el +++ b/clojure-mode-syntax-test.el @@ -1,6 +1,6 @@ ;;; clojure-mode-syntax-test.el --- Clojure Mode: syntax related tests -*- lexical-binding: t; -*- -;; Copyright (C) 2015-2019 Bozhidar Batsov +;; Copyright (C) 2015-2020 Bozhidar Batsov ;; This file is not part of GNU Emacs. diff --git a/clojure-mode-util-test.el b/clojure-mode-util-test.el index ee5591a..f9dd1f6 100644 --- a/clojure-mode-util-test.el +++ b/clojure-mode-util-test.el @@ -1,6 +1,6 @@ ;;; clojure-mode-util-test.el --- Clojure Mode: util test suite -*- lexical-binding: t; -*- -;; Copyright (C) 2014-2019 Bozhidar Batsov +;; Copyright (C) 2014-2020 Bozhidar Batsov ;; This file is not part of GNU Emacs. diff --git a/utils/test-helper.el b/utils/test-helper.el index f16379b..9076312 100644 --- a/utils/test-helper.el +++ b/utils/test-helper.el @@ -1,6 +1,6 @@ ;;; test-helper.el --- Clojure Mode: Non-interactive unit-test setup -*- lexical-binding: t; -*- -;; Copyright (C) 2014-2019 Bozhidar Batsov +;; Copyright (C) 2014-2020 Bozhidar Batsov ;; This file is not part of GNU Emacs. From 28024c5d400f95cde195134d0814241c5dffc2ed Mon Sep 17 00:00:00 2001 From: yuhan0 Date: Fri, 20 Mar 2020 07:05:30 +0800 Subject: [PATCH 148/199] update find-ns tests --- clojure-mode-util-test.el | 92 ++++++++++++++++++++++----------------- 1 file changed, 51 insertions(+), 41 deletions(-) diff --git a/clojure-mode-util-test.el b/clojure-mode-util-test.el index f9dd1f6..8d1c059 100644 --- a/clojure-mode-util-test.el +++ b/clojure-mode-util-test.el @@ -57,47 +57,57 @@ (clojure-expected-ns)) clj-file-ns)))))) -(describe "clojure-namespace-name-regex" - (it "should match common namespace declarations" - (let ((ns "(ns foo)")) - (expect (string-match clojure-namespace-name-regex ns)) - (match-string 4 ns)) - (let ((ns "(ns - foo)")) - (expect (string-match clojure-namespace-name-regex ns)) - (expect (match-string 4 ns) :to-equal "foo")) - (let ((ns "(ns foo.baz)")) - (expect (string-match clojure-namespace-name-regex ns)) - (expect (match-string 4 ns) :to-equal "foo.baz")) - (let ((ns "(ns ^:bar foo)")) - (expect (string-match clojure-namespace-name-regex ns)) - (expect (match-string 4 ns) :to-equal "foo")) - (let ((ns "(ns ^:bar ^:baz foo)")) - (expect (string-match clojure-namespace-name-regex ns)) - (expect (match-string 4 ns) :to-equal "foo")) - (let ((ns "(ns ^{:bar true} foo)")) - (expect (string-match clojure-namespace-name-regex ns)) - (expect (match-string 4 ns) :to-equal "foo")) - (let ((ns "(ns #^{:bar true} foo)")) - (expect (string-match clojure-namespace-name-regex ns)) - (expect (match-string 4 ns) :to-equal "foo")) - ;; TODO - ;; (let ((ns "(ns #^{:fail {}} foo)")) - ;; (should (string-match clojure-namespace-name-regex ns)) - ;; (match-string 4 ns)) - ;; (let ((ns "(ns ^{:fail2 {}} foo.baz)")) - ;; (should (string-match clojure-namespace-name-regex ns)) - ;; (should (equal "foo.baz" (match-string 4 ns)))) - (let ((ns "(ns ^{} foo)")) - (expect (string-match clojure-namespace-name-regex ns)) - (expect (match-string 4 ns) :to-equal "foo")) - (let ((ns "(ns ^{:skip-wiki true} - aleph.netty")) - (expect (string-match clojure-namespace-name-regex ns)) - (expect (match-string 4 ns) :to-equal "aleph.netty")) - (let ((ns "(ns foo+)")) - (expect (string-match clojure-namespace-name-regex ns)) - (expect (match-string 4 ns) :to-equal "foo+")))) +(describe "clojure-find-ns" + (it "should find common namespace declarations" + (with-clojure-buffer "(ns foo)" + (expect (clojure-find-ns) :to-equal "foo")) + (with-clojure-buffer "(ns + foo)" + (expect (clojure-find-ns) :to-equal "foo")) + (with-clojure-buffer "(ns foo.baz)" + (expect (clojure-find-ns) :to-equal "foo.baz")) + (with-clojure-buffer "(ns ^:bar foo)" + (expect (clojure-find-ns) :to-equal "foo")) + (with-clojure-buffer "(ns ^:bar ^:baz foo)" + (expect (clojure-find-ns) :to-equal "foo"))) + (it "should find namespace declarations with nested metadata and docstrings" + (with-clojure-buffer "(ns ^{:bar true} foo)" + (expect (clojure-find-ns) :to-equal "foo")) + (with-clojure-buffer "(ns #^{:bar true} foo)" + (expect (clojure-find-ns) :to-equal "foo")) + (with-clojure-buffer "(ns #^{:fail {}} foo)" + (expect (clojure-find-ns) :to-equal "foo")) + (with-clojure-buffer "(ns ^{:fail2 {}} foo.baz)" + (expect (clojure-find-ns) :to-equal "foo.baz")) + (with-clojure-buffer "(ns ^{} foo)" + (expect (clojure-find-ns) :to-equal "foo")) + (with-clojure-buffer "(ns ^{:skip-wiki true} + aleph.netty" + (expect (clojure-find-ns) :to-equal "aleph.netty")) + (with-clojure-buffer "(ns ^{:foo {:bar :baz} :fake (ns in.meta)} foo + \"docstring +(ns misleading)\")" + (expect (clojure-find-ns) :to-equal "foo"))) + (it "should support non-alphanumeric characters" + (with-clojure-buffer "(ns foo+)" + (expect (clojure-find-ns) :to-equal "foo+")) + (with-clojure-buffer "(ns bar**baz$-_quux)" + (expect (clojure-find-ns) :to-equal "bar**baz$-_quux"))) + (it "should support in-ns forms" + (with-clojure-buffer "(in-ns 'bar.baz)" + (expect (clojure-find-ns) :to-equal "bar.baz"))) + (it "should take the closest ns before point" + (with-clojure-buffer " (ns foo1) + +(ns foo2)" + (expect (clojure-find-ns) :to-equal "foo2")) + (with-clojure-buffer " (in-ns foo1) +(ns 'foo2) +(in-ns 'foo3) +| +(ns foo4)" + (re-search-backward "|") + (expect (clojure-find-ns) :to-equal "foo3")))) (describe "clojure-sort-ns" (it "should sort requires in a basic ns" From fa3389a811e3cbcbd2513694a86a804e61b0819d Mon Sep 17 00:00:00 2001 From: Kyle Cesare Date: Sat, 21 Mar 2020 01:29:13 -0700 Subject: [PATCH 149/199] [Fix #551] Indent `clojure-align` region before aligning (#552) This prevents issues when aligning improperly indented code. Before, the region would be aligned while retaining the improper indentation. The follow-up indentation step would then break the alignment that was just performed. With this commit, we switch the order by indenting first then aligning. This retains compatibility with the test cases in #360. --- clojure-mode-indentation-test.el | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/clojure-mode-indentation-test.el b/clojure-mode-indentation-test.el index cb37941..abbb350 100644 --- a/clojure-mode-indentation-test.el +++ b/clojure-mode-indentation-test.el @@ -659,6 +659,13 @@ x "#?@(:clj [2] :cljs [2])") + (it "should handle improperly indented content" + (let ((content "(let [a-long-name 10\nb 20])") + (aligned-content "(let [a-long-name 10\n b 20])")) + (with-clojure-buffer content + (call-interactively #'clojure-align) + (expect (buffer-string) :to-equal aligned-content)))) + (it "should not align reader conditionals by default" (let ((content "#?(:clj 2\n :cljs 2)")) (with-clojure-buffer content From c85c16fa246f3aa9bf96378133cb530fff1698d1 Mon Sep 17 00:00:00 2001 From: yuhan0 Date: Sat, 21 Mar 2020 13:40:03 +0800 Subject: [PATCH 150/199] Fix ns detection with namespaces containing numbers --- clojure-mode-util-test.el | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/clojure-mode-util-test.el b/clojure-mode-util-test.el index 8d1c059..ad843a5 100644 --- a/clojure-mode-util-test.el +++ b/clojure-mode-util-test.el @@ -92,7 +92,9 @@ (with-clojure-buffer "(ns foo+)" (expect (clojure-find-ns) :to-equal "foo+")) (with-clojure-buffer "(ns bar**baz$-_quux)" - (expect (clojure-find-ns) :to-equal "bar**baz$-_quux"))) + (expect (clojure-find-ns) :to-equal "bar**baz$-_quux")) + (with-clojure-buffer "(ns aoc-2019.puzzles.day14)" + (expect (clojure-find-ns) :to-equal "aoc-2019.puzzles.day14"))) (it "should support in-ns forms" (with-clojure-buffer "(in-ns 'bar.baz)" (expect (clojure-find-ns) :to-equal "bar.baz"))) From 7b1e9a248123facadb6a9be24f0e32e305a36904 Mon Sep 17 00:00:00 2001 From: yuhan0 Date: Fri, 20 Mar 2020 18:42:40 +0800 Subject: [PATCH 151/199] Add tests for new rename-ns-alias functionality --- clojure-mode-refactor-rename-ns-alias-test.el | 32 +++++++++++++++++-- 1 file changed, 29 insertions(+), 3 deletions(-) diff --git a/clojure-mode-refactor-rename-ns-alias-test.el b/clojure-mode-refactor-rename-ns-alias-test.el index aba75b3..2f68f44 100644 --- a/clojure-mode-refactor-rename-ns-alias-test.el +++ b/clojure-mode-refactor-rename-ns-alias-test.el @@ -95,8 +95,34 @@ ;; TODO refactor using new-lib/foo (+ (new-lib/a 1) (b 2))" - (clojure--rename-ns-alias-internal "lib" "new-lib"))) - - (provide 'clojure-mode-refactor-rename-ns-alias-test) + (clojure--rename-ns-alias-internal "lib" "new-lib")) + + (when-refactoring-it "should escape regex characters" + "(ns test.ns + (:require [my.math.subtraction :as math.-] + [my.math.multiplication :as math.*])) + +(math.*/operator 1 (math.-/subtract 2 3))" + "(ns test.ns + (:require [my.math.subtraction :as math.-] + [my.math.multiplication :as m*])) + +(m*/operator 1 (math.-/subtract 2 3))" + (clojure--rename-ns-alias-internal "math.*" "m*")) + + (it "should offer completions" + (expect + (clojure-collect-ns-aliases + "(ns test.ns + (:require [my.math.subtraction :as math.-] + [my.math.multiplication :as math.*] + [clojure.spec.alpha :as s] + ;; [clojure.spec.alpha2 :as s2] + [symbols :as abc123.-$#.%*+!@])) + +(math.*/operator 1 (math.-/subtract 2 3))") + :to-equal '("abc123.-$#.%*+!@" "s" "math.*" "math.-")))) + +(provide 'clojure-mode-refactor-rename-ns-alias-test) ;;; clojure-mode-refactor-rename-ns-alias-test.el ends here From d39d5d58b008743b5ed7b0a80b8f55c93ec087d4 Mon Sep 17 00:00:00 2001 From: yuhan0 Date: Tue, 24 Mar 2020 01:57:31 +0800 Subject: [PATCH 152/199] Fix bug when renaming ns aliases with common prefixes --- clojure-mode-refactor-rename-ns-alias-test.el | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/clojure-mode-refactor-rename-ns-alias-test.el b/clojure-mode-refactor-rename-ns-alias-test.el index 2f68f44..d5d99cb 100644 --- a/clojure-mode-refactor-rename-ns-alias-test.el +++ b/clojure-mode-refactor-rename-ns-alias-test.el @@ -43,6 +43,23 @@ (+ (foo/a 1) (b 2))" (clojure--rename-ns-alias-internal "lib" "foo")) + (when-refactoring-it "should handle multiple aliases with common prefixes" + + "(ns foo + (:require [clojure.string :as string] + [clojure.spec.alpha :as s] + [clojure.java.shell :as shell])) + +(s/def ::abc string/blank?) +" + "(ns foo + (:require [clojure.string :as string] + [clojure.spec.alpha :as spec] + [clojure.java.shell :as shell])) + +(spec/def ::abc string/blank?) +" + (clojure--rename-ns-alias-internal "s" "spec")) (when-refactoring-it "should handle ns declarations with missing as" "(ns cljr.core From 8261674e5b76e794bb12b1899721c1d0e48e123e Mon Sep 17 00:00:00 2001 From: yuhan0 Date: Thu, 26 Mar 2020 22:44:16 +0800 Subject: [PATCH 153/199] [Fix #547] Fix character literal regexp (#560) --- clojure-mode-font-lock-test.el | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/clojure-mode-font-lock-test.el b/clojure-mode-font-lock-test.el index a45e3de..23dade2 100644 --- a/clojure-mode-font-lock-test.el +++ b/clojure-mode-font-lock-test.el @@ -884,15 +884,30 @@ DESCRIPTION is the description of the spec." ("\\a" (1 2 clojure-character-face)) + ("\\A" + (1 2 clojure-character-face)) + ("\\newline" (1 8 clojure-character-face)) + ("\\abc" + (1 4 nil)) + + ("\\newlin" + (1 7 nil)) + + ("\\newlinex" + (1 9 nil)) + ("\\1" (1 2 clojure-character-face)) ("\\u0032" (1 6 clojure-character-face)) + ("\\o127" + (1 4 clojure-character-face)) + ("\\+" (1 2 clojure-character-face)) @@ -903,6 +918,12 @@ DESCRIPTION is the description of the spec." (1 2 clojure-character-face)) ("\\;" + (1 2 clojure-character-face)) + + ("\\Ω" + (1 2 clojure-character-face)) + + ("\\ク" (1 2 clojure-character-face))) (when-fontifying-it "should handle referred vars" From 7b06524b40f1a91b2d7b597cd810639289a20b1a Mon Sep 17 00:00:00 2001 From: yuhan0 Date: Thu, 26 Mar 2020 18:45:57 +0800 Subject: [PATCH 154/199] Add test for quotes in tail of symbols/keywords --- clojure-mode-font-lock-test.el | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/clojure-mode-font-lock-test.el b/clojure-mode-font-lock-test.el index 23dade2..3cd9604 100644 --- a/clojure-mode-font-lock-test.el +++ b/clojure-mode-font-lock-test.el @@ -417,6 +417,16 @@ DESCRIPTION is the description of the spec." (9 10 nil) (12 29 nil))) + (when-fontifying-it "should handle quotes in tail of symbols and keywords" + ("'quot'ed'/sy'm'bol''" + (2 9 font-lock-type-face) + (10 20 nil)) + + (":qu'ote'd''/key'word'" + (2 11 font-lock-type-face) + (12 12 default) + (13 21 clojure-keyword-face))) + (when-fontifying-it "should handle very complex stuff" (" ve/yCom|pLex.stu-ff" (3 4 font-lock-type-face) From 25d8595237e29622aa77541b9c1888832771aafc Mon Sep 17 00:00:00 2001 From: yuhan0 Date: Tue, 24 Mar 2020 01:42:03 +0800 Subject: [PATCH 155/199] Declare indentation spec for test util functions And auto-indent some lines --- clojure-mode-font-lock-test.el | 9 +++++---- utils/test-helper.el | 2 ++ 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/clojure-mode-font-lock-test.el b/clojure-mode-font-lock-test.el index 3cd9604..ecf5ac8 100644 --- a/clojure-mode-font-lock-test.el +++ b/clojure-mode-font-lock-test.el @@ -77,6 +77,7 @@ TESTS are lists of the form (content (start end expected-face)*). For each test check that each `expected-face` is found in `content` between `start` and `end`. DESCRIPTION is the description of the spec." + (declare (indent 1)) `(it ,description (dolist (test (quote ,tests)) (apply #'expect-faces-at test)))) @@ -797,8 +798,8 @@ DESCRIPTION is the description of the spec." ("(def foo \"usage\" \"hello\" )" (18 24 font-lock-string-face)) - ("(def foo \"usage\" \n \"hello\")" - (21 27 font-lock-string-face)) + ("(def foo \"usage\" \n \"hello\")" + (21 27 font-lock-string-face)) ("(def foo \n \"usage\" \"hello\")" (13 19 font-lock-doc-face)) @@ -864,8 +865,8 @@ DESCRIPTION is the description of the spec." (when-fontifying-it "should handle keyword-meta" ("^:meta-data" - (1 1 nil) - (2 11 clojure-keyword-face))) + (1 1 nil) + (2 11 clojure-keyword-face))) (when-fontifying-it "should handle a keyword with allowed characters" (":aaa#bbb" diff --git a/utils/test-helper.el b/utils/test-helper.el index 9076312..2cb2071 100644 --- a/utils/test-helper.el +++ b/utils/test-helper.el @@ -34,6 +34,7 @@ (defmacro with-clojure-buffer (text &rest body) "Create a temporary buffer, insert TEXT, switch to clojure-mode and evaluate BODY." + (declare (indent 1)) `(with-temp-buffer (erase-buffer) (insert ,text) @@ -49,6 +50,7 @@ AFTER. BODY should contain the refactoring that transforms BEFORE into AFTER. DESCRIPTION is the description of the spec." + (declare (indent 1)) `(it ,description (with-clojure-buffer ,before ,@body From d489b2704f1bb766b995de7aacea43f1b801a2a0 Mon Sep 17 00:00:00 2001 From: yuhan0 Date: Sat, 4 Apr 2020 01:22:24 +0800 Subject: [PATCH 156/199] Add test and changelog entry --- clojure-mode-font-lock-test.el | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/clojure-mode-font-lock-test.el b/clojure-mode-font-lock-test.el index ecf5ac8..5baa555 100644 --- a/clojure-mode-font-lock-test.el +++ b/clojure-mode-font-lock-test.el @@ -806,7 +806,12 @@ DESCRIPTION is the description of the spec." ("(def foo \n \"usage\" \n \"hello\")" (13 19 font-lock-doc-face) - (24 30 font-lock-string-face))) + (24 30 font-lock-string-face)) + + ("(def test-string\n \"this\\n\n is\n my\n string\")" + (20 24 font-lock-string-face) + (25 26 (bold font-lock-string-face)) + (27 46 font-lock-string-face))) (when-fontifying-it "should handle deftype" ("(deftype Foo)" From fb436f6cc67e8f1719525ec4d8183f3b75223491 Mon Sep 17 00:00:00 2001 From: yuhan0 Date: Sun, 5 Apr 2020 22:05:09 +0800 Subject: [PATCH 157/199] Fix ns detection bug The new regex was missing symbol-end, causing it to match (ns-... functions --- clojure-mode-util-test.el | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/clojure-mode-util-test.el b/clojure-mode-util-test.el index ad843a5..27ce4c5 100644 --- a/clojure-mode-util-test.el +++ b/clojure-mode-util-test.el @@ -109,7 +109,11 @@ | (ns foo4)" (re-search-backward "|") - (expect (clojure-find-ns) :to-equal "foo3")))) + (expect (clojure-find-ns) :to-equal "foo3")) + (with-clojure-buffer "(ns foo) +(ns-unmap *ns* 'map) +(ns.misleading 1 2 3)" + (expect (clojure-find-ns) :to-equal "foo")))) (describe "clojure-sort-ns" (it "should sort requires in a basic ns" From e9c328a33a8839e1bb193a66780703d43b5afc90 Mon Sep 17 00:00:00 2001 From: yuhan0 Date: Sat, 18 Apr 2020 15:04:55 +0800 Subject: [PATCH 158/199] Add tests for paredit interaction --- clojure-mode-external-interaction-test.el | 90 +++++++++++++++++++++++ 1 file changed, 90 insertions(+) create mode 100644 clojure-mode-external-interaction-test.el diff --git a/clojure-mode-external-interaction-test.el b/clojure-mode-external-interaction-test.el new file mode 100644 index 0000000..5e3d854 --- /dev/null +++ b/clojure-mode-external-interaction-test.el @@ -0,0 +1,90 @@ +;;; clojure-mode-external-interaction-test.el --- Clojure Mode interactions with external packages test suite -*- lexical-binding: t; -*- + +;; Copyright (C) 2014-2020 Bozhidar Batsov + +;; This file is not part of GNU Emacs. + +;; This program is free software; you can redistribute it and/or modify +;; it under the terms of the GNU General Public License as published by +;; the Free Software Foundation, either version 3 of the License, or +;; (at your option) any later version. + +;; This program is distributed in the hope that it will be useful, +;; but WITHOUT ANY WARRANTY; without even the implied warranty of +;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +;; GNU General Public License for more details. + +;; You should have received a copy of the GNU General Public License +;; along with this program. If not, see . + +;;; Code: + +(require 'clojure-mode) +(require 'buttercup) +(require 'paredit) + +(describe "Interactions with Paredit" + ;; reuse existing when-refactoring-it macro + (describe "it should insert a space" + (when-refactoring-it "before lists" + "foo" + "foo ()" + (paredit-mode) + (paredit-open-round)) + (when-refactoring-it "before vectors" + "foo" + "foo []" + (paredit-mode) + (paredit-open-square)) + (when-refactoring-it "before maps" + "foo" + "foo {}" + (paredit-mode) + (paredit-open-curly)) + (when-refactoring-it "before strings" + "foo" + "foo \"\"" + (paredit-mode) + (paredit-doublequote)) + (when-refactoring-it "after gensym" + "foo#" + "foo# ()" + (paredit-mode) + (paredit-open-round)) + (when-refactoring-it "after symbols ending with '" + "foo'" + "foo' ()" + (paredit-mode) + (paredit-open-round))) + (describe "should not insert a space" + (when-refactoring-it "for anonymous fn syntax" + "foo #" + "foo #()" + (paredit-mode) + (paredit-open-round)) + (when-refactoring-it "for hash sets" + "foo #" + "foo #{}" + (paredit-mode) + (paredit-open-curly)) + (when-refactoring-it "for regexes" + "foo #" + "foo #\"\"" + (paredit-mode) + (paredit-doublequote)) + (when-refactoring-it "for quoted collections" + "foo '" + "foo '()" + (paredit-mode) + (paredit-open-round)) + (when-refactoring-it "for reader conditionals" + "foo #?" + "foo #?()" + (paredit-mode) + (paredit-open-round)))) + + +(provide 'clojure-mode-external-interaction-test) + + +;;; clojure-mode-external-interaction-test.el ends here From 61f10885779a1815a9584b7c25c5ad1635a4bb7e Mon Sep 17 00:00:00 2001 From: yuhan0 Date: Sat, 18 Apr 2020 15:05:41 +0800 Subject: [PATCH 159/199] Add delete-trailing-whitespace tests --- clojure-mode-external-interaction-test.el | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/clojure-mode-external-interaction-test.el b/clojure-mode-external-interaction-test.el index 5e3d854..41b1aeb 100644 --- a/clojure-mode-external-interaction-test.el +++ b/clojure-mode-external-interaction-test.el @@ -84,6 +84,24 @@ (paredit-open-round)))) +(describe "Interactions with delete-trailing-whitespace" + (when-refactoring-it "should not delete trailing commas" + "(def foo + \\\"foo\\\": 1, + \\\"bar\\\": 2} + +(-> m + (assoc ,,, + :foo 123))" + "(def foo + \\\"foo\\\": 1, + \\\"bar\\\": 2} + +(-> m + (assoc ,,, + :foo 123))" + (delete-trailing-whitespace))) + (provide 'clojure-mode-external-interaction-test) From 234cadedf594000d3b29a43bc0fa58a13c212170 Mon Sep 17 00:00:00 2001 From: yuhan0 Date: Sat, 18 Apr 2020 16:34:33 +0800 Subject: [PATCH 160/199] Refactor clojure-no-space-after-tag Consolidate into single predicate, make collection-tag-regexp obsolete --- clojure-mode-syntax-test.el | 9 --------- 1 file changed, 9 deletions(-) diff --git a/clojure-mode-syntax-test.el b/clojure-mode-syntax-test.el index af00c1a..f3699f6 100644 --- a/clojure-mode-syntax-test.el +++ b/clojure-mode-syntax-test.el @@ -75,15 +75,6 @@ (backward-prefix-chars) (expect (bobp)))))) -(describe "clojure-no-space-after-tag" - (it "should allow allow collection tags" - (dolist (tag '("#::ns" "#:ns" "#ns" "#:f.q/ns" "#f.q/ns" "#::")) - (with-clojure-buffer tag - (expect (clojure-no-space-after-tag nil ?{) :to-be nil))) - (dolist (tag '("#$:" "#/f" "#:/f" "#::f.q/ns" "::ns" "::" "#f:ns")) - (with-clojure-buffer tag - (expect (clojure-no-space-after-tag nil ?{)))))) - (describe "fill-paragraph" (it "should work within comments" From 04267d8230680d64da07d0e94b5cf87a0a34f63e Mon Sep 17 00:00:00 2001 From: yuhan0 Date: Sat, 18 Apr 2020 16:52:01 +0800 Subject: [PATCH 161/199] Add tests for paredit reader tags --- clojure-mode-external-interaction-test.el | 32 ++++++++++++++++++++--- 1 file changed, 29 insertions(+), 3 deletions(-) diff --git a/clojure-mode-external-interaction-test.el b/clojure-mode-external-interaction-test.el index 41b1aeb..8451abe 100644 --- a/clojure-mode-external-interaction-test.el +++ b/clojure-mode-external-interaction-test.el @@ -23,7 +23,7 @@ (require 'buttercup) (require 'paredit) -(describe "Interactions with Paredit" +(describe "Interactions with Paredit:" ;; reuse existing when-refactoring-it macro (describe "it should insert a space" (when-refactoring-it "before lists" @@ -56,7 +56,7 @@ "foo' ()" (paredit-mode) (paredit-open-round))) - (describe "should not insert a space" + (describe "it should not insert a space" (when-refactoring-it "for anonymous fn syntax" "foo #" "foo #()" @@ -81,7 +81,33 @@ "foo #?" "foo #?()" (paredit-mode) - (paredit-open-round)))) + (paredit-open-round))) + (describe "reader tags" + (when-refactoring-it "should insert a space before strings" + "#uuid" + "#uuid \"\"" + (paredit-mode) + (paredit-doublequote)) + (when-refactoring-it "should not insert a space before namespaced maps" + "#::my-ns" + "#::my-ns{}" + (paredit-mode) + (paredit-open-curly)) + (when-refactoring-it "should not insert a space before namespaced maps 2" + "#::" + "#::{}" + (paredit-mode) + (paredit-open-curly)) + (when-refactoring-it "should not insert a space before namespaced maps 3" + "#:fully.qualified.ns123.-$#.%*+!" + "#:fully.qualified.ns123.-$#.%*+!{}" + (paredit-mode) + (paredit-open-curly)) + (when-refactoring-it "should not insert a space before tagged vectors" + "#tag123.-$#.%*+!" + "#tag123.-$#.%*+![]" + (paredit-mode) + (paredit-open-square)))) (describe "Interactions with delete-trailing-whitespace" From 2fa5aae310f95b8776be9bb1e800336df81d6cb6 Mon Sep 17 00:00:00 2001 From: yuhan0 Date: Tue, 23 Feb 2021 02:20:45 +0800 Subject: [PATCH 162/199] Move test macros to utils file --- clojure-mode-refactor-add-arity-test.el | 25 ---------------- clojure-mode-sexp-test.el | 13 --------- utils/test-helper.el | 38 +++++++++++++++++++++++++ 3 files changed, 38 insertions(+), 38 deletions(-) diff --git a/clojure-mode-refactor-add-arity-test.el b/clojure-mode-refactor-add-arity-test.el index 2b3cbc5..e4deefc 100644 --- a/clojure-mode-refactor-add-arity-test.el +++ b/clojure-mode-refactor-add-arity-test.el @@ -25,31 +25,6 @@ (require 'clojure-mode) (require 'buttercup) -(defmacro when-refactoring-with-point-it (description before after &rest body) - "Return a buttercup spec. - -Like when-refactor-it but also checks whether point is moved to the expected -position. - -BEFORE is the buffer string before refactoring, where a pipe (|) represents -point. - -AFTER is the expected buffer string after refactoring, where a pipe (|) -represents the expected position of point. - -DESCRIPTION is a string with the description of the spec." - `(it ,description - (let* ((after ,after) - (expected-cursor-pos (1+ (s-index-of "|" after))) - (expected-state (delete ?| after))) - (with-clojure-buffer ,before - (goto-char (point-min)) - (search-forward "|") - (delete-char -1) - ,@body - (expect (buffer-string) :to-equal expected-state) - (expect (point) :to-equal expected-cursor-pos))))) - (describe "clojure-add-arity" (when-refactoring-with-point-it "should add an arity to a single-arity defn with args on same line" diff --git a/clojure-mode-sexp-test.el b/clojure-mode-sexp-test.el index da0c08f..f9c15a3 100644 --- a/clojure-mode-sexp-test.el +++ b/clojure-mode-sexp-test.el @@ -22,19 +22,6 @@ (require 'clojure-mode) (require 'buttercup) -(defmacro with-clojure-buffer-point (text &rest body) - "Run BODY in a temporary clojure buffer with TEXT. - -TEXT is a string with a | indicating where point is. The | will be erased -and point left there." - (declare (indent 2)) - `(progn - (with-clojure-buffer ,text - (goto-char (point-min)) - (re-search-forward "|") - (delete-char -1) - ,@body))) - (describe "clojure-top-level-form-p" (it "should return true when passed the correct form" (with-clojure-buffer-point diff --git a/utils/test-helper.el b/utils/test-helper.el index 2cb2071..f15b285 100644 --- a/utils/test-helper.el +++ b/utils/test-helper.el @@ -41,6 +41,19 @@ (clojure-mode) ,@body)) +(defmacro with-clojure-buffer-point (text &rest body) + "Run BODY in a temporary clojure buffer with TEXT. + +TEXT is a string with a | indicating where point is. The | will be erased +and point left there." + (declare (indent 2)) + `(progn + (with-clojure-buffer ,text + (goto-char (point-min)) + (re-search-forward "|") + (delete-char -1) + ,@body))) + (defmacro when-refactoring-it (description before after &rest body) "Return a buttercup spec. @@ -56,4 +69,29 @@ DESCRIPTION is the description of the spec." ,@body (expect (buffer-string) :to-equal ,after)))) +(defmacro when-refactoring-with-point-it (description before after &rest body) + "Return a buttercup spec. + +Like when-refactor-it but also checks whether point is moved to the expected +position. + +BEFORE is the buffer string before refactoring, where a pipe (|) represents +point. + +AFTER is the expected buffer string after refactoring, where a pipe (|) +represents the expected position of point. + +DESCRIPTION is a string with the description of the spec." + `(it ,description + (let* ((after ,after) + (expected-cursor-pos (1+ (s-index-of "|" after))) + (expected-state (delete ?| after))) + (with-clojure-buffer ,before + (goto-char (point-min)) + (search-forward "|") + (delete-char -1) + ,@body + (expect (buffer-string) :to-equal expected-state) + (expect (point) :to-equal expected-cursor-pos))))) + ;;; test-helper.el ends here From 8f08712ee5c41b6ad7ecc1e32f38f41b227980ef Mon Sep 17 00:00:00 2001 From: yuhan0 Date: Tue, 23 Feb 2021 02:22:06 +0800 Subject: [PATCH 163/199] add indent spec to when-refactoring-with-point-it --- utils/test-helper.el | 1 + 1 file changed, 1 insertion(+) diff --git a/utils/test-helper.el b/utils/test-helper.el index f15b285..756def3 100644 --- a/utils/test-helper.el +++ b/utils/test-helper.el @@ -82,6 +82,7 @@ AFTER is the expected buffer string after refactoring, where a pipe (|) represents the expected position of point. DESCRIPTION is a string with the description of the spec." + (declare (indent 1)) `(it ,description (let* ((after ,after) (expected-cursor-pos (1+ (s-index-of "|" after))) From ef047846f968b6ecfb15681720718caed248e1f9 Mon Sep 17 00:00:00 2001 From: yuhan0 Date: Tue, 23 Feb 2021 04:51:28 +0800 Subject: [PATCH 164/199] Add tests for toggling ignore forms --- clojure-mode-util-test.el | 87 ++++++++++++++++++++++++++++++++++++++- 1 file changed, 86 insertions(+), 1 deletion(-) diff --git a/clojure-mode-util-test.el b/clojure-mode-util-test.el index 27ce4c5..4a0bbbb 100644 --- a/clojure-mode-util-test.el +++ b/clojure-mode-util-test.el @@ -139,7 +139,7 @@ (clojure-mode) (clojure-sort-ns) (expect (buffer-string) :to-equal - "\n(ns my-app.core + "\n(ns my-app.core (:require [my-app.state :refer [state]] ; Comments too. my-app.util.api [my-app.views [front-page :as front-page]] @@ -149,6 +149,91 @@ (:import [clojure.lang AFunction Atom MultiFn Namespace] java.io.Writer))")))) +(describe "clojure-toggle-ignore" + (when-refactoring-with-point-it "should add #_ to literals" + "[1 |2 3]" "[1 #_|2 3]" + (clojure-toggle-ignore)) + (when-refactoring-with-point-it "should work with point in middle of symbol" + "[foo b|ar baz]" "[foo #_b|ar baz]" + (clojure-toggle-ignore)) + (when-refactoring-with-point-it "should remove #_ after cursor" + "[1 |#_2 3]" "[1 |2 3]" + (clojure-toggle-ignore)) + (when-refactoring-with-point-it "should remove #_ before cursor" + "[#_:fo|o :bar :baz]" "[:fo|o :bar :baz]" + (clojure-toggle-ignore)) + (when-refactoring-with-point-it "should insert multiple #_" + "{:foo| 1 :bar 2 :baz 3}" + "{#_#_#_#_:foo| 1 :bar 2 :baz 3}" + (clojure-toggle-ignore 4)) + (when-refactoring-with-point-it "should remove multiple #_" + "{#_#_#_#_:foo| 1 :bar 2 :baz 3}" + "{#_#_:foo| 1 :bar 2 :baz 3}" + (clojure-toggle-ignore 2)) + (when-refactoring-with-point-it "should handle spaces and newlines" + "[foo #_ \n #_ \r\n b|ar baz]" "[foo b|ar baz]" + (clojure-toggle-ignore 2)) + (when-refactoring-with-point-it "should toggle entire string" + "[:div \"lorem ips|um text\"]" + "[:div #_\"lorem ips|um text\"]" + (clojure-toggle-ignore)) + (when-refactoring-with-point-it "should toggle regexps" + "[|#\".*\"]" + "[#_|#\".*\"]" + (clojure-toggle-ignore)) + (when-refactoring-with-point-it "should toggle collections" + "[foo |[bar baz]]" + "[foo #_|[bar baz]]" + (clojure-toggle-ignore)) + (when-refactoring-with-point-it "should toggle hash sets" + "[foo #|{bar baz}]" + "[foo #_#|{bar baz}]" + (clojure-toggle-ignore)) + (when-refactoring-with-point-it "should work on last-sexp" + "[foo '(bar baz)| quux]" + "[foo #_'(bar baz)| quux]" + (clojure-toggle-ignore)) + (when-refactoring-with-point-it "should insert newline before top-level form" + "|[foo bar baz]" + "#_ +|[foo bar baz]" + (clojure-toggle-ignore))) + +(describe "clojure-toggle-ignore-surrounding-form" + (when-refactoring-with-point-it "should toggle lists" + "(li|st [vector {map #{set}}])" + "#_\n(li|st [vector {map #{set}}])" + (clojure-toggle-ignore-surrounding-form)) + (when-refactoring-with-point-it "should toggle vectors" + "(list #_[vector| {map #{set}}])" + "(list [vector| {map #{set}}])" + (clojure-toggle-ignore-surrounding-form)) + (when-refactoring-with-point-it "should toggle maps" + "(list [vector #_ \n {map #{set}|}])" + "(list [vector {map #{set}|}])" + (clojure-toggle-ignore-surrounding-form)) + (when-refactoring-with-point-it "should toggle sets" + "(list [vector {map #{set|}}])" + "(list [vector {map #_#{set|}}])" + (clojure-toggle-ignore-surrounding-form)) + (when-refactoring-with-point-it "should work with numeric arg" + "(four (three (two (on|e)))" + "(four (three #_(two (on|e)))" + (clojure-toggle-ignore-surrounding-form 2)) + (when-refactoring-with-point-it "should remove #_ with numeric arg" + "(four #_(three (two (on|e)))" + "(four (three (two (on|e)))" + (clojure-toggle-ignore-surrounding-form 3))) + +(describe "clojure-toggle-ignore-defun" + (when-refactoring-with-point-it "should ignore defun with newline" + "(defn foo [x] + {:nested (in|c x)})" + "#_ +(defn foo [x] + {:nested (in|c x)})" + (clojure-toggle-ignore-defun))) + (provide 'clojure-mode-util-test) ;;; clojure-mode-util-test.el ends here From 214bf02d3e0fab52dd0c014fa1e56d099aba442e Mon Sep 17 00:00:00 2001 From: Hugo Duncan Date: Mon, 1 Mar 2021 14:41:43 -0500 Subject: [PATCH 165/199] Make indentation of special arguments customisable (#582) Allow control of the indentation of special arguments through a defcustom. - introduces clojure-special-arg-indent-factor, which is used as a factor of lisp-body-ident to indent special arguments. Defaults to 2, the currently hard coded value for this. --- clojure-mode-indentation-test.el | 45 ++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) diff --git a/clojure-mode-indentation-test.el b/clojure-mode-indentation-test.el index abbb350..b908172 100644 --- a/clojure-mode-indentation-test.el +++ b/clojure-mode-indentation-test.el @@ -233,6 +233,51 @@ DESCRIPTION is a string with the description of the spec." (ala/bala top |one)")) + (describe "specify an indentation for symbol" + (put-clojure-indent 'cala 1) + + (when-indenting-with-point-it "should handle a symbol with ns" + " + (cala top + |one)" + " + (cala top + |one)") + (when-indenting-with-point-it "should handle special arguments" + " + (cala + |top + one)" + " + (cala + |top + one)")) + (describe "should respect special argument indentation" + :var (clojure-special-arg-indent-factor) + (before-each + (setq clojure-special-arg-indent-factor 1)) + (after-each + (setq clojure-special-arg-indent-factor 2)) + + (put-clojure-indent 'cala 1) + + (when-indenting-with-point-it "should handle a symbol with ns" + " + (cala top + |one)" + " + (cala top + |one)") + (when-indenting-with-point-it "should handle special arguments" + " + (cala + |top + one)" + " + (cala + |top + one)")) + (describe "we can pass a lambda to explicitly set the column" (put-clojure-indent 'arsymbol (lambda (indent-point state) 0)) From a3c442a82c9ca6a88df370239148d1d4da5598de Mon Sep 17 00:00:00 2001 From: Bozhidar Batsov Date: Mon, 22 Mar 2021 09:04:25 +0200 Subject: [PATCH 166/199] Bump the copyright years --- clojure-mode-bytecomp-warnings.el | 2 +- clojure-mode-convert-collection-test.el | 2 +- clojure-mode-cycling-test.el | 2 +- clojure-mode-external-interaction-test.el | 2 +- clojure-mode-font-lock-test.el | 2 +- clojure-mode-indentation-test.el | 2 +- clojure-mode-refactor-let-test.el | 2 +- clojure-mode-refactor-threading-test.el | 2 +- clojure-mode-sexp-test.el | 2 +- clojure-mode-syntax-test.el | 2 +- clojure-mode-util-test.el | 2 +- utils/test-helper.el | 2 +- 12 files changed, 12 insertions(+), 12 deletions(-) diff --git a/clojure-mode-bytecomp-warnings.el b/clojure-mode-bytecomp-warnings.el index 7c65dda..d3cc19a 100644 --- a/clojure-mode-bytecomp-warnings.el +++ b/clojure-mode-bytecomp-warnings.el @@ -1,6 +1,6 @@ ;;; clojure-mode-bytecomp-warnings.el --- Check for byte-compilation problems -;; Copyright © 2012-2020 Bozhidar Batsov and contributors +;; Copyright © 2012-2021 Bozhidar Batsov and contributors ;; ;; This program is free software: you can redistribute it and/or modify ;; it under the terms of the GNU General Public License as published by diff --git a/clojure-mode-convert-collection-test.el b/clojure-mode-convert-collection-test.el index 34d6b12..cd28f51 100644 --- a/clojure-mode-convert-collection-test.el +++ b/clojure-mode-convert-collection-test.el @@ -1,6 +1,6 @@ ;;; clojure-mode-convert-collection-test.el --- Clojure Mode: convert collection type -*- lexical-binding: t; -*- -;; Copyright (C) 2016-2020 Benedek Fazekas +;; Copyright (C) 2016-2021 Benedek Fazekas ;; This file is not part of GNU Emacs. diff --git a/clojure-mode-cycling-test.el b/clojure-mode-cycling-test.el index f4d6297..afc2476 100644 --- a/clojure-mode-cycling-test.el +++ b/clojure-mode-cycling-test.el @@ -1,6 +1,6 @@ ;;; clojure-mode-cycling-test.el --- Clojure Mode: cycling things tests -*- lexical-binding: t; -*- -;; Copyright (C) 2016-2020 Benedek Fazekas +;; Copyright (C) 2016-2021 Benedek Fazekas ;; This file is not part of GNU Emacs. diff --git a/clojure-mode-external-interaction-test.el b/clojure-mode-external-interaction-test.el index 8451abe..f6dba50 100644 --- a/clojure-mode-external-interaction-test.el +++ b/clojure-mode-external-interaction-test.el @@ -1,6 +1,6 @@ ;;; clojure-mode-external-interaction-test.el --- Clojure Mode interactions with external packages test suite -*- lexical-binding: t; -*- -;; Copyright (C) 2014-2020 Bozhidar Batsov +;; Copyright (C) 2014-2021 Bozhidar Batsov ;; This file is not part of GNU Emacs. diff --git a/clojure-mode-font-lock-test.el b/clojure-mode-font-lock-test.el index 5baa555..c626122 100644 --- a/clojure-mode-font-lock-test.el +++ b/clojure-mode-font-lock-test.el @@ -1,7 +1,7 @@ ;;; clojure-mode-font-lock-test.el --- Clojure Mode: Font lock test suite ;; -*- lexical-binding: t; -*- -;; Copyright (C) 2014-2020 Bozhidar Batsov +;; Copyright (C) 2014-2021 Bozhidar Batsov ;; This file is not part of GNU Emacs. diff --git a/clojure-mode-indentation-test.el b/clojure-mode-indentation-test.el index b908172..61e4867 100644 --- a/clojure-mode-indentation-test.el +++ b/clojure-mode-indentation-test.el @@ -1,6 +1,6 @@ ;;; clojure-mode-indentation-test.el --- Clojure Mode: indentation tests -*- lexical-binding: t; -*- -;; Copyright (C) 2015-2020 Bozhidar Batsov +;; Copyright (C) 2015-2021 Bozhidar Batsov ;; This file is not part of GNU Emacs. diff --git a/clojure-mode-refactor-let-test.el b/clojure-mode-refactor-let-test.el index 0e178f7..196db79 100644 --- a/clojure-mode-refactor-let-test.el +++ b/clojure-mode-refactor-let-test.el @@ -1,6 +1,6 @@ ;;; clojure-mode-refactor-let-test.el --- Clojure Mode: refactor let -*- lexical-binding: t; -*- -;; Copyright (C) 2016-2020 Benedek Fazekas +;; Copyright (C) 2016-2021 Benedek Fazekas ;; This file is not part of GNU Emacs. diff --git a/clojure-mode-refactor-threading-test.el b/clojure-mode-refactor-threading-test.el index 76e5810..65b2a78 100644 --- a/clojure-mode-refactor-threading-test.el +++ b/clojure-mode-refactor-threading-test.el @@ -1,6 +1,6 @@ ;;; clojure-mode-refactor-threading-test.el --- Clojure Mode: refactor threading tests -*- lexical-binding: t; -*- -;; Copyright (C) 2016-2020 Benedek Fazekas +;; Copyright (C) 2016-2021 Benedek Fazekas ;; This file is not part of GNU Emacs. diff --git a/clojure-mode-sexp-test.el b/clojure-mode-sexp-test.el index f9c15a3..de4bea7 100644 --- a/clojure-mode-sexp-test.el +++ b/clojure-mode-sexp-test.el @@ -1,6 +1,6 @@ ;;; clojure-mode-sexp-test.el --- Clojure Mode: sexp tests -*- lexical-binding: t; -*- -;; Copyright (C) 2015-2020 Artur Malabarba +;; Copyright (C) 2015-2021 Artur Malabarba ;; This file is not part of GNU Emacs. diff --git a/clojure-mode-syntax-test.el b/clojure-mode-syntax-test.el index f3699f6..174b93e 100644 --- a/clojure-mode-syntax-test.el +++ b/clojure-mode-syntax-test.el @@ -1,6 +1,6 @@ ;;; clojure-mode-syntax-test.el --- Clojure Mode: syntax related tests -*- lexical-binding: t; -*- -;; Copyright (C) 2015-2020 Bozhidar Batsov +;; Copyright (C) 2015-2021 Bozhidar Batsov ;; This file is not part of GNU Emacs. diff --git a/clojure-mode-util-test.el b/clojure-mode-util-test.el index 4a0bbbb..da7aec0 100644 --- a/clojure-mode-util-test.el +++ b/clojure-mode-util-test.el @@ -1,6 +1,6 @@ ;;; clojure-mode-util-test.el --- Clojure Mode: util test suite -*- lexical-binding: t; -*- -;; Copyright (C) 2014-2020 Bozhidar Batsov +;; Copyright (C) 2014-2021 Bozhidar Batsov ;; This file is not part of GNU Emacs. diff --git a/utils/test-helper.el b/utils/test-helper.el index 756def3..d822fef 100644 --- a/utils/test-helper.el +++ b/utils/test-helper.el @@ -1,6 +1,6 @@ ;;; test-helper.el --- Clojure Mode: Non-interactive unit-test setup -*- lexical-binding: t; -*- -;; Copyright (C) 2014-2020 Bozhidar Batsov +;; Copyright (C) 2014-2021 Bozhidar Batsov ;; This file is not part of GNU Emacs. From c211a27f7bbcac692547ed440b64ba3554e3cc7e Mon Sep 17 00:00:00 2001 From: yuhan0 Date: Sun, 2 May 2021 15:52:20 +0800 Subject: [PATCH 167/199] Rename ns aliases in selected region (#590) --- clojure-mode-refactor-rename-ns-alias-test.el | 40 ++++++++++++++++--- 1 file changed, 35 insertions(+), 5 deletions(-) diff --git a/clojure-mode-refactor-rename-ns-alias-test.el b/clojure-mode-refactor-rename-ns-alias-test.el index d5d99cb..37fe90c 100644 --- a/clojure-mode-refactor-rename-ns-alias-test.el +++ b/clojure-mode-refactor-rename-ns-alias-test.el @@ -127,18 +127,48 @@ (m*/operator 1 (math.-/subtract 2 3))" (clojure--rename-ns-alias-internal "math.*" "m*")) - (it "should offer completions" + (when-refactoring-it "should replace aliases in region" + "(str/join []) + +(s/with-gen #(string/includes? % \"gen/nope\") + #(gen/fmap (fn [[s1 s2]] (str s1 \"hello\" s2)) + (gen/tuple (gen/string-alphanumeric) (gen/string-alphanumeric)))) + +(gen/different-library)" + "(string/join []) + +(s/with-gen #(string/includes? % \"gen/nope\") + #(s.gen/fmap (fn [[s1 s2]] (str s1 \"hello\" s2)) + (s.gen/tuple (s.gen/string-alphanumeric) (s.gen/string-alphanumeric)))) + +(gen/different-library)" + + (clojure--rename-ns-alias-usages "str" "string" (point-min) 13) + (clojure--rename-ns-alias-usages "gen" "s.gen" (point-min) (- (point-max) 23))) + + (it "should offer completions for ns forms" (expect - (clojure-collect-ns-aliases - "(ns test.ns + (with-clojure-buffer + "(ns test.ns (:require [my.math.subtraction :as math.-] [my.math.multiplication :as math.*] [clojure.spec.alpha :as s] ;; [clojure.spec.alpha2 :as s2] [symbols :as abc123.-$#.%*+!@])) -(math.*/operator 1 (math.-/subtract 2 3))") - :to-equal '("abc123.-$#.%*+!@" "s" "math.*" "math.-")))) +(math.*/operator 1 (math.-/subtract 2 3))" + (clojure--collect-ns-aliases (point-min) (point-max) 'ns-form)) + :to-equal '("math.-" "math.*" "s" "abc123.-$#.%*+!@"))) + + (it "should offer completions for usages in region" + (expect + (with-clojure-buffer + "(s/with-gen #(string/includes? % \"hello\") + #(gen/fmap (fn [[s1 s2]] (str s1 \"hello\" s2)) + (gen/tuple (gen/string-alphanumeric) (gen/string-alphanumeric))))" + (clojure--collect-ns-aliases (point-min) (point-max) nil)) + :to-equal '("s" "string" "gen")))) + (provide 'clojure-mode-refactor-rename-ns-alias-test) From 70c1ac65d1dcbfe623979d1f1f734d34db6e5e46 Mon Sep 17 00:00:00 2001 From: Marconi Rivello Date: Mon, 22 Mar 2021 16:40:59 -0300 Subject: [PATCH 168/199] Fix for character literal font-lock (#588) When inside a vector or before white space, some escaped characters, like comma, square and curly brackets, weren't being formatted. * Added tests. * Added examples in test.clj for visual inspection. --- clojure-mode-font-lock-test.el | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/clojure-mode-font-lock-test.el b/clojure-mode-font-lock-test.el index c626122..5e2b63a 100644 --- a/clojure-mode-font-lock-test.el +++ b/clojure-mode-font-lock-test.el @@ -942,6 +942,22 @@ DESCRIPTION is the description of the spec." ("\\ク" (1 2 clojure-character-face))) + (when-fontifying-it "should handle characters not by themselves" + ("[\\,,]" + (1 1 nil) + (2 3 clojure-character-face) + (4 5 nil)) + + ("[\\[]" + (1 1 nil) + (2 3 clojure-character-face) + (4 4 nil))) + + (when-fontifying-it "should handle % character literal" + ("#(str \\% %)" + (7 8 clojure-character-face) + (10 10 font-lock-variable-name-face))) + (when-fontifying-it "should handle referred vars" ("foo/var" (1 3 font-lock-type-face)) From 347dd1f58c7bb3907b9a45dda2e7ae86786c5310 Mon Sep 17 00:00:00 2001 From: Rob Browning Date: Fri, 2 Jul 2021 13:17:39 -0500 Subject: [PATCH 169/199] Mark put-clojure-indent safe for use in .dir-locals.el, etc. Add a put-clojure-indent form validator and attach it as a safe-local-eval-function property so that safe invocations won't trigger open-file prompts when used in local variables, or when added to .dir-locals.el like this: ((clojure-mode (eval . (put-clojure-indent 'defrecord '(2 :form :form (1)))))) For now, only support specs specified as lists, not vectors. --- clojure-mode-safe-eval-test.el | 74 ++++++++++++++++++++++++++++++++++ 1 file changed, 74 insertions(+) create mode 100644 clojure-mode-safe-eval-test.el diff --git a/clojure-mode-safe-eval-test.el b/clojure-mode-safe-eval-test.el new file mode 100644 index 0000000..39c94ed --- /dev/null +++ b/clojure-mode-safe-eval-test.el @@ -0,0 +1,74 @@ +;;; clojure-mode-safe-eval-test.el --- Clojure Mode: safe eval test suite -*- lexical-binding: t; -*- + +;; Copyright (C) 2014-2021 Bozhidar Batsov +;; Copyright (C) 2021 Rob Browning + +;; This file is not part of GNU Emacs. + +;; This program is free software; you can redistribute it and/or modify +;; it under the terms of the GNU General Public License as published by +;; the Free Software Foundation, either version 3 of the License, or +;; (at your option) any later version. + +;; This program is distributed in the hope that it will be useful, +;; but WITHOUT ANY WARRANTY; without even the implied warranty of +;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +;; GNU General Public License for more details. + +;; You should have received a copy of the GNU General Public License +;; along with this program. If not, see . + +;;; Commentary: + +;; The safe eval test suite of Clojure Mode + +;;; Code: +(require 'clojure-mode) +(require 'buttercup) + +(describe "put-clojure-indent safe-local-eval-function property" + (it "should be set to clojure--valid-put-clojure-indent-call-p" + (expect (get 'put-clojure-indent 'safe-local-eval-function) + :to-be 'clojure--valid-put-clojure-indent-call-p))) + +(describe "clojure--valid-put-clojure-indent-call-p" + (it "should approve valid forms" + (expect (clojure--valid-put-clojure-indent-call-p + '(put-clojure-indent 'foo 1))) + (expect (clojure--valid-put-clojure-indent-call-p + '(put-clojure-indent 'foo :defn))) + (expect (clojure--valid-put-clojure-indent-call-p + '(put-clojure-indent 'foo :form))) + (expect (clojure--valid-put-clojure-indent-call-p + '(put-clojure-indent 'foo '(1)))) + (expect (clojure--valid-put-clojure-indent-call-p + '(put-clojure-indent 'foo '(:defn)))) + (expect (clojure--valid-put-clojure-indent-call-p + '(put-clojure-indent 'foo '(:form)))) + (expect (clojure--valid-put-clojure-indent-call-p + '(put-clojure-indent 'foo '(1 1)))) + (expect (clojure--valid-put-clojure-indent-call-p + '(put-clojure-indent 'foo '(2 :form :form (1)))))) + (it "should reject invalid forms" + (expect (clojure--valid-put-clojure-indent-call-p + '(put-clojure-indent 1 1)) + :to-throw 'error) + (expect (clojure--valid-put-clojure-indent-call-p + '(put-clojure-indent 'foo :foo)) + :to-throw 'error) + (expect (clojure--valid-put-clojure-indent-call-p + '(put-clojure-indent 'foo (:defn))) + :to-throw 'error) + (expect (clojure--valid-put-clojure-indent-call-p + '(put-clojure-indent 'foo '(:foo))) + :to-throw 'error) + (expect (clojure--valid-put-clojure-indent-call-p + '(put-clojure-indent 'foo '(1 :foo))) + :to-throw 'error) + (expect (clojure--valid-put-clojure-indent-call-p + '(put-clojure-indent 'foo '(1 "foo"))) + :to-throw 'error))) + +(provide 'clojure-mode-safe-eval-test) + +;;; clojure-mode-safe-eval-test.el ends here From a815ab9afe42c87d33136650954d88cd12c63301 Mon Sep 17 00:00:00 2001 From: Bozhidar Batsov Date: Wed, 10 Nov 2021 11:15:16 +0100 Subject: [PATCH 170/199] Update my email --- clojure-mode-external-interaction-test.el | 2 +- clojure-mode-font-lock-test.el | 2 +- clojure-mode-indentation-test.el | 2 +- clojure-mode-safe-eval-test.el | 2 +- clojure-mode-syntax-test.el | 2 +- clojure-mode-util-test.el | 2 +- utils/test-helper.el | 2 +- 7 files changed, 7 insertions(+), 7 deletions(-) diff --git a/clojure-mode-external-interaction-test.el b/clojure-mode-external-interaction-test.el index f6dba50..f8c8caf 100644 --- a/clojure-mode-external-interaction-test.el +++ b/clojure-mode-external-interaction-test.el @@ -1,6 +1,6 @@ ;;; clojure-mode-external-interaction-test.el --- Clojure Mode interactions with external packages test suite -*- lexical-binding: t; -*- -;; Copyright (C) 2014-2021 Bozhidar Batsov +;; Copyright (C) 2014-2021 Bozhidar Batsov ;; This file is not part of GNU Emacs. diff --git a/clojure-mode-font-lock-test.el b/clojure-mode-font-lock-test.el index 5e2b63a..da9cae2 100644 --- a/clojure-mode-font-lock-test.el +++ b/clojure-mode-font-lock-test.el @@ -1,7 +1,7 @@ ;;; clojure-mode-font-lock-test.el --- Clojure Mode: Font lock test suite ;; -*- lexical-binding: t; -*- -;; Copyright (C) 2014-2021 Bozhidar Batsov +;; Copyright (C) 2014-2021 Bozhidar Batsov ;; This file is not part of GNU Emacs. diff --git a/clojure-mode-indentation-test.el b/clojure-mode-indentation-test.el index 61e4867..c1c918a 100644 --- a/clojure-mode-indentation-test.el +++ b/clojure-mode-indentation-test.el @@ -1,6 +1,6 @@ ;;; clojure-mode-indentation-test.el --- Clojure Mode: indentation tests -*- lexical-binding: t; -*- -;; Copyright (C) 2015-2021 Bozhidar Batsov +;; Copyright (C) 2015-2021 Bozhidar Batsov ;; This file is not part of GNU Emacs. diff --git a/clojure-mode-safe-eval-test.el b/clojure-mode-safe-eval-test.el index 39c94ed..47b7c5b 100644 --- a/clojure-mode-safe-eval-test.el +++ b/clojure-mode-safe-eval-test.el @@ -1,6 +1,6 @@ ;;; clojure-mode-safe-eval-test.el --- Clojure Mode: safe eval test suite -*- lexical-binding: t; -*- -;; Copyright (C) 2014-2021 Bozhidar Batsov +;; Copyright (C) 2014-2021 Bozhidar Batsov ;; Copyright (C) 2021 Rob Browning ;; This file is not part of GNU Emacs. diff --git a/clojure-mode-syntax-test.el b/clojure-mode-syntax-test.el index 174b93e..2b03b04 100644 --- a/clojure-mode-syntax-test.el +++ b/clojure-mode-syntax-test.el @@ -1,6 +1,6 @@ ;;; clojure-mode-syntax-test.el --- Clojure Mode: syntax related tests -*- lexical-binding: t; -*- -;; Copyright (C) 2015-2021 Bozhidar Batsov +;; Copyright (C) 2015-2021 Bozhidar Batsov ;; This file is not part of GNU Emacs. diff --git a/clojure-mode-util-test.el b/clojure-mode-util-test.el index da7aec0..2ff86f2 100644 --- a/clojure-mode-util-test.el +++ b/clojure-mode-util-test.el @@ -1,6 +1,6 @@ ;;; clojure-mode-util-test.el --- Clojure Mode: util test suite -*- lexical-binding: t; -*- -;; Copyright (C) 2014-2021 Bozhidar Batsov +;; Copyright (C) 2014-2021 Bozhidar Batsov ;; This file is not part of GNU Emacs. diff --git a/utils/test-helper.el b/utils/test-helper.el index d822fef..a8fb38d 100644 --- a/utils/test-helper.el +++ b/utils/test-helper.el @@ -1,6 +1,6 @@ ;;; test-helper.el --- Clojure Mode: Non-interactive unit-test setup -*- lexical-binding: t; -*- -;; Copyright (C) 2014-2021 Bozhidar Batsov +;; Copyright (C) 2014-2021 Bozhidar Batsov ;; This file is not part of GNU Emacs. From 748e68504f3212998e397536d39603215c99b559 Mon Sep 17 00:00:00 2001 From: yuhan0 Date: Sat, 20 Nov 2021 03:04:01 +0800 Subject: [PATCH 171/199] Add refactoring command for converting #() shorthand to (fn ...) (#601) --- clojure-mode-promote-fn-literal-test.el | 72 +++++++++++++++++++++++++ 1 file changed, 72 insertions(+) create mode 100644 clojure-mode-promote-fn-literal-test.el diff --git a/clojure-mode-promote-fn-literal-test.el b/clojure-mode-promote-fn-literal-test.el new file mode 100644 index 0000000..07b5dba --- /dev/null +++ b/clojure-mode-promote-fn-literal-test.el @@ -0,0 +1,72 @@ +;;; clojure-mode-promote-fn-literal-test.el --- Clojure Mode: convert fn syntax -*- lexical-binding: t; -*- + +;; This file is not part of GNU Emacs. + +;; This program is free software; you can redistribute it and/or modify +;; it under the terms of the GNU General Public License as published by +;; the Free Software Foundation, either version 3 of the License, or +;; (at your option) any later version. + +;; This program is distributed in the hope that it will be useful, +;; but WITHOUT ANY WARRANTY; without even the implied warranty of +;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +;; GNU General Public License for more details. + +;; You should have received a copy of the GNU General Public License +;; along with this program. If not, see . + +;;; Commentary: + +;; Tests for clojure-promote-fn-literal + +;;; Code: + +(require 'clojure-mode) +(require 'buttercup) + +(describe "clojure-promote-fn-literal" + :var (names) + + (before-each + (spy-on 'read-string + :and-call-fake (lambda (_) (or (pop names) (error ""))))) + + (when-refactoring-it "should convert 0-arg fns" + "#(rand)" + "(fn [] (rand))" + (clojure-promote-fn-literal)) + + (when-refactoring-it "should convert 1-arg fns" + "#(= % 1)" + "(fn [x] (= x 1))" + (setq names '("x")) + (clojure-promote-fn-literal)) + + (when-refactoring-it "should convert 2-arg fns" + "#(conj (pop %) (assoc (peek %1) %2 (* %2 %2)))" + "(fn [acc x] (conj (pop acc) (assoc (peek acc) x (* x x))))" + (setq names '("acc" "x")) + (clojure-promote-fn-literal)) + + (when-refactoring-it "should convert variadic fns" + ;; from https://hypirion.com/musings/swearjure + "#(* (`[~@%&] (+)) + ((% (+)) % (- (`[~@%&] (+)) (*))))" + "(fn [v & vs] (* (`[~@vs] (+)) + ((v (+)) v (- (`[~@vs] (+)) (*)))))" + (setq names '("v" "vs")) + (clojure-promote-fn-literal)) + + (when-refactoring-it "should ignore strings and comments" + "#(format \"%2\" ;; FIXME: %2 is an illegal specifier + %7) " + "(fn [_ _ _ _ _ _ id] (format \"%2\" ;; FIXME: %2 is an illegal specifier + id)) " + (setq names '("_" "_" "_" "_" "_" "_" "id")) + (clojure-promote-fn-literal))) + + +(provide 'clojure-mode-convert-fn-test) + + +;;; clojure-mode-promote-fn-literal-test.el ends here From c1ae4bed355516701d2d6ca7e8e285625bb8ef2d Mon Sep 17 00:00:00 2001 From: Bozhidar Batsov Date: Thu, 30 Dec 2021 10:17:37 +0200 Subject: [PATCH 172/199] Address some byte-compilation warnings Thanks for the patch, Stefan! --- clojure-mode-bytecomp-warnings.el | 2 +- clojure-mode-external-interaction-test.el | 1 + clojure-mode-font-lock-test.el | 3 ++- clojure-mode-indentation-test.el | 5 +++-- clojure-mode-promote-fn-literal-test.el | 1 + clojure-mode-syntax-test.el | 2 ++ clojure-mode-util-test.el | 8 +++++--- test-checks.el | 2 +- utils/test-helper.el | 2 ++ 9 files changed, 18 insertions(+), 8 deletions(-) diff --git a/clojure-mode-bytecomp-warnings.el b/clojure-mode-bytecomp-warnings.el index d3cc19a..2b94d07 100644 --- a/clojure-mode-bytecomp-warnings.el +++ b/clojure-mode-bytecomp-warnings.el @@ -1,4 +1,4 @@ -;;; clojure-mode-bytecomp-warnings.el --- Check for byte-compilation problems +;;; clojure-mode-bytecomp-warnings.el --- Check for byte-compilation problems -*- lexical-binding: t; -*- ;; Copyright © 2012-2021 Bozhidar Batsov and contributors ;; diff --git a/clojure-mode-external-interaction-test.el b/clojure-mode-external-interaction-test.el index f8c8caf..da038e5 100644 --- a/clojure-mode-external-interaction-test.el +++ b/clojure-mode-external-interaction-test.el @@ -22,6 +22,7 @@ (require 'clojure-mode) (require 'buttercup) (require 'paredit) +(require 'test-helper "test/utils/test-helper") (describe "Interactions with Paredit:" ;; reuse existing when-refactoring-it macro diff --git a/clojure-mode-font-lock-test.el b/clojure-mode-font-lock-test.el index da9cae2..b3687aa 100644 --- a/clojure-mode-font-lock-test.el +++ b/clojure-mode-font-lock-test.el @@ -27,6 +27,7 @@ (require 'clojure-mode) (require 'cl-lib) (require 'buttercup) +(require 'test-helper "test/utils/test-helper") ;;;; Utilities @@ -36,7 +37,7 @@ (declare (debug t) (indent 1)) `(with-clojure-buffer ,content - (font-lock-fontify-buffer) + (font-lock-ensure) (goto-char (point-min)) ,@body)) diff --git a/clojure-mode-indentation-test.el b/clojure-mode-indentation-test.el index c1c918a..9c12b9a 100644 --- a/clojure-mode-indentation-test.el +++ b/clojure-mode-indentation-test.el @@ -26,7 +26,8 @@ (require 'clojure-mode) (require 'cl-lib) (require 'buttercup) -(require 's) +(require 's nil t) ;Don't burp if it's missing during compilation. +(require 'test-helper "test/utils/test-helper") (defmacro when-indenting-with-point-it (description before after) "Return a buttercup spec. @@ -279,7 +280,7 @@ DESCRIPTION is a string with the description of the spec." one)")) (describe "we can pass a lambda to explicitly set the column" - (put-clojure-indent 'arsymbol (lambda (indent-point state) 0)) + (put-clojure-indent 'arsymbol (lambda (_indent-point _state) 0)) (when-indenting-with-point-it "should handle a symbol with lambda" " diff --git a/clojure-mode-promote-fn-literal-test.el b/clojure-mode-promote-fn-literal-test.el index 07b5dba..194e493 100644 --- a/clojure-mode-promote-fn-literal-test.el +++ b/clojure-mode-promote-fn-literal-test.el @@ -23,6 +23,7 @@ (require 'clojure-mode) (require 'buttercup) +(require 'test-helper "test/utils/test-helper") (describe "clojure-promote-fn-literal" :var (names) diff --git a/clojure-mode-syntax-test.el b/clojure-mode-syntax-test.el index 2b03b04..bc71eaa 100644 --- a/clojure-mode-syntax-test.el +++ b/clojure-mode-syntax-test.el @@ -25,6 +25,7 @@ (require 'clojure-mode) (require 'buttercup) +(require 'test-helper "test/utils/test-helper") (defun non-func (form-a form-b) (with-clojure-buffer form-a @@ -66,6 +67,7 @@ ("#aaa" . "aaa") ("'aaa" . "aaa"))) (with-clojure-buffer (car form) + ;; FIXME: Shouldn't there be an `expect' here? (equal (symbol-name (symbol-at-point)) (cdr form))))) (it "skips prefixes" diff --git a/clojure-mode-util-test.el b/clojure-mode-util-test.el index 2ff86f2..95931d9 100644 --- a/clojure-mode-util-test.el +++ b/clojure-mode-util-test.el @@ -25,12 +25,14 @@ (require 'clojure-mode) (require 'cl-lib) (require 'buttercup) - +(require 'test-helper "test/utils/test-helper") (describe "clojure-mode-version" (it "should not be nil" (expect clojure-mode-version))) +(defvar clojure-cache-project) + (let ((project-dir "/home/user/projects/my-project/") (clj-file-path "/home/user/projects/my-project/src/clj/my_project/my_ns/my_file.clj") (project-relative-clj-file-path "src/clj/my_project/my_ns/my_file.clj") @@ -45,13 +47,13 @@ (describe "clojure-expected-ns" (it "should return the namespace matching a path" (cl-letf (((symbol-function 'clojure-project-relative-path) - (lambda (&optional current-buffer-file-name) + (lambda (&optional _current-buffer-file-name) project-relative-clj-file-path))) (expect (string= (clojure-expected-ns clj-file-path) clj-file-ns)))) (it "should return the namespace even without a path" (cl-letf (((symbol-function 'clojure-project-relative-path) - (lambda (&optional current-buffer-file-name) + (lambda (&optional _current-buffer-file-name) project-relative-clj-file-path))) (expect (string= (let ((buffer-file-name clj-file-path)) (clojure-expected-ns)) diff --git a/test-checks.el b/test-checks.el index ad23c36..a4b4208 100644 --- a/test-checks.el +++ b/test-checks.el @@ -1,4 +1,4 @@ -;; This is a script to be loaded from the root `clojure-mode' directory. It will +;; This is a script to be loaded from the root `clojure-mode' directory. It will -*- lexical-binding: t; -*- ;; prepare all requirements and then run `check-declare-directory' on ;; `default-directory'. For example: emacs -Q --batch -l test/test-checkdoc.el diff --git a/utils/test-helper.el b/utils/test-helper.el index a8fb38d..fd3db30 100644 --- a/utils/test-helper.el +++ b/utils/test-helper.el @@ -95,4 +95,6 @@ DESCRIPTION is a string with the description of the spec." (expect (buffer-string) :to-equal expected-state) (expect (point) :to-equal expected-cursor-pos))))) + +(provide 'test-helper) ;;; test-helper.el ends here From 1f87e5c6c375084df9e954348af4a43052fd507d Mon Sep 17 00:00:00 2001 From: Sam Waggoner Date: Sun, 23 Jan 2022 11:58:06 -0800 Subject: [PATCH 173/199] [Fix #608] Fix alignment issue involving margin comments. Alignment wasn't working properly when nested, multi-line sexps were followed by margin comments. --- clojure-mode-indentation-test.el | 37 ++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/clojure-mode-indentation-test.el b/clojure-mode-indentation-test.el index 9c12b9a..91a9dcb 100644 --- a/clojure-mode-indentation-test.el +++ b/clojure-mode-indentation-test.el @@ -705,6 +705,43 @@ x "#?@(:clj [2] :cljs [2])") + (when-aligning-it "should handle sexps broken up by line comments" + " +(let [x 1 + ;; comment + xx 1] + xx)" + + " +{:x 1 + ;; comment + :xxx 2}" + + " +(case x + :aa 1 + ;; comment + :a 2)") + + (when-aligning-it "should work correctly when margin comments appear after nested, multi-line, non-terminal sexps" + " +(let [x {:a 1 + :b 2} ; comment + xx 3] + x)" + + " +{:aa {:b 1 + :cc 2} ;; comment + :a 1}}" + + " +(case x + :a (let [a 1 + aa (+ a 1)] + aa); comment + :aa 2)") + (it "should handle improperly indented content" (let ((content "(let [a-long-name 10\nb 20])") (aligned-content "(let [a-long-name 10\n b 20])")) From 17ecddbc0cffc81c725e42aa3282632ce2b2cab0 Mon Sep 17 00:00:00 2001 From: Sam Waggoner Date: Thu, 3 Feb 2022 22:09:33 -0800 Subject: [PATCH 174/199] Update indentation tests for consistent style. Begin multi-line example strings with a newline so that the indentation of the first line in relation to the rest of the string is plain to see. --- clojure-mode-indentation-test.el | 201 ++++++++++++++++++++----------- 1 file changed, 134 insertions(+), 67 deletions(-) diff --git a/clojure-mode-indentation-test.el b/clojure-mode-indentation-test.el index 91a9dcb..ac9485e 100644 --- a/clojure-mode-indentation-test.el +++ b/clojure-mode-indentation-test.el @@ -327,43 +327,51 @@ DESCRIPTION is a string with the description of the spec." :a)") (when-indenting-with-point-it "should handle fixed-normal-indent" - "(cond + " + (cond (or 1 2) 3 |:else 4)" - "(cond + " + (cond (or 1 2) 3 |:else 4)") (when-indenting-with-point-it "should handle fixed-normal-indent-2" - "(fact {:spec-type + " +(fact {:spec-type :charnock-column-id} #{\"charnock\"} |{:spec-type :charnock-column-id} #{\"current_charnock\"})" - "(fact {:spec-type + " +(fact {:spec-type :charnock-column-id} #{\"charnock\"} |{:spec-type :charnock-column-id} #{\"current_charnock\"})") (when-indenting-it "closing-paren" - "(ns ca + " +(ns ca (:gen-class) )") (when-indenting-it "default-is-not-a-define" - "(default a + " +(default a b b)" - "(some.namespace/default a + " +(some.namespace/default a b b)") (when-indenting-it "should handle extend-type with multiarity" - "(extend-type Banana + " +(extend-type Banana Fruit (subtotal ([item] @@ -371,7 +379,8 @@ DESCRIPTION is a string with the description of the spec." ([item a] (* a (:qty item)))))" - "(extend-protocol Banana + " +(extend-protocol Banana Fruit (subtotal ([item] @@ -381,7 +390,8 @@ DESCRIPTION is a string with the description of the spec." (when-indenting-it "should handle deftype with multiarity" - "(deftype Banana [] + " +(deftype Banana [] Fruit (subtotal ([item] @@ -390,7 +400,8 @@ DESCRIPTION is a string with the description of the spec." (* a (:qty item)))))") (when-indenting-it "should handle defprotocol" - "(defprotocol IFoo + " +(defprotocol IFoo (foo [this] \"Why is this over here?\") (foo-2 @@ -399,7 +410,8 @@ DESCRIPTION is a string with the description of the spec." (when-indenting-it "should handle definterface" - "(definterface IFoo + " +(definterface IFoo (foo [this] \"Why is this over here?\") (foo-2 @@ -407,7 +419,8 @@ DESCRIPTION is a string with the description of the spec." \"Why is this over here?\"))") (when-indenting-it "should handle specify" - "(specify obj + " +(specify obj ISwap (-swap! ([this f] (reset! this (f @this))) @@ -416,7 +429,8 @@ DESCRIPTION is a string with the description of the spec." ([this f a b xs] (reset! this (apply f @this a b xs)))))") (when-indenting-it "should handle specify!" - "(specify! obj + " +(specify! obj ISwap (-swap! ([this f] (reset! this (f @this))) @@ -425,27 +439,32 @@ DESCRIPTION is a string with the description of the spec." ([this f a b xs] (reset! this (apply f @this a b xs)))))") (when-indenting-it "should handle non-symbol at start" - "{\"1\" 2 + " +{\"1\" 2 *3 4}") (when-indenting-it "should handle non-symbol at start 2" - "(\"1\" 2 + " +(\"1\" 2 *3 4)") (when-indenting-it "should handle defrecord" - "(defrecord TheNameOfTheRecord + " +(defrecord TheNameOfTheRecord [a pretty long argument list] SomeType (assoc [_ x] (.assoc pretty x 10)))") (when-indenting-it "should handle defrecord 2" - "(defrecord TheNameOfTheRecord [a pretty long argument list] + " +(defrecord TheNameOfTheRecord [a pretty long argument list] SomeType (assoc [_ x] (.assoc pretty x 10)))") (when-indenting-it "should handle defrecord with multiarity" - "(defrecord Banana [] + " +(defrecord Banana [] Fruit (subtotal ([item] @@ -454,7 +473,8 @@ DESCRIPTION is a string with the description of the spec." (* a (:qty item)))))") (when-indenting-it "should handle letfn" - "(letfn [(f [x] + " +(letfn [(f [x] (* x 2)) (f [x] (* x 2))] @@ -463,11 +483,13 @@ DESCRIPTION is a string with the description of the spec." e)") (when-indenting-it "should handle reify" - "(reify Object + " +(reify Object (x [_] 1))" - "(reify + " +(reify om/IRender (render [this] (let [indent-test :fail] @@ -478,7 +500,8 @@ DESCRIPTION is a string with the description of the spec." ...)))") (when-indenting-it "proxy" - "(proxy [Writer] [] + " +(proxy [Writer] [] (close [] (.flush ^Writer this)) (write ([x] @@ -496,29 +519,36 @@ DESCRIPTION is a string with the description of the spec." :cljs [])") (when-indenting-it "should handle an empty close paren" - "(let [x] + " +(let [x] )" - "(ns ok + " +(ns ok )" - "(ns ^{:zen :dikar} + " +(ns ^{:zen :dikar} ok )") (when-indenting-it "should handle unfinished sexps" - "(letfn [(tw [x] + " +(letfn [(tw [x] dd") (when-indenting-it "should handle symbols ending in crap" - "(msg? ExceptionInfo + " +(msg? ExceptionInfo 10)" - "(thrown-with-msg? ExceptionInfo + " +(thrown-with-msg? ExceptionInfo #\"Storage must be initialized before use\" (f))" - "(msg' 1 + " +(msg' 1 10)") (when-indenting-it "should handle let, when and while forms" @@ -553,14 +583,16 @@ DESCRIPTION is a string with the description of the spec." (when-indenting-it "should handle function spec" - "(when me + " +(when me (test-cond x 1 2 3))" - "(when me + " +(when me (test-cond-0 x 1 @@ -570,139 +602,174 @@ x (when-indenting-it "should respect indent style 'align-arguments" 'align-arguments - "(some-function + " +(some-function 10 1 2)" - "(some-function 10 + " +(some-function 10 1 2)") (when-indenting-it "should respect indent style 'always-indent" 'always-indent - "(some-function + " +(some-function 10 1 2)" - "(some-function 10 + " +(some-function 10 1 2)") (when-aligning-it "should basic forms" - "{:this-is-a-form b + " +{:this-is-a-form b c d}" - "{:this-is b + " +{:this-is b c d}" - "{:this b + " +{:this b c d}" - "{:a b + " +{:a b c d}" - "(let [this-is-a-form b + " +(let [this-is-a-form b c d])" - "(let [this-is b + " +(let [this-is b c d])" - "(let [this b + " +(let [this b c d])" - "(let [a b + " +(let [a b c d])") (when-aligning-it "should handle a blank line" - "(let [this-is-a-form b + " +(let [this-is-a-form b c d another form k g])" - "{:this-is-a-form b + " +{:this-is-a-form b c d :another form k g}") (when-aligning-it "should handle basic forms (reversed)" - "{c d + " +{c d :this-is-a-form b}" - "{c d + " +{c d :this-is b}" - "{c d + " +{c d :this b}" - "{c d + " +{c d :a b}" - "(let [c d + " +(let [c d this-is-a-form b])" - "(let [c d + " +(let [c d this-is b])" - "(let [c d + " +(let [c d this b])" - "(let [c d + " +(let [c d a b])") (when-aligning-it "should handle incomplete sexps" - "(cond aa b + " +(cond aa b casodkas )" - "(cond aa b + " +(cond aa b casodkas)" - "(cond aa b + " +(cond aa b casodkas " - "(cond aa b + " +(cond aa b casodkas" - "(cond aa b + " +(cond aa b casodkas a)" - "(cond casodkas a + " +(cond casodkas a aa b)" - "(cond casodkas + " +(cond casodkas aa b)") (when-aligning-it "should handle multiple words" - "(cond this is just + " +(cond this is just a test of how well multiple words will work)") (when-aligning-it "should handle nested maps" - "{:a {:a :a + " +{:a {:a :a :bbbb :b} :bbbb :b}") (when-aligning-it "should regard end as a marker" - "{:a {:a :a + " +{:a {:a :a :aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa :a} :b {:a :a :aa :a}}") (when-aligning-it "should handle trailing commas" - "{:a {:a :a, + " +{:a {:a :a, :aa :a}, :b {:a :a, :aa :a}}") (when-aligning-it "should handle standard reader conditionals" - "#?(:clj 2 + " +#?(:clj 2 :cljs 2)") (when-aligning-it "should handle splicing reader conditional" - "#?@(:clj [2] + " +#?@(:clj [2] :cljs [2])") (when-aligning-it "should handle sexps broken up by line comments" From aae566e578f4e7e8230f97ac5b7c38216c683203 Mon Sep 17 00:00:00 2001 From: Vadim <47952597+OknoLombarda@users.noreply.github.com> Date: Tue, 19 Jul 2022 23:09:05 +0600 Subject: [PATCH 175/199] Fix infinite loop when reverse searching for next definition (#624) Fixes #595 Fixes #612 --- clojure-mode-syntax-test.el | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/clojure-mode-syntax-test.el b/clojure-mode-syntax-test.el index bc71eaa..8ac8938 100644 --- a/clojure-mode-syntax-test.el +++ b/clojure-mode-syntax-test.el @@ -60,6 +60,37 @@ (expect (non-func "^hint " form) :to-be nil) (expect (non-func "#macro " form) :to-be nil)))) +(describe "clojure-match-next-def" + (let ((some-sexp "\n(list [1 2 3])")) + (it "handles vars with metadata" + (dolist (form '("(def ^Integer a 1)" + "(def ^:a a 1)" + "(def ^::a a 1)" + "(def ^::a/b a 1)" + "(def ^{:macro true} a 1)")) + (with-clojure-buffer (concat form some-sexp) + (end-of-buffer) + (clojure-match-next-def) + (expect (looking-at "(def"))))) + + (it "handles vars without metadata" + (with-clojure-buffer (concat "(def a 1)" some-sexp) + (end-of-buffer) + (clojure-match-next-def) + (expect (looking-at "(def")))) + + (it "handles invalid def forms" + (dolist (form '("(def ^Integer)" + "(def)" + "(def ^{:macro})" + "(def ^{:macro true})" + "(def ^{:macro true} foo)" + "(def ^{:macro} foo)")) + (with-clojure-buffer (concat form some-sexp) + (end-of-buffer) + (clojure-match-next-def) + (expect (looking-at "(def"))))))) + (describe "clojure syntax" (it "handles prefixed symbols" (dolist (form '(("#?@aaa" . "aaa") From 372787359fb629f82fff511a496ee83ebb936792 Mon Sep 17 00:00:00 2001 From: Vadim <47952597+OknoLombarda@users.noreply.github.com> Date: Fri, 29 Jul 2022 14:11:59 +0600 Subject: [PATCH 176/199] [Fix #625] Fix imenu displaying metadata instead of var name (#626) Fix metadata being captured instead of var name in clojure-match-next-def. Co-authored-by: Vadim Rodionov --- clojure-mode-syntax-test.el | 26 +++++++++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) diff --git a/clojure-mode-syntax-test.el b/clojure-mode-syntax-test.el index 8ac8938..1766e14 100644 --- a/clojure-mode-syntax-test.el +++ b/clojure-mode-syntax-test.el @@ -89,7 +89,31 @@ (with-clojure-buffer (concat form some-sexp) (end-of-buffer) (clojure-match-next-def) - (expect (looking-at "(def"))))))) + (expect (looking-at "(def")))))) + + (it "captures var name" + (let ((var-name "some-name")) + (dolist (form '("(def %s 1)" + "(def %s)" + "(def ^:private %s 2)" + "(def ^{:private true} %s 3)")) + (with-clojure-buffer (format form var-name) + (end-of-buffer) + (clojure-match-next-def) + (cl-destructuring-bind (name-beg name-end) (match-data) + (expect (string= var-name (buffer-substring name-beg name-end)))))))) + + (it "captures var name with dispatch value for defmethod" + (let ((name "some-name :key")) + (dolist (form '("(defmethod %s [a])" + "(defmethod ^:meta %s [a])" + "(defmethod ^{:meta true} %s [a])" + "(defmethod %s)")) + (with-clojure-buffer (format form name) + (end-of-buffer) + (clojure-match-next-def) + (cl-destructuring-bind (name-beg name-end) (match-data) + (expect (string= name (buffer-substring name-beg name-end))))))))) (describe "clojure syntax" (it "handles prefixed symbols" From 016c7b22af6f00f2b89287fd00dde331d4cbfd95 Mon Sep 17 00:00:00 2001 From: Vadim <47952597+OknoLombarda@users.noreply.github.com> Date: Fri, 29 Jul 2022 15:33:43 +0600 Subject: [PATCH 177/199] Use constant values instead of variables in clojure-match-next-def tests (#627) --- clojure-mode-syntax-test.el | 38 ++++++++++++++++++------------------- 1 file changed, 18 insertions(+), 20 deletions(-) diff --git a/clojure-mode-syntax-test.el b/clojure-mode-syntax-test.el index 1766e14..934af5e 100644 --- a/clojure-mode-syntax-test.el +++ b/clojure-mode-syntax-test.el @@ -92,28 +92,26 @@ (expect (looking-at "(def")))))) (it "captures var name" - (let ((var-name "some-name")) - (dolist (form '("(def %s 1)" - "(def %s)" - "(def ^:private %s 2)" - "(def ^{:private true} %s 3)")) - (with-clojure-buffer (format form var-name) - (end-of-buffer) - (clojure-match-next-def) - (cl-destructuring-bind (name-beg name-end) (match-data) - (expect (string= var-name (buffer-substring name-beg name-end)))))))) + (dolist (form '("(def some-name 1)" + "(def some-name)" + "(def ^:private some-name 2)" + "(def ^{:private true} some-name 3)")) + (with-clojure-buffer form + (end-of-buffer) + (clojure-match-next-def) + (cl-destructuring-bind (name-beg name-end) (match-data) + (expect (string= "some-name" (buffer-substring name-beg name-end))))))) (it "captures var name with dispatch value for defmethod" - (let ((name "some-name :key")) - (dolist (form '("(defmethod %s [a])" - "(defmethod ^:meta %s [a])" - "(defmethod ^{:meta true} %s [a])" - "(defmethod %s)")) - (with-clojure-buffer (format form name) - (end-of-buffer) - (clojure-match-next-def) - (cl-destructuring-bind (name-beg name-end) (match-data) - (expect (string= name (buffer-substring name-beg name-end))))))))) + (dolist (form '("(defmethod some-name :key [a])" + "(defmethod ^:meta some-name :key [a])" + "(defmethod ^{:meta true} some-name :key [a])" + "(defmethod some-name :key)")) + (with-clojure-buffer form + (end-of-buffer) + (clojure-match-next-def) + (cl-destructuring-bind (name-beg name-end) (match-data) + (expect (string= "some-name :key" (buffer-substring name-beg name-end)))))))) (describe "clojure syntax" (it "handles prefixed symbols" From 123e569b99506d232b36037d4d1bb54dbebed379 Mon Sep 17 00:00:00 2001 From: Vadim Rodionov <47952597+OknoLombarda@users.noreply.github.com> Date: Wed, 24 Aug 2022 23:06:51 +0600 Subject: [PATCH 178/199] [Fix #581] Fix font locking for keywords starting with a number (#628) --- clojure-mode-font-lock-test.el | 25 +++++++++++++++++++++++-- 1 file changed, 23 insertions(+), 2 deletions(-) diff --git a/clojure-mode-font-lock-test.el b/clojure-mode-font-lock-test.el index b3687aa..c8304a0 100644 --- a/clojure-mode-font-lock-test.el +++ b/clojure-mode-font-lock-test.el @@ -487,11 +487,17 @@ DESCRIPTION is the description of the spec." (when-fontifying-it "should handle oneword keywords" (" :oneword" - (3 9 clojure-keyword-face )) + (3 9 clojure-keyword-face)) + + (" :1oneword" + (3 10 clojure-keyword-face)) ("{:oneword 0}" (3 9 clojure-keyword-face)) + ("{:1oneword 0}" + (3 10 clojure-keyword-face)) + ("{:#oneword 0}" (3 10 clojure-keyword-face)) @@ -563,7 +569,22 @@ DESCRIPTION is the description of the spec." (10 17 clojure-keyword-face)) (":_:_:foo/bar_:_:foo" - (10 19 clojure-keyword-face))) + (10 19 clojure-keyword-face)) + + (":1foo/bar" + (2 5 font-lock-type-face) + (6 6 default) + (7 9 clojure-keyword-face)) + + (":foo/1bar" + (2 4 font-lock-type-face) + (5 5 default) + (6 9 clojure-keyword-face)) + + (":1foo/1bar" + (2 5 font-lock-type-face) + (6 6 default) + (7 10 clojure-keyword-face))) (when-fontifying-it "should handle segment keywords" (" :seg.mnt" From 264c40ecf2a6b66d6b1097942b861ffa98e4bc08 Mon Sep 17 00:00:00 2001 From: Vadim Rodionov <47952597+OknoLombarda@users.noreply.github.com> Date: Tue, 30 Aug 2022 16:36:45 +0600 Subject: [PATCH 179/199] [Fix #377] Fix font locking for def forms (#630) --- clojure-mode-font-lock-test.el | 56 ++++++++++++++++++++-------------- 1 file changed, 33 insertions(+), 23 deletions(-) diff --git a/clojure-mode-font-lock-test.el b/clojure-mode-font-lock-test.el index c8304a0..cd4f21f 100644 --- a/clojure-mode-font-lock-test.el +++ b/clojure-mode-font-lock-test.el @@ -776,17 +776,17 @@ DESCRIPTION is the description of the spec." (6 42 clojure-keyword-face))) (when-fontifying-it "should handle namespaced defs" - ("(_c4/defconstrainedfn bar [] nil)" + ("(_c4/defn bar [] nil)" (2 4 font-lock-type-face) (5 5 nil) - (6 18 font-lock-keyword-face) - (23 25 font-lock-function-name-face)) + (6 9 font-lock-keyword-face) + (11 13 font-lock-function-name-face)) - ("(clo/defbar foo nil)" + ("(clo/defrecord foo nil)" (2 4 font-lock-type-face) (5 5 nil) - (6 11 font-lock-keyword-face) - (13 15 font-lock-function-name-face)) + (6 14 font-lock-keyword-face) + (16 18 font-lock-function-name-face)) ("(s/def ::keyword)" (2 2 font-lock-type-face) @@ -794,6 +794,33 @@ DESCRIPTION is the description of the spec." (4 6 font-lock-keyword-face) (8 16 clojure-keyword-face))) + (when-fontifying-it "should handle any known def form" + ("(def a 1)" (2 4 font-lock-keyword-face)) + ("(defonce a 1)" (2 8 font-lock-keyword-face)) + ("(defn a [b])" (2 5 font-lock-keyword-face)) + ("(defmacro a [b])" (2 9 font-lock-keyword-face)) + ("(definline a [b])" (2 10 font-lock-keyword-face)) + ("(defmulti a identity)" (2 9 font-lock-keyword-face)) + ("(defmethod a :foo [b] (println \"bar\"))" (2 10 font-lock-keyword-face)) + ("(defprotocol a (b [this] \"that\"))" (2 12 font-lock-keyword-face)) + ("(definterface a (b [c]))" (2 13 font-lock-keyword-face)) + ("(defrecord a [b c])" (2 10 font-lock-keyword-face)) + ("(deftype a [b c])" (2 8 font-lock-keyword-face)) + ("(defstruct a :b :c)" (2 10 font-lock-keyword-face)) + ("(deftest a (is (= 1 1)))" (2 8 font-lock-keyword-face)) + ("(defne [x y])" (2 6 font-lock-keyword-face)) + ("(defnm a b)" (2 6 font-lock-keyword-face)) + ("(defnu)" (2 6 font-lock-keyword-face)) + ("(defnc [a])" (2 6 font-lock-keyword-face)) + ("(defna)" (2 6 font-lock-keyword-face)) + ("(deftask a)" (2 8 font-lock-keyword-face)) + ("(defstate a :start \"b\" :stop \"c\")" (2 9 font-lock-keyword-face))) + + (when-fontifying-it "should ignore unknown def forms" + ("(defbugproducer me)" (2 15 nil)) + ("(default-user-settings {:a 1})" (2 24 nil)) + ("(s/deftartar :foo)" (4 10 nil))) + (when-fontifying-it "should handle variables defined with def" ("(def foo 10)" (2 4 font-lock-keyword-face) @@ -845,23 +872,6 @@ DESCRIPTION is the description of the spec." (2 5 font-lock-keyword-face) (7 9 font-lock-function-name-face))) - (when-fontifying-it "should handle a custom def with special chars 1" - ("(defn* foo [x] x)" - (2 6 font-lock-keyword-face) - (8 10 font-lock-function-name-face))) - - (when-fontifying-it "should handle a custom def with special chars 2" - ("(defsomething! foo [x] x)" - (2 14 font-lock-keyword-face) - (16 18 font-lock-function-name-face))) - - (when-fontifying-it "should handle a custom def with special chars 3" - ("(def-something foo [x] x)" - (2 14 font-lock-keyword-face)) - - ("(def-something foo [x] x)" - (16 18 font-lock-function-name-face))) - (when-fontifying-it "should handle fn" ;; try to byte-recompile the clojure-mode.el when the face of 'fn' is 't' ("(fn foo [x] x)" From b41b92efac3535d107ad948cabafb16effcb1279 Mon Sep 17 00:00:00 2001 From: Vadim Rodionov Date: Sat, 3 Sep 2022 14:59:02 +0600 Subject: [PATCH 180/199] Make function definition regexp only look for 'clojure.core/defn' forms --- clojure-mode-font-lock-test.el | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/clojure-mode-font-lock-test.el b/clojure-mode-font-lock-test.el index cd4f21f..4a7877b 100644 --- a/clojure-mode-font-lock-test.el +++ b/clojure-mode-font-lock-test.el @@ -776,17 +776,17 @@ DESCRIPTION is the description of the spec." (6 42 clojure-keyword-face))) (when-fontifying-it "should handle namespaced defs" - ("(_c4/defn bar [] nil)" - (2 4 font-lock-type-face) - (5 5 nil) - (6 9 font-lock-keyword-face) - (11 13 font-lock-function-name-face)) - - ("(clo/defrecord foo nil)" - (2 4 font-lock-type-face) - (5 5 nil) - (6 14 font-lock-keyword-face) - (16 18 font-lock-function-name-face)) + ("(clojure.core/defn bar [] nil)" + (2 13 font-lock-type-face) + (14 14 nil) + (15 18 font-lock-keyword-face) + (20 22 font-lock-function-name-face)) + + ("(clojure.core/defrecord foo nil)" + (2 13 font-lock-type-face) + (14 14 nil) + (15 23 font-lock-keyword-face) + (25 27 font-lock-type-face)) ("(s/def ::keyword)" (2 2 font-lock-type-face) From 0d5ce21d16e1fd38b475a3d1f753df336364e685 Mon Sep 17 00:00:00 2001 From: chaos Date: Sat, 3 Dec 2022 13:49:08 +0000 Subject: [PATCH 181/199] Nbb support --- clojure-mode-util-test.el | 10 ++++++++++ utils/test-helper.el | 10 ++++++++++ 2 files changed, 20 insertions(+) diff --git a/clojure-mode-util-test.el b/clojure-mode-util-test.el index 95931d9..bf17d02 100644 --- a/clojure-mode-util-test.el +++ b/clojure-mode-util-test.el @@ -39,6 +39,16 @@ (clj-file-ns "my-project.my-ns.my-file") (clojure-cache-project nil)) + (describe "clojure-project-root-path" + (it "nbb subdir" + (with-temp-dir temp-dir + (let* ((bb-edn (expand-file-name "nbb.edn" temp-dir)) + (bb-edn-src (expand-file-name "src" temp-dir))) + (write-region "{}" nil bb-edn) + (make-directory bb-edn-src) + (expect (clojure-project-dir bb-edn-src) + :to-equal (file-name-as-directory temp-dir)))))) + (describe "clojure-project-relative-path" (cl-letf (((symbol-function 'clojure-project-dir) (lambda () project-dir))) (expect (string= (clojure-project-relative-path clj-file-path) diff --git a/utils/test-helper.el b/utils/test-helper.el index fd3db30..c8dfed8 100644 --- a/utils/test-helper.el +++ b/utils/test-helper.el @@ -96,5 +96,15 @@ DESCRIPTION is a string with the description of the spec." (expect (point) :to-equal expected-cursor-pos))))) +;; https://emacs.stackexchange.com/a/55031 +(defmacro with-temp-dir (temp-dir &rest body) + "Create a temporary directory and bind its to TEMP-DIR while evaluating BODY. +Removes the temp directory at the end of evaluation." + `(let ((,temp-dir (make-temp-file "" t))) + (unwind-protect + (progn + ,@body) + (delete-directory ,temp-dir t)))) + (provide 'test-helper) ;;; test-helper.el ends here From f5bc38bc915febf399b35fe7574ff2197de6e134 Mon Sep 17 00:00:00 2001 From: Vadim Rodionov <47952597+OknoLombarda@users.noreply.github.com> Date: Sat, 24 Jun 2023 02:48:42 +0600 Subject: [PATCH 182/199] Fix infinite loop when opening file containing "comment" (#651) Closes #586 --- clojure-mode-sexp-test.el | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/clojure-mode-sexp-test.el b/clojure-mode-sexp-test.el index de4bea7..f82552a 100644 --- a/clojure-mode-sexp-test.el +++ b/clojure-mode-sexp-test.el @@ -169,6 +169,24 @@ (goto-char (point-max)) (expect (clojure-find-ns) :to-equal expected))))))) +(describe "clojure-sexp-starts-until-position" + (it "should return starting points for forms after POINT until POSITION" + (with-clojure-buffer "(run 1) (def b 2) (slurp \"file\")\n" + (goto-char (point-min)) + (expect (not (cl-set-difference '(19 9 1) + (clojure-sexp-starts-until-position (point-max))))))) + + (it "should return starting point for a single form in buffer after POINT" + (with-clojure-buffer "comment\n" + (goto-char (point-min)) + (expect (not (cl-set-difference '(1) + (clojure-sexp-starts-until-position (point-max))))))) + + (it "should return nil if POSITION is behind POINT" + (with-clojure-buffer "(run 1) (def b 2)\n" + (goto-char (point-max)) + (expect (not (clojure-sexp-starts-until-position (- (point-max) 1))))))) + (provide 'clojure-mode-sexp-test) ;;; clojure-mode-sexp-test.el ends here From 6be228ea99f78586ec96291319c9c8fd7b4a86b6 Mon Sep 17 00:00:00 2001 From: p4v4n Date: Sun, 25 Jun 2023 00:27:54 +0530 Subject: [PATCH 183/199] Fix clojure-sort-ns with comments in the end (#646) Closes #645 --- clojure-mode-util-test.el | 44 ++++++++++++++++++++++++++++++++++++++- 1 file changed, 43 insertions(+), 1 deletion(-) diff --git a/clojure-mode-util-test.el b/clojure-mode-util-test.el index bf17d02..353f0e5 100644 --- a/clojure-mode-util-test.el +++ b/clojure-mode-util-test.el @@ -136,7 +136,49 @@ (expect (buffer-string) :to-equal "(ns my-app.core (:require [my-app.views [user-page :as user-page]] - [rum.core :as rum] ;comment\n))"))) + [rum.core :as rum] ;comment +))"))) + + (it "should sort requires in a basic ns with comments in the end" + (with-clojure-buffer "(ns my-app.core + (:require [rum.core :as rum] ;comment + [my-app.views [user-page :as user-page]] + ;;[comment2] +))" + (clojure-sort-ns) + (expect (buffer-string) :to-equal + "(ns my-app.core + (:require [my-app.views [user-page :as user-page]] + [rum.core :as rum] ;comment + + ;;[comment2] +))"))) + (it "should sort requires in ns with copyright disclamer and comments" + (with-clojure-buffer ";; Copyright (c) John Doe. All rights reserved. +;; The use and distribution terms for this software are covered by the +;; Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php) +(ns clojure.core + (:require + ;; The first comment + [foo] ;; foo comment + ;; Middle comment + [bar] ;; bar comment + ;; A last comment + ))" + (clojure-sort-ns) + (expect (buffer-string) :to-equal + ";; Copyright (c) John Doe. All rights reserved. +;; The use and distribution terms for this software are covered by the +;; Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php) +(ns clojure.core + (:require + ;; Middle comment + [bar] ;; bar comment + ;; The first comment + [foo] ;; foo comment + + ;; A last comment + ))"))) (it "should also sort imports in a ns" (with-clojure-buffer "\n(ns my-app.core From f9dd268987d51fc1508f62a29f78790144a92d62 Mon Sep 17 00:00:00 2001 From: vemv Date: Wed, 23 Aug 2023 13:41:26 +0200 Subject: [PATCH 184/199] `clojure-find-ns`: add an option to suppress errors (#654) --- clojure-mode-sexp-test.el | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/clojure-mode-sexp-test.el b/clojure-mode-sexp-test.el index f82552a..edec580 100644 --- a/clojure-mode-sexp-test.el +++ b/clojure-mode-sexp-test.el @@ -167,7 +167,22 @@ (expect (clojure-find-ns) :to-equal expected) ;; After both namespaces (goto-char (point-max)) - (expect (clojure-find-ns) :to-equal expected))))))) + (expect (clojure-find-ns) :to-equal expected)))))) + + (describe "`suppress-errors' argument" + (let ((clojure-cache-ns nil)) + (describe "given a faulty ns form" + (let ((ns-form "(ns )")) + (describe "when the argument is `t'" + (it "causes `clojure-find-ns' to return nil" + (with-clojure-buffer ns-form + (expect (equal nil (clojure-find-ns t)))))) + + (describe "when the argument is `nil'" + (it "causes `clojure-find-ns' to return raise an error" + (with-clojure-buffer ns-form + (expect (clojure-find-ns nil) + :to-throw 'error))))))))) (describe "clojure-sexp-starts-until-position" (it "should return starting points for forms after POINT until POSITION" From b823f3acd017cbe21b5bc24793f432ed7b5ea8d6 Mon Sep 17 00:00:00 2001 From: vemv Date: Wed, 23 Aug 2023 19:20:41 +0200 Subject: [PATCH 185/199] Replace `http` -> `https` everywhere (#655) --- clojure-mode-bytecomp-warnings.el | 2 +- clojure-mode-convert-collection-test.el | 2 +- clojure-mode-cycling-test.el | 2 +- clojure-mode-external-interaction-test.el | 2 +- clojure-mode-font-lock-test.el | 2 +- clojure-mode-indentation-test.el | 2 +- clojure-mode-promote-fn-literal-test.el | 2 +- clojure-mode-refactor-add-arity-test.el | 2 +- clojure-mode-refactor-let-test.el | 2 +- clojure-mode-refactor-rename-ns-alias-test.el | 2 +- clojure-mode-refactor-threading-test.el | 2 +- clojure-mode-safe-eval-test.el | 2 +- clojure-mode-sexp-test.el | 2 +- clojure-mode-syntax-test.el | 2 +- clojure-mode-util-test.el | 6 +++--- utils/test-helper.el | 2 +- 16 files changed, 18 insertions(+), 18 deletions(-) diff --git a/clojure-mode-bytecomp-warnings.el b/clojure-mode-bytecomp-warnings.el index 2b94d07..41b3230 100644 --- a/clojure-mode-bytecomp-warnings.el +++ b/clojure-mode-bytecomp-warnings.el @@ -13,7 +13,7 @@ ;; GNU General Public License for more details. ;; You should have received a copy of the GNU General Public License -;; along with this program. If not, see . +;; along with this program. If not, see . ;; This file is not part of GNU Emacs. diff --git a/clojure-mode-convert-collection-test.el b/clojure-mode-convert-collection-test.el index cd28f51..28c5977 100644 --- a/clojure-mode-convert-collection-test.el +++ b/clojure-mode-convert-collection-test.el @@ -15,7 +15,7 @@ ;; GNU General Public License for more details. ;; You should have received a copy of the GNU General Public License -;; along with this program. If not, see . +;; along with this program. If not, see . ;;; Commentary: diff --git a/clojure-mode-cycling-test.el b/clojure-mode-cycling-test.el index afc2476..e1dcc46 100644 --- a/clojure-mode-cycling-test.el +++ b/clojure-mode-cycling-test.el @@ -15,7 +15,7 @@ ;; GNU General Public License for more details. ;; You should have received a copy of the GNU General Public License -;; along with this program. If not, see . +;; along with this program. If not, see . ;;; Commentary: diff --git a/clojure-mode-external-interaction-test.el b/clojure-mode-external-interaction-test.el index da038e5..e394f9d 100644 --- a/clojure-mode-external-interaction-test.el +++ b/clojure-mode-external-interaction-test.el @@ -15,7 +15,7 @@ ;; GNU General Public License for more details. ;; You should have received a copy of the GNU General Public License -;; along with this program. If not, see . +;; along with this program. If not, see . ;;; Code: diff --git a/clojure-mode-font-lock-test.el b/clojure-mode-font-lock-test.el index 4a7877b..bb6ef74 100644 --- a/clojure-mode-font-lock-test.el +++ b/clojure-mode-font-lock-test.el @@ -16,7 +16,7 @@ ;; GNU General Public License for more details. ;; You should have received a copy of the GNU General Public License -;; along with this program. If not, see . +;; along with this program. If not, see . ;;; Commentary: diff --git a/clojure-mode-indentation-test.el b/clojure-mode-indentation-test.el index ac9485e..1a03656 100644 --- a/clojure-mode-indentation-test.el +++ b/clojure-mode-indentation-test.el @@ -15,7 +15,7 @@ ;; GNU General Public License for more details. ;; You should have received a copy of the GNU General Public License -;; along with this program. If not, see . +;; along with this program. If not, see . ;;; Commentary: diff --git a/clojure-mode-promote-fn-literal-test.el b/clojure-mode-promote-fn-literal-test.el index 194e493..13aa006 100644 --- a/clojure-mode-promote-fn-literal-test.el +++ b/clojure-mode-promote-fn-literal-test.el @@ -13,7 +13,7 @@ ;; GNU General Public License for more details. ;; You should have received a copy of the GNU General Public License -;; along with this program. If not, see . +;; along with this program. If not, see . ;;; Commentary: diff --git a/clojure-mode-refactor-add-arity-test.el b/clojure-mode-refactor-add-arity-test.el index e4deefc..9c75f12 100644 --- a/clojure-mode-refactor-add-arity-test.el +++ b/clojure-mode-refactor-add-arity-test.el @@ -13,7 +13,7 @@ ;; GNU General Public License for more details. ;; You should have received a copy of the GNU General Public License -;; along with this program. If not, see . +;; along with this program. If not, see . ;;; Commentary: diff --git a/clojure-mode-refactor-let-test.el b/clojure-mode-refactor-let-test.el index 196db79..a197012 100644 --- a/clojure-mode-refactor-let-test.el +++ b/clojure-mode-refactor-let-test.el @@ -15,7 +15,7 @@ ;; GNU General Public License for more details. ;; You should have received a copy of the GNU General Public License -;; along with this program. If not, see . +;; along with this program. If not, see . ;;; Commentary: diff --git a/clojure-mode-refactor-rename-ns-alias-test.el b/clojure-mode-refactor-rename-ns-alias-test.el index 37fe90c..919a3cd 100644 --- a/clojure-mode-refactor-rename-ns-alias-test.el +++ b/clojure-mode-refactor-rename-ns-alias-test.el @@ -13,7 +13,7 @@ ;; GNU General Public License for more details. ;; You should have received a copy of the GNU General Public License -;; along with this program. If not, see . +;; along with this program. If not, see . ;;; Commentary: diff --git a/clojure-mode-refactor-threading-test.el b/clojure-mode-refactor-threading-test.el index 65b2a78..61ad598 100644 --- a/clojure-mode-refactor-threading-test.el +++ b/clojure-mode-refactor-threading-test.el @@ -15,7 +15,7 @@ ;; GNU General Public License for more details. ;; You should have received a copy of the GNU General Public License -;; along with this program. If not, see . +;; along with this program. If not, see . ;;; Commentary: diff --git a/clojure-mode-safe-eval-test.el b/clojure-mode-safe-eval-test.el index 47b7c5b..fe1e2a6 100644 --- a/clojure-mode-safe-eval-test.el +++ b/clojure-mode-safe-eval-test.el @@ -16,7 +16,7 @@ ;; GNU General Public License for more details. ;; You should have received a copy of the GNU General Public License -;; along with this program. If not, see . +;; along with this program. If not, see . ;;; Commentary: diff --git a/clojure-mode-sexp-test.el b/clojure-mode-sexp-test.el index edec580..1db0e70 100644 --- a/clojure-mode-sexp-test.el +++ b/clojure-mode-sexp-test.el @@ -15,7 +15,7 @@ ;; GNU General Public License for more details. ;; You should have received a copy of the GNU General Public License -;; along with this program. If not, see . +;; along with this program. If not, see . ;;; Code: diff --git a/clojure-mode-syntax-test.el b/clojure-mode-syntax-test.el index 934af5e..dfe2505 100644 --- a/clojure-mode-syntax-test.el +++ b/clojure-mode-syntax-test.el @@ -15,7 +15,7 @@ ;; GNU General Public License for more details. ;; You should have received a copy of the GNU General Public License -;; along with this program. If not, see . +;; along with this program. If not, see . ;;; Commentary: diff --git a/clojure-mode-util-test.el b/clojure-mode-util-test.el index 353f0e5..a35babb 100644 --- a/clojure-mode-util-test.el +++ b/clojure-mode-util-test.el @@ -15,7 +15,7 @@ ;; GNU General Public License for more details. ;; You should have received a copy of the GNU General Public License -;; along with this program. If not, see . +;; along with this program. If not, see . ;;; Commentary: @@ -156,7 +156,7 @@ (it "should sort requires in ns with copyright disclamer and comments" (with-clojure-buffer ";; Copyright (c) John Doe. All rights reserved. ;; The use and distribution terms for this software are covered by the -;; Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php) +;; Eclipse Public License 1.0 (https://opensource.org/license/epl-1-0/) (ns clojure.core (:require ;; The first comment @@ -169,7 +169,7 @@ (expect (buffer-string) :to-equal ";; Copyright (c) John Doe. All rights reserved. ;; The use and distribution terms for this software are covered by the -;; Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php) +;; Eclipse Public License 1.0 (https://opensource.org/license/epl-1-0/) (ns clojure.core (:require ;; Middle comment diff --git a/utils/test-helper.el b/utils/test-helper.el index c8dfed8..b359277 100644 --- a/utils/test-helper.el +++ b/utils/test-helper.el @@ -15,7 +15,7 @@ ;; GNU General Public License for more details. ;; You should have received a copy of the GNU General Public License -;; along with this program. If not, see . +;; along with this program. If not, see . ;;; Commentary: From 2f834cc7d5f695e5e061963fa01b6f3af1df3006 Mon Sep 17 00:00:00 2001 From: p4v4n Date: Wed, 6 Sep 2023 22:05:01 +0530 Subject: [PATCH 186/199] Add and modify tests for checking multiple forms on same line --- clojure-mode-refactor-threading-test.el | 13 +++++++++++-- clojure-mode-sexp-test.el | 21 ++++++++++++++------- 2 files changed, 25 insertions(+), 9 deletions(-) diff --git a/clojure-mode-refactor-threading-test.el b/clojure-mode-refactor-threading-test.el index 61ad598..efd7eb1 100644 --- a/clojure-mode-refactor-threading-test.el +++ b/clojure-mode-refactor-threading-test.el @@ -247,6 +247,16 @@ (clojure-unwind '(4))) + (when-refactoring-it "should unwind correctly when multiple ->> are present on same line" + "(->> 1 inc) (->> [1 2 3 4 5] + (filter even?) + (map square))" + + "(->> 1 inc) (->> (map square (filter even? [1 2 3 4 5])))" + + (clojure-unwind) + (clojure-unwind)) + (when-refactoring-it "should unwind with function name" "(->> [1 2 3 4 5] sum @@ -299,8 +309,7 @@ (when-refactoring-it "should unwind some->>" "(some->> :b - (find {:a 1}) - val + (find {:a 1}) val (+ 5))" "(some->> (+ 5 (val (find {:a 1} :b))))" diff --git a/clojure-mode-sexp-test.el b/clojure-mode-sexp-test.el index 1db0e70..aaeb798 100644 --- a/clojure-mode-sexp-test.el +++ b/clojure-mode-sexp-test.el @@ -31,30 +31,37 @@ (wrong))" ;; make this use the native beginning of defun since this is used to ;; determine whether to use the comment aware version or not. + (expect (let ((beginning-of-defun-function nil)) + (clojure-top-level-form-p "comment"))))) + (it "should return true when multiple forms are present" + (with-clojure-buffer-point + "(+ 1 2) (comment + (wrong) + (rig|ht) + (wrong))" (expect (let ((beginning-of-defun-function nil)) (clojure-top-level-form-p "comment")))))) (describe "clojure-beginning-of-defun-function" (it "should go to top level form" (with-clojure-buffer-point - "(comment + " (comment (wrong) (wrong) (rig|ht) (wrong))" - (beginning-of-defun) + (clojure-beginning-of-defun-function) (expect (looking-at-p "(comment")))) (it "should eval top level forms inside comment forms when clojure-toplevel-inside-comment-form set to true" (with-clojure-buffer-point - "(comment - (wrong) + "(+ inc 1) (comment (wrong) - (rig|ht) + (wrong) (rig|ht) (wrong))" (let ((clojure-toplevel-inside-comment-form t)) - (beginning-of-defun)) - (expect (looking-at-p "[[:space:]]*(right)")))) + (clojure-beginning-of-defun-function)) + (expect (looking-at-p "(right)")))) (it "should go to beginning of previous top level form" (with-clojure-buffer-point From 788cc5a77caec4675cc5de7c7a2d59c2704f6330 Mon Sep 17 00:00:00 2001 From: p4v4n Date: Thu, 7 Sep 2023 13:26:29 +0530 Subject: [PATCH 187/199] Fix clojure-find-ns for ns forms preceded by whitespace (#661) Closes https://github.com/clojure-emacs/clojure-mode/issues/593 --- clojure-mode-util-test.el | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/clojure-mode-util-test.el b/clojure-mode-util-test.el index a35babb..3f6e2de 100644 --- a/clojure-mode-util-test.el +++ b/clojure-mode-util-test.el @@ -82,6 +82,23 @@ (expect (clojure-find-ns) :to-equal "foo")) (with-clojure-buffer "(ns ^:bar ^:baz foo)" (expect (clojure-find-ns) :to-equal "foo"))) + (it "should find namespaces with spaces before ns form" + (with-clojure-buffer " (ns foo)" + (expect (clojure-find-ns) :to-equal "foo"))) + (it "should skip namespaces within any comment forms" + (with-clojure-buffer "(comment + (ns foo))" + (expect (clojure-find-ns) :to-equal nil)) + (with-clojure-buffer " (ns foo) + (comment + (ns bar))" + (expect (clojure-find-ns) :to-equal "foo")) + (with-clojure-buffer " (comment + (ns foo)) + (ns bar) + (comment + (ns baz))" + (expect (clojure-find-ns) :to-equal "bar"))) (it "should find namespace declarations with nested metadata and docstrings" (with-clojure-buffer "(ns ^{:bar true} foo)" (expect (clojure-find-ns) :to-equal "foo")) From e3642284816cd4a175e390ec8daaeed9a934d3f3 Mon Sep 17 00:00:00 2001 From: p4v4n Date: Mon, 11 Sep 2023 22:20:39 +0530 Subject: [PATCH 188/199] Make `clojure-find-ns` work when preceded by other forms (#664) Fixes #656 --- clojure-mode-sexp-test.el | 25 ++++++++++++++++++++++--- clojure-mode-util-test.el | 21 +++++++++++++++++++++ 2 files changed, 43 insertions(+), 3 deletions(-) diff --git a/clojure-mode-sexp-test.el b/clojure-mode-sexp-test.el index aaeb798..11bf519 100644 --- a/clojure-mode-sexp-test.el +++ b/clojure-mode-sexp-test.el @@ -41,7 +41,26 @@ (wrong))" (expect (let ((beginning-of-defun-function nil)) (clojure-top-level-form-p "comment")))))) - +(describe "clojure--looking-at-top-level-form" + (it "should return nil when point is inside a top level form" + (with-clojure-buffer-point + "(comment + |(ns foo))" + (expect (clojure--looking-at-top-level-form) :to-equal nil)) + (with-clojure-buffer-point + "\"|(ns foo)\"" + (expect (clojure--looking-at-top-level-form) :to-equal nil)) + (with-clojure-buffer-point + "^{:fake-ns |(ns foo)}" + (expect (clojure--looking-at-top-level-form) :to-equal nil))) + (it "should return true when point is looking at a top level form" + (with-clojure-buffer-point + "(comment + |(ns foo))" + (expect (clojure--looking-at-top-level-form (point-min)) :to-equal t)) + (with-clojure-buffer-point + "|(ns foo)" + (expect (clojure--looking-at-top-level-form) :to-equal t)))) (describe "clojure-beginning-of-defun-function" (it "should go to top level form" (with-clojure-buffer-point @@ -164,9 +183,9 @@ (expect (equal "baz-quux" (clojure-find-ns)))) (let ((data '(("\"\n(ns foo-bar)\"\n" "(in-ns 'baz-quux)" "baz-quux") - (";(ns foo-bar)\n" "(in-ns 'baz-quux)" "baz-quux") + (";(ns foo-bar)\n" "(in-ns 'baz-quux2)" "baz-quux2") ("(ns foo-bar)\n" "\"\n(in-ns 'baz-quux)\"" "foo-bar") - ("(ns foo-bar)\n" ";(in-ns 'baz-quux)" "foo-bar")))) + ("(ns foo-bar2)\n" ";(in-ns 'baz-quux)" "foo-bar2")))) (pcase-dolist (`(,form1 ,form2 ,expected) data) (with-clojure-buffer form1 (save-excursion (insert form2)) diff --git a/clojure-mode-util-test.el b/clojure-mode-util-test.el index 3f6e2de..565773d 100644 --- a/clojure-mode-util-test.el +++ b/clojure-mode-util-test.el @@ -142,6 +142,27 @@ (with-clojure-buffer "(ns foo) (ns-unmap *ns* 'map) (ns.misleading 1 2 3)" + (expect (clojure-find-ns) :to-equal "foo"))) + (it "should skip leading garbage" + (with-clojure-buffer " (ns foo)" + (expect (clojure-find-ns) :to-equal "foo")) + (with-clojure-buffer "1(ns foo)" + (expect (clojure-find-ns) :to-equal "foo")) + (with-clojure-buffer "1 (ns foo)" + (expect (clojure-find-ns) :to-equal "foo")) + (with-clojure-buffer "1 +(ns foo)" + (expect (clojure-find-ns) :to-equal "foo")) + (with-clojure-buffer "[1] +(ns foo)" + (expect (clojure-find-ns) :to-equal "foo")) + (with-clojure-buffer "[1] (ns foo)" + (expect (clojure-find-ns) :to-equal "foo")) + (with-clojure-buffer "[1](ns foo)" + (expect (clojure-find-ns) :to-equal "foo")) + (with-clojure-buffer "(ns)(ns foo)" + (expect (clojure-find-ns) :to-equal "foo")) + (with-clojure-buffer "(ns )(ns foo)" (expect (clojure-find-ns) :to-equal "foo")))) (describe "clojure-sort-ns" From 6bccf8c25ec3e7f074d2563273cb8de57e201d79 Mon Sep 17 00:00:00 2001 From: p4v4n Date: Sun, 5 Nov 2023 18:24:09 +0530 Subject: [PATCH 189/199] Use Eldev (#669) Closes https://github.com/clojure-emacs/clojure-mode/issues/666 --- clojure-mode-bytecomp-warnings.el | 40 ------------------------- clojure-mode-convert-collection-test.el | 1 + clojure-mode-refactor-add-arity-test.el | 1 + clojure-mode-util-test.el | 2 +- test-checks.el | 30 ------------------- utils/test-helper.el | 2 +- 6 files changed, 4 insertions(+), 72 deletions(-) delete mode 100644 clojure-mode-bytecomp-warnings.el delete mode 100644 test-checks.el diff --git a/clojure-mode-bytecomp-warnings.el b/clojure-mode-bytecomp-warnings.el deleted file mode 100644 index 41b3230..0000000 --- a/clojure-mode-bytecomp-warnings.el +++ /dev/null @@ -1,40 +0,0 @@ -;;; clojure-mode-bytecomp-warnings.el --- Check for byte-compilation problems -*- lexical-binding: t; -*- - -;; Copyright © 2012-2021 Bozhidar Batsov and contributors -;; -;; This program is free software: you can redistribute it and/or modify -;; it under the terms of the GNU General Public License as published by -;; the Free Software Foundation, either version 3 of the License, or -;; (at your option) any later version. - -;; This program is distributed in the hope that it will be useful, -;; but WITHOUT ANY WARRANTY; without even the implied warranty of -;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -;; GNU General Public License for more details. - -;; You should have received a copy of the GNU General Public License -;; along with this program. If not, see . - -;; This file is not part of GNU Emacs. - -;;; Commentary: - -;; This is a script to be loaded while visiting a `clojure-mode' source file. -;; It will prepare all requirements and then byte-compile the file and signal an -;; error on any warning. For example: -;; -;; emacs -Q --batch -l test/clojure-mode-bytecomp-warnings.el clojure-mode.el - -;; This assumes that all `clojure-mode' dependencies are already on the package -;; dir (probably from running `cask install'). - -(setq load-prefer-newer t) -(add-to-list 'load-path (expand-file-name "./")) -(require 'package) -(package-generate-autoloads 'clojure-mode default-directory) -(package-initialize) -(load-file "clojure-mode-autoloads.el") -(setq byte-compile-error-on-warn t) -(batch-byte-compile) - -;;; clojure-mode-bytecomp-warnings.el ends here diff --git a/clojure-mode-convert-collection-test.el b/clojure-mode-convert-collection-test.el index 28c5977..14e5291 100644 --- a/clojure-mode-convert-collection-test.el +++ b/clojure-mode-convert-collection-test.el @@ -27,6 +27,7 @@ (require 'clojure-mode) (require 'buttercup) +(require 'test-helper "test/utils/test-helper") (describe "clojure-convert-collection-to-map" (when-refactoring-it "should convert a list to a map" diff --git a/clojure-mode-refactor-add-arity-test.el b/clojure-mode-refactor-add-arity-test.el index 9c75f12..5f1c5fb 100644 --- a/clojure-mode-refactor-add-arity-test.el +++ b/clojure-mode-refactor-add-arity-test.el @@ -24,6 +24,7 @@ (require 'clojure-mode) (require 'buttercup) +(require 'test-helper "test/utils/test-helper") (describe "clojure-add-arity" diff --git a/clojure-mode-util-test.el b/clojure-mode-util-test.el index 565773d..6157a3d 100644 --- a/clojure-mode-util-test.el +++ b/clojure-mode-util-test.el @@ -46,7 +46,7 @@ (bb-edn-src (expand-file-name "src" temp-dir))) (write-region "{}" nil bb-edn) (make-directory bb-edn-src) - (expect (clojure-project-dir bb-edn-src) + (expect (expand-file-name (clojure-project-dir bb-edn-src)) :to-equal (file-name-as-directory temp-dir)))))) (describe "clojure-project-relative-path" diff --git a/test-checks.el b/test-checks.el deleted file mode 100644 index a4b4208..0000000 --- a/test-checks.el +++ /dev/null @@ -1,30 +0,0 @@ -;; This is a script to be loaded from the root `clojure-mode' directory. It will -*- lexical-binding: t; -*- -;; prepare all requirements and then run `check-declare-directory' on -;; `default-directory'. For example: emacs -Q --batch -l test/test-checkdoc.el - -;; This assumes that all `clojure-mode' dependencies are already on the package -;; dir (probably from running `cask install'). - -(add-to-list 'load-path (expand-file-name "./")) -(require 'package) -(require 'check-declare) -(package-initialize) - -;; disable some annoying (or non-applicable) checkdoc checks -(setq checkdoc-package-keywords-flag nil) -(setq checkdoc-arguments-in-order-flag nil) -(setq checkdoc-verb-check-experimental-flag nil) - -(let ((files (directory-files default-directory t - "\\`[^.].*\\.el\\'" t))) - - ;; `checkdoc-file' was introduced in Emacs 25 - (when (fboundp 'checkdoc-file) - (dolist (file files) - (checkdoc-file file)) - (when (get-buffer "*Warnings*") - (message "Failing due to checkdoc warnings...") - (kill-emacs 1))) - - (when (apply #'check-declare-files files) - (kill-emacs 1))) diff --git a/utils/test-helper.el b/utils/test-helper.el index b359277..e7894f0 100644 --- a/utils/test-helper.el +++ b/utils/test-helper.el @@ -26,7 +26,7 @@ (message "Running tests on Emacs %s" emacs-version) (let* ((current-file (if load-in-progress load-file-name (buffer-file-name))) - (source-directory (locate-dominating-file current-file "Cask")) + (source-directory (locate-dominating-file current-file "Eldev")) ;; Do not load outdated byte code for tests (load-prefer-newer t)) ;; Load the file under test From 27915a0e40be75c9f112d213ae30dec52831a6da Mon Sep 17 00:00:00 2001 From: Dave Liepmann Date: Fri, 24 Nov 2023 08:27:44 +0100 Subject: [PATCH 190/199] Don't highlight vars with colons as keywords (#670) Changes syntax highlighting regexp for keywords to match a colon/double-colon only at the beginning of a word, not in the middle. This allows local vars like `foo:bar` to be highlighted correctly instead of like an unknown symbol for the part before the colon and a keyword for the rest. Fixes #653 --- clojure-mode-font-lock-test.el | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/clojure-mode-font-lock-test.el b/clojure-mode-font-lock-test.el index bb6ef74..5e578ba 100644 --- a/clojure-mode-font-lock-test.el +++ b/clojure-mode-font-lock-test.el @@ -262,6 +262,13 @@ DESCRIPTION is the description of the spec." (9 10 nil) (11 16 nil)) + ("(colons:are:okay)" + (2 16 nil)) + + ("(some-ns/colons:are:okay)" + (2 8 font-lock-type-face) + (9 24 nil)) + ("(oneword/ve/yCom|pLex.stu-ff)" (2 8 font-lock-type-face) (9 10 nil) @@ -715,6 +722,19 @@ DESCRIPTION is the description of the spec." (10 10 default) (11 30 clojure-keyword-face))) + (when-fontifying-it "should handle keywords with colons" + (":a:a" + (1 4 clojure-keyword-face)) + + (":a:a/:a" + (1 7 clojure-keyword-face)) + + ("::a:a" + (1 5 clojure-keyword-face)) + + ("::a.a:a" + (1 7 clojure-keyword-face))) + (when-fontifying-it "should handle very complex keywords" (" :ve/yCom|pLex.stu-ff" (3 4 font-lock-type-face) @@ -824,7 +844,10 @@ DESCRIPTION is the description of the spec." (when-fontifying-it "should handle variables defined with def" ("(def foo 10)" (2 4 font-lock-keyword-face) - (6 8 font-lock-variable-name-face))) + (6 8 font-lock-variable-name-face)) + ("(def foo:bar 10)" + (2 4 font-lock-keyword-face) + (6 12 font-lock-variable-name-face))) (when-fontifying-it "should handle variables definitions of type string" ("(def foo \"hello\")" From 29e37c2b0040e165774fb0641eb40f523d1cbb72 Mon Sep 17 00:00:00 2001 From: Dave Liepmann Date: Fri, 24 Nov 2023 18:21:41 +0100 Subject: [PATCH 191/199] [Fix #671] Font-lock properly multi-digit lambda args (#672) --- clojure-mode-font-lock-test.el | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/clojure-mode-font-lock-test.el b/clojure-mode-font-lock-test.el index 5e578ba..e25fb57 100644 --- a/clojure-mode-font-lock-test.el +++ b/clojure-mode-font-lock-test.el @@ -901,13 +901,24 @@ DESCRIPTION is the description of the spec." (2 3 font-lock-keyword-face) ( 5 7 font-lock-function-name-face))) - (when-fontifying-it "should handle lambda-params" + (when-fontifying-it "should handle lambda-params %, %1, %n..." ("#(+ % %2 %3 %&)" (5 5 font-lock-variable-name-face) (7 8 font-lock-variable-name-face) (10 11 font-lock-variable-name-face) (13 14 font-lock-variable-name-face))) + (when-fontifying-it "should handle multi-digit lambda-params" + ;; % args with >1 digit are rare and unidiomatic but legal up to + ;; `MAX_POSITIONAL_ARITY` in Clojure's compiler, which as of today is 20 + ("#(* %10 %15 %19 %20)" + ;; it would be better if this were just `font-lock-variable-name-face` but + ;; it seems to work as-is + (5 7 various-faces) + (9 11 font-lock-variable-name-face) + (13 15 font-lock-variable-name-face) + (17 19 various-faces))) + (when-fontifying-it "should handle nils" ("(= nil x)" (4 6 font-lock-constant-face)) From 52c8626af4174ebf39d78fb50ec948526d1a87bd Mon Sep 17 00:00:00 2001 From: Ola Nilsson Date: Tue, 5 Mar 2024 21:32:42 +0100 Subject: [PATCH 192/199] Set lexical-binding in clojure-mode-font-lock-test.el Must have been moved to the second line by a well-meaning fill operation. Unfortunately, it has no effect on the second line and the tests broke on buttercup 1.34. --- clojure-mode-font-lock-test.el | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/clojure-mode-font-lock-test.el b/clojure-mode-font-lock-test.el index e25fb57..3477190 100644 --- a/clojure-mode-font-lock-test.el +++ b/clojure-mode-font-lock-test.el @@ -1,5 +1,4 @@ -;;; clojure-mode-font-lock-test.el --- Clojure Mode: Font lock test suite -;; -*- lexical-binding: t; -*- +;;; clojure-mode-font-lock-test.el --- Clojure Mode: Font lock test suite -*- lexical-binding: t; -*- ;; Copyright (C) 2014-2021 Bozhidar Batsov From 897dd6c78de6709015968c18d3fbad0e7be2f234 Mon Sep 17 00:00:00 2001 From: yuhan0 Date: Thu, 16 May 2024 04:42:17 +0800 Subject: [PATCH 193/199] Add tests and changelog --- clojure-mode-util-test.el | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/clojure-mode-util-test.el b/clojure-mode-util-test.el index 6157a3d..78a2ac1 100644 --- a/clojure-mode-util-test.el +++ b/clojure-mode-util-test.el @@ -163,6 +163,11 @@ (with-clojure-buffer "(ns)(ns foo)" (expect (clojure-find-ns) :to-equal "foo")) (with-clojure-buffer "(ns )(ns foo)" + (expect (clojure-find-ns) :to-equal "foo"))) + (it "should ignore carriage returns" + (with-clojure-buffer "(ns \r\n foo)" + (expect (clojure-find-ns) :to-equal "foo")) + (with-clojure-buffer "(ns\r\n ^{:doc \"meta\r\n\"}\r\n foo\r\n)" (expect (clojure-find-ns) :to-equal "foo")))) (describe "clojure-sort-ns" From a49f9e17d202b90d5f4576373efe693b845a1e97 Mon Sep 17 00:00:00 2001 From: Xiyue Deng Date: Mon, 3 Jun 2024 02:35:25 -0700 Subject: [PATCH 194/199] Don't use custom logic to find source directory of clojure-mode.el * Or this will prevent buttercup tests from working with installed clojure-mode under ELPA directories. * A bit more background: in Debian there is autopkgtest which tests the installed package. dh-elpa enables a mode that runs the same ERT or Buttercup tests against the installed package instead of the source tree. In this case, it will let the tests pass during build phase, but autopkgtest will fail as this custom code will still try to locate the source code which will no longer be available. * I have tested under Debian sbuild that removing the code will let the buttercup tests pass under autopkgtest, but not sure whether this is still required for Eldev to work. --- utils/test-helper.el | 7 ------- 1 file changed, 7 deletions(-) diff --git a/utils/test-helper.el b/utils/test-helper.el index e7894f0..af5273a 100644 --- a/utils/test-helper.el +++ b/utils/test-helper.el @@ -25,13 +25,6 @@ (message "Running tests on Emacs %s" emacs-version) -(let* ((current-file (if load-in-progress load-file-name (buffer-file-name))) - (source-directory (locate-dominating-file current-file "Eldev")) - ;; Do not load outdated byte code for tests - (load-prefer-newer t)) - ;; Load the file under test - (load (expand-file-name "clojure-mode" source-directory))) - (defmacro with-clojure-buffer (text &rest body) "Create a temporary buffer, insert TEXT, switch to clojure-mode and evaluate BODY." (declare (indent 1)) From a39b4d95feb45dfb55c3f3aa04a425aac86abac0 Mon Sep 17 00:00:00 2001 From: Dieter Komendera Date: Thu, 31 Oct 2024 17:35:06 +0100 Subject: [PATCH 195/199] Disable tests merged from clojure-mode for now using eldev --- Eldev | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/Eldev b/Eldev index e6b3c00..9793a9b 100644 --- a/Eldev +++ b/Eldev @@ -25,3 +25,8 @@ enable-local-variables :safe)) (setq eldev-project-main-file "clojure-ts-mode.el") + +;; Exclude tests merged from clojure-mode +(setf eldev-test-fileset + `(:and ,eldev-test-fileset + (:not "./clojure-mode-*"))) From b3817dca78df3a0fa124c17cf08e99a84b056eaa Mon Sep 17 00:00:00 2001 From: Dieter Komendera Date: Thu, 31 Oct 2024 19:20:32 +0100 Subject: [PATCH 196/199] Don't lint tests merged from clojure-mode --- Eldev | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/Eldev b/Eldev index 9793a9b..69f390a 100644 --- a/Eldev +++ b/Eldev @@ -26,7 +26,9 @@ (setq eldev-project-main-file "clojure-ts-mode.el") -;; Exclude tests merged from clojure-mode +;; Exclude tests merged from clojure-mode from running and linting (setf eldev-test-fileset `(:and ,eldev-test-fileset (:not "./clojure-mode-*"))) +(setf eldev-lint-ignored-fileset + `(:or ,eldev-lint-ignored-fileset "./clojure-mode-*")) From c259d308cbfa33b6dddfd3d17e452d8488a3c419 Mon Sep 17 00:00:00 2001 From: Dieter Komendera Date: Thu, 31 Oct 2024 19:21:04 +0100 Subject: [PATCH 197/199] Move over remaining test utils from the clojure-mode test-helper --- test/test-helper.el | 52 ++++++++++++++++++++++ utils/test-helper.el | 103 ------------------------------------------- 2 files changed, 52 insertions(+), 103 deletions(-) delete mode 100644 utils/test-helper.el diff --git a/test/test-helper.el b/test/test-helper.el index 3866003..cb0a2ad 100644 --- a/test/test-helper.el +++ b/test/test-helper.el @@ -55,4 +55,56 @@ attention to case differences." (let ((case-fold-search ignore-case)) (string-match-p (regexp-quote needle) s))) +(defmacro when-refactoring-it (description before after &rest body) + "Return a buttercup spec. + +Insert BEFORE into a buffer, evaluate BODY and compare the resulting buffer to +AFTER. + +BODY should contain the refactoring that transforms BEFORE into AFTER. + +DESCRIPTION is the description of the spec." + (declare (indent 1)) + `(it ,description + (with-clojure-ts-buffer ,before + ,@body + (expect (buffer-string) :to-equal ,after)))) + +(defmacro when-refactoring-with-point-it (description before after &rest body) + "Return a buttercup spec. + +Like when-refactor-it but also checks whether point is moved to the expected +position. + +BEFORE is the buffer string before refactoring, where a pipe (|) represents +point. + +AFTER is the expected buffer string after refactoring, where a pipe (|) +represents the expected position of point. + +DESCRIPTION is a string with the description of the spec." + (declare (indent 1)) + `(it ,description + (let* ((after ,after) + (expected-cursor-pos (1+ (clojure-ts--s-index-of "|" after))) + (expected-state (delete ?| after))) + (with-clojure-ts-buffer ,before + (goto-char (point-min)) + (search-forward "|") + (delete-char -1) + ,@body + (expect (buffer-string) :to-equal expected-state) + (expect (point) :to-equal expected-cursor-pos))))) + + +;; https://emacs.stackexchange.com/a/55031 +(defmacro with-temp-dir (temp-dir &rest body) + "Create a temporary directory and bind its to TEMP-DIR while evaluating BODY. +Removes the temp directory at the end of evaluation." + `(let ((,temp-dir (make-temp-file "" t))) + (unwind-protect + (progn + ,@body) + (delete-directory ,temp-dir t)))) + ;;; test-helper.el ends here diff --git a/utils/test-helper.el b/utils/test-helper.el deleted file mode 100644 index af5273a..0000000 --- a/utils/test-helper.el +++ /dev/null @@ -1,103 +0,0 @@ -;;; test-helper.el --- Clojure Mode: Non-interactive unit-test setup -*- lexical-binding: t; -*- - -;; Copyright (C) 2014-2021 Bozhidar Batsov - -;; This file is not part of GNU Emacs. - -;; This program is free software; you can redistribute it and/or modify -;; it under the terms of the GNU General Public License as published by -;; the Free Software Foundation, either version 3 of the License, or -;; (at your option) any later version. - -;; This program is distributed in the hope that it will be useful, -;; but WITHOUT ANY WARRANTY; without even the implied warranty of -;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -;; GNU General Public License for more details. - -;; You should have received a copy of the GNU General Public License -;; along with this program. If not, see . - -;;; Commentary: - -;; Non-interactive test suite setup. - -;;; Code: - -(message "Running tests on Emacs %s" emacs-version) - -(defmacro with-clojure-buffer (text &rest body) - "Create a temporary buffer, insert TEXT, switch to clojure-mode and evaluate BODY." - (declare (indent 1)) - `(with-temp-buffer - (erase-buffer) - (insert ,text) - (clojure-mode) - ,@body)) - -(defmacro with-clojure-buffer-point (text &rest body) - "Run BODY in a temporary clojure buffer with TEXT. - -TEXT is a string with a | indicating where point is. The | will be erased -and point left there." - (declare (indent 2)) - `(progn - (with-clojure-buffer ,text - (goto-char (point-min)) - (re-search-forward "|") - (delete-char -1) - ,@body))) - -(defmacro when-refactoring-it (description before after &rest body) - "Return a buttercup spec. - -Insert BEFORE into a buffer, evaluate BODY and compare the resulting buffer to -AFTER. - -BODY should contain the refactoring that transforms BEFORE into AFTER. - -DESCRIPTION is the description of the spec." - (declare (indent 1)) - `(it ,description - (with-clojure-buffer ,before - ,@body - (expect (buffer-string) :to-equal ,after)))) - -(defmacro when-refactoring-with-point-it (description before after &rest body) - "Return a buttercup spec. - -Like when-refactor-it but also checks whether point is moved to the expected -position. - -BEFORE is the buffer string before refactoring, where a pipe (|) represents -point. - -AFTER is the expected buffer string after refactoring, where a pipe (|) -represents the expected position of point. - -DESCRIPTION is a string with the description of the spec." - (declare (indent 1)) - `(it ,description - (let* ((after ,after) - (expected-cursor-pos (1+ (s-index-of "|" after))) - (expected-state (delete ?| after))) - (with-clojure-buffer ,before - (goto-char (point-min)) - (search-forward "|") - (delete-char -1) - ,@body - (expect (buffer-string) :to-equal expected-state) - (expect (point) :to-equal expected-cursor-pos))))) - - -;; https://emacs.stackexchange.com/a/55031 -(defmacro with-temp-dir (temp-dir &rest body) - "Create a temporary directory and bind its to TEMP-DIR while evaluating BODY. -Removes the temp directory at the end of evaluation." - `(let ((,temp-dir (make-temp-file "" t))) - (unwind-protect - (progn - ,@body) - (delete-directory ,temp-dir t)))) - -(provide 'test-helper) -;;; test-helper.el ends here From 75349eccbda99c5f5332bb6236936cbeb0de5b56 Mon Sep 17 00:00:00 2001 From: Dieter Komendera Date: Thu, 31 Oct 2024 19:35:29 +0100 Subject: [PATCH 198/199] Fix byte compile by excluding tests merged from clojure-mode --- Eldev | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/Eldev b/Eldev index 69f390a..68641f9 100644 --- a/Eldev +++ b/Eldev @@ -26,9 +26,11 @@ (setq eldev-project-main-file "clojure-ts-mode.el") -;; Exclude tests merged from clojure-mode from running and linting +;; Exclude tests merged from clojure-mode from running, linting and byte compiling (setf eldev-test-fileset `(:and ,eldev-test-fileset (:not "./clojure-mode-*"))) +(setf eldev-standard-excludes + `(:or ,eldev-standard-excludes "./clojure-mode-*")) (setf eldev-lint-ignored-fileset `(:or ,eldev-lint-ignored-fileset "./clojure-mode-*")) From 1d7f84db02b4f4b787fb4da9db908001f52642e4 Mon Sep 17 00:00:00 2001 From: Dieter Komendera Date: Thu, 31 Oct 2024 21:35:41 +0100 Subject: [PATCH 199/199] Move clojure-mode tests into their own directory to better keep track of them --- Eldev | 6 +++--- .../clojure-mode-convert-collection-test.el | 0 .../clojure-mode-cycling-test.el | 0 .../clojure-mode-external-interaction-test.el | 0 .../clojure-mode-font-lock-test.el | 0 .../clojure-mode-indentation-test.el | 0 .../clojure-mode-promote-fn-literal-test.el | 0 .../clojure-mode-refactor-add-arity-test.el | 0 .../clojure-mode-refactor-let-test.el | 0 .../clojure-mode-refactor-rename-ns-alias-test.el | 0 .../clojure-mode-refactor-threading-test.el | 0 .../clojure-mode-safe-eval-test.el | 0 .../clojure-mode-sexp-test.el | 0 .../clojure-mode-syntax-test.el | 0 .../clojure-mode-util-test.el | 0 15 files changed, 3 insertions(+), 3 deletions(-) rename clojure-mode-convert-collection-test.el => clojure-mode-tests/clojure-mode-convert-collection-test.el (100%) rename clojure-mode-cycling-test.el => clojure-mode-tests/clojure-mode-cycling-test.el (100%) rename clojure-mode-external-interaction-test.el => clojure-mode-tests/clojure-mode-external-interaction-test.el (100%) rename clojure-mode-font-lock-test.el => clojure-mode-tests/clojure-mode-font-lock-test.el (100%) rename clojure-mode-indentation-test.el => clojure-mode-tests/clojure-mode-indentation-test.el (100%) rename clojure-mode-promote-fn-literal-test.el => clojure-mode-tests/clojure-mode-promote-fn-literal-test.el (100%) rename clojure-mode-refactor-add-arity-test.el => clojure-mode-tests/clojure-mode-refactor-add-arity-test.el (100%) rename clojure-mode-refactor-let-test.el => clojure-mode-tests/clojure-mode-refactor-let-test.el (100%) rename clojure-mode-refactor-rename-ns-alias-test.el => clojure-mode-tests/clojure-mode-refactor-rename-ns-alias-test.el (100%) rename clojure-mode-refactor-threading-test.el => clojure-mode-tests/clojure-mode-refactor-threading-test.el (100%) rename clojure-mode-safe-eval-test.el => clojure-mode-tests/clojure-mode-safe-eval-test.el (100%) rename clojure-mode-sexp-test.el => clojure-mode-tests/clojure-mode-sexp-test.el (100%) rename clojure-mode-syntax-test.el => clojure-mode-tests/clojure-mode-syntax-test.el (100%) rename clojure-mode-util-test.el => clojure-mode-tests/clojure-mode-util-test.el (100%) diff --git a/Eldev b/Eldev index 68641f9..7a30881 100644 --- a/Eldev +++ b/Eldev @@ -29,8 +29,8 @@ ;; Exclude tests merged from clojure-mode from running, linting and byte compiling (setf eldev-test-fileset `(:and ,eldev-test-fileset - (:not "./clojure-mode-*"))) + (:not "./clojure-mode-tests/*"))) (setf eldev-standard-excludes - `(:or ,eldev-standard-excludes "./clojure-mode-*")) + `(:or ,eldev-standard-excludes "./clojure-mode-tests/*")) (setf eldev-lint-ignored-fileset - `(:or ,eldev-lint-ignored-fileset "./clojure-mode-*")) + `(:or ,eldev-lint-ignored-fileset "./clojure-mode-tests/*")) diff --git a/clojure-mode-convert-collection-test.el b/clojure-mode-tests/clojure-mode-convert-collection-test.el similarity index 100% rename from clojure-mode-convert-collection-test.el rename to clojure-mode-tests/clojure-mode-convert-collection-test.el diff --git a/clojure-mode-cycling-test.el b/clojure-mode-tests/clojure-mode-cycling-test.el similarity index 100% rename from clojure-mode-cycling-test.el rename to clojure-mode-tests/clojure-mode-cycling-test.el diff --git a/clojure-mode-external-interaction-test.el b/clojure-mode-tests/clojure-mode-external-interaction-test.el similarity index 100% rename from clojure-mode-external-interaction-test.el rename to clojure-mode-tests/clojure-mode-external-interaction-test.el diff --git a/clojure-mode-font-lock-test.el b/clojure-mode-tests/clojure-mode-font-lock-test.el similarity index 100% rename from clojure-mode-font-lock-test.el rename to clojure-mode-tests/clojure-mode-font-lock-test.el diff --git a/clojure-mode-indentation-test.el b/clojure-mode-tests/clojure-mode-indentation-test.el similarity index 100% rename from clojure-mode-indentation-test.el rename to clojure-mode-tests/clojure-mode-indentation-test.el diff --git a/clojure-mode-promote-fn-literal-test.el b/clojure-mode-tests/clojure-mode-promote-fn-literal-test.el similarity index 100% rename from clojure-mode-promote-fn-literal-test.el rename to clojure-mode-tests/clojure-mode-promote-fn-literal-test.el diff --git a/clojure-mode-refactor-add-arity-test.el b/clojure-mode-tests/clojure-mode-refactor-add-arity-test.el similarity index 100% rename from clojure-mode-refactor-add-arity-test.el rename to clojure-mode-tests/clojure-mode-refactor-add-arity-test.el diff --git a/clojure-mode-refactor-let-test.el b/clojure-mode-tests/clojure-mode-refactor-let-test.el similarity index 100% rename from clojure-mode-refactor-let-test.el rename to clojure-mode-tests/clojure-mode-refactor-let-test.el diff --git a/clojure-mode-refactor-rename-ns-alias-test.el b/clojure-mode-tests/clojure-mode-refactor-rename-ns-alias-test.el similarity index 100% rename from clojure-mode-refactor-rename-ns-alias-test.el rename to clojure-mode-tests/clojure-mode-refactor-rename-ns-alias-test.el diff --git a/clojure-mode-refactor-threading-test.el b/clojure-mode-tests/clojure-mode-refactor-threading-test.el similarity index 100% rename from clojure-mode-refactor-threading-test.el rename to clojure-mode-tests/clojure-mode-refactor-threading-test.el diff --git a/clojure-mode-safe-eval-test.el b/clojure-mode-tests/clojure-mode-safe-eval-test.el similarity index 100% rename from clojure-mode-safe-eval-test.el rename to clojure-mode-tests/clojure-mode-safe-eval-test.el diff --git a/clojure-mode-sexp-test.el b/clojure-mode-tests/clojure-mode-sexp-test.el similarity index 100% rename from clojure-mode-sexp-test.el rename to clojure-mode-tests/clojure-mode-sexp-test.el diff --git a/clojure-mode-syntax-test.el b/clojure-mode-tests/clojure-mode-syntax-test.el similarity index 100% rename from clojure-mode-syntax-test.el rename to clojure-mode-tests/clojure-mode-syntax-test.el diff --git a/clojure-mode-util-test.el b/clojure-mode-tests/clojure-mode-util-test.el similarity index 100% rename from clojure-mode-util-test.el rename to clojure-mode-tests/clojure-mode-util-test.el