use super::*;
use std::collections::BTreeSet;
fn every_variant() -> Vec<Section> {
let all = vec![
Section::Main,
Section::Stats,
Section::Network,
Section::Library,
Section::Benchmarks,
Section::Terminal,
Section::Help,
];
for s in &all {
match s {
Section::Main
| Section::Stats
| Section::Network
| Section::Library
| Section::Benchmarks
| Section::Terminal
| Section::Help => {}
}
}
all
}
#[test]
fn all_lists_every_section_exactly_once() {
let listed: Vec<Section> = Section::ALL.to_vec();
for s in every_variant() {
assert_eq!(
listed.iter().filter(|l| **l == s).count(),
1,
"{s:?} must appear exactly once in ALL"
);
}
assert_eq!(listed.len(), every_variant().len());
}
#[test]
fn labels_and_icons_are_present_and_distinct() {
let mut labels = BTreeSet::new();
let mut icons = BTreeSet::new();
for s in Section::ALL {
assert!(!s.label().is_empty(), "{s:?} has no label");
assert!(!s.icon().is_empty(), "{s:?} has no icon");
assert!(labels.insert(s.label()), "duplicate label {}", s.label());
assert!(icons.insert(s.icon()), "duplicate icon {}", s.icon());
assert_eq!(
s.icon().chars().count(),
1,
"the sidebar draws the icon in one cell: {:?}",
s.icon()
);
}
}
#[test]
fn subsections_are_either_absent_or_a_pair() {
for s in Section::ALL {
let subs = s.subs();
assert!(
subs.is_empty() || subs.len() == 2,
"{s:?} has {} subsections",
subs.len()
);
for name in subs {
assert!(!name.is_empty(), "{s:?} has an unnamed subsection");
}
}
}
#[test]
fn the_sections_with_subsections_are_the_ones_that_have_two_panes() {
assert_eq!(Section::Main.subs().to_vec(), vec!["Overview", "Kernels"]);
assert_eq!(
Section::Benchmarks.subs().to_vec(),
vec!["Suite", "History"]
);
assert_eq!(Section::Terminal.subs().to_vec(), vec!["Ops", "Chat"]);
assert_eq!(Section::Help.subs().to_vec(), vec!["Guide", "Report Issue"]);
for s in [Section::Stats, Section::Network, Section::Library] {
assert!(s.subs().is_empty(), "{s:?}");
}
}
#[test]
fn the_navigable_row_count_is_what_the_sidebar_draws() {
let rows: usize = Section::ALL.iter().map(|s| s.subs().len().max(1)).sum();
assert_eq!(rows, 3 + 4 * 2, "3 plain sections and 4 with a pair each");
}
#[test]
fn benchmarks_is_last_but_one_so_terminal_keeps_the_bottom_row() {
assert_eq!(Section::ALL[4], Section::Benchmarks);
assert_eq!(Section::ALL[5], Section::Terminal);
assert_eq!(Section::ALL[6], Section::Help);
}