[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] master 4473b4e 112/177: New test for cc-mode's fontification func
From: |
João Távora |
Subject: |
[elpa] master 4473b4e 112/177: New test for cc-mode's fontification functions |
Date: |
Sat, 28 Mar 2015 15:41:18 +0000 |
branch: master
commit 4473b4ede5b9fb4736ef78482511349d2fe171eb
Author: Noam Postavsky <address@hidden>
Commit: Noam Postavsky <address@hidden>
New test for cc-mode's fontification functions
This issue requires font locking to trigger. This can be be done by
let-binding noninteractive to nil and using a buffer name that doesn't
start with a space, instead of the external emacs hack which is now
redundant.
* yasnippet-tests.el (yas--with-font-locked-temp-buffer): new macro
similar to with-temp-buffer but enables font-lock-mode even in -batch
mode.
(example-for-issue-474): new test
(example-for-issue-404, example-for-issue-404-c-mode): use new macro
(example-for-issue-404-external-emacs): removed
---
yasnippet-tests.el | 74 ++++++++++++++++++++++++---------------------------
1 files changed, 35 insertions(+), 39 deletions(-)
diff --git a/yasnippet-tests.el b/yasnippet-tests.el
index 02bf10c..f87b3d4 100644
--- a/yasnippet-tests.el
+++ b/yasnippet-tests.el
@@ -204,60 +204,56 @@
(ert-simulate-command `(yas-mock-insert "bbb"))
(should (string= (yas--buffer-contents) "if
condition\naaa\nelse\nbbb\nend")))))
+(defmacro yas--with-font-locked-temp-buffer (&rest body)
+ "Like `with-temp-buffer', but ensure `font-lock-mode'."
+ (declare (indent 0) (debug t))
+ (let ((temp-buffer (make-symbol "temp-buffer")))
+ ;; NOTE: buffer name must not start with a space, otherwise
+ ;; `font-lock-mode' doesn't turn on.
+ `(let ((,temp-buffer (generate-new-buffer "*yas-temp*")))
+ (with-current-buffer ,temp-buffer
+ ;; pretend we're interactive so `font-lock-mode' turns on
+ (let ((noninteractive nil)
+ ;; turn on font locking after major mode change
+ (change-major-mode-after-body-hook #'font-lock-mode))
+ (unwind-protect
+ (progn (require 'font-lock)
+ ;; turn on font locking before major mode change
+ (font-lock-mode +1)
+ ,@body)
+ (and (buffer-name ,temp-buffer)
+ (kill-buffer ,temp-buffer))))))))
+
+(ert-deftest example-for-issue-474 ()
+ (yas--with-font-locked-temp-buffer
+ (c-mode)
+ (yas-minor-mode 1)
+ (insert "#include <foo>\n")
+ (let ((yas-good-grace nil)) (yas-expand-snippet "`(insert \"TODO: \")`"))
+ (should (string= (yas--buffer-contents) "#include <foo>\nTODO: "))))
+
(ert-deftest example-for-issue-404 ()
- (with-temp-buffer
+ (yas--with-font-locked-temp-buffer
(c++-mode)
(yas-minor-mode 1)
(insert "#include <foo>\n")
- (let ((snippet "main"))
- (let ((yas-good-grace nil)) (yas-expand-snippet snippet))
- (should (string= (yas--buffer-contents) "#include <foo>\nmain")))))
+ (let ((yas-good-grace nil)) (yas-expand-snippet "main"))
+ (should (string= (yas--buffer-contents) "#include <foo>\nmain"))))
(ert-deftest example-for-issue-404-c-mode ()
- (with-temp-buffer
+ (yas--with-font-locked-temp-buffer
(c-mode)
(yas-minor-mode 1)
(insert "#include <foo>\n")
- (let ((snippet "main"))
- (let ((yas-good-grace nil)) (yas-expand-snippet snippet))
- (should (string= (yas--buffer-contents) "#include <foo>\nmain")))))
-
-(ert-deftest example-for-issue-404-external-emacs ()
- :tags '(:external)
- (let ((fixture-el-file (make-temp-file "yas-404-fixture" nil ".el")))
- (with-temp-buffer
- (insert (pp-to-string
- `(condition-case _
- (progn
- (require 'yasnippet-tests)
- (yas-with-snippet-dirs
- '((".emacs.d/snippets"
- ("c-mode"
- ("main" . "int main ()"))))
- (yas-global-mode)
- (switch-to-buffer "foo.c")
- (c-mode)
- (insert "#include <iostream>\nmain")
- (setq yas-good-grace nil)
- (yas-expand)
- (should (string= (buffer-string)
- "#include <iostream>\nint main ()"))
- (kill-emacs 0)))
- (error (kill-emacs -1)))))
- (write-file fixture-el-file))
- (should (= 0
- (call-process (concat invocation-directory invocation-name)
- nil nil nil
- "-Q" "--batch"
- "-L" "." "-l" fixture-el-file)))))
+ (let ((yas-good-grace nil)) (yas-expand-snippet "main"))
+ (should (string= (yas--buffer-contents) "#include <foo>\nmain"))))
(ert-deftest middle-of-buffer-snippet-insertion ()
(with-temp-buffer
(yas-minor-mode 1)
(insert "beginning")
(save-excursion (insert "end"))
- (let ((snippet "-middle-"))
- (yas-expand-snippet snippet))
+ (yas-expand-snippet "-middle-")
(should (string= (yas--buffer-contents) "beginning-middle-end"))))
(ert-deftest another-example-for-issue-271 ()
- [elpa] master 8e7295b 108/177: Closes #403: more uniform behaviour for `yas-use-menu', (continued)
- [elpa] master 8e7295b 108/177: Closes #403: more uniform behaviour for `yas-use-menu', João Távora, 2015/03/28
- [elpa] master 498cbe4 105/177: Closes #469: Don't use `yas--init-minor-keymap', João Távora, 2015/03/28
- [elpa] master e7599b9 104/177: Merge pull request #466 from npostavs/no-reverse, João Távora, 2015/03/28
- [elpa] master a4e04f9 109/177: update doc for org 8.x, João Távora, 2015/03/28
- [elpa] master a0c2217 110/177: Merge pull request #473 from npostavs/org8, João Távora, 2015/03/28
- [elpa] master b36a4f7 107/177: Properly closes #469: Don't use `yas--init-minor-keymap', João Távora, 2015/03/28
- [elpa] master d809e88 106/177: Revert "Closes #469: Don't use `yas--init-minor-keymap'", João Távora, 2015/03/28
- [elpa] master 599a262 113/177: Closes #474: fix cc-mode fontification conflict, João Távora, 2015/03/28
- [elpa] master a80033d 115/177: Refactor yas-good-grace error handling, João Távora, 2015/03/28
- [elpa] master 4d9eee9 111/177: Simpler, more effective .travis file, João Távora, 2015/03/28
- [elpa] master 4473b4e 112/177: New test for cc-mode's fontification functions,
João Távora <=
- [elpa] master 8ced5c7 117/177: Remove type, expand-env from new snippet value, João Távora, 2015/03/28
- [elpa] master 4ccf133 114/177: Merge pull request #476 from npostavs/cc-fontify2, João Távora, 2015/03/28
- [elpa] master f176027 118/177: Restore backquotes lost in rst -> org translation, João Távora, 2015/03/28
- [elpa] master 580e5c6 116/177: Don't lose error message when yas-good-grace is t, João Távora, 2015/03/28
- [elpa] master 4c16eae 119/177: Document uuid directive, João Távora, 2015/03/28
- [elpa] master fe288a1 121/177: Fix publishing with org 7.9, João Távora, 2015/03/28
- [elpa] master e1ed662 125/177: Allow jit loading interactively, João Távora, 2015/03/28
- [elpa] master e53ec1e 124/177: Make snippets submodule track master, update it, João Távora, 2015/03/28
- [elpa] master f98c527 123/177: Replace text -> yas-text in documentation, João Távora, 2015/03/28
- [elpa] master 763f5fa 122/177: Closes #474: fix more cc-mode font-lock conflicts, João Távora, 2015/03/28