diff --git a/src/tags/basic/m3u.rs b/src/tags/basic/m3u.rs index 9595a18..2a2c1e2 100644 --- a/src/tags/basic/m3u.rs +++ b/src/tags/basic/m3u.rs @@ -38,9 +38,17 @@ mod test { use super::*; #[test] - fn extm3u() { + fn test_display() { + assert_eq!(ExtM3u.to_string(), "#EXTM3U".to_string()); + } + + #[test] + fn test_parser() { assert_eq!("#EXTM3U".parse::().ok(), Some(ExtM3u)); - assert_eq!(ExtM3u.to_string(), "#EXTM3U"); + } + + #[test] + fn test_requires_version() { assert_eq!(ExtM3u.requires_version(), ProtocolVersion::V1); } } diff --git a/src/tags/basic/version.rs b/src/tags/basic/version.rs index c321e21..cfb968d 100644 --- a/src/tags/basic/version.rs +++ b/src/tags/basic/version.rs @@ -7,21 +7,19 @@ use std::str::FromStr; /// /// [4.3.1.2. EXT-X-VERSION]: https://tools.ietf.org/html/rfc8216#section-4.3.1.2 #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] -pub struct ExtXVersion { - version: ProtocolVersion, -} +pub struct ExtXVersion(ProtocolVersion); impl ExtXVersion { pub(crate) const PREFIX: &'static str = "#EXT-X-VERSION:"; /// Makes a new `ExtXVersion` tag. pub const fn new(version: ProtocolVersion) -> Self { - ExtXVersion { version } + Self(version) } /// Returns the protocol compatibility version of the playlist containing this tag. pub const fn version(&self) -> ProtocolVersion { - self.version + self.0 } /// Returns the protocol compatibility version that this tag requires. @@ -32,17 +30,18 @@ impl ExtXVersion { impl fmt::Display for ExtXVersion { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { - write!(f, "{}{}", Self::PREFIX, self.version) + write!(f, "{}{}", Self::PREFIX, self.0) } } impl FromStr for ExtXVersion { type Err = Error; + fn from_str(s: &str) -> Result { track_assert!(s.starts_with(Self::PREFIX), ErrorKind::InvalidInput); let suffix = s.split_at(Self::PREFIX.len()).1; let version = track!(suffix.parse())?; - Ok(ExtXVersion { version }) + Ok(ExtXVersion::new(version)) } } @@ -51,11 +50,34 @@ mod test { use super::*; #[test] - fn ext_x_version() { - let tag = ExtXVersion::new(ProtocolVersion::V6); - assert_eq!("#EXT-X-VERSION:6".parse().ok(), Some(tag)); - assert_eq!(tag.to_string(), "#EXT-X-VERSION:6"); - assert_eq!(tag.version(), ProtocolVersion::V6); - assert_eq!(tag.requires_version(), ProtocolVersion::V1); + fn test_display() { + assert_eq!( + ExtXVersion::new(ProtocolVersion::V6).to_string(), + "#EXT-X-VERSION:6" + ); + } + + #[test] + fn test_parser() { + assert_eq!( + "#EXT-X-VERSION:6".parse().ok(), + Some(ExtXVersion::new(ProtocolVersion::V6)) + ); + } + + #[test] + fn test_requires_version() { + assert_eq!( + ExtXVersion::new(ProtocolVersion::V6).requires_version(), + ProtocolVersion::V1 + ); + } + + #[test] + fn test_version() { + assert_eq!( + ExtXVersion::new(ProtocolVersion::V6).version(), + ProtocolVersion::V6 + ); } } diff --git a/src/tags/master_playlist/i_frame_stream_inf.rs b/src/tags/master_playlist/i_frame_stream_inf.rs index f10082f..8b64a3b 100644 --- a/src/tags/master_playlist/i_frame_stream_inf.rs +++ b/src/tags/master_playlist/i_frame_stream_inf.rs @@ -152,11 +152,30 @@ mod test { use super::*; #[test] - fn ext_x_i_frame_stream_inf() { - let tag = ExtXIFrameStreamInf::new("foo", 1000); + fn test_display() { let text = r#"#EXT-X-I-FRAME-STREAM-INF:URI="foo",BANDWIDTH=1000"#; - assert_eq!(text.parse().ok(), Some(tag.clone())); - assert_eq!(tag.to_string(), text); - assert_eq!(tag.requires_version(), ProtocolVersion::V1); + assert_eq!(ExtXIFrameStreamInf::new("foo", 1000).to_string(), text); + } + + #[test] + fn test_parser() { + let text = r#"#EXT-X-I-FRAME-STREAM-INF:URI="foo",BANDWIDTH=1000"#; + let i_frame_stream_inf = ExtXIFrameStreamInf::new("foo", 1000); + assert_eq!( + text.parse::().unwrap(), + i_frame_stream_inf.clone() + ); + + assert_eq!(i_frame_stream_inf.uri(), "foo"); + assert_eq!(i_frame_stream_inf.bandwidth(), 1000); + // TODO: test all the optional fields + } + + #[test] + fn test_requires_version() { + assert_eq!( + ExtXIFrameStreamInf::new("foo", 1000).requires_version(), + ProtocolVersion::V1 + ); } }