diff options
| author | Eli Zaretskii | 2012-11-13 16:17:18 +0200 |
|---|---|---|
| committer | Eli Zaretskii | 2012-11-13 16:17:18 +0200 |
| commit | 3c4ca7155293ffc2d04708007131bcbc882d8913 (patch) | |
| tree | 61787be8cd43b6fb3d5159852fbd186eea404de7 /test | |
| parent | 5ade42a5114255c43117065494b96d480c1e1588 (diff) | |
| parent | c708524567662c8911c5ab2695acc7bda0383705 (diff) | |
| download | emacs-3c4ca7155293ffc2d04708007131bcbc882d8913.tar.gz emacs-3c4ca7155293ffc2d04708007131bcbc882d8913.zip | |
Merge from trunk.
Diffstat (limited to 'test')
| -rw-r--r-- | test/ChangeLog | 11 | ||||
| -rw-r--r-- | test/automated/advice-tests.el | 73 | ||||
| -rw-r--r-- | test/automated/ruby-mode-tests.el | 44 |
3 files changed, 121 insertions, 7 deletions
diff --git a/test/ChangeLog b/test/ChangeLog index 72b44747bac..44c013e9887 100644 --- a/test/ChangeLog +++ b/test/ChangeLog | |||
| @@ -1,3 +1,14 @@ | |||
| 1 | 2012-11-13 Dmitry Gutov <dgutov@yandex.ru> | ||
| 2 | |||
| 3 | * automated/ruby-mode-tests.el (ruby-heredoc-font-lock) | ||
| 4 | (ruby-singleton-class-no-heredoc-font-lock) | ||
| 5 | (ruby-add-log-current-method-examples): New tests. | ||
| 6 | (ruby-test-string): Extract from ruby-should-indent-buffer. | ||
| 7 | |||
| 8 | 2012-11-12 Stefan Monnier <monnier@iro.umontreal.ca> | ||
| 9 | |||
| 10 | * automated/advice-tests.el: New tests. | ||
| 11 | |||
| 1 | 2012-10-14 Eli Zaretskii <eliz@gnu.org> | 12 | 2012-10-14 Eli Zaretskii <eliz@gnu.org> |
| 2 | 13 | ||
| 3 | * automated/compile-tests.el (compile-tests--test-regexps-data): | 14 | * automated/compile-tests.el (compile-tests--test-regexps-data): |
diff --git a/test/automated/advice-tests.el b/test/automated/advice-tests.el new file mode 100644 index 00000000000..9f9719fdcfc --- /dev/null +++ b/test/automated/advice-tests.el | |||
| @@ -0,0 +1,73 @@ | |||
| 1 | ;;; advice-tests.el --- Test suite for the new advice thingy. | ||
| 2 | |||
| 3 | ;; Copyright (C) 2012 Free Software Foundation, Inc. | ||
| 4 | |||
| 5 | ;; This file is part of GNU Emacs. | ||
| 6 | |||
| 7 | ;; GNU Emacs is free software: you can redistribute it and/or modify | ||
| 8 | ;; it under the terms of the GNU General Public License as published by | ||
| 9 | ;; the Free Software Foundation, either version 3 of the License, or | ||
| 10 | ;; (at your option) any later version. | ||
| 11 | |||
| 12 | ;; GNU Emacs is distributed in the hope that it will be useful, | ||
| 13 | ;; but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| 14 | ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| 15 | ;; GNU General Public License for more details. | ||
| 16 | |||
| 17 | ;; You should have received a copy of the GNU General Public License | ||
| 18 | ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. | ||
| 19 | |||
| 20 | ;;; Commentary: | ||
| 21 | |||
| 22 | ;;; Code: | ||
| 23 | |||
| 24 | (defvar advice-tests--data | ||
| 25 | '(((defun sm-test1 (x) (+ x 4)) | ||
| 26 | (sm-test1 6) 10) | ||
| 27 | ((advice-add 'sm-test1 :around (lambda (f y) (* (funcall f y) 5))) | ||
| 28 | (sm-test1 6) 50) | ||
| 29 | ((defun sm-test1 (x) (+ x 14)) | ||
| 30 | (sm-test1 6) 100) | ||
| 31 | ((null (get 'sm-test1 'defalias-fset-function)) nil) | ||
| 32 | ((advice-remove 'sm-test1 (lambda (f y) (* (funcall f y) 5))) | ||
| 33 | (sm-test1 6) 20) | ||
| 34 | ((null (get 'sm-test1 'defalias-fset-function)) t) | ||
| 35 | |||
| 36 | ((defun sm-test2 (x) (+ x 4)) | ||
| 37 | (sm-test2 6) 10) | ||
| 38 | ((defadvice sm-test2 (around sm-test activate) | ||
| 39 | ad-do-it (setq ad-return-value (* ad-return-value 5))) | ||
| 40 | (sm-test2 6) 50) | ||
| 41 | ((ad-deactivate 'sm-test2) | ||
| 42 | (sm-test2 6) 10) | ||
| 43 | ((ad-activate 'sm-test2) | ||
| 44 | (sm-test2 6) 50) | ||
| 45 | ((defun sm-test2 (x) (+ x 14)) | ||
| 46 | (sm-test2 6) 100) | ||
| 47 | ((null (get 'sm-test2 'defalias-fset-function)) nil) | ||
| 48 | ((ad-remove-advice 'sm-test2 'around 'sm-test) | ||
| 49 | (sm-test2 6) 100) | ||
| 50 | ((ad-activate 'sm-test2) | ||
| 51 | (sm-test2 6) 20) | ||
| 52 | ((null (get 'sm-test2 'defalias-fset-function)) t) | ||
| 53 | |||
| 54 | ((advice-add 'sm-test3 :around | ||
| 55 | (lambda (f &rest args) `(toto ,(apply f args))) | ||
| 56 | '((name . wrap-with-toto))) | ||
| 57 | (defmacro sm-test3 (x) `(call-test3 ,x)) | ||
| 58 | (macroexpand '(sm-test3 56)) (toto (call-test3 56))) | ||
| 59 | |||
| 60 | )) | ||
| 61 | |||
| 62 | (ert-deftest advice-tests () | ||
| 63 | "Test advice code." | ||
| 64 | (with-temp-buffer | ||
| 65 | (dolist (test advice-tests--data) | ||
| 66 | (let ((res (eval `(progn ,@(butlast test))))) | ||
| 67 | (should (equal (car (last test)) res)))))) | ||
| 68 | |||
| 69 | ;; Local Variables: | ||
| 70 | ;; no-byte-compile: t | ||
| 71 | ;; End: | ||
| 72 | |||
| 73 | ;;; advice-tests.el ends here. | ||
diff --git a/test/automated/ruby-mode-tests.el b/test/automated/ruby-mode-tests.el index ba3040577b1..0e41b2ba1e2 100644 --- a/test/automated/ruby-mode-tests.el +++ b/test/automated/ruby-mode-tests.el | |||
| @@ -36,11 +36,13 @@ | |||
| 36 | 36 | ||
| 37 | The whitespace before and including \"|\" on each line is removed." | 37 | The whitespace before and including \"|\" on each line is removed." |
| 38 | (with-temp-buffer | 38 | (with-temp-buffer |
| 39 | (cl-flet ((fix-indent (s) (replace-regexp-in-string "^[ \t]*|" "" s))) | 39 | (insert (ruby-test-string content)) |
| 40 | (insert (fix-indent content)) | 40 | (ruby-mode) |
| 41 | (ruby-mode) | 41 | (indent-region (point-min) (point-max)) |
| 42 | (indent-region (point-min) (point-max)) | 42 | (should (string= (ruby-test-string expected) (buffer-string))))) |
| 43 | (should (string= (fix-indent expected) (buffer-string)))))) | 43 | |
| 44 | (defun ruby-test-string (s &rest args) | ||
| 45 | (apply 'format (replace-regexp-in-string "^[ \t]*|" "" s) args)) | ||
| 44 | 46 | ||
| 45 | (defun ruby-assert-state (content &rest values-plist) | 47 | (defun ruby-assert-state (content &rest values-plist) |
| 46 | "Assert syntax state values at the end of CONTENT. | 48 | "Assert syntax state values at the end of CONTENT. |
| @@ -76,6 +78,14 @@ VALUES-PLIST is a list with alternating index and value elements." | |||
| 76 | (ruby-assert-state "foo <<asd\n" 3 ?\n) | 78 | (ruby-assert-state "foo <<asd\n" 3 ?\n) |
| 77 | (ruby-assert-state "class <<asd\n" 3 nil)) | 79 | (ruby-assert-state "class <<asd\n" 3 nil)) |
| 78 | 80 | ||
| 81 | (ert-deftest ruby-heredoc-font-lock () | ||
| 82 | (let ((s "foo <<eos.gsub('^ *', '')")) | ||
| 83 | (ruby-assert-face s 9 'font-lock-string-face) | ||
| 84 | (ruby-assert-face s 10 nil))) | ||
| 85 | |||
| 86 | (ert-deftest ruby-singleton-class-no-heredoc-font-lock () | ||
| 87 | (ruby-assert-face "class<<a" 8 nil)) | ||
| 88 | |||
| 79 | (ert-deftest ruby-deep-indent () | 89 | (ert-deftest ruby-deep-indent () |
| 80 | (let ((ruby-deep-arglist nil) | 90 | (let ((ruby-deep-arglist nil) |
| 81 | (ruby-deep-indent-paren '(?\( ?\{ ?\[ ?\] t))) | 91 | (ruby-deep-indent-paren '(?\( ?\{ ?\[ ?\] t))) |
| @@ -202,13 +212,13 @@ VALUES-PLIST is a list with alternating index and value elements." | |||
| 202 | | end | 212 | | end |
| 203 | |")) | 213 | |")) |
| 204 | 214 | ||
| 205 | (ert-deftest ruby-move-to-block-stops-at-opening () | 215 | (ert-deftest ruby-move-to-block-stops-at-indentation () |
| 206 | (with-temp-buffer | 216 | (with-temp-buffer |
| 207 | (insert "def f\nend") | 217 | (insert "def f\nend") |
| 208 | (beginning-of-line) | 218 | (beginning-of-line) |
| 209 | (ruby-mode) | 219 | (ruby-mode) |
| 210 | (ruby-move-to-block -1) | 220 | (ruby-move-to-block -1) |
| 211 | (should (looking-at "f$")))) | 221 | (should (looking-at "^def")))) |
| 212 | 222 | ||
| 213 | (ert-deftest ruby-toggle-block-to-do-end () | 223 | (ert-deftest ruby-toggle-block-to-do-end () |
| 214 | (with-temp-buffer | 224 | (with-temp-buffer |
| @@ -253,6 +263,26 @@ VALUES-PLIST is a list with alternating index and value elements." | |||
| 253 | (ruby-assert-face "# #{comment}\n \"#{interpolation}\"" 16 | 263 | (ruby-assert-face "# #{comment}\n \"#{interpolation}\"" 16 |
| 254 | 'font-lock-variable-name-face)) | 264 | 'font-lock-variable-name-face)) |
| 255 | 265 | ||
| 266 | (ert-deftest ruby-add-log-current-method-examples () | ||
| 267 | (let ((pairs '(("foo" . "#foo") | ||
| 268 | ("C.foo" . ".foo") | ||
| 269 | ("self.foo" . ".foo")))) | ||
| 270 | (loop for (name . value) in pairs | ||
| 271 | do (with-temp-buffer | ||
| 272 | (insert (ruby-test-string | ||
| 273 | "module M | ||
| 274 | | class C | ||
| 275 | | def %s | ||
| 276 | | end | ||
| 277 | | end | ||
| 278 | |end" | ||
| 279 | name)) | ||
| 280 | (ruby-mode) | ||
| 281 | (search-backward "def") | ||
| 282 | (forward-line) | ||
| 283 | (should (string= (ruby-add-log-current-method) | ||
| 284 | (format "M::C%s" value))))))) | ||
| 285 | |||
| 256 | (provide 'ruby-mode-tests) | 286 | (provide 'ruby-mode-tests) |
| 257 | 287 | ||
| 258 | ;;; ruby-mode-tests.el ends here | 288 | ;;; ruby-mode-tests.el ends here |