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

Commit 6d35a45

Browse files
committed
tests: show issue 27
Signed-off-by: Henry Schreiner <[email protected]>
1 parent 0eee83a commit 6d35a45

File tree

5 files changed

+76
-1
lines changed

5 files changed

+76
-1
lines changed

Cargo.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

rust/src/build_system.rs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,25 @@ mod tests {
107107
[[build-system.a]] # empty table within the array
108108
[[build-system.a]]
109109
name = "Nail"
110+
"#},
111+
false
112+
)]
113+
#[case::reorder(
114+
indoc ! {r#"
115+
[build-system]
116+
requires = [
117+
"hatchling",
118+
]
119+
build-backend = "hatchling.build"
120+
121+
"#},
122+
indoc ! {r#"
123+
[build-system]
124+
build-backend = "hatchling.build"
125+
requires = [
126+
"hatchling",
127+
]
128+
110129
"#},
111130
false
112131
)]

rust/src/helpers/table.rs

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -316,3 +316,24 @@ pub fn collapse_sub_tables(tables: &mut Tables, name: &str) {
316316
sub.clear();
317317
}
318318
}
319+
320+
#[cfg(test)]
321+
mod tests {
322+
use super::*;
323+
324+
use taplo::parser::parse;
325+
326+
#[test]
327+
fn test_reorder() {
328+
let root_ast = parse("[A]\nb = 1\na = 1\n\n[B]\nb = 2")
329+
.into_syntax()
330+
.clone_for_update();
331+
let mut tables = Tables::from_ast(&root_ast);
332+
{
333+
let table = &mut tables.get("A").unwrap().first().unwrap().borrow_mut();
334+
reorder_table_keys(table, &["", "a", "b"]);
335+
}
336+
tables.reorder(&root_ast, &["B", "A"]);
337+
assert_eq!(root_ast.to_string(), "[B]\nb = 2\n\n[A]\na = 1\n\nb = 1\n\n");
338+
}
339+
}

rust/src/main.rs

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -272,6 +272,29 @@ mod tests {
272272
true,
273273
(3, 8)
274274
)]
275+
#[case::space_issue_27(
276+
indoc ! {r#"
277+
[build-system]
278+
requires = [
279+
"hatchling",
280+
]
281+
build-backend = "hatchling.build"
282+
283+
[project]
284+
"#},
285+
indoc ! {r#"
286+
[build-system]
287+
build-backend = "hatchling.build"
288+
requires = [
289+
"hatchling",
290+
]
291+
292+
[project]
293+
"#},
294+
2,
295+
true,
296+
(3, 8)
297+
)]
275298
fn test_format_toml(
276299
#[case] start: &str,
277300
#[case] expected: &str,

tests/test_main.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,12 @@
77

88
def test_format_toml() -> None:
99
txt = """
10+
[build-system]
11+
requires = [
12+
"hatchling",
13+
]
14+
build-backend = "hatchling.build"
15+
1016
[project]
1117
keywords = [
1218
"A",
@@ -32,6 +38,12 @@ def test_format_toml() -> None:
3238
res = format_toml(dedent(txt), settings)
3339

3440
expected = """\
41+
[build-system]
42+
build-backend = "hatchling.build"
43+
requires = [
44+
"hatchling",
45+
]
46+
3547
[project]
3648
keywords = [
3749
"A",

0 commit comments

Comments
 (0)