aboutsummaryrefslogtreecommitdiffstats
path: root/test
diff options
context:
space:
mode:
Diffstat (limited to 'test')
-rw-r--r--test/lisp/wid-edit-tests.el77
1 files changed, 77 insertions, 0 deletions
diff --git a/test/lisp/wid-edit-tests.el b/test/lisp/wid-edit-tests.el
index a4350e715ed..679a29af8ff 100644
--- a/test/lisp/wid-edit-tests.el
+++ b/test/lisp/wid-edit-tests.el
@@ -36,4 +36,81 @@
36 (insert-button "overlay button") 36 (insert-button "overlay button")
37 (should-not (widget-at (1- (point)))))) 37 (should-not (widget-at (1- (point))))))
38 38
39;; The following three tests compare the effect of using either %n or \n at the
40;; end of a format string, as well as using %n at the end or in the middle of
41;; the format string. (Bug#12533)
42
43(ert-deftest widget-test-indentation-after-%n ()
44 "Fail when %n is used at the end of a format string."
45 :expected-result :failed
46 (with-temp-buffer
47 (let (wid indented)
48 (widget-insert "Testing indentation.\n")
49 ;; If we use %n at the end of the format string of the widget `other', we
50 ;; screw up indentation of the following widgets.
51 (setq wid (widget-create
52 '(repeat :indent 4
53 (cons
54 string (choice (other :tag "Other" :format "%t%n" c))))))
55 (goto-char (widget-get wid :value-pos))
56 ;; Since we indent the `repeat' widget, we skip the space characters
57 ;; inserted.
58 (skip-chars-forward " ")
59 (setq indented (current-column)) ; Save the column to which we indented.
60 (should (eq indented (or (widget-get wid :indent) 0)))
61 ;; Insert an entry. This simulates a click or RET at the INS button.
62 (widget-apply (widget-at) :action)
63 (goto-char (widget-get wid :value-pos))
64 (skip-chars-forward " ")
65 ;; This fails, because the button is not at the right column.
66 (should (eq (current-column) indented)))))
67
68(ert-deftest widget-test-indentation-after-newline ()
69 "Pass when the newline is used at the end of a format string."
70 (with-temp-buffer
71 (let (wid indented)
72 (widget-insert "Testing indentation.\n")
73 (setq wid (widget-create
74 '(repeat :indent 4
75 (cons
76 string
77 (choice (other :tag "Other" :format "%t\n" c))))))
78 (goto-char (widget-get wid :value-pos))
79 (skip-chars-forward " ")
80 (setq indented (current-column))
81 (should (eq (current-column) (or (widget-get wid :indent) 0)))
82 (widget-apply (widget-at) :action)
83 (goto-char (widget-get wid :value-pos))
84 (skip-chars-forward " ")
85 ;; Because we used \n in the format string, this pass.
86 (should (eq (current-column) indented)))))
87
88(ert-deftest widget-test-newline-and-indent-same-widget ()
89 "It's OK to use the %n escape sequence in the middle of the format string."
90 (with-temp-buffer
91 (let (wid indented)
92 (widget-insert "Testing indentation.\n")
93 (setq wid (widget-create
94 '(repeat :indent 4
95 :format "%{%t%}:%n%v%i\n"
96 (cons
97 string
98 (choice (other :tag "Other" :format "%t\n" c))))))
99 (goto-char (widget-get wid :value-pos))
100 (skip-chars-forward " ")
101 (setq indented (current-column))
102 (should (eq indented (or (widget-get wid :indent) 0)))
103 (widget-apply (widget-at) :action)
104 (goto-char (widget-get wid :value-pos))
105 (skip-chars-forward " ")
106 (should (eq (current-column) indented))
107
108 ;; Also, the children are indented correctly.
109 (let ((grandchild
110 ;; This gets the `string' widget.
111 (car (widget-get (car (widget-get wid :children)) :children))))
112 (goto-char (widget-get grandchild :from))
113 (should (eq (current-column)
114 (widget-get grandchild :indent)))))))
115
39;;; wid-edit-tests.el ends here 116;;; wid-edit-tests.el ends here