summaryrefslogtreecommitdiff
path: root/rust-mode-tests.el
diff options
context:
space:
mode:
authorSibi Prabakaran <sibi@psibi.in>2024-11-12 10:08:39 +0530
committerGitHub <noreply@github.com>2024-11-12 10:08:39 +0530
commit542f1755d8929ca83564322d7030d558f3392fe1 (patch)
tree66e5d3b13b2feb38974507ffd5c11793702990d7 /rust-mode-tests.el
parent3bd0863f28414e629ca15ad2852a429a126226c5 (diff)
parentc0cdf44dfe43091e737984792045139bfa8ddc29 (diff)
downloadrust-mode-542f1755d8929ca83564322d7030d558f3392fe1.tar.gz
Merge pull request #563 from bemoody/indent-doc
Indent example-code blocks in comments
Diffstat (limited to 'rust-mode-tests.el')
-rw-r--r--rust-mode-tests.el92
1 files changed, 92 insertions, 0 deletions
diff --git a/rust-mode-tests.el b/rust-mode-tests.el
index 62cd261..a0ee0bb 100644
--- a/rust-mode-tests.el
+++ b/rust-mode-tests.el
@@ -887,6 +887,98 @@ struct A {
"
))
+;; When point is inside an example code block, indent-for-tab-command
+;; should reindent the example code.
+(ert-deftest indent-inside-doc-example ()
+ (rust-test-manip-code
+ "
+/// ```
+/// if 2 + 2 == 4 {
+/// success();
+/// }
+/// ```
+"
+ 34
+ #'indent-for-tab-command
+ "
+/// ```
+/// if 2 + 2 == 4 {
+/// success();
+/// }
+/// ```
+"
+ 38))
+
+;; Inside example code blocks, hidden lines starting with "# " should
+;; be indented as if the "# " wasn't there.
+(ert-deftest indent-inside-doc-example-hidden-code ()
+ (rust-test-manip-code
+ "
+/// ```
+/// # if 2 + 2 == 4 {
+/// # success();
+/// # }
+/// ```
+"
+ 36
+ #'indent-for-tab-command
+ "
+/// ```
+/// # if 2 + 2 == 4 {
+/// # success();
+/// # }
+/// ```
+"
+ 42))
+
+;; Inside example code blocks, hidden lines starting with "# "
+;; shouldn't affect indentation of non-hidden lines.
+(ert-deftest indent-inside-doc-example-with-hidden-block ()
+ (rust-test-manip-code
+ "
+/// ```
+/// # if 2 + 2 == 4 {
+/// success();
+/// # }
+/// ```
+"
+ 40
+ #'indent-for-tab-command
+ "
+/// ```
+/// # if 2 + 2 == 4 {
+/// success();
+/// # }
+/// ```
+"
+ 36))
+
+;; When point is outside the comment, indent-for-tab-command should
+;; reindent the comment line without affecting its contents.
+(ert-deftest indent-outside-doc-example ()
+ (rust-test-manip-code
+ "
+impl Foo {
+ /// ```
+ /// if 2 + 2 == 4 {
+ /// success();
+ /// }
+ /// ```
+}
+"
+ 49
+ #'indent-for-tab-command
+ "
+impl Foo {
+ /// ```
+ /// if 2 + 2 == 4 {
+ /// success();
+ /// }
+ /// ```
+}
+"
+ 53))
+
(defconst rust-test-motion-string
"
fn fn1(arg: i32) -> bool {