mirror of
https://github.com/joaotavora/yasnippet.git
synced 2025-10-13 21:13:04 +00:00
Closes #271: 3rd try, protect escapes after collecting backquote elisp
* Add more tests * Now only need to escape backslashes in mirror/field transformations
This commit is contained in:
parent
6aff6a0894
commit
197104b450
@ -97,7 +97,8 @@
|
||||
;; "brother from another mother!"))))
|
||||
|
||||
|
||||
;;; Snippet expansion
|
||||
;;; Snippet expansion and character escaping
|
||||
;;; Thanks to @zw963 (Billy) for the testing
|
||||
;;;
|
||||
(ert-deftest escape-dollar ()
|
||||
(with-temp-buffer
|
||||
@ -200,15 +201,36 @@
|
||||
(set-mark 4)
|
||||
(goto-char 7)
|
||||
(yas-expand-snippet snippet)
|
||||
(ert-simulate-command `(yas-mock-insert "bbb"))
|
||||
(should (string= (yas--buffer-contents) "if condition\naaa\nelse\nbbb\nend")))))
|
||||
(should (string= (yas--buffer-contents) "aaa${1:bbb}ccc")))))
|
||||
|
||||
(ert-deftest string-match-with-subregexp-in-embedded-elisp ()
|
||||
(with-temp-buffer
|
||||
(yas-minor-mode 1)
|
||||
;; the rule here is: To use regexps in embedded `(elisp)` expressions, write
|
||||
;; it like you would normal elisp, i.e. no need to escape the backslashes.
|
||||
(let ((snippet "`(if (string-match \"foo\\\\(ba+r\\\\)foo\" \"foobaaaaaaaaaarfoo\") \"ok\" \"fail\")`"))
|
||||
(yas-expand-snippet snippet))
|
||||
(should (string= (yas--buffer-contents) "ok"))))
|
||||
|
||||
(ert-deftest string-match-with-subregexp-in-mirror-transformations ()
|
||||
(with-temp-buffer
|
||||
(yas-minor-mode 1)
|
||||
;; the rule here is: To use regexps in embedded `(elisp)` expressions,
|
||||
;; escape backslashes once. i.e. to use \\( \\) constructs, write \\\\( \\\\).
|
||||
(let ((snippet "$1${1:$(if (string-match \"foo\\\\\\\\(ba+r\\\\\\\\)baz\" yas/text) \"ok\" \"fail\")}"))
|
||||
(yas-expand-snippet snippet)
|
||||
(should (string= (yas--buffer-contents) "fail"))
|
||||
(ert-simulate-command `(yas-mock-insert "foobaaar"))
|
||||
(should (string= (yas--buffer-contents) "foobaaarfail"))
|
||||
(ert-simulate-command `(yas-mock-insert "baz"))
|
||||
(should (string= (yas--buffer-contents) "foobaaarbazok")))))
|
||||
|
||||
|
||||
;;; Misc tests
|
||||
;;;
|
||||
|
||||
(ert-deftest protection-overlay-no-cheating ()
|
||||
"Protection overlays at the very end of the buffer, are dealt by cheatingly inserting a newline!
|
||||
"Protection overlays at the very end of the buffer are dealt
|
||||
with by cheatingly inserting a newline!
|
||||
|
||||
TODO: correct this bug!"
|
||||
:expected-result :failed
|
||||
|
@ -3762,13 +3762,13 @@ Meant to be called in a narrowed buffer, does various passes"
|
||||
;; Reset the yas--dollar-regions
|
||||
;;
|
||||
(setq yas--dollar-regions nil)
|
||||
;; protect escaped characters
|
||||
;;
|
||||
(yas--protect-escapes)
|
||||
;; replace all backquoted expressions
|
||||
;;
|
||||
(goto-char parse-start)
|
||||
(yas--save-backquotes)
|
||||
;; protect escaped characters
|
||||
;;
|
||||
(yas--protect-escapes)
|
||||
;; parse fields with {}
|
||||
;;
|
||||
(goto-char parse-start)
|
||||
@ -3925,7 +3925,7 @@ With optional string TEXT do it in string instead of the buffer."
|
||||
"Save all the \"`(lisp-expression)`\"-style expression
|
||||
with their evaluated value into `yas--backquote-markers-and-strings'"
|
||||
(while (re-search-forward yas--backquote-lisp-expression-regexp nil t)
|
||||
(let ((current-string (match-string 1)) transformed)
|
||||
(let ((current-string (match-string-no-properties 1)) transformed)
|
||||
(delete-region (match-beginning 0) (match-end 0))
|
||||
(setq transformed (yas--eval-lisp (yas--read-lisp current-string)))
|
||||
(goto-char (match-beginning 0))
|
||||
|
Loading…
x
Reference in New Issue
Block a user