From fab23328512e47a50caced8d074e86e583cc8a9f Mon Sep 17 00:00:00 2001 From: Michal Nazarewicz Date: Sun, 3 May 2020 16:32:47 +0100 Subject: cc-mode: add ‘c-lineup-ternary-bodies’ (bug#41061) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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. --- test/lisp/progmodes/cc-mode-tests.el | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) (limited to 'test/lisp/progmodes/cc-mode-tests.el') 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 @@ (insert macro-string) (c-mode)))) +(ert-deftest c-lineup-ternary-bodies () + "Test for c-lineup-ternary-bodies function" + (with-temp-buffer + (c-mode) + (let* ((common-prefix "int value = condition ") + (expected-column (length common-prefix))) + (dolist (test '(("? a : \n b" . nil) + ("? a \n ::b" . nil) + ("a \n : b" . nil) + ("? a \n : b" . t) + ("? ::a \n : b" . t) + ("? (p ? q : r) \n : b" . t) + ("? p ?: q \n : b" . t) + ("? p ? : q \n : b" . t) + ("? p ? q : r \n : b" . t))) + (delete-region (point-min) (point-max)) + (insert common-prefix (car test)) + (should (equal + (and (cdr test) (vector expected-column)) + (c-lineup-ternary-bodies '(statement-cont . 1)))))))) + ;;; cc-mode-tests.el ends here -- cgit v1.2.3