use super::{APP_ID, HYDRA, MAIN_R, NODE_R, VOID_DEEP, deep, icon, raster, rgba, svg};
use crate::ui::theme;
mod walk;
fn asset(name: &str) -> String {
let at = std::path::Path::new(env!("CARGO_MANIFEST_DIR"))
.join("assets")
.join(name);
std::fs::read_to_string(&at).unwrap_or_else(|why| panic!("{}: {why}", at.display()))
}
#[test]
fn the_tracked_vector_source_is_exactly_what_the_generator_emits() {
assert_eq!(
asset(&format!("{APP_ID}.svg")),
svg(),
"assets/{APP_ID}.svg is stale — re-emit it with `make icon`, never by hand"
);
}
#[test]
fn the_app_id_the_desktop_entry_and_the_icon_name_are_one_word() {
let entry = asset(&format!("{APP_ID}.desktop"));
for line in [
format!("Icon={APP_ID}"),
format!("StartupWMClass={APP_ID}"),
format!("Exec={APP_ID}"),
] {
assert!(
entry.lines().any(|held| held == line),
"the desktop entry has no {line:?}:\n{entry}"
);
}
}
#[test]
fn the_tracked_entry_carries_exactly_one_exec_and_it_is_generic() {
let entry = asset(&format!("{APP_ID}.desktop"));
let execs: Vec<&str> = entry
.lines()
.filter(|line| line.starts_with("Exec="))
.collect();
assert_eq!(
execs,
vec![format!("Exec={APP_ID}")],
"the installed copy is where an absolute Exec belongs, and there is one \
of them — `make icon-seats` rewrites every ^Exec= line:\n{entry}"
);
}
#[test]
fn every_shape_is_one_element_and_the_order_is_the_icon_s() {
let source = svg();
let elements: Vec<&str> = source
.lines()
.filter(|line| line.starts_with(" <"))
.collect();
assert_eq!(elements.len(), icon().len());
assert_eq!(
elements[0], " <circle cx=\"500.0\" cy=\"500.0\" r=\"500.0\" fill=\"#0d1015\"/>",
"the ground is the void, round, and under everything"
);
assert!(
elements[1].contains("stroke-linejoin=\"round\""),
"{source}"
);
assert!(
elements.last().unwrap().contains(" Z\" fill=\"#0d1015\""),
"the pupil is last"
);
assert!(source.ends_with("</svg>\n"), "{source}");
let attributes = elements
.iter()
.flat_map(|e| e.split('"').skip(1).step_by(2));
for value in attributes.filter(|v| v.contains('.')) {
for figure in value
.split([' ', ',', 'M', 'L'])
.filter(|f| !f.is_empty() && f != &"Z")
{
assert_eq!(
figure.split('.').nth(1).map(str::len),
Some(1),
"{figure} in {value}"
);
}
}
}
#[test]
fn the_palette_hue_is_the_theme_s_attention_and_the_void_is_its_ground() {
assert_eq!(
theme::accent(theme::State::Attention).to_array()[..3],
HYDRA
);
assert_eq!(theme::GROUND.to_array()[..3], VOID_DEEP);
}
#[test]
fn deepening_in_hundredths_lands_on_the_phone_s_own_bytes() {
assert_eq!(deep(HYDRA, super::PHOSPHOR), [32, 255, 108]);
assert_eq!(deep(HYDRA, super::CASING), [12, 99, 42]);
}
fn spot(px: &[u8], n: u16, x: f32, y: f32) -> [u8; 4] {
let at = |v: f32| {
usize::from(
(0..n)
.find(|i| f32::from(*i + 1) / f32::from(n) > v)
.unwrap(),
)
};
let i = (at(y) * usize::from(n) + at(x)) * 4;
px[i..i + 4].try_into().unwrap()
}
fn opaque(hue: [u8; 3]) -> [u8; 4] {
[hue[0], hue[1], hue[2], 255]
}
#[test]
fn the_raster_paints_the_void_ground_the_pupil_the_nodes_and_the_casing() {
let n = 128_u16;
let px = rgba(n);
assert_eq!(px.len(), usize::from(n) * usize::from(n) * 4);
let phosphor = opaque(deep(HYDRA, super::PHOSPHOR));
assert_eq!(
spot(&px, n, 0.02, 0.02),
[0; 4],
"a corner is off the ground"
);
assert_eq!(
spot(&px, n, 0.2, 0.2),
opaque(VOID_DEEP),
"the ground is void"
);
assert_eq!(
spot(&px, n, 0.5, 0.5),
opaque(VOID_DEEP),
"the pupil is void"
);
assert_eq!(spot(&px, n, 0.5 + MAIN_R * 0.8, 0.5), phosphor, "the eye");
assert_eq!(spot(&px, n, 0.5, 0.5 + MAIN_R + NODE_R), phosphor, "a node");
let casing = opaque(deep(HYDRA, super::CASING));
assert!(px.chunks_exact(4).any(|pixel| pixel == casing), "no casing");
}
#[test]
fn a_raster_of_no_size_is_empty() {
assert!(rgba(0).is_empty());
}
#[test]
fn the_edges_are_antialiased_and_every_pixel_is_a_mean_of_the_walk_s_hues() {
let px = rgba(32);
let soft = px
.chunks_exact(4)
.filter(|p| p[3] > 0 && p[3] < 255)
.count();
assert!(soft > 0, "nothing on the mark's edges was ever split");
assert!(px.chunks_exact(4).all(|p| p[0] <= 32 && p[2] <= 108));
}
#[test]
fn the_sample_count_is_the_grid_squared() {
let (sub, samples) = raster::samples();
assert_eq!(u32::from(sub).pow(2), samples);
}