Skip to content

Commit

Permalink
fmt: fix trailing comment in #801
Browse files Browse the repository at this point in the history
  • Loading branch information
udoprog committed Aug 11, 2024
1 parent 97cf544 commit c39adee
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 20 deletions.
1 change: 1 addition & 0 deletions crates/rune/src/fmt/format.rs
Original file line number Diff line number Diff line change
Expand Up @@ -805,6 +805,7 @@ fn exprs_loose<'a>(fmt: &mut Formatter<'a>, p: &mut Stream<'a>) -> Result<()> {
}

fmt.nl(1)?;
fmt.comments(Line)?;
fmt.indent(-1)?;
Ok(())
}
Expand Down
52 changes: 32 additions & 20 deletions crates/rune/src/fmt/tests/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,32 +18,32 @@ fn test_layout_string() {

#[test]
fn fmt_comment_line() {
const EXPECTED: &str = r#"
pub fn main() {
// test 1
if true {
// test 2.1
let a = 1;
// test 2.2
assert_format!(
r#"
pub fn main() {
// test 1
if true {
// test 2.1
let a = 1;
// test 2.2
}
// test 3
}
// test 3
}
"#;

assert_format!(EXPECTED, EXPECTED);
"#
);
}

#[test]
fn avoid_block_inject() {
const EXPECTED: &str = r#"
pub fn main() {
if true {
let a = 1;
assert_format!(
r#"
pub fn main() {
if true {
let a = 1;
}
}
}
"#;

assert_format!(EXPECTED, EXPECTED);
"#
);
}

/// https://github.com/rune-rs/rune/issues/684
Expand Down Expand Up @@ -83,6 +83,18 @@ fn keep_trailing_comments() {
}
"#
);

assert_format!(
r#"
const DOVECOT_UNCHANGED = [
//("dovecot-core", "dovecot-db.conf.ext"),
("dovecot-core", "dovecot-dict-auth.conf.ext"),
("dovecot-core", "dovecot-dict-sql.conf.ext"),
("dovecot-core", "dovecot-sql.conf.ext"),
//("dovecot-core", "dovecot.conf"),
];
"#
);
}

#[test]
Expand Down

0 comments on commit c39adee

Please sign in to comment.