Skip to content

Commit

Permalink
Add tests for indenting example code blocks.
Browse files Browse the repository at this point in the history
  • Loading branch information
Benjamin Moody committed Nov 11, 2024
1 parent f65147c commit c0cdf44
Showing 1 changed file with 92 additions and 0 deletions.
92 changes: 92 additions & 0 deletions rust-mode-tests.el
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit c0cdf44

Please sign in to comment.