1
0
Fork 0
mirror of https://github.com/sile/hls_m3u8.git synced 2024-05-18 16:28:20 +00:00

added test

This commit is contained in:
Luro02 2019-09-14 12:34:34 +02:00
parent 7483f49fe9
commit a2614b5aca
2 changed files with 36 additions and 4 deletions

View file

@ -49,6 +49,12 @@ pub enum ErrorKind {
#[fail(display = "IoError: {}", _0)]
Io(String),
#[fail(
display = "VersionError: required_version: {:?}, specified_version: {:?}",
_0, _1
)]
VersionError(String, String),
/// Hints that destructuring should not be exhaustive.
///
/// This enum may grow additional variants, so this makes sure clients
@ -171,6 +177,17 @@ impl Error {
pub(crate) fn io<T: ToString>(value: T) -> Self {
Self::from(ErrorKind::Io(value.to_string()))
}
pub(crate) fn required_version<T, U>(required_version: T, specified_version: U) -> Self
where
T: ToString,
U: ToString,
{
Self::from(ErrorKind::VersionError(
required_version.to_string(),
specified_version.to_string(),
))
}
}
impl From<std::num::ParseIntError> for Error {

View file

@ -73,9 +73,8 @@ impl MasterPlaylistBuilder {
let required_version = self.required_version();
let specified_version = self.version.unwrap_or(required_version);
if required_version <= specified_version {
// "required_version:{}, specified_version:{}"
return Err(Error::invalid_input());
if required_version < specified_version {
return Err(Error::required_version(required_version, specified_version));
}
(self.validate_stream_inf_tags())?;
@ -379,5 +378,21 @@ mod tests {
use super::*;
#[test]
fn test_parser() {}
fn test_parser() {
let playlist = r#"
#EXTM3U
#EXT-X-STREAM-INF:BANDWIDTH=150000,RESOLUTION=416x234,CODECS="avc1.42e00a,mp4a.40.2"
http://example.com/low/index.m3u8
#EXT-X-STREAM-INF:BANDWIDTH=240000,RESOLUTION=416x234,CODECS="avc1.42e00a,mp4a.40.2"
http://example.com/lo_mid/index.m3u8
#EXT-X-STREAM-INF:BANDWIDTH=440000,RESOLUTION=416x234,CODECS="avc1.42e00a,mp4a.40.2"
http://example.com/hi_mid/index.m3u8
#EXT-X-STREAM-INF:BANDWIDTH=640000,RESOLUTION=640x360,CODECS="avc1.42e00a,mp4a.40.2"
http://example.com/high/index.m3u8
#EXT-X-STREAM-INF:BANDWIDTH=64000,CODECS="mp4a.40.5"
http://example.com/audio/index.m3u8
"#
.parse::<MasterPlaylist>()
.unwrap();
}
}