Files
texrra-engine/tests/native_hyphenation.rs
T

81 lines
3.0 KiB
Rust

//! Actual pattern resources pass through the native CLI World and PDF path.
#[path = "support/native_fonts.rs"]
mod native_fonts;
use sha2::{Digest, Sha256};
use std::{
fs,
path::PathBuf,
process::Command,
sync::atomic::{AtomicU64, Ordering},
};
fn directory() -> PathBuf {
static ID: AtomicU64 = AtomicU64::new(0);
let p = std::env::temp_dir().join(format!(
"texrra-language-cli-{}-{}",
std::process::id(),
ID.fetch_add(1, Ordering::Relaxed)
));
fs::create_dir_all(&p).unwrap();
p
}
#[test]
fn original_language_sources_produce_native_pdf_and_preserve_exact_resource_versions() {
let dir = directory();
for resource in ["hyph-en-us.tex", "hyph-en-gb.tex"] {
let r = Command::new("kpsewhich")
.arg(resource)
.output()
.expect("actual TeX installation required");
assert!(r.status.success());
let path = String::from_utf8(r.stdout).unwrap().trim().to_owned();
let bytes = fs::read(&path).unwrap();
let source = format!(
r"\catcode123=1\catcode125=2\defaulthyphenchar=45\font\p=cmr10\p\hsize=62pt\parindent=0pt\baselineskip=12pt\parfillskip=0pt plus1fil\pretolerance=-1\tolerance=10000\hbadness=10000\vbadness=10000\lefthyphenmin=2\righthyphenmin=3\language=1\input {path} \uppercase{{\def\A{{native language}}}}\A\par X hyphenation demonstration paragraph construction character algorithm memory parameter\par\end"
);
fs::write(dir.join("probe.tex"), &source).unwrap();
let n = native_fonts::command()
.args([
"native",
"--initex",
"--etex",
"--resource-manifest",
"trace.json",
"probe.tex",
"native.pdf",
])
.current_dir(&dir)
.output()
.unwrap();
assert!(
n.status.success(),
"{resource}:{}",
String::from_utf8_lossy(&n.stderr)
);
let t: serde_json::Value =
serde_json::from_slice(&fs::read(dir.join("trace.json")).unwrap()).unwrap();
let record = t["reads"]
.as_array()
.unwrap()
.iter()
.find(|r| r["path"] == path)
.unwrap();
assert_eq!(record["sha256"], format!("{:x}", Sha256::digest(&bytes)));
assert!(
fs::read(dir.join("native.pdf"))
.unwrap()
.starts_with(b"%PDF-")
);
let text = Command::new("pdftotext")
.args(["native.pdf", "-"])
.current_dir(&dir)
.output()
.unwrap();
assert!(text.status.success());
let text = String::from_utf8(text.stdout).unwrap();
assert!(text.contains("NATIVE"), "{text}");
assert_eq!(fs::read(&path).unwrap(), bytes);
assert_eq!(fs::read_to_string(dir.join("probe.tex")).unwrap(), source);
}
fs::remove_dir_all(dir).unwrap();
}