test: add test_entry_by_extra_args test (#1200)

This commit is contained in:
Myriad-Dreamin 2025-01-20 09:51:44 +08:00 committed by GitHub
parent d5ecf052d4
commit a325c6f6c8
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -1069,6 +1069,54 @@ mod tests {
assert!(err.contains("absolute path"), "unexpected error: {err}");
}
#[test]
fn test_entry_by_extra_args() {
let simple_config = {
let mut config = Config::default();
let update = json!({
"typstExtraArgs": ["main.typ"]
});
// It should be able to resolve the entry file from the extra arguments.
config.update(&update).expect("updated");
// Passing it twice doesn't affect the result.
config.update(&update).expect("updated");
config
};
{
let mut config = Config::default();
let update = json!({
"typstExtraArgs": ["main.typ", "main.typ"]
});
let err = format!("{}", config.update(&update).unwrap_err());
assert!(
err.contains("unexpected argument"),
"unexpected error: {err}"
);
assert!(err.contains("help"), "unexpected error: {err}");
}
{
let mut config = Config::default();
let update = json!({
"typstExtraArgs": ["main2.typ"],
"tinymist": {
"typstExtraArgs": ["main.typ"]
}
});
// It should be able to resolve the entry file from the extra arguments.
config.update(&update).expect("updated");
// Passing it twice doesn't affect the result.
config.update(&update).expect("updated");
assert_eq!(
config.compile.typst_extra_args,
simple_config.compile.typst_extra_args
);
}
}
#[test]
fn test_substitute_path() {
let root = Path::new("/root");