use super::*;
use ::std::string::ToString;
#[test]
fn every_named_variant_round_trips() {
for slug in [
"mov", "mp4", "mkv", "webm", "avi", "flv", "mpegts", "ogg", "asf", "rm", "wmv", "mxf", "gxf",
"3gp",
] {
let v: Format = slug.parse().unwrap();
assert!(!v.is_other(), "`{slug}` should be a named variant");
assert_eq!(v.as_str(), slug);
}
}
#[test]
fn unknown_slug_lands_in_other() {
let v: Format = "weird_container".parse().unwrap();
assert!(v.is_other());
assert_eq!(v.as_str(), "weird_container");
assert_eq!(v.to_string(), "weird_container");
}
#[test]
fn display_matches_as_str() {
assert_eq!(Format::Mp4.to_string(), "mp4");
assert_eq!(Format::MpegTs.to_string(), "mpegts");
assert_eq!(Format::Threegp.to_string(), "3gp");
assert_eq!(Format::Other(SmolStr::new("custom")).to_string(), "custom");
}
#[test]
fn is_variant_predicates() {
assert!(Format::Mp4.is_mp4());
assert!(!Format::Mkv.is_mp4());
assert!(Format::Threegp.is_threegp());
assert!(Format::Other(SmolStr::new("x")).is_other());
}
#[test]
fn unwrap_other_borrowed_view() {
let v = Format::Other(SmolStr::new("custom"));
assert_eq!(v.unwrap_other_ref().as_str(), "custom");
assert!(v.try_unwrap_other_ref().is_ok());
let named = Format::Mp4;
assert!(named.try_unwrap_other_ref().is_err());
}
#[test]
fn as_extension_matches_disk_form() {
assert_eq!(Format::Mov.as_extension(), "mov");
assert_eq!(Format::Mp4.as_extension(), "mp4");
assert_eq!(Format::Mkv.as_extension(), "mkv");
assert_eq!(Format::Webm.as_extension(), "webm");
assert_eq!(Format::Avi.as_extension(), "avi");
assert_eq!(Format::Flv.as_extension(), "flv");
assert_eq!(Format::Threegp.as_extension(), "3gp");
assert_eq!(Format::MpegTs.as_str(), "mpegts");
assert_eq!(Format::MpegTs.as_extension(), "ts");
assert_eq!(Format::Ogg.as_str(), "ogg");
assert_eq!(Format::Ogg.as_extension(), "ogv");
assert_eq!(Format::Other(SmolStr::new("weird")).as_extension(), "");
}
#[test]
fn format_slugs_are_lowercase_canonical_and_fold() {
const SLUGS: &[&str] = &["mp4", "mkv", "webm", "mov", "avi", "mpegts", "flv", "ogg"];
for (i, slug) in SLUGS.iter().enumerate() {
assert!(
!slug.bytes().any(|b| b.is_ascii_uppercase()),
"slug {slug:?} is not lowercase-canonical"
);
for prior in &SLUGS[..i] {
assert!(
!prior.eq_ignore_ascii_case(slug),
"two variants fold onto {slug:?}"
);
}
let v: Format = slug.parse().unwrap();
assert!(!v.is_other(), "`{slug}` should be a named variant");
assert_eq!(v.as_str(), *slug, "`{slug}` is not its own canonical form");
}
assert_eq!("mp4", "MP4".parse::<Format>().unwrap().as_str());
let escaped: Format = "MP4_X".parse().unwrap();
assert!(escaped.is_other());
assert_eq!(escaped.as_str(), "mp4_x");
assert_eq!(Format::other("MP4_X"), escaped);
}
#[test]
fn rosters_are_well_formed() {
crate::roster_tests::check(Format::ROSTER, "Format", Format::as_str);
}