pacsea/index/distro.rs
1//! Distro-specific helpers used across the app.
2
3/// What: Determine if a package name is Manjaro-branded
4///
5/// Input:
6/// - `name` package name
7///
8/// Output:
9/// - `true` if it starts with "manjaro-" (case-insensitive)
10///
11/// Details:
12/// - Compares a lowercased name with the "manjaro-" prefix.
13#[must_use]
14pub fn is_name_manjaro(name: &str) -> bool {
15 name.to_lowercase().starts_with("manjaro-")
16}
17
18/// What: Determine if a package or its owner indicates Manjaro
19///
20/// Input:
21/// - `name` package name; `owner` maintainer/owner string
22///
23/// Output:
24/// - `true` if name starts with "manjaro-" or owner contains "manjaro" (case-insensitive)
25///
26/// Details:
27/// - Lowercases both inputs and checks the prefix/substring rules.
28#[must_use]
29pub fn is_manjaro_name_or_owner(name: &str, owner: &str) -> bool {
30 let name_l = name.to_lowercase();
31 let owner_l = owner.to_lowercase();
32 name_l.starts_with("manjaro-") || owner_l.contains("manjaro")
33}
34
35/// What: Check if a repo name is an `EndeavourOS` repo
36///
37/// Input:
38/// - `repo` repository name
39///
40/// Output:
41/// - `true` for "eos" or "endeavouros" (case-insensitive)
42///
43/// Details:
44/// - Lowercases and matches exact names.
45#[must_use]
46pub fn is_eos_repo(repo: &str) -> bool {
47 let r = repo.to_lowercase();
48 r == "eos" || r == "endeavouros"
49}
50
51/// What: Check if a repo name belongs to `CachyOS`
52///
53/// Input:
54/// - `repo` repository name
55///
56/// Output:
57/// - `true` if it starts with "cachyos" (case-insensitive)
58///
59/// Details:
60/// - Lowercases and checks the "cachyos" prefix.
61#[must_use]
62pub fn is_cachyos_repo(repo: &str) -> bool {
63 let r = repo.to_lowercase();
64 r.starts_with("cachyos")
65}
66
67/// What: Check if a repo name belongs to Artix Linux
68///
69/// Input:
70/// - `repo` repository name
71///
72/// Output:
73/// - `true` if it matches known Artix repository names (case-insensitive)
74///
75/// Details:
76/// - Checks against the list of Artix repositories: omniverse, universe, lib32, galaxy, world, system.
77#[must_use]
78pub fn is_artix_repo(repo: &str) -> bool {
79 let r = repo.to_lowercase();
80 matches!(
81 r.as_str(),
82 "omniverse" | "universe" | "lib32" | "galaxy" | "world" | "system"
83 )
84}
85
86/// What: Check if a repo name is the Artix omniverse repository.
87#[must_use]
88pub const fn is_artix_omniverse(repo: &str) -> bool {
89 repo.eq_ignore_ascii_case("omniverse")
90}
91
92/// What: Check if a repo name is the Artix universe repository.
93#[must_use]
94pub const fn is_artix_universe(repo: &str) -> bool {
95 repo.eq_ignore_ascii_case("universe")
96}
97
98/// What: Check if a repo name is the Artix lib32 repository.
99#[must_use]
100pub const fn is_artix_lib32(repo: &str) -> bool {
101 repo.eq_ignore_ascii_case("lib32")
102}
103
104/// What: Check if a repo name is the Artix galaxy repository.
105#[must_use]
106pub const fn is_artix_galaxy(repo: &str) -> bool {
107 repo.eq_ignore_ascii_case("galaxy")
108}
109
110/// What: Check if a repo name is the Artix world repository.
111#[must_use]
112pub const fn is_artix_world(repo: &str) -> bool {
113 repo.eq_ignore_ascii_case("world")
114}
115
116/// What: Check if a repo name is the Artix system repository.
117#[must_use]
118pub const fn is_artix_system(repo: &str) -> bool {
119 repo.eq_ignore_ascii_case("system")
120}
121
122/// What: Check if a repo name belongs to `BlackArch`
123///
124/// Input:
125/// - `repo` repository name
126///
127/// Output:
128/// - `true` if it matches "blackarch" (case-insensitive)
129///
130/// Details:
131/// - Lowercases and checks exact equality.
132#[must_use]
133pub const fn is_blackarch_repo(repo: &str) -> bool {
134 repo.eq_ignore_ascii_case("blackarch")
135}
136
137/// What: Heuristic to treat a name as EndeavourOS-branded
138///
139/// Input:
140/// - `name` package name
141///
142/// Output:
143/// - `true` if it contains "eos-" (case-insensitive)
144///
145/// Details:
146/// - Used when reconstructing installed-only items not present in the official index.
147#[must_use]
148pub fn is_eos_name(name: &str) -> bool {
149 name.to_lowercase().contains("eos-")
150}
151
152#[cfg(test)]
153mod tests {
154 #[test]
155 /// What: Validate Manjaro-specific name detection.
156 ///
157 /// Inputs:
158 /// - Sample strings covering positive and negative cases.
159 ///
160 /// Output:
161 /// - Assertions confirming only Manjaro-branded names return true.
162 ///
163 /// Details:
164 /// - Exercises case-insensitive prefix handling.
165 fn manjaro_name_detection() {
166 assert!(super::is_name_manjaro("manjaro-alsa"));
167 assert!(super::is_name_manjaro("Manjaro-foo"));
168 assert!(!super::is_name_manjaro("alsa"));
169 }
170
171 #[test]
172 /// What: Ensure Manjaro identification works on name or owner fields.
173 ///
174 /// Inputs:
175 /// - Pairs of (name, owner) covering positive and negative scenarios.
176 ///
177 /// Output:
178 /// - Assertions verifying either field triggers detection.
179 ///
180 /// Details:
181 /// - Confirms substring search on owner and prefix match on name.
182 fn manjaro_name_or_owner_detection() {
183 assert!(super::is_manjaro_name_or_owner("manjaro-alsa", ""));
184 assert!(super::is_manjaro_name_or_owner("alsa", "Manjaro Team"));
185 assert!(!super::is_manjaro_name_or_owner("alsa", "Arch Linux"));
186 }
187
188 #[test]
189 /// What: Confirm repo heuristics for `EOS` and `CachyOS`.
190 ///
191 /// Inputs:
192 /// - Various repo strings spanning expected matches and misses.
193 ///
194 /// Output:
195 /// - Assertions that only target repos return true.
196 ///
197 /// Details:
198 /// - Checks both equality and prefix-based rules.
199 fn eos_and_cachyos_repo_rules() {
200 assert!(super::is_eos_repo("eos"));
201 assert!(super::is_eos_repo("EndeavourOS"));
202 assert!(!super::is_eos_repo("core"));
203
204 assert!(super::is_cachyos_repo("cachyos-core"));
205 assert!(super::is_cachyos_repo("CachyOS-extra"));
206 assert!(!super::is_cachyos_repo("extra"));
207 }
208
209 #[test]
210 /// What: Verify EOS-branded name heuristic.
211 ///
212 /// Inputs:
213 /// - Strings with and without the "eos-" fragment.
214 ///
215 /// Output:
216 /// - Assertions matching expected boolean results.
217 ///
218 /// Details:
219 /// - Demonstrates case-insensitive substring detection.
220 fn eos_name_rule() {
221 assert!(super::is_eos_name("eos-hello"));
222 assert!(super::is_eos_name("my-eos-helper"));
223 assert!(!super::is_eos_name("hello"));
224 }
225
226 #[test]
227 /// What: Confirm repo heuristics for `BlackArch`.
228 ///
229 /// Inputs:
230 /// - Various repo strings spanning expected matches and misses.
231 ///
232 /// Output:
233 /// - Assertions that only `BlackArch` repo returns true.
234 ///
235 /// Details:
236 /// - Checks case-insensitive exact matching.
237 fn blackarch_repo_rules() {
238 assert!(super::is_blackarch_repo("blackarch"));
239 assert!(super::is_blackarch_repo("BlackArch"));
240 assert!(super::is_blackarch_repo("BLACKARCH"));
241 assert!(!super::is_blackarch_repo("blackarch-extra"));
242 assert!(!super::is_blackarch_repo("core"));
243 assert!(!super::is_blackarch_repo("cachyos"));
244 assert!(!super::is_blackarch_repo("eos"));
245 }
246
247 #[test]
248 /// What: Confirm repo heuristics for Artix Linux.
249 ///
250 /// Inputs:
251 /// - Various repo strings spanning expected matches and misses.
252 ///
253 /// Output:
254 /// - Assertions that only Artix repos return true.
255 ///
256 /// Details:
257 /// - Checks case-insensitive matching for all Artix repository names.
258 fn artix_repo_rules() {
259 assert!(super::is_artix_repo("omniverse"));
260 assert!(super::is_artix_repo("Omniverse"));
261 assert!(super::is_artix_repo("universe"));
262 assert!(super::is_artix_repo("lib32"));
263 assert!(super::is_artix_repo("galaxy"));
264 assert!(super::is_artix_repo("world"));
265 assert!(super::is_artix_repo("system"));
266 assert!(!super::is_artix_repo("core"));
267 assert!(!super::is_artix_repo("extra"));
268 assert!(!super::is_artix_repo("cachyos"));
269 }
270}