Decode XeTeX input files and streams with original byte spans

This commit is contained in:
gloamxun committed 2026-11-21 17:10:46 +08:00
1 parent 22e3ba993d
commit d11ac0cba1
18 files changed
+1040 -109

No files matched your search

@@ -274,3 +274,40 @@ fn xetex_formats_and_paints_nested_direction_spans() {
.unwrap_err();
assert!(error.message.contains(r"Improper \beginR"));
}
#[test]
fn xetex_default_encoding_survives_dump_and_current_line_is_already_decoded() {
let state = State::initex().with_input_profile(InputProfile::XeTeX).with_etex();
let mut data = br"\catcode123=1 \catcode125=2".to_vec();
data.extend_from_slice("\n\\XeTeXinputencoding \"bytes\" \\message{\\number`é}\n".as_bytes());
data.extend_from_slice(b"\\message{\\number`\xe9}\n");
data.extend_from_slice(br#"{\XeTeXdefaultencoding "utf16be"}\dump"#);
let execution = Executor::new(state, Limits::default())
.run(SourceFile { name: "seed.tex".into(), data: data.clone() }, &mut NoFiles)
.unwrap();
assert_eq!(messages(&execution), ["233", "233"]);
let bytes = FormatImage::from_dump(execution, Vec::new(), Vec::new())
.unwrap().encode().unwrap();
let job = FormatImage::decode(&bytes).unwrap()
.new_job(
Profile::EtexBootstrap,
InputProfile::XeTeX,
JobTime::new(2025, 10, 9, 0).unwrap(),
Limits::default(),
|_| Ok(data.clone()),
)
.unwrap();
let input = r"\def\word{😀}\message{\word}\end";
// A UTF-16 source without a BOM must follow the stored mode.
let data = input.encode_utf16().flat_map(u16::to_be_bytes).collect::<Vec<_>>();
let result = job.run(SourceFile { name: "next.tex".into(), data: data.clone() }, &mut NoFiles)
.unwrap();
assert_eq!(messages(&result), ["😀"]);
let Meaning::Macro(word) = result.state.meaning(&CommandName::Control("word".into())) else {
panic!("expected the real definition");
};
let [Replacement::Token(token)] = word.replacement.as_slice() else {
panic!("expected one scalar token");
};
assert_eq!(&data[token.span.start..token.span.end], [0xd8, 0x3d, 0xde, 0x00]);
}