Execute Unicode math codes and measured OpenType math characters

This commit is contained in:
gloamxun committed 2026-11-21 11:47:56 +08:00
1 parent ce8a780031
commit d17680fcd8
24 files changed
+687 -123

No files matched your search

@@ -115,7 +115,10 @@ fn incomplete_math_fonts_modes_and_fields_are_strict_errors() {
r"\advance\mathcode0 by1",
] {
assert!(
Executor::new(State::initex().with_etex(), Limits::default())
Executor::new(
State::initex().with_etex().with_input_profile(InputProfile::TeX8Bit),
Limits::default(),
)
.run(
SourceFile {
name: "bad.tex".into(),
@@ -122,7 +122,7 @@ fn initex_font_and_unsupported_material_are_not_silently_substituted() {
assert!(
e.events
.iter()
.any(|e| matches!(e,Event::MissingGlyph(m) if m.font==FontId::NULL&&m.slot==b'A'))
.any(|e| matches!(e,Event::MissingGlyph(m) if m.font==FontId::NULL&&m.slot==u32::from(b'A')))
);
let sized = Executor::default()
.run(
@@ -0,0 +1,95 @@
use texrra_tex_core::execution::{
Dependency, Event, Executor, InputProfile, Limits, NoFiles, SourceFile, State,
};
const HEADER: &str = r"\catcode123=1 \catcode125=2 \catcode35=6 ";
fn probe(
text: &str,
profile: InputProfile,
) -> Result<texrra_tex_core::execution::Execution, String> {
Executor::new(
State::initex().with_etex().with_input_profile(profile),
Limits::default(),
)
.run(
SourceFile {
name: "codes.tex".into(),
data: format!("{HEADER}{text}").into_bytes(),
},
&mut NoFiles,
)
.map_err(|error| error.message)
}
#[test]
fn classic_and_unicode_commands_share_scoped_math_codes() {
let result = probe(
r#"\message{D=\the\Umathcodenum"03B1}
\Umathcode"03B1=7 5 "03B2
\message{A=\the\Umathcodenum"03B1}
{\XeTeXmathcode"03B1=2 255 "10FFFF
\message{L=\the\XeTeXmathcodenum"03B1}}
\message{R=\the\Umathcodenum"03B1}
\mathcode"03B1="8000
\message{T=\the\mathcode"03B1}
\message{N=\the\Umathcodenum"03B1}
{\global\Umathcode"03B1=0 3 42}\message{G=\the\mathcode"03B1}"#,
InputProfile::UnicodeScalar,
)
.unwrap();
let output: Vec<_> = result
.events
.iter()
.filter_map(|event| match event {
Event::Message { text, .. } => Some(text.trim()),
_ => None,
})
.collect();
assert_eq!(
output,
[
"D=945",
"A=98567090",
"L=-11468801",
"R=98567090",
"T=32768",
"N=2097151",
"G=810"
]
);
assert!(result.reads.contains(&Dependency::UnicodeMathCode(945)));
}
#[test]
fn unicode_math_code_invalid_queries_preserve_distinct_diagnostics() {
for (source, expected) in [
(r"\message{\the\Umathcode65}", r"try \Umathcodenum"),
(
r"\Umathcode65=0 17 65 \message{\the\mathcode65}",
"Extended mathchar used as mathchar",
),
(r#"\Umathcodenum65="3FFFFF"#, "Bad active XeTeX math code"),
(r"\Umathcode65=8 0 65", "Bad math class"),
(r"\Umathcode65=0 256 65", "math family"),
] {
let error = probe(source, InputProfile::UnicodeScalar).unwrap_err();
assert!(error.contains(expected), "{source}: {error}");
}
let byte_error = probe(r"\Umathcode65=0 0 65", InputProfile::TeX8Bit).unwrap_err();
assert!(byte_error.contains("undefined native control sequence"));
}
#[test]
fn packed_code_with_the_sign_bit_only_is_an_internal_integer() {
let result = probe(
r"\Umathcode65=0 128 0
\Umathcodenum66=\Umathcodenum65
\message{\number\Umathcodenum65/\the\Umathcodenum66}",
InputProfile::UnicodeScalar,
)
.unwrap();
assert!(result.events.iter().any(|event| matches!(
event, Event::Message { text, .. } if text == "-2147483648/-2147483648"
)));
}