mirror of
https://github.com/ouch-org/ouch.git
synced 2025-06-06 11:35:45 +00:00
Add tests to the extension module
This commit is contained in:
parent
a3d4f6ac6b
commit
1a80b919e3
@ -33,7 +33,8 @@ pub const PRETTY_SUPPORTED_EXTENSIONS: &str = "tar, zip, bz, bz2, gz, lz4, xz, l
|
|||||||
pub const PRETTY_SUPPORTED_ALIASES: &str = "tgz, tbz, tlz4, txz, tzlma, tsz, tzst";
|
pub const PRETTY_SUPPORTED_ALIASES: &str = "tgz, tbz, tlz4, txz, tzlma, tsz, tzst";
|
||||||
|
|
||||||
/// A wrapper around `CompressionFormat` that allows combinations like `tgz`
|
/// A wrapper around `CompressionFormat` that allows combinations like `tgz`
|
||||||
#[derive(Debug, Clone, Eq)]
|
#[derive(Debug, Clone)]
|
||||||
|
#[cfg_attr(test, derive(PartialEq))]
|
||||||
#[non_exhaustive]
|
#[non_exhaustive]
|
||||||
pub struct Extension {
|
pub struct Extension {
|
||||||
/// One extension like "tgz" can be made of multiple CompressionFormats ([Tar, Gz])
|
/// One extension like "tgz" can be made of multiple CompressionFormats ([Tar, Gz])
|
||||||
@ -42,13 +43,6 @@ pub struct Extension {
|
|||||||
display_text: String,
|
display_text: String,
|
||||||
}
|
}
|
||||||
|
|
||||||
// The display_text should be ignored when comparing extensions
|
|
||||||
impl PartialEq for Extension {
|
|
||||||
fn eq(&self, other: &Self) -> bool {
|
|
||||||
self.compression_formats == other.compression_formats
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Extension {
|
impl Extension {
|
||||||
/// # Panics:
|
/// # Panics:
|
||||||
/// Will panic if `formats` is empty
|
/// Will panic if `formats` is empty
|
||||||
@ -262,6 +256,37 @@ mod tests {
|
|||||||
assert_eq!(formats, vec![Tar, Gzip]);
|
assert_eq!(formats, vec![Tar, Gzip]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_separate_known_extensions_from_name() {
|
||||||
|
assert_eq!(
|
||||||
|
separate_known_extensions_from_name("file".as_ref()),
|
||||||
|
("file".as_ref(), vec![])
|
||||||
|
);
|
||||||
|
assert_eq!(
|
||||||
|
separate_known_extensions_from_name("tar".as_ref()),
|
||||||
|
("tar".as_ref(), vec![])
|
||||||
|
);
|
||||||
|
assert_eq!(
|
||||||
|
separate_known_extensions_from_name(".tar".as_ref()),
|
||||||
|
(".tar".as_ref(), vec![])
|
||||||
|
);
|
||||||
|
assert_eq!(
|
||||||
|
separate_known_extensions_from_name("file.tar".as_ref()),
|
||||||
|
("file".as_ref(), vec![Extension::new(&[Tar], "tar")])
|
||||||
|
);
|
||||||
|
assert_eq!(
|
||||||
|
separate_known_extensions_from_name("file.tar.gz".as_ref()),
|
||||||
|
(
|
||||||
|
"file".as_ref(),
|
||||||
|
vec![Extension::new(&[Tar], "tar"), Extension::new(&[Gzip], "gz")]
|
||||||
|
)
|
||||||
|
);
|
||||||
|
assert_eq!(
|
||||||
|
separate_known_extensions_from_name(".tar.gz".as_ref()),
|
||||||
|
(".tar".as_ref(), vec![Extension::new(&[Gzip], "gz")])
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn builds_suggestion_correctly() {
|
fn builds_suggestion_correctly() {
|
||||||
assert_eq!(build_archive_file_suggestion(Path::new("linux.png"), ".tar"), None);
|
assert_eq!(build_archive_file_suggestion(Path::new("linux.png"), ".tar"), None);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user