aboutsummaryrefslogtreecommitdiffstats
path: root/test
diff options
context:
space:
mode:
Diffstat (limited to 'test')
-rw-r--r--test/ChangeLog36
-rw-r--r--test/automated/package-test.el28
-rw-r--r--test/automated/python-tests.el255
-rw-r--r--test/automated/seq-tests.el26
-rw-r--r--test/automated/vc-tests.el14
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 @@
12015-02-01 Joakim Verona <joakim@verona.se> 12015-02-07 Fabián Ezequiel Gallina <fgallina@gnu.org>
2 Support for testing xwidgets 2
3 * xwidget-test-manual.el: 3 * automated/python-tests.el
4 (python-eldoc--get-symbol-at-point-1)
5 (python-eldoc--get-symbol-at-point-2)
6 (python-eldoc--get-symbol-at-point-3)
7 (python-eldoc--get-symbol-at-point-4): New tests.
8
92015-02-07 Fabián Ezequiel Gallina <fgallina@gnu.org>
10
11 * automated/python-tests.el
12 (python-tests-visible-string): New function.
13 (python-parens-electric-indent-1)
14 (python-triple-quote-pairing): Fix indentation, move require calls.
15 (python-hideshow-hide-levels-1)
16 (python-hideshow-hide-levels-2): New tests.
17
182015-02-07 Dmitry Gutov <dgutov@yandex.ru>
19
20 * automated/vc-tests.el (vc-test--working-revision): Fix
21 `vc-working-revision' checks to be compared against nil, which is
22 what is should return for unregistered files.
23
242015-02-06 Nicolas Petton <nicolas@petton.fr>
25
26 * automated/seq-tests.el: New tests for seq-mapcat, seq-partition
27 and seq-group-by.
28
292015-02-05 Artur Malabarba <bruce.connor.am@gmail.com>
30
31 * automated/package-test.el (package-test-get-deps): Fix typo.
32 (package-test-sort-by-dependence): New test
4 33
52015-02-03 Artur Malabarba <bruce.connor.am@gmail.com> 342015-02-03 Artur Malabarba <bruce.connor.am@gmail.com>
6 35
7 * automated/package-test.el (package-test-get-deps): New test. 36 * automated/package-test.el (package-test-get-deps): New test.
8 37
9
102015-01-31 Stefan Monnier <monnier@iro.umontreal.ca> 382015-01-31 Stefan Monnier <monnier@iro.umontreal.ca>
11 39
12 * automated/eieio-tests.el (eieio-test-23-inheritance-check): Simplify. 40 * 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."
498 (list 1 package-x-test--single-archive-entry-1-4)))))) 498 (list 1 package-x-test--single-archive-entry-1-4))))))
499 499
500(ert-deftest package-test-get-deps () 500(ert-deftest package-test-get-deps ()
501 "Test `package-test-get-deps' with complex structures." 501 "Test `package--get-deps' with complex structures."
502 (let ((package-alist 502 (let ((package-alist
503 (mapcar (lambda (p) (list (package-desc-name p) p)) 503 (mapcar (lambda (p) (list (package-desc-name p) p))
504 (list simple-single-desc 504 (list simple-single-desc
@@ -526,6 +526,32 @@ Must called from within a `tar-mode' buffer."
526 (equal (package--get-deps 'simple-depend-2 'direct) 526 (equal (package--get-deps 'simple-depend-2 'direct)
527 '(simple-depend-1 multi-file))))) 527 '(simple-depend-1 multi-file)))))
528 528
529(ert-deftest package-test-sort-by-dependence ()
530 "Test `package--sort-by-dependence' with complex structures."
531 (let ((package-alist
532 (mapcar (lambda (p) (list (package-desc-name p) p))
533 (list simple-single-desc
534 simple-depend-desc
535 multi-file-desc
536 new-pkg-desc
537 simple-depend-desc-1
538 simple-depend-desc-2)))
539 (delete-list
540 (list simple-single-desc
541 simple-depend-desc
542 multi-file-desc
543 new-pkg-desc
544 simple-depend-desc-1
545 simple-depend-desc-2)))
546 (should
547 (equal (package--sort-by-dependence delete-list)
548 (list simple-depend-desc-2 simple-depend-desc-1 new-pkg-desc
549 multi-file-desc simple-depend-desc simple-single-desc)))
550 (should
551 (equal (package--sort-by-dependence (reverse delete-list))
552 (list new-pkg-desc simple-depend-desc-2 simple-depend-desc-1
553 multi-file-desc simple-depend-desc simple-single-desc)))))
554
529(provide 'package-test) 555(provide 'package-test)
530 556
531;;; package-test.el ends here 557;;; 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 @@
24(require 'ert) 24(require 'ert)
25(require 'python) 25(require 'python)
26 26
27;; Dependencies for testing:
28(require 'electric)
29(require 'hideshow)
30
31
27(defmacro python-tests-with-temp-buffer (contents &rest body) 32(defmacro python-tests-with-temp-buffer (contents &rest body)
28 "Create a `python-mode' enabled temp buffer with CONTENTS. 33 "Create a `python-mode' enabled temp buffer with CONTENTS.
29BODY is code to be executed within the temp buffer. Point is 34BODY 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."
104 (call-interactively 'self-insert-command))) 109 (call-interactively 'self-insert-command)))
105 chars))) 110 chars)))
106 111
112(defun python-tests-visible-string (&optional min max)
113 "Return the buffer string excluding invisible overlays.
114Argument MIN and MAX delimit the region to be returned and
115default to `point-min' and `point-max' respectively."
116 (let* ((min (or min (point-min)))
117 (max (or max (point-max)))
118 (buffer (current-buffer))
119 (buffer-contents (buffer-substring-no-properties min max))
120 (overlays
121 (sort (overlays-in min max)
122 (lambda (a b)
123 (let ((overlay-end-a (overlay-end a))
124 (overlay-end-b (overlay-end b)))
125 (> overlay-end-a overlay-end-b))))))
126 (with-temp-buffer
127 (insert buffer-contents)
128 (dolist (overlay overlays)
129 (if (overlay-get overlay 'invisible)
130 (delete-region (overlay-start overlay)
131 (overlay-end overlay))))
132 (buffer-substring-no-properties (point-min) (point-max)))))
133
107 134
108;;; Tests for your tests, so you can test while you test. 135;;; Tests for your tests, so you can test while you test.
109 136
@@ -2916,6 +2943,63 @@ class Foo(models.Model):
2916 2943
2917;;; Eldoc 2944;;; Eldoc
2918 2945
2946(ert-deftest python-eldoc--get-symbol-at-point-1 ()
2947 "Test paren handling."
2948 (python-tests-with-temp-buffer
2949 "
2950map(xx
2951map(codecs.open('somefile'
2952"
2953 (python-tests-look-at "ap(xx")
2954 (should (string= (python-eldoc--get-symbol-at-point) "map"))
2955 (goto-char (line-end-position))
2956 (should (string= (python-eldoc--get-symbol-at-point) "map"))
2957 (python-tests-look-at "('somefile'")
2958 (should (string= (python-eldoc--get-symbol-at-point) "map"))
2959 (goto-char (line-end-position))
2960 (should (string= (python-eldoc--get-symbol-at-point) "codecs.open"))))
2961
2962(ert-deftest python-eldoc--get-symbol-at-point-2 ()
2963 "Ensure self is replaced with the class name."
2964 (python-tests-with-temp-buffer
2965 "
2966class TheClass:
2967
2968 def some_method(self, n):
2969 return n
2970
2971 def other(self):
2972 return self.some_method(1234)
2973
2974"
2975 (python-tests-look-at "self.some_method")
2976 (should (string= (python-eldoc--get-symbol-at-point)
2977 "TheClass.some_method"))
2978 (python-tests-look-at "1234)")
2979 (should (string= (python-eldoc--get-symbol-at-point)
2980 "TheClass.some_method"))))
2981
2982(ert-deftest python-eldoc--get-symbol-at-point-3 ()
2983 "Ensure symbol is found when point is at end of buffer."
2984 (python-tests-with-temp-buffer
2985 "
2986some_symbol
2987
2988"
2989 (goto-char (point-max))
2990 (should (string= (python-eldoc--get-symbol-at-point)
2991 "some_symbol"))))
2992
2993(ert-deftest python-eldoc--get-symbol-at-point-4 ()
2994 "Ensure symbol is found when point is at whitespace."
2995 (python-tests-with-temp-buffer
2996 "
2997some_symbol some_other_symbol
2998"
2999 (python-tests-look-at " some_other_symbol")
3000 (should (string= (python-eldoc--get-symbol-at-point)
3001 "some_symbol"))))
3002
2919 3003
2920;;; Imenu 3004;;; Imenu
2921 3005
@@ -4358,12 +4442,11 @@ def foo(a, b, c):
4358;;; Electricity 4442;;; Electricity
4359 4443
4360(ert-deftest python-parens-electric-indent-1 () 4444(ert-deftest python-parens-electric-indent-1 ()
4361 (require 'electric)
4362 (let ((eim electric-indent-mode)) 4445 (let ((eim electric-indent-mode))
4363 (unwind-protect 4446 (unwind-protect
4364 (progn 4447 (progn
4365 (python-tests-with-temp-buffer 4448 (python-tests-with-temp-buffer
4366 " 4449 "
4367from django.conf.urls import patterns, include, url 4450from django.conf.urls import patterns, include, url
4368 4451
4369from django.contrib import admin 4452from django.contrib import admin
@@ -4375,66 +4458,148 @@ urlpatterns = patterns('',
4375 url(r'^$', views.index 4458 url(r'^$', views.index
4376) 4459)
4377" 4460"
4378 (electric-indent-mode 1) 4461 (electric-indent-mode 1)
4379 (python-tests-look-at "views.index") 4462 (python-tests-look-at "views.index")
4380 (end-of-line) 4463 (end-of-line)
4381 4464
4382 ;; Inserting commas within the same line should leave 4465 ;; Inserting commas within the same line should leave
4383 ;; indentation unchanged. 4466 ;; indentation unchanged.
4384 (python-tests-self-insert ",") 4467 (python-tests-self-insert ",")
4385 (should (= (current-indentation) 4)) 4468 (should (= (current-indentation) 4))
4386 4469
4387 ;; As well as any other input happening within the same 4470 ;; As well as any other input happening within the same
4388 ;; set of parens. 4471 ;; set of parens.
4389 (python-tests-self-insert " name='index')") 4472 (python-tests-self-insert " name='index')")
4390 (should (= (current-indentation) 4)) 4473 (should (= (current-indentation) 4))
4391 4474
4392 ;; But a comma outside it, should trigger indentation. 4475 ;; But a comma outside it, should trigger indentation.
4393 (python-tests-self-insert ",") 4476 (python-tests-self-insert ",")
4394 (should (= (current-indentation) 23)) 4477 (should (= (current-indentation) 23))
4395 4478
4396 ;; Newline indents to the first argument column 4479 ;; Newline indents to the first argument column
4397 (python-tests-self-insert "\n") 4480 (python-tests-self-insert "\n")
4398 (should (= (current-indentation) 23)) 4481 (should (= (current-indentation) 23))
4399 4482
4400 ;; All this input must not change indentation 4483 ;; All this input must not change indentation
4401 (indent-line-to 4) 4484 (indent-line-to 4)
4402 (python-tests-self-insert "url(r'^/login$', views.login)") 4485 (python-tests-self-insert "url(r'^/login$', views.login)")
4403 (should (= (current-indentation) 4)) 4486 (should (= (current-indentation) 4))
4404 4487
4405 ;; But this comma does 4488 ;; But this comma does
4406 (python-tests-self-insert ",") 4489 (python-tests-self-insert ",")
4407 (should (= (current-indentation) 23)))) 4490 (should (= (current-indentation) 23))))
4408 (or eim (electric-indent-mode -1))))) 4491 (or eim (electric-indent-mode -1)))))
4409 4492
4410(ert-deftest python-triple-quote-pairing () 4493(ert-deftest python-triple-quote-pairing ()
4411 (require 'electric)
4412 (let ((epm electric-pair-mode)) 4494 (let ((epm electric-pair-mode))
4413 (unwind-protect 4495 (unwind-protect
4414 (progn 4496 (progn
4415 (python-tests-with-temp-buffer 4497 (python-tests-with-temp-buffer
4416 "\"\"\n" 4498 "\"\"\n"
4417 (or epm (electric-pair-mode 1)) 4499 (or epm (electric-pair-mode 1))
4418 (goto-char (1- (point-max))) 4500 (goto-char (1- (point-max)))
4419 (python-tests-self-insert ?\") 4501 (python-tests-self-insert ?\")
4420 (should (string= (buffer-string) 4502 (should (string= (buffer-string)
4421 "\"\"\"\"\"\"\n")) 4503 "\"\"\"\"\"\"\n"))
4422 (should (= (point) 4))) 4504 (should (= (point) 4)))
4423 (python-tests-with-temp-buffer 4505 (python-tests-with-temp-buffer
4424 "\n" 4506 "\n"
4425 (python-tests-self-insert (list ?\" ?\" ?\")) 4507 (python-tests-self-insert (list ?\" ?\" ?\"))
4426 (should (string= (buffer-string) 4508 (should (string= (buffer-string)
4427 "\"\"\"\"\"\"\n")) 4509 "\"\"\"\"\"\"\n"))
4428 (should (= (point) 4))) 4510 (should (= (point) 4)))
4429 (python-tests-with-temp-buffer 4511 (python-tests-with-temp-buffer
4430 "\"\n\"\"\n" 4512 "\"\n\"\"\n"
4431 (goto-char (1- (point-max))) 4513 (goto-char (1- (point-max)))
4432 (python-tests-self-insert ?\") 4514 (python-tests-self-insert ?\")
4433 (should (= (point) (1- (point-max)))) 4515 (should (= (point) (1- (point-max))))
4434 (should (string= (buffer-string) 4516 (should (string= (buffer-string)
4435 "\"\n\"\"\"\n")))) 4517 "\"\n\"\"\"\n"))))
4436 (or epm (electric-pair-mode -1))))) 4518 (or epm (electric-pair-mode -1)))))
4437 4519
4520
4521;;; Hideshow support
4522
4523(ert-deftest python-hideshow-hide-levels-1 ()
4524 "Should hide all methods when called after class start."
4525 (let ((enabled hs-minor-mode))
4526 (unwind-protect
4527 (progn
4528 (python-tests-with-temp-buffer
4529 "
4530class SomeClass:
4531
4532 def __init__(self, arg, kwarg=1):
4533 self.arg = arg
4534 self.kwarg = kwarg
4535
4536 def filter(self, nums):
4537 def fn(item):
4538 return item in [self.arg, self.kwarg]
4539 return filter(fn, nums)
4540
4541 def __str__(self):
4542 return '%s-%s' % (self.arg, self.kwarg)
4543"
4544 (hs-minor-mode 1)
4545 (python-tests-look-at "class SomeClass:")
4546 (forward-line)
4547 (hs-hide-level 1)
4548 (should
4549 (string=
4550 (python-tests-visible-string)
4551 "
4552class SomeClass:
4553
4554 def __init__(self, arg, kwarg=1):
4555 def filter(self, nums):
4556 def __str__(self):"))))
4557 (or enabled (hs-minor-mode -1)))))
4558
4559(ert-deftest python-hideshow-hide-levels-2 ()
4560 "Should hide nested methods and parens at end of defun."
4561 (let ((enabled hs-minor-mode))
4562 (unwind-protect
4563 (progn
4564 (python-tests-with-temp-buffer
4565 "
4566class SomeClass:
4567
4568 def __init__(self, arg, kwarg=1):
4569 self.arg = arg
4570 self.kwarg = kwarg
4571
4572 def filter(self, nums):
4573 def fn(item):
4574 return item in [self.arg, self.kwarg]
4575 return filter(fn, nums)
4576
4577 def __str__(self):
4578 return '%s-%s' % (self.arg, self.kwarg)
4579"
4580 (hs-minor-mode 1)
4581 (python-tests-look-at "def fn(item):")
4582 (hs-hide-block)
4583 (should
4584 (string=
4585 (python-tests-visible-string)
4586 "
4587class SomeClass:
4588
4589 def __init__(self, arg, kwarg=1):
4590 self.arg = arg
4591 self.kwarg = kwarg
4592
4593 def filter(self, nums):
4594 def fn(item):
4595 return filter(fn, nums)
4596
4597 def __str__(self):
4598 return '%s-%s' % (self.arg, self.kwarg)
4599"))))
4600 (or enabled (hs-minor-mode -1)))))
4601
4602
4438 4603
4439(provide 'python-tests) 4604(provide 'python-tests)
4440 4605
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 @@
2 2
3;; Copyright (C) 2014-2015 Free Software Foundation, Inc. 3;; Copyright (C) 2014-2015 Free Software Foundation, Inc.
4 4
5;; Author: Nicolas Petton <petton.nicolas@gmail.com> 5;; Author: Nicolas Petton <nicolas@petton.fr>
6;; Maintainer: emacs-devel@gnu.org 6;; Maintainer: emacs-devel@gnu.org
7 7
8;; This file is part of GNU Emacs. 8;; This file is part of GNU Emacs.
@@ -197,5 +197,29 @@ Evaluate BODY for each created sequence.
197 (should (equal (seq-concatenate 'vector nil '(8 10)) [8 10])) 197 (should (equal (seq-concatenate 'vector nil '(8 10)) [8 10]))
198 (should (equal (seq-concatenate 'vector seq nil) [2 4 6])))) 198 (should (equal (seq-concatenate 'vector seq nil) [2 4 6]))))
199 199
200(ert-deftest test-seq-mapcat ()
201 (should (equal (seq-mapcat #'seq-reverse '((3 2 1) (6 5 4)))
202 '(1 2 3 4 5 6)))
203 (should (equal (seq-mapcat #'seq-reverse '[(3 2 1) (6 5 4)])
204 '(1 2 3 4 5 6)))
205 (should (equal (seq-mapcat #'seq-reverse '((3 2 1) (6 5 4)) 'vector)
206 '[1 2 3 4 5 6])))
207
208(ert-deftest test-seq-partition ()
209 (should (same-contents-p (seq-partition '(0 1 2 3 4 5 6 7) 3)
210 '((0 1 2) (3 4 5) (6 7))))
211 (should (same-contents-p (seq-partition '[0 1 2 3 4 5 6 7] 3)
212 '([0 1 2] [3 4 5] [6 7])))
213 (should (same-contents-p (seq-partition "Hello world" 2)
214 '("He" "ll" "o " "wo" "rl" "d")))
215 (should (equal (seq-partition '() 2) '()))
216 (should (equal (seq-partition '(1 2 3) -1) '())))
217
218(ert-deftest test-seq-group-by ()
219 (should (equal (seq-group-by #'test-sequences-oddp [1 2 3 4])
220 '((t 3 1) (nil 4 2))))
221 (should (equal (seq-group-by #'car '((a 1) (b 3) (c 4) (a 2)))
222 '((a (a 2) (a 1)) (b (b 3)) (c (c 4))))))
223
200(provide 'seq-tests) 224(provide 'seq-tests)
201;;; seq-tests.el ends here 225;;; 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."
330 (vc-working-revision default-directory backend) '("0" "master"))) 330 (vc-working-revision default-directory backend) '("0" "master")))
331 331
332 (let ((tmp-name (expand-file-name "foo" default-directory))) 332 (let ((tmp-name (expand-file-name "foo" default-directory)))
333 ;; Check for initial state. 333 ;; Check for initial state, should be nil until it's registered.
334 (should 334 ;; Don't pass the backend explictly, otherwise some implementations
335 (member (vc-working-revision tmp-name backend) '("0" "master"))) 335 ;; return non-nil.
336 (should (null (vc-working-revision tmp-name)))
336 337
337 ;; Write a new file. Check for state. 338 ;; Write a new file. Check state.
338 (write-region "foo" nil tmp-name nil 'nomessage) 339 (write-region "foo" nil tmp-name nil 'nomessage)
339 (should 340 (should (null (vc-working-revision tmp-name)))
340 (member (vc-working-revision tmp-name backend) '("0" "master")))
341 341
342 ;; Register a file. Check for state. 342 ;; Register a file. Check for state.
343 (vc-register 343 (vc-register
344 (list backend (list (file-name-nondirectory tmp-name)))) 344 (list backend (list (file-name-nondirectory tmp-name))))
345 ;; FIXME: Don't pass the backend. Emacs should be able to
346 ;; figure it out.
345 (should 347 (should
346 (member (vc-working-revision tmp-name backend) '("0" "master"))) 348 (member (vc-working-revision tmp-name backend) '("0" "master")))
347 349