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

increase codecov

This commit is contained in:
Luro02 2019-09-28 16:42:23 +02:00
parent b0b766bc0c
commit 96bb0d470d
3 changed files with 168 additions and 24 deletions

View file

@ -188,12 +188,12 @@ impl MasterPlaylistBuilder {
}
}
match t.closed_captions() {
Some(&ClosedCaptions::GroupId(ref group_id)) => {
&Some(ClosedCaptions::GroupId(ref group_id)) => {
if !self.check_media_group(MediaType::ClosedCaptions, group_id) {
return Err(Error::unmatched_group(group_id));
}
}
Some(&ClosedCaptions::None) => {
&Some(ClosedCaptions::None) => {
has_none_closed_captions = true;
}
None => {}
@ -202,7 +202,7 @@ impl MasterPlaylistBuilder {
if has_none_closed_captions
&& !value
.iter()
.all(|t| t.closed_captions() == Some(&ClosedCaptions::None))
.all(|t| t.closed_captions() == &Some(ClosedCaptions::None))
{
return Err(Error::invalid_input());
}

View file

@ -465,7 +465,15 @@ mod test {
DATA-ID=\"foo\",\
LANGUAGE=\"baz\""
.parse::<ExtXSessionData>()
.is_err())
.is_err());
assert!("#EXT-X-SESSION-DATA:\
DATA-ID=\"foo\",\
LANGUAGE=\"baz\",\
VALUE=\"VALUE\",\
URI=\"https://www.example.com/\""
.parse::<ExtXSessionData>()
.is_err());
}
#[test]

View file

@ -27,14 +27,13 @@ impl ExtXStreamInf {
/// Creates a new [ExtXStreamInf] tag.
///
/// # Examples
/// # Example
/// ```
/// # use hls_m3u8::tags::ExtXStreamInf;
/// #
/// let stream = ExtXStreamInf::new("https://www.example.com/", 20);
/// ```
pub fn new<T: ToString>(uri: T, bandwidth: u64) -> Self {
ExtXStreamInf {
Self {
uri: uri.to_string(),
frame_rate: None,
audio: None,
@ -44,41 +43,160 @@ impl ExtXStreamInf {
}
}
/// Returns the `URI` that identifies the associated media playlist.
///
/// # Example
/// ```
/// # use hls_m3u8::tags::ExtXStreamInf;
/// let stream = ExtXStreamInf::new("https://www.example.com/", 20);
///
/// assert_eq!(stream.uri(), &"https://www.example.com/".to_string());
/// ```
pub const fn uri(&self) -> &String {
&self.uri
}
/// Sets the `URI` that identifies the associated media playlist.
///
/// # Example
/// ```
/// # use hls_m3u8::tags::ExtXStreamInf;
/// let mut stream = ExtXStreamInf::new("https://www.example.com/", 20);
///
/// stream.set_uri("https://www.google.com/");
/// assert_eq!(stream.uri(), &"https://www.google.com/".to_string());
/// ```
pub fn set_uri<T: ToString>(&mut self, value: T) -> &mut Self {
self.uri = value.to_string();
self
}
/// Returns the `URI` that identifies the associated media playlist.
pub const fn uri(&self) -> &String {
&self.uri
}
/// Sets the maximum frame rate for all the video in the variant stream.
///
/// # Example
/// ```
/// # use hls_m3u8::tags::ExtXStreamInf;
/// let mut stream = ExtXStreamInf::new("https://www.example.com/", 20);
/// # assert_eq!(stream.frame_rate(), None);
///
/// stream.set_frame_rate(Some(59.9));
/// assert_eq!(stream.frame_rate(), Some(59.9));
/// ```
pub fn set_frame_rate(&mut self, value: Option<f64>) -> &mut Self {
self.frame_rate = value.map(|v| (v as u32).into());
self.frame_rate = value.map(|v| v.into());
self
}
/// Returns the maximum frame rate for all the video in the variant stream.
///
/// # Example
/// ```
/// # use hls_m3u8::tags::ExtXStreamInf;
/// let mut stream = ExtXStreamInf::new("https://www.example.com/", 20);
/// # assert_eq!(stream.frame_rate(), None);
///
/// stream.set_frame_rate(Some(59.9));
/// assert_eq!(stream.frame_rate(), Some(59.9));
/// ```
pub fn frame_rate(&self) -> Option<f64> {
self.frame_rate.map(|v| v.as_f64())
}
/// Returns the group identifier for the audio in the variant stream.
pub fn audio(&self) -> Option<&String> {
self.audio.as_ref()
///
/// # Example
/// ```
/// # use hls_m3u8::tags::ExtXStreamInf;
/// let mut stream = ExtXStreamInf::new("https://www.example.com/", 20);
/// # assert_eq!(stream.audio(), &None);
///
/// stream.set_audio(Some("audio"));
/// assert_eq!(stream.audio(), &Some("audio".to_string()));
/// ```
pub const fn audio(&self) -> &Option<String> {
&self.audio
}
/// Sets the group identifier for the audio in the variant stream.
///
/// # Example
/// ```
/// # use hls_m3u8::tags::ExtXStreamInf;
/// let mut stream = ExtXStreamInf::new("https://www.example.com/", 20);
/// # assert_eq!(stream.audio(), &None);
///
/// stream.set_audio(Some("audio"));
/// assert_eq!(stream.audio(), &Some("audio".to_string()));
/// ```
pub fn set_audio<T: Into<String>>(&mut self, value: Option<T>) -> &mut Self {
self.audio = value.map(|v| v.into());
self
}
/// Returns the group identifier for the subtitles in the variant stream.
pub fn subtitles(&self) -> Option<&String> {
self.subtitles.as_ref()
///
/// # Example
/// ```
/// # use hls_m3u8::tags::ExtXStreamInf;
/// let mut stream = ExtXStreamInf::new("https://www.example.com/", 20);
/// # assert_eq!(stream.subtitles(), &None);
///
/// stream.set_subtitles(Some("subs"));
/// assert_eq!(stream.subtitles(), &Some("subs".to_string()));
/// ```
pub const fn subtitles(&self) -> &Option<String> {
&self.subtitles
}
/// Returns the value of `CLOSED-CAPTIONS` attribute.
pub fn closed_captions(&self) -> Option<&ClosedCaptions> {
self.closed_captions.as_ref()
/// Sets the group identifier for the subtitles in the variant stream.
///
/// # Example
/// ```
/// # use hls_m3u8::tags::ExtXStreamInf;
/// let mut stream = ExtXStreamInf::new("https://www.example.com/", 20);
/// # assert_eq!(stream.subtitles(), &None);
///
/// stream.set_subtitles(Some("subs"));
/// assert_eq!(stream.subtitles(), &Some("subs".to_string()));
/// ```
pub fn set_subtitles<T: Into<String>>(&mut self, value: Option<T>) -> &mut Self {
self.subtitles = value.map(|v| v.into());
self
}
/// Returns the value of [ClosedCaptions] attribute.
///
/// # Example
/// ```
/// # use hls_m3u8::tags::ExtXStreamInf;
/// use hls_m3u8::types::ClosedCaptions;
///
/// let mut stream = ExtXStreamInf::new("https://www.example.com/", 20);
/// # assert_eq!(stream.closed_captions(), &None);
///
/// stream.set_closed_captions(Some(ClosedCaptions::None));
/// assert_eq!(stream.closed_captions(), &Some(ClosedCaptions::None));
/// ```
pub const fn closed_captions(&self) -> &Option<ClosedCaptions> {
&self.closed_captions
}
/// Returns the value of [ClosedCaptions] attribute.
///
/// # Example
/// ```
/// # use hls_m3u8::tags::ExtXStreamInf;
/// use hls_m3u8::types::ClosedCaptions;
///
/// let mut stream = ExtXStreamInf::new("https://www.example.com/", 20);
/// # assert_eq!(stream.closed_captions(), &None);
///
/// stream.set_closed_captions(Some(ClosedCaptions::None));
/// assert_eq!(stream.closed_captions(), &Some(ClosedCaptions::None));
/// ```
pub fn set_closed_captions(&mut self, value: Option<ClosedCaptions>) -> &mut Self {
self.closed_captions = value;
self
}
}
@ -130,7 +248,7 @@ impl FromStr for ExtXStreamInf {
"FRAME-RATE" => frame_rate = Some((value.parse())?),
"AUDIO" => audio = Some(unquote(value)),
"SUBTITLES" => subtitles = Some(unquote(value)),
"CLOSED-CAPTIONS" => closed_captions = Some((value.parse())?),
"CLOSED-CAPTIONS" => closed_captions = Some(value.parse()?),
_ => {}
}
}
@ -176,6 +294,14 @@ mod test {
);
}
#[test]
fn test_display() {
assert_eq!(
ExtXStreamInf::new("http://www.example.com/", 1000).to_string(),
"#EXT-X-STREAM-INF:BANDWIDTH=1000\nhttp://www.example.com/".to_string()
);
}
#[test]
fn test_required_version() {
assert_eq!(
@ -185,10 +311,20 @@ mod test {
}
#[test]
fn test_display() {
fn test_deref() {
assert_eq!(
ExtXStreamInf::new("http://www.example.com/", 1000).to_string(),
"#EXT-X-STREAM-INF:BANDWIDTH=1000\nhttp://www.example.com/".to_string()
ExtXStreamInf::new("http://www.example.com", 1000).bandwidth(),
1000
);
}
#[test]
fn test_deref_mut() {
assert_eq!(
ExtXStreamInf::new("http://www.example.com", 1000)
.set_bandwidth(1)
.bandwidth(),
1
);
}
}