mirror of
https://github.com/v0l/m3u8-rs.git
synced 2025-06-22 19:18:07 +00:00
Make most internal parser functions private
And move parser internals tests into a test submodule of the parser. Also add actual assertions to various tests so they test something.
This commit is contained in:
152
tests/lib.rs
152
tests/lib.rs
@ -163,158 +163,6 @@ fn playlist_types() {
|
||||
}
|
||||
}
|
||||
|
||||
// -----------------------------------------------------------------------------------------------
|
||||
// Variant
|
||||
|
||||
#[test]
|
||||
fn variant_stream() {
|
||||
let input = b"#EXT-X-STREAM-INF:BANDWIDTH=300000,CODECS=\"xxx\"\n";
|
||||
let result = variant_stream_tag(input);
|
||||
println!("{:?}", result);
|
||||
}
|
||||
|
||||
// -----------------------------------------------------------------------------------------------
|
||||
// Other
|
||||
|
||||
#[test]
|
||||
fn test_key_value_pairs_trailing_equals() {
|
||||
let res = key_value_pairs(b"BANDWIDTH=395000,CODECS=\"avc1.4d001f,mp4a.40.2\"\r\nrest=");
|
||||
println!("{:?}\n\n", res);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_key_value_pairs_multiple_quoted_values() {
|
||||
assert_eq!(
|
||||
key_value_pairs(b"BANDWIDTH=86000,URI=\"low/iframe.m3u8\",PROGRAM-ID=1,RESOLUTION=\"1x1\",VIDEO=1\nrest"),
|
||||
Result::Ok((
|
||||
"\nrest".as_bytes(),
|
||||
vec![
|
||||
("BANDWIDTH".to_string(), "86000".to_string()),
|
||||
("URI".to_string(), "low/iframe.m3u8".to_string()),
|
||||
("PROGRAM-ID".to_string(), "1".to_string()),
|
||||
("RESOLUTION".to_string(), "1x1".to_string()),
|
||||
("VIDEO".to_string(), "1".to_string())
|
||||
].into_iter().collect::<HashMap<String,String>>()
|
||||
))
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_key_value_pairs_quotes() {
|
||||
let res = key_value_pairs(b"BANDWIDTH=300000,CODECS=\"avc1.42c015,mp4a.40.2\"\r\nrest");
|
||||
println!("{:?}\n\n", res);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_key_value_pairs() {
|
||||
let res = key_value_pairs(b"BANDWIDTH=300000,RESOLUTION=22x22,VIDEO=1\r\nrest=");
|
||||
println!("{:?}\n\n", res);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_key_value_pair() {
|
||||
assert_eq!(
|
||||
key_value_pair(b"PROGRAM-ID=1,rest"),
|
||||
Result::Ok((
|
||||
"rest".as_bytes(),
|
||||
("PROGRAM-ID".to_string(), "1".to_string())
|
||||
))
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn ext_with_value() {
|
||||
assert_eq!(
|
||||
ext_tag(b"#EXT-X-CUE-OUT:DURATION=30\nxxx"),
|
||||
Result::Ok((
|
||||
b"xxx".as_bytes(),
|
||||
ExtTag {
|
||||
tag: "X-CUE-OUT".into(),
|
||||
rest: Some("DURATION=30".into())
|
||||
}
|
||||
))
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn ext_without_value() {
|
||||
assert_eq!(
|
||||
ext_tag(b"#EXT-X-CUE-IN\nxxx"),
|
||||
Result::Ok((
|
||||
b"xxx".as_bytes(),
|
||||
ExtTag {
|
||||
tag: "X-CUE-IN".into(),
|
||||
rest: None
|
||||
}
|
||||
))
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn comment() {
|
||||
assert_eq!(
|
||||
comment_tag(b"#Hello\nxxx"),
|
||||
Result::Ok(("xxx".as_bytes(), "Hello".to_string()))
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn quotes() {
|
||||
assert_eq!(
|
||||
quoted(b"\"value\"rest"),
|
||||
Result::Ok(("rest".as_bytes(), "value".to_string()))
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn consume_line_empty() {
|
||||
let expected = Result::Ok(("rest".as_bytes(), "".to_string()));
|
||||
let actual = consume_line(b"\r\nrest");
|
||||
assert_eq!(expected, actual);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn consume_line_n() {
|
||||
assert_eq!(
|
||||
consume_line(b"before\nrest"),
|
||||
Result::Ok(("rest".as_bytes(), "before".into()))
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn consume_line_rn() {
|
||||
assert_eq!(
|
||||
consume_line(b"before\r\nrest"),
|
||||
Result::Ok(("rest".as_bytes(), "before".into()))
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn float_() {
|
||||
assert_eq!(
|
||||
float(b"33.22rest"),
|
||||
Result::Ok(("rest".as_bytes(), 33.22f32))
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn float_no_decimal() {
|
||||
assert_eq!(float(b"33rest"), Result::Ok(("rest".as_bytes(), 33f32)));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn float_should_ignore_trailing_dot() {
|
||||
assert_eq!(float(b"33.rest"), Result::Ok((".rest".as_bytes(), 33f32)));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn parse_duration_title() {
|
||||
assert_eq!(
|
||||
duration_title_tag(b"2.002,title\nrest"),
|
||||
Result::Ok(("rest".as_bytes(), (2.002f32, Some("title".to_string()))))
|
||||
);
|
||||
}
|
||||
|
||||
// -----------------------------------------------------------------------------------------------
|
||||
// Creating playlists
|
||||
|
||||
|
Reference in New Issue
Block a user