From c39adeea823be37636723ef6467eda68f8232f1f Mon Sep 17 00:00:00 2001 From: John-John Tedro Date: Mon, 12 Aug 2024 00:38:05 +0200 Subject: [PATCH] fmt: fix trailing comment in #801 --- crates/rune/src/fmt/format.rs | 1 + crates/rune/src/fmt/tests/mod.rs | 52 ++++++++++++++++++++------------ 2 files changed, 33 insertions(+), 20 deletions(-) diff --git a/crates/rune/src/fmt/format.rs b/crates/rune/src/fmt/format.rs index b2a16f9f0..e6ba2d31e 100644 --- a/crates/rune/src/fmt/format.rs +++ b/crates/rune/src/fmt/format.rs @@ -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(()) } diff --git a/crates/rune/src/fmt/tests/mod.rs b/crates/rune/src/fmt/tests/mod.rs index 449a35801..64b7a9bca 100644 --- a/crates/rune/src/fmt/tests/mod.rs +++ b/crates/rune/src/fmt/tests/mod.rs @@ -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 @@ -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]