From 517e9df9e1eb40feab4cb59c0fa9dc17335d3bd2 Mon Sep 17 00:00:00 2001 From: Christian Visintin Date: Sat, 21 Mar 2026 15:24:58 +0100 Subject: [PATCH] test: extend config and explorer regression coverage --- src/config/serialization.rs | 61 +++++++++++++++++++++++++++++++++++++ src/explorer/formatter.rs | 21 +++++++++++++ 2 files changed, 82 insertions(+) diff --git a/src/config/serialization.rs b/src/config/serialization.rs index ff625da..7809d4b 100644 --- a/src/config/serialization.rs +++ b/src/config/serialization.rs @@ -442,6 +442,34 @@ mod tests { assert!(deserialize::(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::(Box::new(toml_file)).is_err()); + } + #[test] fn test_config_serializer_bookmarks_serializer_serialize() { let mut bookmarks: HashMap = 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" diff --git a/src/explorer/formatter.rs b/src/explorer/formatter.rs index 4c6518f..e37f320 100644 --- a/src/explorer/formatter.rs +++ b/src/explorer/formatter.rs @@ -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,