mirror of
https://github.com/sile/hls_m3u8.git
synced 2025-02-16 13:15:14 +00:00
added test
This commit is contained in:
parent
7483f49fe9
commit
a2614b5aca
2 changed files with 36 additions and 4 deletions
17
src/error.rs
17
src/error.rs
|
@ -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 {
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue