Resolve TeX inputs with the default suffix alternatives

This commit is contained in:
gloamxun committed 2026-11-19 20:01:08 +08:00
1 parent 901a50c36c
commit ee22f25ee0
5 files changed
+204 -10

No files matched your search

+88
View File
@@ -520,3 +520,91 @@ fn frozen_real_reference_resources_are_read_as_their_actual_bytes_and_versions()
);
fs::remove_dir_all(p).unwrap();
}
#[test]
fn tex_unknown_suffix_lookup_keeps_path_priority_and_format_names() {
let root = directory().canonicalize().unwrap();
let first = root.join("first");
let second = root.join("second");
put(first.join("chapter.fragment"), b"first");
put(second.join("chapter.fragment.tex"), b"later");
put(first.join("style.clo.tex"), b"not a style fallback");
let mut config = WorldConfig::new(&root);
config.paths.insert(
ResourceKind::Tex,
vec![
SearchPath::directory(&first, false),
SearchPath::directory(&second, false),
],
);
let entry = root.join("main.tex");
let mut world = FileWorld::new(config.clone()).unwrap();
assert_eq!(
world
.read_tex_input("chapter.fragment", &entry)
.unwrap()
.data,
b"first"
);
let selected = first.join("chapter.fragment.tex");
put(&selected, b"standard suffix");
let resource = world.read_tex_input("chapter.fragment", &entry).unwrap();
assert_eq!(resource.version.path, selected);
assert_eq!(resource.data, b"standard suffix");
assert_eq!(
world
.read_tex_input_optional("chapter.fragment", &entry)
.unwrap()
.unwrap()
.version
.path,
selected
);
assert_eq!(
world
.read_shared(ResourceKind::Tex, "chapter.fragment", &entry)
.unwrap()
.data
.as_ref(),
b"first"
);
assert_eq!(world.resolve_tex_input("style.clo", &entry).unwrap(), None);
let mut capture = FileWorld::new(config.clone()).unwrap();
capture.capture_inputs();
capture.read_tex_input("chapter.fragment", &entry).unwrap();
let captured = serde_json::to_vec(capture.input_snapshot().as_ref()).unwrap();
config.input_policy = InputPolicy::Project;
let mut old_capture = FileWorld::new(config).unwrap();
old_capture.capture_inputs();
old_capture
.read_tex_input("chapter.fragment", &entry)
.unwrap();
// The original serialization omitted the flag and recorded only the
// supplied spelling for inputs such as chapter.fragment.
let mut previous = serde_json::to_value(old_capture.input_snapshot().as_ref()).unwrap();
previous
.as_object_mut()
.unwrap()
.remove("tex_suffix_fallback");
previous["config"]["input_policy"] = serde_json::json!("Tex");
fs::remove_dir_all(&root).unwrap();
let mut recent = FileWorld::from_snapshot(serde_json::from_slice(&captured).unwrap()).unwrap();
assert_eq!(
recent
.read_tex_input("chapter.fragment", &entry)
.unwrap()
.data,
b"standard suffix"
);
let mut older = FileWorld::from_snapshot(serde_json::from_value(previous).unwrap()).unwrap();
assert_eq!(
older
.read_tex_input("chapter.fragment", &entry)
.unwrap()
.data,
b"first"
);
}