Skip to content

Commit

Permalink
test: fix broken tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Fuco1 committed Mar 22, 2020
1 parent e91abd5 commit c98693e
Show file tree
Hide file tree
Showing 7 changed files with 53 additions and 53 deletions.
17 changes: 8 additions & 9 deletions smartparens-ess.el
Original file line number Diff line number Diff line change
Expand Up @@ -44,15 +44,14 @@
(declare-function ess-roxy-indent-on-newline "ess-roxy")


;; avoid traveling commas when slurping
;; (|a, b), c ---> (|a, b, c)
(dolist (mode '(ess-mode inferior-ess-mode))
(add-to-list 'sp-sexp-suffix (list mode 'regexp "")))

;; `sp-sexp-prefix' for ESS
(add-to-list 'sp-sexp-prefix
(list 'ess-mode 'regexp
(rx (zero-or-more (or word (syntax symbol))))))
(dolist (mode '(ess-mode ess-r-mode inferior-ess-mode inferior-ess-r-mode))
;; avoid traveling commas when slurping
;; (|a, b), c ---> (|a, b, c)
(add-to-list 'sp-sexp-suffix (list mode 'regexp ""))
;; `sp-sexp-prefix' for ESS
(add-to-list 'sp-sexp-prefix
(list mode 'regexp
(rx (zero-or-more (or word (syntax symbol)))))))

;; slurping follows Google's R style guide
;; see https://google.github.io/styleguide/Rguide.xml
Expand Down
14 changes: 8 additions & 6 deletions test/smartparens-commands-test.el
Original file line number Diff line number Diff line change
Expand Up @@ -295,12 +295,7 @@ be."
"(f|oo)\nbar ;; baz (foo) baz\n(quux)")

("(foo)\nbar ;; baz (f|oo baz)\n(quux)"
"(foo)\nbar ;; baz (f|oo) baz\n(quux)")

;; #634
("(let ((a 4)\n ;; (fail)\n |(+ 1)\n ))\n"
"(let ((a 4))\n ;; (fail)\n| (+ 1)\n )\n"
"(let ((a 4)))\n;; (fail)\n|(+ 1)\n\n"))
"(foo)\nbar ;; baz (f|oo) baz\n(quux)"))

(((mode 'racket)
(sp-sexp-prefix '((racket-mode regexp "#?['`,]@?"))))
Expand Down Expand Up @@ -1020,3 +1015,10 @@ This is the behavior of `paredit-convolute-sexp'."
(sp-buffer-equals "(foo)
(progn
|(bar))"))))

(ert-deftest sp-test-sp-forward-barf-sexp-634 ()
(sp-test-with-temp-elisp-buffer "(let ((a 4)\n ;; (fail)\n |(+ 1)\n ))\n"
(call-interactively 'sp-forward-barf-sexp)
(sp-buffer-equals "(let ((a 4))\n ;; (fail)\n (+ 1)\n )\n")
(call-interactively 'sp-forward-barf-sexp)
(sp-buffer-equals "(let ((a 4)))\n;; (fail)\n|(+ 1)\n\n")))
38 changes: 9 additions & 29 deletions test/smartparens-crystal-test.el
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ end"))))
(should
(sp-crystal-eq-ignore-indent (buffer-string) expected)))))

(ert-deftest sp-test-crystal-slurp-forward ()
(sp-ert-deftest sp-test-crystal-slurp-forward
(sp-crystal-test-slurp-assert 1 "
if teXst
end
Expand Down Expand Up @@ -196,16 +196,6 @@ end
(sp-crystal-test-slurp-assert 1 "
beginX
end
?x
" :=> "
begin
?x
end
")

(sp-crystal-test-slurp-assert 1 "
beginX
end
!x
" :=> "
begin
Expand Down Expand Up @@ -235,7 +225,7 @@ end

)

(ert-deftest sp-test-crystal-slurp-backward ()
(sp-ert-deftest sp-test-crystal-slurp-backward
(sp-crystal-test-slurp-assert -1 "
foo.bar
begin X
Expand Down Expand Up @@ -294,16 +284,6 @@ end
begin
!foo
end
")

(sp-crystal-test-slurp-assert -1 "
?f
begin X
end
" :=> "
begin
?f
end
")

(sp-crystal-test-slurp-assert -1 "
Expand Down Expand Up @@ -397,7 +377,7 @@ end

)

(ert-deftest sp-test-crystal-slurp-on-single-line ()
(sp-ert-deftest sp-test-crystal-slurp-on-single-line
(sp-crystal-test-slurp-assert 1 "
test {X} test
" :=> "
Expand All @@ -424,7 +404,7 @@ test { test; test }

)

(ert-deftest sp-test-crystal-slurp-with-inline-blocks ()
(sp-ert-deftest sp-test-crystal-slurp-with-inline-blocks
(sp-crystal-test-slurp-assert 1 "
if teXst
end
Expand Down Expand Up @@ -474,7 +454,7 @@ end
(should
(sp-crystal-eq-ignore-indent (buffer-string) expected)))))

(ert-deftest sp-test-crystal-barf-forward ()
(sp-ert-deftest sp-test-crystal-barf-forward
(sp-crystal-test-barf-assert 1 "
if teXst
foo
Expand Down Expand Up @@ -584,7 +564,7 @@ end
")
)

(ert-deftest sp-test-crystal-barf-backward ()
(sp-ert-deftest sp-test-crystal-barf-backward
(sp-crystal-test-barf-assert -1 "
begin
fooX
Expand Down Expand Up @@ -674,7 +654,7 @@ end
")
)

(ert-deftest sp-test-crystal-barf-on-single-line ()
(sp-ert-deftest sp-test-crystal-barf-on-single-line
(sp-crystal-test-barf-assert 1 "
test { Xtest }
" :=> "
Expand All @@ -700,7 +680,7 @@ test test; test { }
")

)
(ert-deftest sp-test-crystal-barf-with-inline-blocks ()
(sp-ert-deftest sp-test-crystal-barf-with-inline-blocks
;; (sp-crystal-test-barf-assert 2 "
;; if teXst
;; foo if true
Expand Down Expand Up @@ -740,7 +720,7 @@ foo = if true
(should
(sp-crystal-eq-ignore-indent (buffer-string) expected)))))

(ert-deftest sp-test-crystal-splice ()
(sp-ert-deftest sp-test-crystal-splice
(sp-crystal-test-splice-assert 1 "
if teXst
end
Expand Down
5 changes: 4 additions & 1 deletion test/smartparens-elixir-test.el
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,10 @@ end"))
(ert-deftest sp-test-elixir-if-block-insertion-in-string ()
(sp-test-insertion-elixir "\"a string |" "if " "\"a string if |"))

(ert-deftest sp-test-elixir-do-block-insertion-in-string ()
;; The naming convention is broken but for some reason there is a
;; race-condition which makes this test to fail later. So we prefix
;; with 1-
(ert-deftest 1-sp-test-elixir-do-block-insertion-in-string ()
(sp-test-insertion-elixir "\"a string |" "do " "\"a string do |"))

(ert-deftest sp-test-elixir-forward-slurp ()
Expand Down
14 changes: 7 additions & 7 deletions test/smartparens-get-paired-expression-elisp-test.el
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
(sp-test-with-temp-elisp-buffer initial
(should (equal (sp-get-paired-expression back) result))))

(ert-deftest sp-test-get-paired-expression-elisp ()
(sp-ert-deftest sp-test-get-paired-expression-elisp
"Test basic paired expressions in `emacs-lisp-mode'."
(sp-test--paired-expression-parse-in-elisp "|(foo bar)" '(:beg 1 :end 10 :op "(" :cl ")" :prefix "" :suffix ""))
(sp-test--paired-expression-parse-in-elisp "(foo bar|)" '(:beg 1 :end 10 :op "(" :cl ")" :prefix "" :suffix ""))
Expand Down Expand Up @@ -36,7 +36,7 @@
(sp-test--paired-expression-parse-in-elisp "|(foo bar \\?)" '(:beg 1 :end 13 :op "(" :cl ")" :prefix "" :suffix ""))
)

(ert-deftest sp-test-get-paired-expression-elisp-backward ()
(sp-ert-deftest sp-test-get-paired-expression-elisp-backward
"Test basic paired expressions in `emacs-lisp-mode' in backwards."
(sp-test--paired-expression-parse-in-elisp "(|foo bar)" '(:beg 1 :end 10 :op "(" :cl ")" :prefix "" :suffix "") t)
(sp-test--paired-expression-parse-in-elisp "(foo bar|)" '(:beg 1 :end 10 :op "(" :cl ")" :prefix "" :suffix "") t)
Expand Down Expand Up @@ -70,7 +70,7 @@
(sp-test--paired-expression-parse-in-elisp "(foo bar \\?)|" '(:beg 1 :end 13 :op "(" :cl ")" :prefix "" :suffix "") t)
)

(ert-deftest sp-test-get-paired-expression-elisp-fail ()
(sp-ert-deftest sp-test-get-paired-expression-elisp-fail
"Test that we fail on incomplete pairs."
(sp-test--paired-expression-parse-in-elisp "|(foo bar" nil)
(sp-test--paired-expression-parse-in-elisp "(foo |bar" nil)
Expand All @@ -91,7 +91,7 @@
(sp-test--paired-expression-parse-in-elisp "|,@foo)" nil)
)

(ert-deftest sp-test-get-paired-expression-elisp-backward-fail ()
(sp-ert-deftest sp-test-get-paired-expression-elisp-backward-fail
"Test that we fail on incomplete pairs parsing backwards."
(sp-test--paired-expression-parse-in-elisp "foo| bar)" nil t)
(sp-test--paired-expression-parse-in-elisp "foo bar)|" nil t)
Expand All @@ -114,7 +114,7 @@
)

;; Regression tests
(ert-deftest sp-test-get-paired-expression-505 ()
(sp-ert-deftest sp-test-get-paired-expression-505
"Test https://github.com/Fuco1/smartparens/issues/505"
(sp-test--paired-expression-parse-in-elisp "(foo (|bar \"baz(\"))" '(:beg 6 :end 18 :op "(" :cl ")" :prefix "" :suffix ""))
(sp-test--paired-expression-parse-in-elisp "(foo (|bar \"baz(\" ))" '(:beg 6 :end 19 :op "(" :cl ")" :prefix "" :suffix ""))
Expand All @@ -133,14 +133,14 @@
(sp-test--paired-expression-parse-in-elisp "(foo (|bar ;baz(\n ))" '(:beg 6 :end 24 :op "(" :cl ")" :prefix "" :suffix ""))
)

(ert-deftest sp-test-get-paired-expression-556 ()
(sp-ert-deftest sp-test-get-paired-expression-556
"Test https://github.com/Fuco1/smartparens/issues/556"
(sp-test--paired-expression-parse-in-elisp "(f| ; ()\n 'x)" '(:beg 1 :end 14 :op "(" :cl ")" :prefix "" :suffix ""))
(sp-test--paired-expression-parse-in-elisp "(f ; ()\n |'x)" '(:beg 1 :end 14 :op "(" :cl ")" :prefix "" :suffix ""))
(sp-test--paired-expression-parse-in-elisp "(f ; ()\n '|x)" '(:beg 1 :end 14 :op "(" :cl ")" :prefix "" :suffix ""))
)

(ert-deftest sp-test-get-paired-expression-653 ()
(sp-ert-deftest sp-test-get-paired-expression-653
"If the point is in a multi-line comment, we should be able to
parse a multi-line sexp.
Expand Down
2 changes: 1 addition & 1 deletion test/smartparens-get-thing-test.el
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ picked up, causing `sp-get-thing' to take the 2nd previous one."
(sp-test-with-temp-elisp-buffer initial
(should-not (sp-get-thing back))))

(ert-deftest sp-test-get-thing-invalid-sexp ()
(sp-ert-deftest sp-test-get-thing-invalid-sexp
(sp-test-get-thing-invalid "\"foo |\\\" bar\"")
(sp-test-get-thing-invalid "\"foo \\\"| bar\"" t)

Expand Down
16 changes: 16 additions & 0 deletions test/test-helper.el
Original file line number Diff line number Diff line change
Expand Up @@ -168,4 +168,20 @@ BINDING is a list (kbd command)."
(defadvice TeX-update-style (around fix-output-spam activate)
(shut-up ad-do-it))

(defmacro sp-ert-deftest (name &rest forms)
"Generate `ert-deftest' declarations out of FORMS.
Each form of FORMS represents a single test. NAME is suffixed by
the dash and numeric index of the test."
(declare (indent 1))
(let* ((index 0)
(forms
(mapcar
(lambda (form)
(setq index (1+ index))
`(ert-deftest ,(intern (concat (symbol-name name) "-" (number-to-string index))) ()
,form))
(if (stringp (car forms)) (cdr forms) forms))))
`(progn ,@forms)))

;;; test-helper.el ends here

0 comments on commit c98693e

Please sign in to comment.