Skip to content

Commit

Permalink
Merge pull request #1202 from temyurchenko/master
Browse files Browse the repository at this point in the history
fix some of the tests; partially addresses #1201
  • Loading branch information
Fuco1 committed Apr 10, 2024
2 parents 3ed34cb + 7e72c30 commit e96ef29
Show file tree
Hide file tree
Showing 5 changed files with 108 additions and 6 deletions.
102 changes: 102 additions & 0 deletions test/smartparens-LaTeX-test.el
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
(require 'smartparens-latex)

(ert-deftest sp-test-LaTeX-dont-insert-space-on-forward-slurp-where-not-necessary ()
(sp-test-with-temp-buffer "foo (|)(bar)(baz)"
(LaTeX-mode)
(sp-forward-slurp-sexp 2)
(sp-buffer-equals "foo (|(bar)(baz))")
(sp-forward-barf-sexp 2)
(sp-buffer-equals "foo (|)(bar)(baz)")))

(ert-deftest sp-test-LaTeX-insert-space-on-forward-slurp-where-necessary ()
(sp-test-with-temp-buffer "foo (|bar)baz"
(LaTeX-mode)
(sp-forward-slurp-sexp)
(sp-buffer-equals "foo (|bar baz)")
(sp-forward-barf-sexp)
(sp-buffer-equals "foo (|bar) baz")))

(ert-deftest sp-test-LaTeX-dont-insert-space-on-backward-slurp-where-not-necessary ()
(sp-test-with-temp-buffer "foo (bar)(baz)(|)"
(LaTeX-mode)
(sp-backward-slurp-sexp 2)
(sp-buffer-equals "foo ((bar)(baz)|)")
(sp-backward-barf-sexp 2)
(sp-buffer-equals "foo (bar)(baz)(|)")))

(ert-deftest sp-test-LaTeX-insert-space-on-backward-slurp-where-necessary ()
(sp-test-with-temp-buffer "foo bar(baz|)"
(LaTeX-mode)
(sp-backward-slurp-sexp)
(sp-buffer-equals "foo (bar baz|)")
(sp-backward-barf-sexp)
(sp-buffer-equals "foo bar (baz|)")))

(ert-deftest sp-test-LaTeX-navigate-single-quote-pair-backwards-at-opener ()
(sp-test-with-temp-buffer "\\foo{bar} `|foo bar'baz'"
(LaTeX-mode)
(should (equal (sp-get-thing t)
'(:beg 11 :end 24 :op "`" :cl "'" :prefix "" :suffix "")))))

(ert-deftest sp-test-LaTeX-navigate-single-quote-pair-backwards-at-closer ()
(sp-test-with-temp-buffer "\\foo{bar} `foo bar'baz'|"
(LaTeX-mode)
(should (equal (sp-get-thing t)
'(:beg 11 :end 24 :op "`" :cl "'" :prefix "" :suffix "")))))

;; SKIP:
;; (ert-deftest sp-test-LaTeX-navigate-single-quote-pair-backwards-at-contraction ()
;; (sp-test-with-temp-buffer "\\foo{bar} `foo bar'|bar'"
;; (LaTeX-mode)
;; (should (equal (sp-get-thing t)
;; '(:beg 16 :end 19 :op "" :cl "" :prefix "" :suffix "")))))

;; #820
(ert-deftest sp-test-LaTeX-do-not-fix-closing-delimiter-on-insert-when-inserting-more-than-one-char ()
"Some electric keys sometimes insert more than one character.
In this case the behaviour is more complicated and we shouldn't
try to fix the buffer.
For example quote in LaTeX inserts two backticks which messes up
with the search logic (if inserted one-by-one they would pair by
thesmeves and would not break unrelated pair)"
(sp-test-with-temp-buffer "quote: | $f' = 0$"
(LaTeX-mode)
(execute-kbd-macro "\"")
(sp-buffer-equals "quote: ``|'' $f' = 0$")))

;; #990
(ert-deftest sp-test-LaTeX-do-parse-string-quotes-outside-math ()
(sp-test-with-temp-buffer "foo ``bar''| baz"
(LaTeX-mode)
(sp-backward-sexp)
(sp-buffer-equals "foo |``bar'' baz")))

;; #990
(ert-deftest sp-test-LaTeX-dont-parse-string-quotes-in-math ()
(sp-test-with-temp-buffer "$foo ``bar''| baz$"
(LaTeX-mode)
(sp-backward-sexp)
(sp-buffer-equals "$foo ``|bar'' baz$")))

;; #990
(ert-deftest sp-test-LaTeX-do-pair-string-quotes-outside-math ()
(sp-test-with-temp-buffer "foo | baz"
(LaTeX-mode)
(execute-kbd-macro "``")
(sp-buffer-equals "foo ``|'' baz")))

;; #990
(ert-deftest sp-test-LaTeX-dont-pair-string-quotes-in-math ()
(sp-test-with-temp-buffer "$foo | baz$"
(LaTeX-mode)
(execute-kbd-macro "``")
(sp-buffer-equals "$foo ``| baz$")))

;; #834
(ert-deftest sp-test-LaTeX-wrap-with-trigger ()
"A region should be wrapped with a pair if trigger key is pressed."
(sp-test-with-temp-buffer "foo Mbar baz| bam"
(LaTeX-mode)
(execute-kbd-macro "\"")
(sp-buffer-equals "foo ``bar baz''| bam")))
2 changes: 1 addition & 1 deletion test/smartparens-delete-pair-test.el
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
(delete-backward-char 1)
(should (equal (buffer-string) "\\{")))))

(ert-deftest sp-test-delete-pair-closing ()
(ert-deftest sp-test-delete-pair-opening ()
(let ((sp-pairs sp--test-basic-pairs))
(sp-test-with-temp-elisp-buffer "\\{|"
(smartparens-strict-mode -1)
Expand Down
2 changes: 1 addition & 1 deletion test/smartparens-elixir-test.el
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ end"
end"
'(:beg 1 :end 87 :op "defmodule" :cl "end" :prefix "" :suffix "")))

(ert-deftest sp-test-elixir-parse-bodyless-defp-w-keyword-list ()
(ert-deftest sp-test-elixir-parse-bodyless-def-w-keyword-list ()
"Parse bodyless defp correctly with keyword-list body"
(sp-test-elixir-parse "|defmodule HelloWorld do
def hello
Expand Down
2 changes: 1 addition & 1 deletion test/smartparens-latex-test.el
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
(sp-backward-slurp-sexp 2)
(sp-buffer-equals "foo ((bar)(baz)|)")
(sp-backward-barf-sexp 2)
(sp-buffer-equals "foo (bar)(baz)|()")))
(sp-buffer-equals "foo (bar)(baz)(|)")))

(ert-deftest sp-test-latex-insert-space-on-backward-slurp-where-necessary ()
(sp-test-with-temp-buffer "foo bar(baz|)"
Expand Down
6 changes: 3 additions & 3 deletions test/smartparens-org-test.el
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@
(execute-kbd-macro "foo /bar")
(sp-buffer-equals "foo /bar|/")))

(ert-deftest sp-test-org-do-not-insert-star-pair-after-word ()
(ert-deftest sp-test-org-do-not-insert-slash-pair-after-word ()
(sp-test-with-temp-buffer "|"
(org-mode)
(execute-kbd-macro "foo bar/ baz")
Expand Down Expand Up @@ -98,7 +98,7 @@
(execute-kbd-macro "foo ~bar")
(sp-buffer-equals "foo ~bar|~")))

(ert-deftest sp-test-org-do-not-insert-star-pair-after-word ()
(ert-deftest sp-test-org-do-not-insert-tilde-pair-after-word ()
(sp-test-with-temp-buffer "|"
(org-mode)
(execute-kbd-macro "foo bar~ baz")
Expand Down Expand Up @@ -130,7 +130,7 @@
(execute-kbd-macro "foo =bar")
(sp-buffer-equals "foo =bar|=")))

(ert-deftest sp-test-org-do-not-insert-star-pair-after-word ()
(ert-deftest sp-test-org-do-not-insert-equals-pair-after-word ()
(sp-test-with-temp-buffer "|"
(org-mode)
(execute-kbd-macro "foo bar= baz")
Expand Down

0 comments on commit e96ef29

Please sign in to comment.