test: extend config and explorer regression coverage

This commit is contained in:
Christian Visintin
2026-03-21 15:24:58 +01:00
parent 478f25304f
commit 517e9df9e1
2 changed files with 82 additions and 0 deletions

View File

@@ -442,6 +442,34 @@ mod tests {
assert!(deserialize::<UserHosts>(Box::new(toml_file)).is_err());
}
#[test]
fn test_should_deserialize_webdav_bookmark_protocol_alias() {
let toml_file: tempfile::NamedTempFile = create_http_alias_toml_bookmarks();
toml_file.as_file().sync_all().unwrap();
toml_file.as_file().rewind().unwrap();
let hosts: UserHosts = deserialize(Box::new(toml_file)).unwrap();
let host = hosts.bookmarks.get("webdav").unwrap();
assert_eq!(host.protocol, FileTransferProtocol::WebDAV);
assert_eq!(host.address.as_deref(), Some("https://myserver:4445"));
assert_eq!(host.username.as_deref(), Some("omar"));
assert_eq!(host.password.as_deref(), Some("mypassword"));
assert_eq!(
host.remote_path.as_deref(),
Some(std::path::Path::new("/myshare/dir/subdir"))
);
}
#[test]
fn test_should_fail_deserialize_bookmark_with_invalid_protocol() {
let toml_file: tempfile::NamedTempFile = create_invalid_protocol_toml_bookmarks();
toml_file.as_file().sync_all().unwrap();
toml_file.as_file().rewind().unwrap();
assert!(deserialize::<UserHosts>(Box::new(toml_file)).is_err());
}
#[test]
fn test_config_serializer_bookmarks_serializer_serialize() {
let mut bookmarks: HashMap<String, Bookmark> = HashMap::with_capacity(2);
@@ -693,6 +721,39 @@ mod tests {
tmpfile
}
fn create_http_alias_toml_bookmarks() -> tempfile::NamedTempFile {
let mut tmpfile: tempfile::NamedTempFile = tempfile::NamedTempFile::new().unwrap();
let file_content: &str = r#"
[bookmarks]
[bookmarks.webdav]
protocol = "HTTPS"
address = "https://myserver:4445"
username = "omar"
password = "mypassword"
directory = "/myshare/dir/subdir"
[recents]
"#;
tmpfile.write_all(file_content.as_bytes()).unwrap();
tmpfile
}
fn create_invalid_protocol_toml_bookmarks() -> tempfile::NamedTempFile {
let mut tmpfile: tempfile::NamedTempFile = tempfile::NamedTempFile::new().unwrap();
let file_content: &str = r#"
[bookmarks]
[bookmarks.broken]
protocol = "GOPHER"
address = "gopher://myserver"
[recents]
"#;
tmpfile.write_all(file_content.as_bytes()).unwrap();
tmpfile
}
fn create_good_toml_theme() -> tempfile::NamedTempFile {
let mut tmpfile: tempfile::NamedTempFile = tempfile::NamedTempFile::new().unwrap();
let file_content: &str = r##"auth_address = "Yellow"

View File

@@ -1026,6 +1026,27 @@ mod tests {
assert_eq!(formatter.fmt(&entry).as_str(), "喵喵喵喵喵喵喵…");
}
#[test]
fn should_ignore_unknown_formatter_keys() {
let entry = File {
path: PathBuf::from("/tmp/foo.txt"),
metadata: Metadata {
accessed: None,
created: None,
modified: None,
file_type: FileType::File,
size: 8192,
symlink: None,
uid: None,
gid: None,
mode: None,
},
};
let formatter: Formatter = Formatter::new("before {UNKNOWN:12} after {NAME:8}");
assert_eq!(formatter.fmt(&entry).as_str(), "before after foo.txt ");
}
/// Dummy formatter, just yelds an 'A' at the end of the current string
fn dummy_fmt(
_fmt: &Formatter,