Skip to content
This repository has been archived by the owner on Oct 17, 2024. It is now read-only.

Commit

Permalink
tests: add a table test
Browse files Browse the repository at this point in the history
Signed-off-by: Henry Schreiner <[email protected]>
  • Loading branch information
henryiii committed Sep 18, 2024
1 parent c3228f7 commit b48069e
Showing 1 changed file with 32 additions and 5 deletions.
37 changes: 32 additions & 5 deletions rust/src/helpers/table.rs
Original file line number Diff line number Diff line change
Expand Up @@ -321,19 +321,46 @@ pub fn collapse_sub_tables(tables: &mut Tables, name: &str) {
mod tests {
use super::*;

use indoc::indoc;
use taplo::parser::parse;

#[test]
fn test_reorder() {
let root_ast = parse("[A]\nb = 1\na = 1\n\n[B]\nb = 2")
.into_syntax()
.clone_for_update();
let root_ast = parse(indoc! {r#"

Check failure on line 329 in rust/src/helpers/table.rs

View workflow job for this annotation

GitHub Actions / rust-check

unnecessary hashes around raw string literal
[A]
b = 1
a = 1
[B]
b = 2
[C]
b = 3
# Notes on A
a = 3"#})
.into_syntax()
.clone_for_update();
let tables = Tables::from_ast(&root_ast);
{
let table = &mut tables.get("A").unwrap().first().unwrap().borrow_mut();
reorder_table_keys(table, &["", "a", "b"]);
}
tables.reorder(&root_ast, &["B", "A"]);
assert_eq!(root_ast.to_string(), "[B]\nb = 2\n\n[A]\na = 1\n\nb = 1\n\n");
tables.reorder(&root_ast, &["C", "B", "A"]);
assert_eq!(
root_ast.to_string(),
indoc! {r#"

Check failure on line 350 in rust/src/helpers/table.rs

View workflow job for this annotation

GitHub Actions / rust-check

unnecessary hashes around raw string literal
[C]
# Notes on A
a = 3
b = 3
[B]
b = 2
[A]
a = 1
b = 1
"#}
);
}
}

0 comments on commit b48069e

Please sign in to comment.