open-standards/wai/wai-rs/tests/access_services.rs
Transaction Science 00bbc69536 wai.access.services: caption quality from the signed revisions, audio description, sign language and a completeness claim
The extension (extensions/access-services.md), the access_services module of wai-rs
behind its own feature, and the corpus live-conformance/access/ written from fixed seeds
by wai_access_services_vectors: three accepted sessions and a negative control for every
reason of §10, and the DAPT document of each description.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
2026-10-21 12:13:31 -04:00

69 lines
3.1 KiB
Rust

//! `wai.access.services` (extensions/access-services.md): the committed corpus
//! `live-conformance/access/` regenerates byte for byte from its fixed seeds, holds no
//! other file, every vector and document in it gets the outcome it states, every reason of
//! §10 refuses a case, and the extension's §10 lists exactly the reasons the reference
//! reports.
#![cfg(feature = "access_services")]
use std::collections::{BTreeMap, BTreeSet};
use std::path::PathBuf;
use wai::access_services::{corpus, Reason};
fn wai_dir() -> PathBuf {
PathBuf::from(env!("CARGO_MANIFEST_DIR")).join("..")
}
fn committed() -> BTreeMap<String, String> {
let dir = wai_dir().join("live-conformance/access");
std::fs::read_dir(&dir)
.expect("the committed corpus")
.flatten()
.map(|e| (e.file_name().to_string_lossy().into_owned(), e.path()))
.filter(|(n, _)| n != "README.md")
.map(|(n, p)| (n, std::fs::read_to_string(p).expect("a text file")))
.collect()
}
#[test]
fn the_committed_corpus_regenerates_from_its_seeds() {
let files = committed();
let generated: BTreeMap<String, String> = corpus::generate().into_iter().collect();
let extra: Vec<&String> = files.keys().filter(|k| !generated.contains_key(*k)).collect();
let missing: Vec<&String> = generated.keys().filter(|k| !files.contains_key(*k)).collect();
let differ: Vec<&String> = generated.iter().filter(|(k, v)| files.get(*k).is_some_and(|f| f != *v)).map(|(k, _)| k).collect();
assert!(extra.is_empty() && missing.is_empty() && differ.is_empty(), "extra {extra:?}, missing {missing:?}, differ {differ:?}: run `wai_access_services_vectors gen`");
}
#[test]
fn every_case_gets_its_stated_outcome() {
let fails = corpus::verify(&committed());
assert!(fails.is_empty(), "{}", fails.join("\n"));
}
/// Every reason of §10 refuses a vector or a document of the committed corpus.
#[test]
fn every_reason_refuses_a_case() {
let files = committed();
let root: serde_json::Value = serde_json::from_str(&files["vectors.json"]).expect("vectors.json");
let mut seen = BTreeSet::new();
for v in root["vectors"].as_array().into_iter().flatten().chain(root["documents"].as_array().into_iter().flatten()) {
if let Some(r) = v["reason"].as_str() {
seen.insert(r.to_string());
}
}
for r in Reason::ALL {
assert!(seen.contains(r.code()), "no case of the corpus is refused {}", r.code());
}
}
/// §10 of the extension lists exactly the codes `Reason` has, each once, in order.
#[test]
fn the_extension_lists_the_reasons() {
let text = std::fs::read_to_string(wai_dir().join("extensions/access-services.md")).expect("the extension");
let at = text.find("\n## 10. Reasons").expect("a §10");
let end = text[at + 1..].find("\n## ").map_or(text.len(), |e| at + 1 + e);
let listed: Vec<String> =
text[at..end].lines().filter(|l| l.starts_with("| `")).filter_map(|l| l.split('`').nth(1).map(String::from)).collect();
let want: Vec<String> = Reason::ALL.iter().map(|r| r.code().to_string()).collect();
assert_eq!(listed, want, "§10's table and Reason::ALL differ");
}