-
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathhelpers.rs
More file actions
76 lines (70 loc) · 2.11 KB
/
helpers.rs
File metadata and controls
76 lines (70 loc) · 2.11 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
// SPDX-FileCopyrightText: 2026 Sephyi <me@sephy.io>
//
// SPDX-License-Identifier: AGPL-3.0-only OR LicenseRef-Commercial
use std::path::PathBuf;
use std::sync::Arc;
use commitbee::domain::{ChangeStatus, DiffStats, FileCategory, FileChange, StagedChanges};
/// Create a minimal FileChange for testing
#[allow(dead_code)]
pub fn make_file_change(
path: &str,
status: ChangeStatus,
diff: &str,
additions: usize,
deletions: usize,
) -> FileChange {
FileChange {
path: PathBuf::from(path),
status,
diff: Arc::from(diff),
additions,
deletions,
category: FileCategory::from_path(&PathBuf::from(path)),
is_binary: false,
old_path: None,
rename_similarity: None,
}
}
/// Create a renamed FileChange for testing
#[allow(dead_code)]
pub fn make_renamed_file(old_path: &str, new_path: &str, similarity: u8) -> FileChange {
make_renamed_file_with_diff(old_path, new_path, similarity, "", 0, 0)
}
/// Create a renamed FileChange with a diff body and explicit add/delete counts.
///
/// Useful for splitter tests that exercise diff-shape grouping on renames.
#[allow(dead_code)]
pub fn make_renamed_file_with_diff(
old_path: &str,
new_path: &str,
similarity: u8,
diff: &str,
additions: usize,
deletions: usize,
) -> FileChange {
FileChange {
path: PathBuf::from(new_path),
status: ChangeStatus::Renamed,
diff: Arc::from(diff),
additions,
deletions,
category: FileCategory::from_path(&PathBuf::from(new_path)),
is_binary: false,
old_path: Some(PathBuf::from(old_path)),
rename_similarity: Some(similarity),
}
}
/// Create StagedChanges from a list of FileChanges
#[allow(dead_code)]
pub fn make_staged_changes(files: Vec<FileChange>) -> StagedChanges {
let insertions: usize = files.iter().map(|f| f.additions).sum();
let deletions: usize = files.iter().map(|f| f.deletions).sum();
StagedChanges {
stats: DiffStats {
files_changed: files.len(),
insertions,
deletions,
},
files,
}
}