Skip to content

Commit 3cc45c5

Browse files
CopilotKSXGitHub
andcommitted
refactor(tests): use builder API for FsTreeBuilder, TreeBuilder, and Visualizer in test files
Co-authored-by: KSXGitHub <11488886+KSXGitHub@users.noreply.github.com>
1 parent efe960e commit 3cc45c5

6 files changed

Lines changed: 329 additions & 308 deletions

File tree

tests/_utils.rs

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -366,18 +366,18 @@ where
366366
}
367367

368368
let measure = |suffix: &str| {
369-
FsTreeBuilder {
370-
size_getter,
371-
hardlinks_recorder: &HardlinkIgnorant,
372-
reporter: &ErrorOnlyReporter::new(|error| {
369+
FsTreeBuilder::builder()
370+
.size_getter(size_getter)
371+
.hardlinks_recorder(&HardlinkIgnorant)
372+
.reporter(&ErrorOnlyReporter::new(|error| {
373373
panic!("Unexpected call to report_error: {error:?}")
374-
}),
375-
root: root.join(suffix),
376-
max_depth: 10,
377-
}
378-
.pipe(DataTree::<OsStringDisplay, Size>::from)
379-
.into_par_sorted(|left, right| left.name().cmp(right.name()))
380-
.into_reflection()
374+
}))
375+
.root(root.join(suffix))
376+
.max_depth(10)
377+
.build()
378+
.pipe(DataTree::<OsStringDisplay, Size>::from)
379+
.into_par_sorted(|left, right| left.name().cmp(right.name()))
380+
.into_reflection()
381381
};
382382

383383
let sub = |suffix: &str| root.join(suffix).pipe(OsStringDisplay::os_string_from);

tests/cli_errors.rs

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -130,23 +130,24 @@ fn fs_errors() {
130130
dbg!(&status);
131131
eprintln!("STDERR+STDOUT:\n{stderr}{stdout}\n");
132132

133-
let builder = FsTreeBuilder {
134-
root: workspace.to_path_buf(),
135-
size_getter: GetApparentSize,
136-
hardlinks_recorder: &HardlinkIgnorant,
137-
reporter: &ErrorOnlyReporter::new(ErrorReport::SILENT),
138-
max_depth: 10,
139-
};
133+
let reporter = ErrorOnlyReporter::new(ErrorReport::SILENT);
134+
let builder = FsTreeBuilder::builder()
135+
.root(workspace.to_path_buf())
136+
.size_getter(GetApparentSize)
137+
.hardlinks_recorder(&HardlinkIgnorant)
138+
.reporter(&reporter)
139+
.max_depth(10)
140+
.build();
140141
let mut data_tree: DataTree<OsStringDisplay, _> = builder.into();
141142
data_tree.par_sort_by(|left, right| left.size().cmp(&right.size()).reverse());
142143
*data_tree.name_mut() = OsStringDisplay::os_string_from(".");
143-
let visualizer = Visualizer {
144-
data_tree: &data_tree,
145-
bytes_format: BytesFormat::MetricUnits,
146-
direction: Direction::BottomUp,
147-
bar_alignment: BarAlignment::Left,
148-
column_width_distribution: ColumnWidthDistribution::total(100),
149-
};
144+
let visualizer = Visualizer::builder()
145+
.data_tree(&data_tree)
146+
.bytes_format(BytesFormat::MetricUnits)
147+
.direction(Direction::BottomUp)
148+
.bar_alignment(BarAlignment::Left)
149+
.column_width_distribution(ColumnWidthDistribution::total(100))
150+
.build();
150151
let expected_stdout = format!("{visualizer}");
151152
eprintln!("EXPECTED STDOUT:\n{}\n", &expected_stdout);
152153

tests/json.rs

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -80,13 +80,14 @@ fn json_output() {
8080
.tree
8181
.pipe(sanitize_tree_reflection);
8282
dbg!(&actual);
83-
let builder = FsTreeBuilder {
84-
root: workspace.to_path_buf(),
85-
size_getter: GetApparentSize,
86-
hardlinks_recorder: &HardlinkIgnorant,
87-
reporter: &ErrorOnlyReporter::new(ErrorReport::SILENT),
88-
max_depth: 10,
89-
};
83+
let reporter = ErrorOnlyReporter::new(ErrorReport::SILENT);
84+
let builder = FsTreeBuilder::builder()
85+
.root(workspace.to_path_buf())
86+
.size_getter(GetApparentSize)
87+
.hardlinks_recorder(&HardlinkIgnorant)
88+
.reporter(&reporter)
89+
.max_depth(10)
90+
.build();
9091
let expected = builder
9192
.pipe(DataTree::<_, Bytes>::from)
9293
.into_reflection()
@@ -135,13 +136,14 @@ fn json_input() {
135136
let actual = actual.trim_end();
136137
eprintln!("ACTUAL:\n{actual}\n");
137138

138-
let visualizer = Visualizer {
139-
data_tree: &sample_tree(),
140-
bytes_format: BytesFormat::MetricUnits,
141-
direction: Direction::BottomUp,
142-
bar_alignment: BarAlignment::Left,
143-
column_width_distribution: ColumnWidthDistribution::total(100),
144-
};
139+
let tree = sample_tree();
140+
let visualizer = Visualizer::builder()
141+
.data_tree(&tree)
142+
.bytes_format(BytesFormat::MetricUnits)
143+
.direction(Direction::BottomUp)
144+
.bar_alignment(BarAlignment::Left)
145+
.column_width_distribution(ColumnWidthDistribution::total(100))
146+
.build();
145147
let expected = format!("{visualizer}");
146148
let expected = expected.trim_end();
147149
eprintln!("EXPECTED:\n{expected}\n");

tests/tree_builder.rs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -39,10 +39,10 @@ impl SampleTree {
3939
}
4040

4141
fn tree(&self, root: &'static str) -> DataTree<SampleName, SampleData> {
42-
TreeBuilder {
43-
path: root.to_string(),
44-
name: root.to_string(),
45-
get_info: |path| {
42+
TreeBuilder::builder()
43+
.path(root.to_string())
44+
.name(root.to_string())
45+
.get_info(|path| {
4646
let path: Vec<_> = path
4747
.split(SAMPLE_SEPARATOR)
4848
.map(ToString::to_string)
@@ -56,12 +56,12 @@ impl SampleTree {
5656
)),
5757
None => panic!("Path does not exist"),
5858
}
59-
},
60-
join_path: |prefix, name| format!("{prefix}{SAMPLE_SEPARATOR}{name}"),
61-
max_depth: 10,
62-
}
63-
.pipe(DataTree::from)
64-
.into_par_sorted(|left, right| left.name().as_str().cmp(right.name().as_str()))
59+
})
60+
.join_path(|prefix, name| format!("{prefix}{SAMPLE_SEPARATOR}{name}"))
61+
.max_depth(10)
62+
.build()
63+
.pipe(DataTree::from)
64+
.into_par_sorted(|left, right| left.name().as_str().cmp(right.name().as_str()))
6565
}
6666
}
6767

0 commit comments

Comments
 (0)