-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #57 from kommen/add-clojure-mode-tests
Merge clojure-mode tests into clojure-ts-mode
- Loading branch information
Showing
16 changed files
with
4,495 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
82 changes: 82 additions & 0 deletions
82
clojure-mode-tests/clojure-mode-convert-collection-test.el
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
;;; clojure-mode-convert-collection-test.el --- Clojure Mode: convert collection type -*- lexical-binding: t; -*- | ||
|
||
;; Copyright (C) 2016-2021 Benedek Fazekas <[email protected]> | ||
|
||
;; 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 <https://www.gnu.org/licenses/>. | ||
|
||
;;; 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 'buttercup) | ||
(require 'test-helper "test/utils/test-helper") | ||
|
||
(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) | ||
|
||
;;; clojure-mode-convert-collection-test.el ends here |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,194 @@ | ||
;;; clojure-mode-cycling-test.el --- Clojure Mode: cycling things tests -*- lexical-binding: t; -*- | ||
|
||
;; Copyright (C) 2016-2021 Benedek Fazekas <[email protected]> | ||
|
||
;; 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 <https://www.gnu.org/licenses/>. | ||
|
||
;;; 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 'buttercup) | ||
|
||
(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] | ||
(+ 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] | ||
(+ 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] | ||
(+ a b))" | ||
|
||
(let ((clojure-use-metadata-for-privacy t)) | ||
(clojure-cycle-privacy))) | ||
|
||
(when-refactoring-it "should turn a private defn into a public defn" | ||
"(defn- add [a b] | ||
(+ a b))" | ||
|
||
"(defn add [a b] | ||
(+ 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] | ||
(+ a b))" | ||
|
||
(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 | ||
\"docs\" | ||
{:env \"staging\"})" | ||
|
||
(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 | ||
\"docs\" | ||
{:env \"staging\"})" | ||
|
||
(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-not that | ||
(else BBB) | ||
(then AAA)) | ||
(otherwise CCC))" | ||
|
||
(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 | ||
(otherwise CCC) | ||
(if that | ||
(then AAA) | ||
(else BBB)))" | ||
|
||
(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-not that | ||
(aaa) | ||
(bbb)) | ||
(ccc))" | ||
|
||
(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 that | ||
(aaa) | ||
(bbb)) | ||
(ccc))" | ||
|
||
(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) | ||
|
||
;;; clojure-mode-cycling-test.el ends here |
Oops, something went wrong.