]> code.delx.au - gnu-emacs/blobdiff - test/automated/electric-tests.el
Update copyright year to 2015
[gnu-emacs] / test / automated / electric-tests.el
index 830b61e50045d87533d2eaae0ebabd75b21ee8e8..b675989c07279e47d84c925250e182edccdc423b 100644 (file)
@@ -1,6 +1,6 @@
 ;;; electric-tests.el --- tests for electric.el
 
-;; Copyright (C) 2013 Free Software Foundation, Inc.
+;; Copyright (C) 2013-2015 Free Software Foundation, Inc.
 
 ;; Author: João Távora <joaotavora@gmail.com>
 ;; Keywords:
@@ -60,7 +60,7 @@
         (cl-progv
             (mapcar #'car bindings)
             (mapcar #'cdr bindings)
-          (self-insert-command 1))))
+          (call-interactively (key-binding `[,last-command-event])))))
     (should (equal (buffer-substring-no-properties (point-min) (point-max))
                    expected-string))
     (should (equal (point)
                                      mode
                                      extra-desc))
            ()
-         ,(format "With \"%s\", try input %c at point %d. \
-Should %s \"%s\" and point at %d"
+         ,(format "With |%s|, try input %c at point %d. \
+Should %s |%s| and point at %d"
                   fixture
                   char
                   (1+ pos)
@@ -141,7 +141,7 @@ Should %s \"%s\" and point at %d"
           expected-string
           expected-point
           bindings
-          (modes '(quote (emacs-lisp-mode ruby-mode c++-mode)))
+          (modes '(quote (ruby-mode c++-mode)))
           (test-in-comments t)
           (test-in-strings t)
           (test-in-code t)
@@ -186,7 +186,7 @@ Should %s \"%s\" and point at %d"
                    bindings
                    fixture-fn))))))
 \f
-;;; Basic pairings and skippings
+;;; Basic pairs and skips
 ;;;
 (define-electric-pair-test balanced-situation
   " (())  " "(((((((" :skip-pair-string "ppppppp"
@@ -237,7 +237,7 @@ Should %s \"%s\" and point at %d"
 (define-electric-pair-test find-matching-different-paren-type-inside-list
   "( ()]) " "-[-----" :skip-pair-string "-------")
 
-(define-electric-pair-test ignore-different-unmatching-paren-type
+(define-electric-pair-test ignore-different-nonmatching-paren-type
   "( ()]) " "-(-----" :skip-pair-string "-p-----")
 
 (define-electric-pair-test autopair-keep-least-amount-of-mixed-unbalance
@@ -295,14 +295,56 @@ Should %s \"%s\" and point at %d"
   :bindings `((electric-pair-text-syntax-table
                . ,prog-mode-syntax-table)))
 
-(define-electric-pair-test inhibit-only-if-next-is-mismatched
+(define-electric-pair-test inhibit-if-strings-mismatched
   "\"foo\"\"bar" "\""
-  :expected-string "\"\"\"foo\"\"bar"
+  :expected-string "\"\"foo\"\"bar"
   :expected-point 2
   :test-in-strings nil
   :bindings `((electric-pair-text-syntax-table
                . ,prog-mode-syntax-table)))
 
+(define-electric-pair-test inhibit-in-mismatched-string-inside-ruby-comments
+  "foo\"\"
+#
+#    \"bar\"
+#    \"   \"
+#    \"
+#
+baz\"\""
+  "\""
+  :modes '(ruby-mode)
+  :test-in-strings nil
+  :test-in-comments nil
+  :expected-point 19
+  :expected-string
+  "foo\"\"
+#
+#    \"bar\"\"
+#    \"   \"
+#    \"
+#
+baz\"\""
+  :fixture-fn #'(lambda () (goto-char (point-min)) (search-forward "bar")))
+
+(define-electric-pair-test inhibit-in-mismatched-string-inside-c-comments
+  "foo\"\"/*
+    \"bar\"
+    \"   \"
+    \"
+*/baz\"\""
+  "\""
+  :modes '(c-mode)
+  :test-in-strings nil
+  :test-in-comments nil
+  :expected-point 18
+  :expected-string
+  "foo\"\"/*
+    \"bar\"\"
+    \"   \"
+    \"
+*/baz\"\""
+  :fixture-fn #'(lambda () (goto-char (point-min)) (search-forward "bar")))
+
 \f
 ;;; More quotes, but now don't bind `electric-pair-text-syntax-table'
 ;;; to `prog-mode-syntax-table'. Use the defaults for
@@ -341,6 +383,31 @@ Should %s \"%s\" and point at %d"
   :test-in-code nil
   :test-in-comments t)
 
+(define-electric-pair-test whitespace-skipping-for-quotes-not-outside
+  "  \"  \"" "\"-----" :expected-string "\"\"  \"  \""
+  :expected-point 2
+  :bindings '((electric-pair-skip-whitespace . chomp))
+  :test-in-strings nil
+  :test-in-code t
+  :test-in-comments nil)
+
+(define-electric-pair-test whitespace-skipping-for-quotes-only-inside
+  "  \"  \"" "---\"--" :expected-string "  \"\""
+  :expected-point 5
+  :bindings '((electric-pair-skip-whitespace . chomp))
+  :test-in-strings nil
+  :test-in-code t
+  :test-in-comments nil)
+
+(define-electric-pair-test whitespace-skipping-quotes-not-without-proper-syntax
+  "  \"  \"" "---\"--" :expected-string "  \"\"\"  \""
+  :expected-point 5
+  :modes '(text-mode)
+  :bindings '((electric-pair-skip-whitespace . chomp))
+  :test-in-strings nil
+  :test-in-code t
+  :test-in-comments nil)
+
 \f
 ;;; Pairing arbitrary characters
 ;;;
@@ -442,7 +509,7 @@ Should %s \"%s\" and point at %d"
     (with-temp-buffer
       (insert "()")
       (goto-char 2)
-      (electric-pair-backward-delete-char 1)
+      (electric-pair-delete-pair 1)
       (should (equal "" (buffer-string))))))
 
 \f
@@ -508,5 +575,14 @@ Should %s \"%s\" and point at %d"
                   (skip-chars-backward "\"")
                   (mark-sexp -1)))
 
+(define-electric-pair-test autowrapping-7
+  "foo" "\"" :expected-string "``foo''" :expected-point 8
+  :modes '(tex-mode)
+  :fixture-fn #'(lambda ()
+                  (electric-pair-mode 1)
+                  (goto-char (point-max))
+                  (skip-chars-backward "\"")
+                  (mark-sexp -1)))
+
 (provide 'electric-tests)
 ;;; electric-tests.el ends here