From 601824cf552d09db62f0cef42c00dc85bd728b04 Mon Sep 17 00:00:00 2001 From: Michael Lee Date: Thu, 3 Aug 2023 15:46:54 +0800 Subject: Improve the usability of `rust-dbg-wrap-or-unwrap` (#498) * rust-dbg-wrap-or-unwrap: Cut unnecessary conditional branches for region-active-p * rust-dbg-wrap-or-unwrap: Do not using save-excursion anymore * rust-dbg-wrap-or-unwrap: Use cond, allow more other cases. * rust-dbg-wrap-or-unwrap: Introduce rust-insert-dbg-alone * rust-dbg-wrap-or-unwrap: Adjust cursor position after insertion * rust-dbg-wrap-or-unwrap: Add tests for empty line * rust-dbg-wrap-or-unwrap: Test final position in empty line case * rust-dbg-wrap-or-unwrap: Test final cursor position in existing wrap tests --- rust-mode-tests.el | 50 ++++++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 44 insertions(+), 6 deletions(-) (limited to 'rust-mode-tests.el') diff --git a/rust-mode-tests.el b/rust-mode-tests.el index 3b23046..7b791b6 100644 --- a/rust-mode-tests.el +++ b/rust-mode-tests.el @@ -45,14 +45,16 @@ (put 'rust-compare-code-after-manip 'ert-explainer 'rust-test-explain-bad-manip) -(defun rust-test-manip-code (original point-pos manip-func expected) +(defun rust-test-manip-code (original manip-pos manip-func expected &optional final-pos) (with-temp-buffer (rust-mode) (insert original) - (goto-char point-pos) + (goto-char manip-pos) (funcall manip-func) (should (rust-compare-code-after-manip - original point-pos manip-func expected (buffer-string))))) + original manip-pos manip-func expected (buffer-string))) + (if final-pos + (should (equal (point) final-pos))))) (defmacro rust-test-with-standard-fill-settings (&rest body) (declare (indent defun)) @@ -3452,14 +3454,49 @@ impl Two<'a> { "let x = add(first, second);" 15 #'rust-dbg-wrap-or-unwrap - "let x = add(dbg!(first), second);")) + "let x = add(dbg!(first), second);" + 24)) + +(ert-deftest rust-test-dbg-wrap-empty-line () + (rust-test-manip-code + "let a = 1; + +let b = 1;" + 12 + #'rust-dbg-wrap-or-unwrap + "let a = 1; +dbg!() +let b = 1;" + 17)) + +(ert-deftest rust-test-dbg-wrap-empty-before-comment () + (rust-test-manip-code + "let a = 1; +// comment +let b = 1;" + 12 + #'rust-dbg-wrap-or-unwrap + "let a = 1; +dbg!()// comment +let b = 1;" + 17) + ;; between statements and comments + (rust-test-manip-code + "let a = 1;// comment +let b = 1;" + 11 + #'rust-dbg-wrap-or-unwrap + "let a = 1;dbg!()// comment +let b = 1;" + 16)) (ert-deftest rust-test-dbg-wrap-symbol-unbalanced () (rust-test-manip-code "let x = add((first, second);" 14 #'rust-dbg-wrap-or-unwrap - "let x = add((dbg!(first), second);")) + "let x = add((dbg!(first), second);" + 25)) (ert-deftest rust-test-dbg-wrap-region () (rust-test-manip-code @@ -3470,7 +3507,8 @@ impl Two<'a> { (push-mark nil t t) (goto-char 26) (rust-dbg-wrap-or-unwrap)) - "let x = dbg!(add(first, second));")) + "let x = dbg!(add(first, second));" + 33)) (defun rust-test-dbg-unwrap (position) (rust-test-manip-code -- cgit v1.2.3