Skip to content
This repository was archived by the owner on Oct 17, 2024. It is now read-only.
/ pyproject-fmt-rust Public archive
  • Sponsor tox-dev/pyproject-fmt-rust

  • Notifications You must be signed in to change notification settings
  • Fork 8

tests: show issue 27 #31

Closed
wants to merge 5 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions rust/src/build_system.rs
Original file line number Diff line number Diff line change
@@ -107,6 +107,25 @@ mod tests {
[[build-system.a]] # empty table within the array
[[build-system.a]]
name = "Nail"
"#},
false
)]
#[case::reorder(
indoc ! {r#"
[build-system]
requires = [
"hatchling",
]
build-backend = "hatchling.build"

"#},
indoc ! {r#"
[build-system]
build-backend = "hatchling.build"
requires = [
"hatchling",
]

"#},
false
)]
48 changes: 48 additions & 0 deletions rust/src/helpers/table.rs
Original file line number Diff line number Diff line change
@@ -316,3 +316,51 @@
sub.clear();
}
}

#[cfg(test)]
mod tests {
use super::*;

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

#[test]
fn test_reorder() {
let root_ast = parse(indoc! {r#"

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

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, &["C", "B", "A"]);
assert_eq!(
root_ast.to_string(),
indoc! {r#"

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

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

"#}
);
}
}
23 changes: 23 additions & 0 deletions rust/src/main.rs
Original file line number Diff line number Diff line change
@@ -272,6 +272,29 @@ mod tests {
true,
(3, 8)
)]
#[case::space_issue_27(
indoc ! {r#"
[build-system]
requires = [
"hatchling",
]
build-backend = "hatchling.build"

[project]
"#},
indoc ! {r#"
[build-system]
build-backend = "hatchling.build"
requires = [
"hatchling",
]

[project]
"#},
2,
true,
(3, 8)
)]
fn test_format_toml(
#[case] start: &str,
#[case] expected: &str,
47 changes: 47 additions & 0 deletions tests/test_main.py
Original file line number Diff line number Diff line change
@@ -66,6 +66,53 @@
""",
id="collapsed",
),
pytest.param(
"""
[build-system]
requires = [
"hatchling",
]
build-backend = "hatchling.build"

[project]
keywords = [
"A",
]
classifiers = [
"Programming Language :: Python :: 3 :: Only",
]
dynamic = [
"B",
]
dependencies = [
"requests>=2.0",
]
""",
"""\
[build-system]
build-backend = "hatchling.build"
requires = [
"hatchling",
]

[project]
keywords = [
"A",
]
classifiers = [
"Programming Language :: Python :: 3 :: Only",
"Programming Language :: Python :: 3.7",
"Programming Language :: Python :: 3.8",
]
dynamic = [
"B",
]
dependencies = [
"requests>=2.0",
]
""",
id="multi",
),
],
)
def test_format_toml(start: str, expected: str) -> None: