1
0
Fork 0
mirror of https://github.com/sile/hls_m3u8.git synced 2024-06-09 00:39:35 +00:00

more codecov

This commit is contained in:
Luro02 2019-09-28 15:48:42 +02:00
parent c9493ea8e5
commit b0b766bc0c
3 changed files with 147 additions and 21 deletions

View file

@ -31,6 +31,12 @@ impl ExtXIFrameStreamInf {
pub(crate) const PREFIX: &'static str = "#EXT-X-I-FRAME-STREAM-INF:";
/// Makes a new [ExtXIFrameStreamInf] tag.
///
/// # Example
/// ```
/// # use hls_m3u8::tags::ExtXIFrameStreamInf;
/// let stream = ExtXIFrameStreamInf::new("https://www.example.com", 20);
/// ```
pub fn new<T: ToString>(uri: T, bandwidth: u64) -> Self {
ExtXIFrameStreamInf {
uri: uri.to_string(),
@ -43,7 +49,6 @@ impl ExtXIFrameStreamInf {
/// # Example
/// ```
/// # use hls_m3u8::tags::ExtXIFrameStreamInf;
/// #
/// let stream = ExtXIFrameStreamInf::new("https://www.example.com", 20);
/// assert_eq!(stream.uri(), &"https://www.example.com".to_string());
/// ```
@ -139,6 +144,8 @@ mod test {
.unwrap(),
ExtXIFrameStreamInf::new("foo", 1000)
);
assert!("garbage".parse::<ExtXIFrameStreamInf>().is_err());
}
#[test]
@ -148,4 +155,22 @@ mod test {
ProtocolVersion::V1
);
}
#[test]
fn test_deref() {
assert_eq!(
ExtXIFrameStreamInf::new("https://www.example.com", 20).average_bandwidth(),
None
)
}
#[test]
fn test_deref_mut() {
assert_eq!(
ExtXIFrameStreamInf::new("https://www.example.com", 20)
.set_average_bandwidth(Some(4))
.average_bandwidth(),
Some(4)
)
}
}

View file

@ -324,7 +324,10 @@ mod test {
#[test]
fn test_display() {
assert_eq!(
"#EXT-X-SESSION-DATA:DATA-ID=\"com.example.lyrics\",URI=\"lyrics.json\"".to_string(),
"#EXT-X-SESSION-DATA:\
DATA-ID=\"com.example.lyrics\",\
URI=\"lyrics.json\""
.to_string(),
ExtXSessionData::new(
"com.example.lyrics",
SessionData::Uri("lyrics.json".to_string())
@ -333,8 +336,10 @@ mod test {
);
assert_eq!(
"#EXT-X-SESSION-DATA:DATA-ID=\"com.example.title\",\
VALUE=\"This is an example\",LANGUAGE=\"en\""
"#EXT-X-SESSION-DATA:\
DATA-ID=\"com.example.title\",\
VALUE=\"This is an example\",\
LANGUAGE=\"en\""
.to_string(),
ExtXSessionData::with_language(
"com.example.title",
@ -345,8 +350,10 @@ mod test {
);
assert_eq!(
"#EXT-X-SESSION-DATA:DATA-ID=\"com.example.title\",\
VALUE=\"Este es un ejemplo\",LANGUAGE=\"es\""
"#EXT-X-SESSION-DATA:\
DATA-ID=\"com.example.title\",\
VALUE=\"Este es un ejemplo\",\
LANGUAGE=\"es\""
.to_string(),
ExtXSessionData::with_language(
"com.example.title",
@ -357,17 +364,27 @@ mod test {
);
assert_eq!(
"#EXT-X-SESSION-DATA:DATA-ID=\"foo\",VALUE=\"bar\"".to_string(),
"#EXT-X-SESSION-DATA:\
DATA-ID=\"foo\",\
VALUE=\"bar\""
.to_string(),
ExtXSessionData::new("foo", SessionData::Value("bar".into())).to_string()
);
assert_eq!(
"#EXT-X-SESSION-DATA:DATA-ID=\"foo\",URI=\"bar\"".to_string(),
"#EXT-X-SESSION-DATA:\
DATA-ID=\"foo\",\
URI=\"bar\""
.to_string(),
ExtXSessionData::new("foo", SessionData::Uri("bar".into())).to_string()
);
assert_eq!(
"#EXT-X-SESSION-DATA:DATA-ID=\"foo\",VALUE=\"bar\",LANGUAGE=\"baz\"".to_string(),
"#EXT-X-SESSION-DATA:\
DATA-ID=\"foo\",\
VALUE=\"bar\",\
LANGUAGE=\"baz\""
.to_string(),
ExtXSessionData::with_language("foo", SessionData::Value("bar".into()), "baz")
.to_string()
);
@ -376,7 +393,9 @@ mod test {
#[test]
fn test_parser() {
assert_eq!(
"#EXT-X-SESSION-DATA:DATA-ID=\"com.example.lyrics\",URI=\"lyrics.json\""
"#EXT-X-SESSION-DATA:\
DATA-ID=\"com.example.lyrics\",\
URI=\"lyrics.json\""
.parse::<ExtXSessionData>()
.unwrap(),
ExtXSessionData::new(
@ -386,8 +405,10 @@ mod test {
);
assert_eq!(
"#EXT-X-SESSION-DATA:DATA-ID=\"com.example.title\",\
LANGUAGE=\"en\", VALUE=\"This is an example\""
"#EXT-X-SESSION-DATA:\
DATA-ID=\"com.example.title\",\
LANGUAGE=\"en\",\
VALUE=\"This is an example\""
.parse::<ExtXSessionData>()
.unwrap(),
ExtXSessionData::with_language(
@ -398,8 +419,10 @@ mod test {
);
assert_eq!(
"#EXT-X-SESSION-DATA:DATA-ID=\"com.example.title\",\
LANGUAGE=\"es\", VALUE=\"Este es un ejemplo\""
"#EXT-X-SESSION-DATA:\
DATA-ID=\"com.example.title\",\
LANGUAGE=\"es\",\
VALUE=\"Este es un ejemplo\""
.parse::<ExtXSessionData>()
.unwrap(),
ExtXSessionData::with_language(
@ -410,27 +433,37 @@ mod test {
);
assert_eq!(
"#EXT-X-SESSION-DATA:DATA-ID=\"foo\",VALUE=\"bar\""
"#EXT-X-SESSION-DATA:\
DATA-ID=\"foo\",\
VALUE=\"bar\""
.parse::<ExtXSessionData>()
.unwrap(),
ExtXSessionData::new("foo", SessionData::Value("bar".into()))
);
assert_eq!(
"#EXT-X-SESSION-DATA:DATA-ID=\"foo\",URI=\"bar\""
"#EXT-X-SESSION-DATA:\
DATA-ID=\"foo\",\
URI=\"bar\""
.parse::<ExtXSessionData>()
.unwrap(),
ExtXSessionData::new("foo", SessionData::Uri("bar".into()))
);
assert_eq!(
"#EXT-X-SESSION-DATA:DATA-ID=\"foo\",VALUE=\"bar\",LANGUAGE=\"baz\""
"#EXT-X-SESSION-DATA:\
DATA-ID=\"foo\",\
VALUE=\"bar\",\
LANGUAGE=\"baz\",\
UNKNOWN=TAG"
.parse::<ExtXSessionData>()
.unwrap(),
ExtXSessionData::with_language("foo", SessionData::Value("bar".into()), "baz")
);
assert!("#EXT-X-SESSION-DATA:DATA-ID=\"foo\",LANGUAGE=\"baz\""
assert!("#EXT-X-SESSION-DATA:\
DATA-ID=\"foo\",\
LANGUAGE=\"baz\""
.parse::<ExtXSessionData>()
.is_err())
}

View file

@ -18,10 +18,16 @@ pub struct ExtXStart {
impl ExtXStart {
pub(crate) const PREFIX: &'static str = "#EXT-X-START:";
/// Makes a new `ExtXStart` tag.
/// Makes a new [ExtXStart] tag.
///
/// # Panic
/// Panics if the time_offset value is infinite.
///
/// # Example
/// ```
/// # use hls_m3u8::tags::ExtXStart;
/// ExtXStart::new(20.123456);
/// ```
pub fn new(time_offset: f64) -> Self {
Self {
time_offset: SignedDecimalFloatingPoint::new(time_offset),
@ -29,10 +35,17 @@ impl ExtXStart {
}
}
/// Makes a new `ExtXStart` tag with the given `precise` flag.
/// Makes a new [ExtXStart] tag with the given `precise` flag.
///
/// # Panic
/// Panics if the time_offset value is infinite.
///
/// # Example
/// ```
/// # use hls_m3u8::tags::ExtXStart;
/// let start = ExtXStart::with_precise(20.123456, true);
/// assert_eq!(start.precise(), true);
/// ```
pub fn with_precise(time_offset: f64, precise: bool) -> Self {
Self {
time_offset: SignedDecimalFloatingPoint::new(time_offset),
@ -41,15 +54,63 @@ impl ExtXStart {
}
/// Returns the time offset of the media segments in the playlist.
///
/// # Example
/// ```
/// # use hls_m3u8::tags::ExtXStart;
/// let start = ExtXStart::new(20.123456);
/// assert_eq!(start.time_offset(), 20.123456);
/// ```
pub const fn time_offset(&self) -> f64 {
self.time_offset.as_f64()
}
/// Sets the time offset of the media segments in the playlist.
///
/// # Example
/// ```
/// # use hls_m3u8::tags::ExtXStart;
/// let mut start = ExtXStart::new(20.123456);
/// # assert_eq!(start.time_offset(), 20.123456);
///
/// start.set_time_offset(1.0);
///
/// assert_eq!(start.time_offset(), 1.0);
/// ```
pub fn set_time_offset(&mut self, value: f64) -> &mut Self {
self.time_offset = SignedDecimalFloatingPoint::new(value);
self
}
/// Returns whether clients should not render media stream whose presentation times are
/// prior to the specified time offset.
///
/// # Example
/// ```
/// # use hls_m3u8::tags::ExtXStart;
/// let start = ExtXStart::with_precise(20.123456, true);
/// assert_eq!(start.precise(), true);
/// ```
pub const fn precise(&self) -> bool {
self.precise
}
/// Sets the `precise` flag.
///
/// # Example
/// ```
/// # use hls_m3u8::tags::ExtXStart;
/// let mut start = ExtXStart::new(20.123456);
/// # assert_eq!(start.precise(), false);
///
/// start.set_precise(true);
///
/// assert_eq!(start.precise(), true);
/// ```
pub fn set_precise(&mut self, value: bool) -> &mut Self {
self.precise = value;
self
}
}
impl RequiredVersion for ExtXStart {
@ -91,7 +152,7 @@ impl FromStr for ExtXStart {
let time_offset = time_offset.ok_or_else(|| Error::missing_value("EXT-X-TIME-OFFSET"))?;
Ok(ExtXStart {
Ok(Self {
time_offset,
precise,
})
@ -139,5 +200,12 @@ mod test {
ExtXStart::with_precise(1.23, true),
"#EXT-X-START:TIME-OFFSET=1.23,PRECISE=YES".parse().unwrap(),
);
assert_eq!(
ExtXStart::with_precise(1.23, true),
"#EXT-X-START:TIME-OFFSET=1.23,PRECISE=YES,UNKNOWN=TAG"
.parse()
.unwrap(),
);
}
}