Skip to content

Commit

Permalink
test: add test_entry_by_extra_args test (#1200)
Browse files Browse the repository at this point in the history
  • Loading branch information
Myriad-Dreamin authored Jan 20, 2025
1 parent d5ecf05 commit a325c6f
Showing 1 changed file with 48 additions and 0 deletions.
48 changes: 48 additions & 0 deletions crates/tinymist/src/init.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down

0 comments on commit a325c6f

Please sign in to comment.