diff options
Diffstat (limited to 'test')
-rw-r--r-- | test/ChangeLog | 36 | ||||
-rw-r--r-- | test/automated/package-test.el | 28 | ||||
-rw-r--r-- | test/automated/python-tests.el | 255 | ||||
-rw-r--r-- | test/automated/seq-tests.el | 26 | ||||
-rw-r--r-- | test/automated/vc-tests.el | 14 |
5 files changed, 302 insertions, 57 deletions
diff --git a/test/ChangeLog b/test/ChangeLog index 60b3ed352d0..ff02bd6a25d 100644 --- a/test/ChangeLog +++ b/test/ChangeLog @@ -1,12 +1,40 @@ -2015-02-01 Joakim Verona <joakim@verona.se> - Support for testing xwidgets - * xwidget-test-manual.el: +2015-02-07 Fabián Ezequiel Gallina <fgallina@gnu.org> + + * automated/python-tests.el + (python-eldoc--get-symbol-at-point-1) + (python-eldoc--get-symbol-at-point-2) + (python-eldoc--get-symbol-at-point-3) + (python-eldoc--get-symbol-at-point-4): New tests. + +2015-02-07 Fabián Ezequiel Gallina <fgallina@gnu.org> + + * automated/python-tests.el + (python-tests-visible-string): New function. + (python-parens-electric-indent-1) + (python-triple-quote-pairing): Fix indentation, move require calls. + (python-hideshow-hide-levels-1) + (python-hideshow-hide-levels-2): New tests. + +2015-02-07 Dmitry Gutov <dgutov@yandex.ru> + + * automated/vc-tests.el (vc-test--working-revision): Fix + `vc-working-revision' checks to be compared against nil, which is + what is should return for unregistered files. + +2015-02-06 Nicolas Petton <nicolas@petton.fr> + + * automated/seq-tests.el: New tests for seq-mapcat, seq-partition + and seq-group-by. + +2015-02-05 Artur Malabarba <bruce.connor.am@gmail.com> + + * automated/package-test.el (package-test-get-deps): Fix typo. + (package-test-sort-by-dependence): New test 2015-02-03 Artur Malabarba <bruce.connor.am@gmail.com> * automated/package-test.el (package-test-get-deps): New test. - 2015-01-31 Stefan Monnier <monnier@iro.umontreal.ca> * automated/eieio-tests.el (eieio-test-23-inheritance-check): Simplify. diff --git a/test/automated/package-test.el b/test/automated/package-test.el index 004e2e89895..7d2a343a077 100644 --- a/test/automated/package-test.el +++ b/test/automated/package-test.el @@ -498,7 +498,7 @@ Must called from within a `tar-mode' buffer." (list 1 package-x-test--single-archive-entry-1-4)))))) (ert-deftest package-test-get-deps () - "Test `package-test-get-deps' with complex structures." + "Test `package--get-deps' with complex structures." (let ((package-alist (mapcar (lambda (p) (list (package-desc-name p) p)) (list simple-single-desc @@ -526,6 +526,32 @@ Must called from within a `tar-mode' buffer." (equal (package--get-deps 'simple-depend-2 'direct) '(simple-depend-1 multi-file))))) +(ert-deftest package-test-sort-by-dependence () + "Test `package--sort-by-dependence' with complex structures." + (let ((package-alist + (mapcar (lambda (p) (list (package-desc-name p) p)) + (list simple-single-desc + simple-depend-desc + multi-file-desc + new-pkg-desc + simple-depend-desc-1 + simple-depend-desc-2))) + (delete-list + (list simple-single-desc + simple-depend-desc + multi-file-desc + new-pkg-desc + simple-depend-desc-1 + simple-depend-desc-2))) + (should + (equal (package--sort-by-dependence delete-list) + (list simple-depend-desc-2 simple-depend-desc-1 new-pkg-desc + multi-file-desc simple-depend-desc simple-single-desc))) + (should + (equal (package--sort-by-dependence (reverse delete-list)) + (list new-pkg-desc simple-depend-desc-2 simple-depend-desc-1 + multi-file-desc simple-depend-desc simple-single-desc))))) + (provide 'package-test) ;;; package-test.el ends here diff --git a/test/automated/python-tests.el b/test/automated/python-tests.el index 672b05c39de..47e2a6e8195 100644 --- a/test/automated/python-tests.el +++ b/test/automated/python-tests.el @@ -24,6 +24,11 @@ (require 'ert) (require 'python) +;; Dependencies for testing: +(require 'electric) +(require 'hideshow) + + (defmacro python-tests-with-temp-buffer (contents &rest body) "Create a `python-mode' enabled temp buffer with CONTENTS. BODY is code to be executed within the temp buffer. Point is @@ -104,6 +109,28 @@ STRING, it is skipped so the next STRING occurrence is selected." (call-interactively 'self-insert-command))) chars))) +(defun python-tests-visible-string (&optional min max) + "Return the buffer string excluding invisible overlays. +Argument MIN and MAX delimit the region to be returned and +default to `point-min' and `point-max' respectively." + (let* ((min (or min (point-min))) + (max (or max (point-max))) + (buffer (current-buffer)) + (buffer-contents (buffer-substring-no-properties min max)) + (overlays + (sort (overlays-in min max) + (lambda (a b) + (let ((overlay-end-a (overlay-end a)) + (overlay-end-b (overlay-end b))) + (> overlay-end-a overlay-end-b)))))) + (with-temp-buffer + (insert buffer-contents) + (dolist (overlay overlays) + (if (overlay-get overlay 'invisible) + (delete-region (overlay-start overlay) + (overlay-end overlay)))) + (buffer-substring-no-properties (point-min) (point-max))))) + ;;; Tests for your tests, so you can test while you test. @@ -2916,6 +2943,63 @@ class Foo(models.Model): ;;; Eldoc +(ert-deftest python-eldoc--get-symbol-at-point-1 () + "Test paren handling." + (python-tests-with-temp-buffer + " +map(xx +map(codecs.open('somefile' +" + (python-tests-look-at "ap(xx") + (should (string= (python-eldoc--get-symbol-at-point) "map")) + (goto-char (line-end-position)) + (should (string= (python-eldoc--get-symbol-at-point) "map")) + (python-tests-look-at "('somefile'") + (should (string= (python-eldoc--get-symbol-at-point) "map")) + (goto-char (line-end-position)) + (should (string= (python-eldoc--get-symbol-at-point) "codecs.open")))) + +(ert-deftest python-eldoc--get-symbol-at-point-2 () + "Ensure self is replaced with the class name." + (python-tests-with-temp-buffer + " +class TheClass: + + def some_method(self, n): + return n + + def other(self): + return self.some_method(1234) + +" + (python-tests-look-at "self.some_method") + (should (string= (python-eldoc--get-symbol-at-point) + "TheClass.some_method")) + (python-tests-look-at "1234)") + (should (string= (python-eldoc--get-symbol-at-point) + "TheClass.some_method")))) + +(ert-deftest python-eldoc--get-symbol-at-point-3 () + "Ensure symbol is found when point is at end of buffer." + (python-tests-with-temp-buffer + " +some_symbol + +" + (goto-char (point-max)) + (should (string= (python-eldoc--get-symbol-at-point) + "some_symbol")))) + +(ert-deftest python-eldoc--get-symbol-at-point-4 () + "Ensure symbol is found when point is at whitespace." + (python-tests-with-temp-buffer + " +some_symbol some_other_symbol +" + (python-tests-look-at " some_other_symbol") + (should (string= (python-eldoc--get-symbol-at-point) + "some_symbol")))) + ;;; Imenu @@ -4358,12 +4442,11 @@ def foo(a, b, c): ;;; Electricity (ert-deftest python-parens-electric-indent-1 () - (require 'electric) (let ((eim electric-indent-mode)) (unwind-protect (progn (python-tests-with-temp-buffer - " + " from django.conf.urls import patterns, include, url from django.contrib import admin @@ -4375,66 +4458,148 @@ urlpatterns = patterns('', url(r'^$', views.index ) " - (electric-indent-mode 1) - (python-tests-look-at "views.index") - (end-of-line) + (electric-indent-mode 1) + (python-tests-look-at "views.index") + (end-of-line) - ;; Inserting commas within the same line should leave - ;; indentation unchanged. - (python-tests-self-insert ",") - (should (= (current-indentation) 4)) + ;; Inserting commas within the same line should leave + ;; indentation unchanged. + (python-tests-self-insert ",") + (should (= (current-indentation) 4)) - ;; As well as any other input happening within the same - ;; set of parens. - (python-tests-self-insert " name='index')") - (should (= (current-indentation) 4)) + ;; As well as any other input happening within the same + ;; set of parens. + (python-tests-self-insert " name='index')") + (should (= (current-indentation) 4)) - ;; But a comma outside it, should trigger indentation. - (python-tests-self-insert ",") - (should (= (current-indentation) 23)) + ;; But a comma outside it, should trigger indentation. + (python-tests-self-insert ",") + (should (= (current-indentation) 23)) - ;; Newline indents to the first argument column - (python-tests-self-insert "\n") - (should (= (current-indentation) 23)) + ;; Newline indents to the first argument column + (python-tests-self-insert "\n") + (should (= (current-indentation) 23)) - ;; All this input must not change indentation - (indent-line-to 4) - (python-tests-self-insert "url(r'^/login$', views.login)") - (should (= (current-indentation) 4)) + ;; All this input must not change indentation + (indent-line-to 4) + (python-tests-self-insert "url(r'^/login$', views.login)") + (should (= (current-indentation) 4)) - ;; But this comma does - (python-tests-self-insert ",") - (should (= (current-indentation) 23)))) + ;; But this comma does + (python-tests-self-insert ",") + (should (= (current-indentation) 23)))) (or eim (electric-indent-mode -1))))) (ert-deftest python-triple-quote-pairing () - (require 'electric) (let ((epm electric-pair-mode)) (unwind-protect (progn (python-tests-with-temp-buffer - "\"\"\n" - (or epm (electric-pair-mode 1)) - (goto-char (1- (point-max))) - (python-tests-self-insert ?\") - (should (string= (buffer-string) - "\"\"\"\"\"\"\n")) - (should (= (point) 4))) + "\"\"\n" + (or epm (electric-pair-mode 1)) + (goto-char (1- (point-max))) + (python-tests-self-insert ?\") + (should (string= (buffer-string) + "\"\"\"\"\"\"\n")) + (should (= (point) 4))) (python-tests-with-temp-buffer - "\n" - (python-tests-self-insert (list ?\" ?\" ?\")) - (should (string= (buffer-string) - "\"\"\"\"\"\"\n")) - (should (= (point) 4))) + "\n" + (python-tests-self-insert (list ?\" ?\" ?\")) + (should (string= (buffer-string) + "\"\"\"\"\"\"\n")) + (should (= (point) 4))) (python-tests-with-temp-buffer - "\"\n\"\"\n" - (goto-char (1- (point-max))) - (python-tests-self-insert ?\") - (should (= (point) (1- (point-max)))) - (should (string= (buffer-string) - "\"\n\"\"\"\n")))) + "\"\n\"\"\n" + (goto-char (1- (point-max))) + (python-tests-self-insert ?\") + (should (= (point) (1- (point-max)))) + (should (string= (buffer-string) + "\"\n\"\"\"\n")))) (or epm (electric-pair-mode -1))))) + +;;; Hideshow support + +(ert-deftest python-hideshow-hide-levels-1 () + "Should hide all methods when called after class start." + (let ((enabled hs-minor-mode)) + (unwind-protect + (progn + (python-tests-with-temp-buffer + " +class SomeClass: + + def __init__(self, arg, kwarg=1): + self.arg = arg + self.kwarg = kwarg + + def filter(self, nums): + def fn(item): + return item in [self.arg, self.kwarg] + return filter(fn, nums) + + def __str__(self): + return '%s-%s' % (self.arg, self.kwarg) +" + (hs-minor-mode 1) + (python-tests-look-at "class SomeClass:") + (forward-line) + (hs-hide-level 1) + (should + (string= + (python-tests-visible-string) + " +class SomeClass: + + def __init__(self, arg, kwarg=1): + def filter(self, nums): + def __str__(self):")))) + (or enabled (hs-minor-mode -1))))) + +(ert-deftest python-hideshow-hide-levels-2 () + "Should hide nested methods and parens at end of defun." + (let ((enabled hs-minor-mode)) + (unwind-protect + (progn + (python-tests-with-temp-buffer + " +class SomeClass: + + def __init__(self, arg, kwarg=1): + self.arg = arg + self.kwarg = kwarg + + def filter(self, nums): + def fn(item): + return item in [self.arg, self.kwarg] + return filter(fn, nums) + + def __str__(self): + return '%s-%s' % (self.arg, self.kwarg) +" + (hs-minor-mode 1) + (python-tests-look-at "def fn(item):") + (hs-hide-block) + (should + (string= + (python-tests-visible-string) + " +class SomeClass: + + def __init__(self, arg, kwarg=1): + self.arg = arg + self.kwarg = kwarg + + def filter(self, nums): + def fn(item): + return filter(fn, nums) + + def __str__(self): + return '%s-%s' % (self.arg, self.kwarg) +")))) + (or enabled (hs-minor-mode -1))))) + + (provide 'python-tests) diff --git a/test/automated/seq-tests.el b/test/automated/seq-tests.el index 23989799306..ecbc0043210 100644 --- a/test/automated/seq-tests.el +++ b/test/automated/seq-tests.el @@ -2,7 +2,7 @@ ;; Copyright (C) 2014-2015 Free Software Foundation, Inc. -;; Author: Nicolas Petton <petton.nicolas@gmail.com> +;; Author: Nicolas Petton <nicolas@petton.fr> ;; Maintainer: emacs-devel@gnu.org ;; This file is part of GNU Emacs. @@ -197,5 +197,29 @@ Evaluate BODY for each created sequence. (should (equal (seq-concatenate 'vector nil '(8 10)) [8 10])) (should (equal (seq-concatenate 'vector seq nil) [2 4 6])))) +(ert-deftest test-seq-mapcat () + (should (equal (seq-mapcat #'seq-reverse '((3 2 1) (6 5 4))) + '(1 2 3 4 5 6))) + (should (equal (seq-mapcat #'seq-reverse '[(3 2 1) (6 5 4)]) + '(1 2 3 4 5 6))) + (should (equal (seq-mapcat #'seq-reverse '((3 2 1) (6 5 4)) 'vector) + '[1 2 3 4 5 6]))) + +(ert-deftest test-seq-partition () + (should (same-contents-p (seq-partition '(0 1 2 3 4 5 6 7) 3) + '((0 1 2) (3 4 5) (6 7)))) + (should (same-contents-p (seq-partition '[0 1 2 3 4 5 6 7] 3) + '([0 1 2] [3 4 5] [6 7]))) + (should (same-contents-p (seq-partition "Hello world" 2) + '("He" "ll" "o " "wo" "rl" "d"))) + (should (equal (seq-partition '() 2) '())) + (should (equal (seq-partition '(1 2 3) -1) '()))) + +(ert-deftest test-seq-group-by () + (should (equal (seq-group-by #'test-sequences-oddp [1 2 3 4]) + '((t 3 1) (nil 4 2)))) + (should (equal (seq-group-by #'car '((a 1) (b 3) (c 4) (a 2))) + '((a (a 2) (a 1)) (b (b 3)) (c (c 4)))))) + (provide 'seq-tests) ;;; seq-tests.el ends here diff --git a/test/automated/vc-tests.el b/test/automated/vc-tests.el index 5b7b3cce039..e83eb85c0fe 100644 --- a/test/automated/vc-tests.el +++ b/test/automated/vc-tests.el @@ -330,18 +330,20 @@ For backends which dont support it, `vc-not-supported' is signalled." (vc-working-revision default-directory backend) '("0" "master"))) (let ((tmp-name (expand-file-name "foo" default-directory))) - ;; Check for initial state. - (should - (member (vc-working-revision tmp-name backend) '("0" "master"))) + ;; Check for initial state, should be nil until it's registered. + ;; Don't pass the backend explictly, otherwise some implementations + ;; return non-nil. + (should (null (vc-working-revision tmp-name))) - ;; Write a new file. Check for state. + ;; Write a new file. Check state. (write-region "foo" nil tmp-name nil 'nomessage) - (should - (member (vc-working-revision tmp-name backend) '("0" "master"))) + (should (null (vc-working-revision tmp-name))) ;; Register a file. Check for state. (vc-register (list backend (list (file-name-nondirectory tmp-name)))) + ;; FIXME: Don't pass the backend. Emacs should be able to + ;; figure it out. (should (member (vc-working-revision tmp-name backend) '("0" "master"))) |