#[must_use]
pub fn repo_toggle_for(repo: &str, app: &crate::state::AppState) -> bool {
let r = repo.to_lowercase();
if r == "core" {
app.results_filter_show_core
} else if r == "extra" {
app.results_filter_show_extra
} else if r == "multilib" {
app.results_filter_show_multilib
} else if crate::index::is_eos_repo(&r) {
app.results_filter_show_eos
} else if crate::index::is_cachyos_repo(&r) {
app.results_filter_show_cachyos
} else if crate::index::is_artix_omniverse(&r) {
app.results_filter_show_artix_omniverse
} else if crate::index::is_artix_universe(&r) {
app.results_filter_show_artix_universe
} else if crate::index::is_artix_lib32(&r) {
app.results_filter_show_artix_lib32
} else if crate::index::is_artix_galaxy(&r) {
app.results_filter_show_artix_galaxy
} else if crate::index::is_artix_world(&r) {
app.results_filter_show_artix_world
} else if crate::index::is_artix_system(&r) {
app.results_filter_show_artix_system
} else if crate::index::is_artix_repo(&r) {
app.results_filter_show_artix
} else if crate::index::is_blackarch_repo(&r) {
app.results_filter_show_blackarch
} else if let Some(filter_key) = app.repo_results_filter_by_name.get(&r) {
app.results_filter_dynamic
.get(filter_key)
.copied()
.unwrap_or(true)
} else {
app.results_filter_show_core
&& app.results_filter_show_extra
&& app.results_filter_show_multilib
&& app.results_filter_show_eos
&& app.results_filter_show_cachyos
&& app.results_filter_show_artix
&& app.results_filter_show_artix_omniverse
&& app.results_filter_show_artix_universe
&& app.results_filter_show_artix_lib32
&& app.results_filter_show_artix_galaxy
&& app.results_filter_show_artix_world
&& app.results_filter_show_artix_system
&& app.results_filter_show_blackarch
}
}
#[must_use]
pub fn label_for_official(repo: &str, name: &str, owner: &str) -> String {
let r = repo.to_lowercase();
if crate::index::is_eos_repo(&r) {
"EOS".to_string()
} else if crate::index::is_cachyos_repo(&r) {
"CachyOS".to_string()
} else if crate::index::is_artix_omniverse(&r) {
"OMNI".to_string()
} else if crate::index::is_artix_universe(&r) {
"UNI".to_string()
} else if crate::index::is_artix_lib32(&r) {
"LIB32".to_string()
} else if crate::index::is_artix_galaxy(&r) {
"GALAXY".to_string()
} else if crate::index::is_artix_world(&r) {
"WORLD".to_string()
} else if crate::index::is_artix_system(&r) {
"SYSTEM".to_string()
} else if crate::index::is_artix_repo(&r) {
"Artix".to_string()
} else if crate::index::is_blackarch_repo(&r) {
"BlackArch".to_string()
} else if crate::index::is_manjaro_name_or_owner(name, owner) {
"Manjaro".to_string()
} else {
repo.to_string()
}
}
#[cfg(test)]
mod tests {
use std::collections::HashMap;
use super::*;
use crate::state::AppState;
#[test]
fn repo_toggle_respects_individual_flags() {
let app = AppState {
results_filter_show_core: true,
results_filter_show_extra: false,
results_filter_show_multilib: false,
results_filter_show_eos: false,
results_filter_show_cachyos: false,
results_filter_show_artix: false,
results_filter_show_artix_omniverse: false,
results_filter_show_artix_universe: false,
results_filter_show_artix_lib32: false,
results_filter_show_artix_galaxy: false,
results_filter_show_artix_world: false,
results_filter_show_artix_system: false,
..Default::default()
};
assert!(repo_toggle_for("core", &app));
assert!(!repo_toggle_for("extra", &app));
assert!(!repo_toggle_for("multilib", &app));
}
#[test]
fn repo_toggle_unknown_only_with_full_whitelist() {
let mut app = AppState {
results_filter_show_core: true,
results_filter_show_extra: true,
results_filter_show_multilib: true,
results_filter_show_eos: true,
results_filter_show_cachyos: true,
results_filter_show_artix: true,
results_filter_show_artix_omniverse: true,
results_filter_show_artix_universe: true,
results_filter_show_artix_lib32: true,
results_filter_show_artix_galaxy: true,
results_filter_show_artix_world: true,
results_filter_show_artix_system: true,
..Default::default()
};
assert!(repo_toggle_for("unlisted", &app));
app.results_filter_show_multilib = false;
assert!(!repo_toggle_for("unlisted", &app));
}
#[test]
fn label_for_official_prefers_special_cases() {
assert_eq!(label_for_official("endeavouros", "pkg", ""), "EOS");
assert_eq!(label_for_official("cachyos-extra", "pkg", ""), "CachyOS");
assert_eq!(label_for_official("omniverse", "pkg", ""), "OMNI");
assert_eq!(label_for_official("universe", "pkg", ""), "UNI");
assert_eq!(label_for_official("blackarch", "pkg", ""), "BlackArch");
assert_eq!(label_for_official("extra", "manjaro-kernel", ""), "Manjaro");
assert_eq!(label_for_official("core", "glibc", ""), "core");
}
#[test]
fn repo_toggle_blackarch_flag() {
let mut app = AppState {
results_filter_show_blackarch: true,
..Default::default()
};
assert!(repo_toggle_for("blackarch", &app));
assert!(repo_toggle_for("BlackArch", &app));
app.results_filter_show_blackarch = false;
assert!(!repo_toggle_for("blackarch", &app));
}
#[test]
fn repo_toggle_unknown_includes_blackarch_flag() {
let mut app = AppState {
results_filter_show_core: true,
results_filter_show_extra: true,
results_filter_show_multilib: true,
results_filter_show_eos: true,
results_filter_show_cachyos: true,
results_filter_show_artix: true,
results_filter_show_artix_omniverse: true,
results_filter_show_artix_universe: true,
results_filter_show_artix_lib32: true,
results_filter_show_artix_galaxy: true,
results_filter_show_artix_world: true,
results_filter_show_artix_system: true,
results_filter_show_blackarch: true,
..Default::default()
};
assert!(repo_toggle_for("unlisted", &app));
app.results_filter_show_blackarch = false;
assert!(!repo_toggle_for("unlisted", &app));
}
#[test]
fn repo_toggle_respects_repos_conf_dynamic_filter() {
let mut by_name = HashMap::new();
by_name.insert("myvendor".to_string(), "vendor_pkgs".to_string());
let mut dynamic = HashMap::new();
dynamic.insert("vendor_pkgs".to_string(), false);
let app = AppState {
repo_results_filter_by_name: by_name,
results_filter_dynamic: dynamic,
..Default::default()
};
assert!(!repo_toggle_for("myvendor", &app));
assert!(!repo_toggle_for("MyVendor", &app));
}
}