aboutsummaryrefslogtreecommitdiffstats
path: root/test
diff options
context:
space:
mode:
authorFabián Ezequiel Gallina2014-07-01 00:54:11 -0300
committerFabián Ezequiel Gallina2014-07-01 00:54:11 -0300
commit3acd6262d993cb445a3656808ce544cf68754f89 (patch)
tree0a7216ec13d284e4976944b34cd0cad0ab257085 /test
parent64c11219d16ae5f971d51f1fb19405b0e24f9269 (diff)
downloademacs-3acd6262d993cb445a3656808ce544cf68754f89.tar.gz
emacs-3acd6262d993cb445a3656808ce544cf68754f89.zip
* lisp/progmodes/python.el (python-indent-post-self-insert-function):
Enhancements to electric indentation behavior inside parens. * test/automated/python-tests.el (python-tests-self-insert): New function. (python-triple-quote-pairing): Use it. (python-util-forward-comment-1): New test. (Bug#17658)
Diffstat (limited to 'test')
-rw-r--r--test/ChangeLog7
-rw-r--r--test/automated/python-tests.el114
2 files changed, 96 insertions, 25 deletions
diff --git a/test/ChangeLog b/test/ChangeLog
index dea6f4a9264..f93b553f341 100644
--- a/test/ChangeLog
+++ b/test/ChangeLog
@@ -1,3 +1,10 @@
12014-07-01 Fabián Ezequiel Gallina <fgallina@gnu.org>
2
3 * automated/python-tests.el
4 (python-tests-self-insert): New function.
5 (python-triple-quote-pairing): Use it.
6 (python-util-forward-comment-1): New test. (Bug#17658)
7
12014-06-28 Leo Liu <sdl.web@gmail.com> 82014-06-28 Leo Liu <sdl.web@gmail.com>
2 9
3 * automated/calc-tests.el: New file and add tests for math-bignum. 10 * automated/calc-tests.el: New file and add tests for math-bignum.
diff --git a/test/automated/python-tests.el b/test/automated/python-tests.el
index f580e946b8f..a35242fe882 100644
--- a/test/automated/python-tests.el
+++ b/test/automated/python-tests.el
@@ -86,6 +86,24 @@ STRING, it is skipped so the next STRING occurrence is selected."
86 found-point 86 found-point
87 (and restore-point (goto-char starting-point))))) 87 (and restore-point (goto-char starting-point)))))
88 88
89(defun python-tests-self-insert (char-or-str)
90 "Call `self-insert-command' for chars in CHAR-OR-STR."
91 (let ((chars
92 (cond
93 ((characterp char-or-str)
94 (list char-or-str))
95 ((stringp char-or-str)
96 (string-to-list char-or-str))
97 ((not
98 (cl-remove-if #'characterp char-or-str))
99 char-or-str)
100 (t (error "CHAR-OR-STR must be a char, string, or list of char")))))
101 (mapc
102 (lambda (char)
103 (let ((last-command-event char))
104 (call-interactively 'self-insert-command)))
105 chars)))
106
89 107
90;;; Tests for your tests, so you can test while you test. 108;;; Tests for your tests, so you can test while you test.
91 109
@@ -2715,9 +2733,6 @@ def foo(a, b, c):
2715 (should (string= (python-util-strip-string "\n \t \n\r ") "")) 2733 (should (string= (python-util-strip-string "\n \t \n\r ") ""))
2716 (should (string= (python-util-strip-string "") ""))) 2734 (should (string= (python-util-strip-string "") "")))
2717 2735
2718
2719;;; Electricity
2720
2721(ert-deftest python-util-forward-comment-1 () 2736(ert-deftest python-util-forward-comment-1 ()
2722 (python-tests-with-temp-buffer 2737 (python-tests-with-temp-buffer
2723 (concat 2738 (concat
@@ -2730,36 +2745,85 @@ def foo(a, b, c):
2730 (python-util-forward-comment -1) 2745 (python-util-forward-comment -1)
2731 (should (= (point) (point-min))))) 2746 (should (= (point) (point-min)))))
2732 2747
2748
2749;;; Electricity
2750
2751(ert-deftest python-parens-electric-indent-1 ()
2752 (require 'electric)
2753 (let ((eim electric-indent-mode))
2754 (unwind-protect
2755 (progn
2756 (python-tests-with-temp-buffer
2757 "
2758from django.conf.urls import patterns, include, url
2759
2760from django.contrib import admin
2761
2762from myapp import views
2763
2764
2765urlpatterns = patterns('',
2766 url(r'^$', views.index
2767)
2768"
2769 (electric-indent-mode 1)
2770 (python-tests-look-at "views.index")
2771 (end-of-line)
2772
2773 ;; Inserting commas within the same line should leave
2774 ;; indentation unchanged.
2775 (python-tests-self-insert ",")
2776 (should (= (current-indentation) 4))
2777
2778 ;; As well as any other input happening within the same
2779 ;; set of parens.
2780 (python-tests-self-insert " name='index')")
2781 (should (= (current-indentation) 4))
2782
2783 ;; But a comma outside it, should trigger indentation.
2784 (python-tests-self-insert ",")
2785 (should (= (current-indentation) 23))
2786
2787 ;; Newline indents to the first argument column
2788 (python-tests-self-insert "\n")
2789 (should (= (current-indentation) 23))
2790
2791 ;; All this input must not change indentation
2792 (indent-line-to 4)
2793 (python-tests-self-insert "url(r'^/login$', views.login)")
2794 (should (= (current-indentation) 4))
2795
2796 ;; But this comma does
2797 (python-tests-self-insert ",")
2798 (should (= (current-indentation) 23))))
2799 (or eim (electric-indent-mode -1)))))
2800
2733(ert-deftest python-triple-quote-pairing () 2801(ert-deftest python-triple-quote-pairing ()
2734 (require 'electric) 2802 (require 'electric)
2735 (let ((epm electric-pair-mode)) 2803 (let ((epm electric-pair-mode))
2736 (unwind-protect 2804 (unwind-protect
2737 (progn 2805 (progn
2738 (python-tests-with-temp-buffer 2806 (python-tests-with-temp-buffer
2739 "\"\"\n" 2807 "\"\"\n"
2740 (or epm (electric-pair-mode 1)) 2808 (or epm (electric-pair-mode 1))
2741 (goto-char (1- (point-max))) 2809 (goto-char (1- (point-max)))
2742 (let ((last-command-event ?\")) 2810 (python-tests-self-insert ?\")
2743 (call-interactively 'self-insert-command)) 2811 (should (string= (buffer-string)
2744 (should (string= (buffer-string) 2812 "\"\"\"\"\"\"\n"))
2745 "\"\"\"\"\"\"\n")) 2813 (should (= (point) 4)))
2746 (should (= (point) 4)))
2747 (python-tests-with-temp-buffer 2814 (python-tests-with-temp-buffer
2748 "\n" 2815 "\n"
2749 (let ((last-command-event ?\")) 2816 (python-tests-self-insert (list ?\" ?\" ?\"))
2750 (dotimes (i 3) 2817 (should (string= (buffer-string)
2751 (call-interactively 'self-insert-command))) 2818 "\"\"\"\"\"\"\n"))
2752 (should (string= (buffer-string) 2819 (should (= (point) 4)))
2753 "\"\"\"\"\"\"\n"))
2754 (should (= (point) 4)))
2755 (python-tests-with-temp-buffer 2820 (python-tests-with-temp-buffer
2756 "\"\n\"\"\n" 2821 "\"\n\"\"\n"
2757 (goto-char (1- (point-max))) 2822 (goto-char (1- (point-max)))
2758 (let ((last-command-event ?\")) 2823 (python-tests-self-insert ?\")
2759 (call-interactively 'self-insert-command)) 2824 (should (= (point) (1- (point-max))))
2760 (should (= (point) (1- (point-max)))) 2825 (should (string= (buffer-string)
2761 (should (string= (buffer-string) 2826 "\"\n\"\"\"\n"))))
2762 "\"\n\"\"\"\n"))))
2763 (or epm (electric-pair-mode -1))))) 2827 (or epm (electric-pair-mode -1)))))
2764 2828
2765 2829