1
0
Fork 0
mirror of https://github.com/sile/hls_m3u8.git synced 2024-11-15 20:01:01 +00:00
hls_m3u8/tests/playlist.rs

48 lines
1.2 KiB
Rust
Raw Normal View History

2019-09-15 08:40:45 +00:00
//! Credits go to
//! - https://github.com/globocom/m3u8/blob/master/tests/playlists.py
use hls_m3u8::tags::*;
use hls_m3u8::MediaPlaylist;
use std::time::Duration;
#[test]
fn test_simple_playlist() {
2020-02-10 12:20:39 +00:00
let playlist = concat!(
"#EXTM3U\n",
"#EXT-X-TARGETDURATION:5220\n",
"#EXTINF:0,\n",
"http://media.example.com/entire1.ts\n",
"#EXTINF:5220,\n",
"http://media.example.com/entire2.ts\n",
"#EXT-X-ENDLIST\n"
);
2019-09-15 08:40:45 +00:00
let media_playlist = playlist.parse::<MediaPlaylist>().unwrap();
assert_eq!(
2020-02-10 12:20:39 +00:00
media_playlist.target_duration(),
2019-09-15 08:40:45 +00:00
ExtXTargetDuration::new(Duration::from_secs(5220))
);
assert_eq!(media_playlist.segments().len(), 2);
assert_eq!(
media_playlist.segments()[0].inf_tag(),
&ExtInf::new(Duration::from_secs(0))
);
assert_eq!(
media_playlist.segments()[1].inf_tag(),
&ExtInf::new(Duration::from_secs(5220))
);
assert_eq!(
media_playlist.segments()[0].uri(),
2019-09-21 10:11:36 +00:00
&"http://media.example.com/entire1.ts".to_string()
2019-09-15 08:40:45 +00:00
);
assert_eq!(
media_playlist.segments()[1].uri(),
2019-09-21 10:11:36 +00:00
&"http://media.example.com/entire2.ts".to_string()
2019-09-15 08:40:45 +00:00
);
}