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

Commit 009d817

Browse files
committed
tests: show issue 27
Signed-off-by: Henry Schreiner <[email protected]>
1 parent 805edf2 commit 009d817

File tree

4 files changed

+110
-0
lines changed

4 files changed

+110
-0
lines changed

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: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,53 @@
6666
""",
6767
id="collapsed",
6868
),
69+
pytest.param(
70+
"""
71+
[build-system]
72+
requires = [
73+
"hatchling",
74+
]
75+
build-backend = "hatchling.build"
76+
77+
[project]
78+
keywords = [
79+
"A",
80+
]
81+
classifiers = [
82+
"Programming Language :: Python :: 3 :: Only",
83+
]
84+
dynamic = [
85+
"B",
86+
]
87+
dependencies = [
88+
"requests>=2.0",
89+
]
90+
""",
91+
"""\
92+
[build-system]
93+
build-backend = "hatchling.build"
94+
requires = [
95+
"hatchling",
96+
]
97+
98+
[project]
99+
keywords = [
100+
"A",
101+
]
102+
classifiers = [
103+
"Programming Language :: Python :: 3 :: Only",
104+
"Programming Language :: Python :: 3.7",
105+
"Programming Language :: Python :: 3.8",
106+
]
107+
dynamic = [
108+
"B",
109+
]
110+
dependencies = [
111+
"requests>=2.0",
112+
]
113+
""",
114+
id="multi",
115+
),
69116
],
70117
)
71118
def test_format_toml(start: str, expected: str) -> None:

0 commit comments

Comments
 (0)