[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[nongnu] elpa/clojure-ts-mode f199d20141 093/210: Add threading macros r
From: |
ELPA Syncer |
Subject: |
[nongnu] elpa/clojure-ts-mode f199d20141 093/210: Add threading macros related refactorings |
Date: |
Thu, 31 Oct 2024 18:59:44 -0400 (EDT) |
branch: elpa/clojure-ts-mode
commit f199d201419b6ca02f074ce23584a732e9f416c9
Author: Benedek Fazekas <benedek.fazekas@gmail.com>
Commit: Benedek Fazekas <benedek.fazekas@gmail.com>
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(+)
diff --git a/clojure-mode-refactor-threading-test.el
b/clojure-mode-refactor-threading-test.el
new file mode 100644
index 0000000000..a92a3e1b6f
--- /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 <benedek.fazekas@gmail.com>
+
+;; 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 <http://www.gnu.org/licenses/>.
+
+;;; 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
- [nongnu] elpa/clojure-ts-mode 39262aeaf7 084/210: [#361] Add a regression test, (continued)
- [nongnu] elpa/clojure-ts-mode 39262aeaf7 084/210: [#361] Add a regression test, ELPA Syncer, 2024/10/31
- [nongnu] elpa/clojure-ts-mode 0e671ec3f1 085/210: Add a test for %& font-locking, ELPA Syncer, 2024/10/31
- [nongnu] elpa/clojure-ts-mode 35062b412e 089/210: Make clojure-align cleanup commas, ELPA Syncer, 2024/10/31
- [nongnu] elpa/clojure-ts-mode f196516d7f 087/210: Add a test for the previous fix, ELPA Syncer, 2024/10/31
- [nongnu] elpa/clojure-ts-mode 44beeb05ce 090/210: Fix a silly test, ELPA Syncer, 2024/10/31
- [nongnu] elpa/clojure-ts-mode 09abee8a6e 086/210: Add a test for proxy indentation, ELPA Syncer, 2024/10/31
- [nongnu] elpa/clojure-ts-mode 55b6fe7d94 092/210: Add tests for the escape char font-locking, ELPA Syncer, 2024/10/31
- [nongnu] elpa/clojure-ts-mode 8fa3e1f9da 097/210: Preserve previously removed line-breaks when unwinding, ELPA Syncer, 2024/10/31
- [nongnu] elpa/clojure-ts-mode 4599b47b58 104/210: Add indentation rule for definterface (#395), ELPA Syncer, 2024/10/31
- [nongnu] elpa/clojure-ts-mode 29ba69e72d 107/210: [Fix #399] Fix font-locking of prefix characters inside keywords (#401), ELPA Syncer, 2024/10/31
- [nongnu] elpa/clojure-ts-mode f199d20141 093/210: Add threading macros related refactorings,
ELPA Syncer <=
- [nongnu] elpa/clojure-ts-mode 99b74128f2 105/210: Add tests for correct treatment of prefix syntax, ELPA Syncer, 2024/10/31
- [nongnu] elpa/clojure-ts-mode ce815f99a3 106/210: Create separate clojure-mode-syntax-test suite, ELPA Syncer, 2024/10/31
- [nongnu] elpa/clojure-ts-mode cbbf18a6a7 108/210: Port let related refactorings from clj-refactor.el, ELPA Syncer, 2024/10/31
- [nongnu] elpa/clojure-ts-mode 294714b89f 101/210: Fix bug when passing lambda to define-clojure-indent, closes #383, ELPA Syncer, 2024/10/31
- [nongnu] elpa/clojure-ts-mode 9c98734cb6 099/210: Add a test for ns-sort, ELPA Syncer, 2024/10/31
- [nongnu] elpa/clojure-ts-mode fbf55ac199 141/210: Merge pull request #505 from carlosgeos/fix-445, ELPA Syncer, 2024/10/31
- [nongnu] elpa/clojure-ts-mode 18d6f4f2ec 113/210: Remove ; from paragraph-start regexp during fill (#434), ELPA Syncer, 2024/10/31
- [nongnu] elpa/clojure-ts-mode 4e4b03e2de 137/210: [Fix #508] Correct font-lock for namespaces, ELPA Syncer, 2024/10/31
- [nongnu] elpa/clojure-ts-mode fb88b3b3c8 116/210: Move to top-level before `re-search-backward` in `clojure-find-ns`, ELPA Syncer, 2024/10/31
- [nongnu] elpa/clojure-ts-mode 1d604dbafc 139/210: Merge pull request #509 from carlosgeos/fix-508, ELPA Syncer, 2024/10/31