49 lines
1.6 KiB
Rust
49 lines
1.6 KiB
Rust
|
|
use std::ffi::OsString;
|
||
|
|
use std::path::Path;
|
||
|
|
|
||
|
|
use rcom::actions::EditorCommand;
|
||
|
|
use rcom::fs::FsError;
|
||
|
|
|
||
|
|
#[test]
|
||
|
|
fn visual_has_priority_and_quoted_arguments_are_parsed_without_a_shell() {
|
||
|
|
let command = EditorCommand::from_values(
|
||
|
|
Some(OsString::from("custom-editor --wait \"two words\"")),
|
||
|
|
Some(OsString::from("ignored-editor")),
|
||
|
|
)
|
||
|
|
.unwrap();
|
||
|
|
|
||
|
|
assert_eq!(command.program(), "custom-editor");
|
||
|
|
assert_eq!(command.arguments(), ["--wait", "two words"]);
|
||
|
|
let process = command.process(Path::new("/tmp/a file;not-executed"));
|
||
|
|
let process = process.as_std();
|
||
|
|
assert_eq!(process.get_program(), "custom-editor");
|
||
|
|
let arguments: Vec<_> = process.get_args().collect();
|
||
|
|
assert_eq!(
|
||
|
|
arguments,
|
||
|
|
["--wait", "two words", "/tmp/a file;not-executed"]
|
||
|
|
);
|
||
|
|
}
|
||
|
|
|
||
|
|
#[test]
|
||
|
|
fn editor_is_the_fallback_and_empty_or_invalid_commands_are_rejected() {
|
||
|
|
let command = EditorCommand::from_values(None, Some(OsString::from("vi --clean"))).unwrap();
|
||
|
|
assert_eq!(command.program(), "vi");
|
||
|
|
assert_eq!(command.arguments(), ["--clean"]);
|
||
|
|
|
||
|
|
for (visual, editor) in [
|
||
|
|
(None, None),
|
||
|
|
(Some(OsString::new()), Some(OsString::new())),
|
||
|
|
(Some(OsString::from(" ")), None),
|
||
|
|
(Some(OsString::from("editor 'unterminated")), None),
|
||
|
|
] {
|
||
|
|
assert!(EditorCommand::from_values(visual, editor).is_err());
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
#[test]
|
||
|
|
fn parse_errors_use_the_central_safe_error_channel() {
|
||
|
|
let error = EditorCommand::parse("editor 'token=super-secret").unwrap_err();
|
||
|
|
assert!(matches!(error, FsError::Other(_)));
|
||
|
|
assert!(!error.user_message().contains("super-secret"));
|
||
|
|
}
|