Skip to content

Commit

Permalink
test: refactor clojure tests to have one assert per test
Browse files Browse the repository at this point in the history
  • Loading branch information
Fuco1 committed Apr 2, 2024
1 parent 33392b9 commit 6a1d93d
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 118 deletions.
140 changes: 23 additions & 117 deletions test/smarparents-clojure-test.el
Original file line number Diff line number Diff line change
Expand Up @@ -2,124 +2,30 @@
(require 'smartparens-clojure)
(require 'clojure-mode)

(ert-deftest sp-test-clojure-slurp-with-prefix ()
"Ensure we correctly slurp over prefixed expressions."
(let ((before "(do|
(foo) #{...}
(foo) ^{:a 1}
(foo) #(xyzzy 1 2 %)
(foo) #_(comment reader macro)
(foo) ~unquote-me
(foo) `~'unquote-me
(foo) ~@(splice-me)
(foo) `(quote-me)
(foo) @(deref-me)
(foo) @deref-me
(foo) #?@(:clj [3 4] :cljs [5 6])
(foo) #?(:clj Double/NaN
:cljs js/NaN
:default nil))")
(after "(do
(foo #{...})
(foo ^{:a 1})
(foo #(xyzzy 1 2 %))
(foo #_(comment reader macro))
(foo ~unquote-me)
(foo `~'unquote-me)
(foo ~@(splice-me))
(foo `(quote-me))
(foo @(deref-me))
(foo @deref-me)
(foo #?@(:clj [3 4] :cljs [5 6]))
(foo #?(:clj Double/NaN
:cljs js/NaN
:default nil)))"))
(sp-test-with-temp-buffer before (clojure-mode)
(while (re-search-forward "(foo" nil t)
(sp-forward-slurp-sexp)
(forward-line))
(should (equal (buffer-string) after)))))

(ert-deftest sp-test-clojure-wrap-with-prefix ()
(sp-ert-deftest sp-test-clojure-wrap-with-prefix
:let ((sp-pairs sp--test-basic-pairs))
:mode 'clojure-mode
"Ensure correct wrap-pair over prefixed expressions."
(let ((before "(do
|#{...}
^{:a 1}
#(xyzzy 1 2 %)
#_(comment reader macro)
~unquote-me
`~'unquote-me
~@(splice-me)
`(quote-me)
@(deref-me)
@deref-me
#?@(:clj [3 4] :cljs [5 6])
#?(:clj Double/NaN
(sp-test-kbd-macro "|#{...}M" "(" "(|#{...}M)")
(sp-test-kbd-macro "|^{:a 1}M" "(" "(|^{:a 1}M)")
(sp-test-kbd-macro "|#(xyzzy 1 2 %)M" "(" "(|#(xyzzy 1 2 %)M)")
(sp-test-kbd-macro "|#_(comment reader macro)M" "(" "(|#_(comment reader macro)M)")
(sp-test-kbd-macro "|~unquote-meM" "(" "(|~unquote-meM)")
(sp-test-kbd-macro "|`~'unquote-meM" "(" "(|`~'unquote-meM)")
(sp-test-kbd-macro "|~@(splice-me)M" "(" "(|~@(splice-me)M)")
(sp-test-kbd-macro "|`(quote-me)M" "(" "(|`(quote-me)M)")
(sp-test-kbd-macro "|@(deref-me)M" "(" "(|@(deref-me)M)")
(sp-test-kbd-macro "|@deref-meM" "(" "(|@deref-meM)")
(sp-test-kbd-macro "|#?@(:clj [3 4] :cljs [5 6])M" "(" "(|#?@(:clj [3 4] :cljs [5 6])M)")
(sp-test-kbd-macro "|#?(:clj Double/NaN
:cljs js/NaN
:default nil)M" "(" "(|#?(:clj Double/NaN
:cljs js/NaN
:default nil))")
(after "(do
(#{...})
(^{:a 1})
(#(xyzzy 1 2 %))
(#_(comment reader macro))
(~unquote-me)
(`~'unquote-me)
(~@(splice-me))
(`(quote-me))
(@(deref-me))
(@deref-me)
(#?@(:clj [3 4] :cljs [5 6]))
(#?(:clj Double/NaN
:cljs js/NaN
:default nil)))"))
(sp-test-with-temp-buffer before (clojure-mode)
(while (< (current-column) 3)
(sp-wrap-with-pair "(")
(forward-line)
;; FIXME: sp-wrap-with-pair keeps region active for no clear reason
(deactivate-mark)
(back-to-indentation))
(should (equal (buffer-string) after)))))
:default nil)M)"))

(ert-deftest sp-test-clojure-wrap-with-fence-prefix ()
(sp-ert-deftest sp-test-clojure-wrap-with-fence-prefix
:let ((sp-pairs sp--test-basic-pairs))
:mode 'clojure-mode
"Ensure correct wrap-pair over #-prefixed expressions."
(let ((before "(do
|#\"...\"
#~xyzzy)")
(after "(do
(#\"...\")
(#~xyzzy))"))
(sp-test-with-temp-buffer before (clojure-mode)
(while (not (eobp))
(back-to-indentation)
(sp-wrap-with-pair "(")
(forward-line)
;; FIXME: sp-wrap-with-pair keeps region active
(deactivate-mark))
(should (equal (buffer-string) after)))))

;; FIXME: fails
;; (ert-deftest sp-test-clojure-barf-with-fence-prefix ()
;; "Ensure correct forward-barf over #-prefixed expressions."
;; (let ((before "(do|
;; (#{...})
;; (#(xyzzy 1 2 %))
;; (#_(comment reader macro))
;; (#?@(:clj [3 4] :cljs [5 6]))
;; (#?(:clj Double/NaN
;; :cljs js/NaN
;; :default nil)))")
;; (after "(do
;; ()#{...}
;; ()#(xyzzy 1 2 %)
;; ()#_(comment reader macro)
;; ()#?@(:clj [3 4] :cljs [5 6])
;; ()#?(:clj Double/NaN
;; :cljs js/NaN
;; :default nil))"))
;; (sp-test-with-temp-buffer before (clojure-mode)
;; (while (re-search-forward "(#" nil t)
;; (backward-char)
;; (sp-forward-barf-sexp)
;; (forward-line))
;; (should (equal (buffer-string) after)))))
(sp-test-kbd-macro "|#\"...\"M" "(" "(#\"...\")")
(sp-test-kbd-macro "|#~xyzzyM" "(" "(#~xyzzy)"))
28 changes: 27 additions & 1 deletion test/smartparens-commands-test.el
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,23 @@ be."
("(f|oo) #'(bar)" "(f|oo #'(bar))"))
(((sp-sexp-prefix '((emacs-lisp-mode regexp "\\(?:['`]*,@?\\|[',`]\\)"))))
("(fo|o) `',(bar)" "(fo|o `',(bar))")
("(fo|o) ,@(bar)" "(fo|o ,@(bar))"))))
("(fo|o) ,@(bar)" "(fo|o ,@(bar))"))
(((mode 'clojure))
;; was sp-test-clojure-slurp-with-prefix
("(foo|) #{...}" "(foo| #{...})")
("(foo|) ^{:a 1}" "(foo| ^{:a 1})")
("(foo|) #(xyzzy 1 2 %)" "(foo| #(xyzzy 1 2 %))")
("(foo|) #_(comment reader macro)" "(foo| #_(comment reader macro))")
("(foo|) ~unquote-me" "(foo| ~unquote-me)")
("(foo|) `~'unquote-me" "(foo| `~'unquote-me)")
("(foo|) ~@(splice-me)" "(foo| ~@(splice-me))")
("(foo|) `(quote-me)" "(foo| `(quote-me))")
("(foo|) @(deref-me)" "(foo| @(deref-me))")
("(foo|) @deref-me" "(foo| @deref-me)")
("(foo|) #?@(:clj [3 4] :cljs [5 6])" "(foo| #?@(:clj [3 4] :cljs [5 6]))")
("(foo|) #?(:clj Double/NaN\n :cljs js/NaN\n :default nil)"
;; longer because slurp causes "autoformat"
"(foo| #?(:clj Double/NaN\n :cljs js/NaN\n :default nil))"))))

(sp-test-command sp-backward-slurp-sexp
((nil
Expand Down Expand Up @@ -307,6 +323,16 @@ be."
("(foo)\nbar ;; baz (f|oo baz)\n(quux)"
"(foo)\nbar ;; baz (f|oo) baz\n(quux)"))

(((mode 'clojure))
("(|#{...})" "(|)#{...}")
("(|#(xyzzy 1 2 %))" "(|)#(xyzzy 1 2 %)")
("(|#_(comment reader macro))" "(|)#_(comment reader macro)")
("(|#?@(:clj [3 4] :cljs [5 6]))" "(|)#?@(:clj [3 4] :cljs [5 6])")
("(|#?(:clj Double/NaN
:cljs js/NaN
:default nil))"
"(|)#?(:clj Double/NaN\n :cljs js/NaN\n :default nil)"))

(((mode 'racket)
(sp-sexp-prefix '((racket-mode regexp "#?['`,]@?"))))
("(f|oo #'(bar))" "(f|oo) #'(bar)"))))
Expand Down

0 comments on commit 6a1d93d

Please sign in to comment.