aboutsummaryrefslogtreecommitdiffstats
path: root/test
diff options
context:
space:
mode:
authorMichal Nazarewicz2020-05-03 16:32:47 +0100
committerMichal Nazarewicz2020-05-09 11:30:32 +0100
commitfab23328512e47a50caced8d074e86e583cc8a9f (patch)
treecff2b8a73606da98e98cd74e0ccabc70b281a847 /test
parent0bd6ae773a1ade1bdec2c233df4f260d028fd6c5 (diff)
downloademacs-fab23328512e47a50caced8d074e86e583cc8a9f.tar.gz
emacs-fab23328512e47a50caced8d074e86e583cc8a9f.zip
cc-mode: add ‘c-lineup-ternary-bodies’ (bug#41061)
Introduce ‘c-lineup-ternary-bodies’ function which, when used as a c lineup function, aligns question mark and colon of a ternary operator. For example: return arg % 2 == 0 ? arg / 2 : (3 * arg + 1); * lisp/progmodes/cc-align.el (c-lineup-ternary-bodies): New function. * doc/misc/cc-mode.texi (Operator Line-Up Functions): Document the new function. * test/lisp/progmodes/cc-mode-tests.el (c-lineup-ternary-bodies): New test case.
Diffstat (limited to 'test')
-rw-r--r--test/lisp/progmodes/cc-mode-tests.el21
1 files changed, 21 insertions, 0 deletions
diff --git a/test/lisp/progmodes/cc-mode-tests.el b/test/lisp/progmodes/cc-mode-tests.el
index 0729841ce6f..ad7a52b40d9 100644
--- a/test/lisp/progmodes/cc-mode-tests.el
+++ b/test/lisp/progmodes/cc-mode-tests.el
@@ -78,4 +78,25 @@
78 (insert macro-string) 78 (insert macro-string)
79 (c-mode)))) 79 (c-mode))))
80 80
81(ert-deftest c-lineup-ternary-bodies ()
82 "Test for c-lineup-ternary-bodies function"
83 (with-temp-buffer
84 (c-mode)
85 (let* ((common-prefix "int value = condition ")
86 (expected-column (length common-prefix)))
87 (dolist (test '(("? a : \n b" . nil)
88 ("? a \n ::b" . nil)
89 ("a \n : b" . nil)
90 ("? a \n : b" . t)
91 ("? ::a \n : b" . t)
92 ("? (p ? q : r) \n : b" . t)
93 ("? p ?: q \n : b" . t)
94 ("? p ? : q \n : b" . t)
95 ("? p ? q : r \n : b" . t)))
96 (delete-region (point-min) (point-max))
97 (insert common-prefix (car test))
98 (should (equal
99 (and (cdr test) (vector expected-column))
100 (c-lineup-ternary-bodies '(statement-cont . 1))))))))
101
81;;; cc-mode-tests.el ends here 102;;; cc-mode-tests.el ends here