Skip to content

Commit

Permalink
Fix realign of comment makes debug assert fail (#609)
Browse files Browse the repository at this point in the history
  • Loading branch information
gaborbernat authored May 16, 2024
1 parent 8365926 commit acec15f
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
2 changes: 1 addition & 1 deletion crates/taplo/src/formatter/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -681,7 +681,7 @@ fn add_entries(
entry.value.clear();

if let Some(c) = value.trailing_comment() {
debug_assert!(entry.comment.is_none());
debug_assert!(entry.comment.is_none() || entry.comment.clone().unwrap() == c);
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 acec15f

Please sign in to comment.