pub static DEFAULT_PAGE: &str = include_str!("../content/default.html");
pub static MINIMAL_PAGE: &str = include_str!("../content/minimal.html");
pub static TERMINAL_PAGE: &str = include_str!("../content/terminal.html");
pub static PAPER_PAGE: &str = include_str!("../content/paper.html");
pub static AMBER_PAGE: &str = include_str!("../content/amber.html");
pub static COMPACT_PAGE: &str = include_str!("../content/compact.html");
pub static MATRIX_PAGE: &str = include_str!("../content/matrix.html");
#[cfg(test)]
mod tests {
use super::{
AMBER_PAGE, COMPACT_PAGE, DEFAULT_PAGE, MATRIX_PAGE, MINIMAL_PAGE, PAPER_PAGE,
TERMINAL_PAGE,
};
use std::path::PathBuf;
const PAGINAS: [(&str, &str); 7] = [
("default", DEFAULT_PAGE),
("minimal", MINIMAL_PAGE),
("terminal", TERMINAL_PAGE),
("paper", PAPER_PAGE),
("amber", AMBER_PAGE),
("compact", COMPACT_PAGE),
("matrix", MATRIX_PAGE),
];
fn content_dir() -> PathBuf {
PathBuf::from(env!("CARGO_MANIFEST_DIR")).join("content")
}
fn paginas_del_directorio() -> Vec<PathBuf> {
let entradas = std::fs::read_dir(content_dir())
.expect("el directorio `content/` tiene que poder listarse");
let mut paginas: Vec<PathBuf> = entradas
.filter_map(Result::ok)
.map(|entrada| entrada.path())
.filter(|ruta| ruta.extension().is_some_and(|ext| ext == "html"))
.collect();
paginas.sort();
paginas
}
#[test]
fn las_paginas_embebidas_son_byte_a_byte_las_de_content() {
for (nombre, embebida) in PAGINAS {
let ruta = content_dir().join(format!("{nombre}.html"));
let del_disco = std::fs::read(&ruta)
.unwrap_or_else(|error| panic!("no se pudo leer {}: {error}", ruta.display()));
assert_eq!(
embebida.as_bytes(),
del_disco.as_slice(),
"la página embebida del tema `{nombre}` no coincide byte a byte con {}",
ruta.display()
);
}
}
#[test]
fn cada_pagina_embebida_lleva_los_tres_marcadores() {
for (nombre, embebida) in PAGINAS {
for marcador in ["{{code}}", "{{reason}}", "{{description}}"] {
assert!(
embebida.contains(marcador),
"la página embebida del tema `{nombre}` tiene que llevar `{marcador}`"
);
}
}
}
#[test]
fn el_directorio_entrega_exactamente_las_siete_paginas_de_tema() {
let mut esperadas: Vec<PathBuf> = PAGINAS
.iter()
.map(|(nombre, _)| content_dir().join(format!("{nombre}.html")))
.collect();
esperadas.sort();
assert_eq!(
paginas_del_directorio(),
esperadas,
"`content/` tiene que entregar las siete páginas de tema, ni una más ni una menos"
);
}
}