Skip to content

Commit

Permalink
Fix realign of comment makes debug assert fail
Browse files Browse the repository at this point in the history
Signed-off-by: Bernát Gábor <bgabor8@bloomberg.net>
  • Loading branch information
gaborbernat committed May 7, 2024
1 parent f7c5279 commit b56c70f
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
1 change: 0 additions & 1 deletion crates/taplo/src/formatter/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -681,7 +681,6 @@ fn add_entries(
entry.value.clear();

if let Some(c) = value.trailing_comment() {
debug_assert!(entry.comment.is_none());
entry.comment = Some(c);
}

Expand Down
19 changes: 19 additions & 0 deletions crates/taplo/src/tests/formatter.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use difference::Changeset;

use crate::formatter;
use crate::formatter::Options;

macro_rules! assert_format {
($expected:expr, $actual:expr) => {
Expand Down Expand Up @@ -1164,3 +1165,21 @@ my_array = [

assert_format!(expected, &formatted);
}

#[test]
fn test_comment_after_entry() {
let src = r#"
a = "b" # comment
"#;

let expected = r#"
a = "b" # comment
"#;
let opt = Options {
column_width: 1,
..Default::default()
};
let formatted = crate::formatter::format(src, opt);

assert_format!(expected, &formatted);
}

0 comments on commit b56c70f

Please sign in to comment.