Merge pull request #11 from vagetman/vagetman-nom-5.1.0

Upgraded macros to Nom 5
This commit is contained in:
rutgersc
2020-07-01 16:43:30 +02:00
committed by GitHub
6 changed files with 190 additions and 153 deletions

View File

@ -41,7 +41,7 @@ fn print_parse_playlist_test(playlist_name: &str) -> bool {
println!("Parsing playlist file: {:?}", playlist_name);
let parsed = parse_playlist(input.as_bytes());
if let IResult::Done(i,o) = parsed {
if let Result::Ok((i,o)) = parsed {
println!("{:?}", o);
true
}
@ -116,9 +116,9 @@ fn playlist_types() {
let input = getm3u(path);
let is_master = is_master_playlist(input.as_bytes());
assert!(path.to_lowercase().contains("master") == is_master);
println!("{:?} = {:?}", path, is_master);
assert!(path.to_lowercase().contains("master") == is_master);
}
}
@ -146,7 +146,7 @@ fn test_key_value_pairs_trailing_equals() {
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"),
IResult::Done(
Result::Ok((
"\nrest".as_bytes(),
vec![
("BANDWIDTH".to_string(), "86000".to_string()),
@ -155,7 +155,7 @@ fn test_key_value_pairs_multiple_quoted_values() {
("RESOLUTION".to_string(), "1x1".to_string()),
("VIDEO".to_string(), "1".to_string())
].into_iter().collect::<HashMap<String,String>>()
)
))
);
}
@ -176,10 +176,10 @@ fn test_key_value_pairs() {
fn test_key_value_pair() {
assert_eq!(
key_value_pair(b"PROGRAM-ID=1,rest"),
IResult::Done(
Result::Ok((
"rest".as_bytes(),
("PROGRAM-ID".to_string(), "1".to_string())
)
))
);
}
@ -187,7 +187,7 @@ fn test_key_value_pair() {
fn comment() {
assert_eq!(
comment_tag(b"#Hello\nxxx"),
IResult::Done("xxx".as_bytes(), "Hello".to_string())
Result::Ok(("xxx".as_bytes(), "Hello".to_string()))
);
}
@ -195,21 +195,39 @@ fn comment() {
fn quotes() {
assert_eq!(
quoted(b"\"value\"rest"),
IResult::Done("rest".as_bytes(), "value".to_string())
Result::Ok(("rest".as_bytes(), "value".to_string()))
);
}
#[test]
fn consume_empty_line() {
let line = consume_line(b"\r\nrest");
println!("{:?}", line);
fn consume_line_empty() {
assert_eq!(
consume_line(b"\r\nrest"),
Result::Err(nom::Err::Error(("\r\nrest".as_bytes(), nom::error::ErrorKind::IsNot)))
);
}
#[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"),
IResult::Done("rest".as_bytes(), 33.22f32)
Result::Ok(("rest".as_bytes(), 33.22f32))
);
}
@ -217,7 +235,7 @@ fn float_() {
fn float_no_decimal() {
assert_eq!(
float(b"33rest"),
IResult::Done("rest".as_bytes(), 33f32)
Result::Ok(("rest".as_bytes(), 33f32))
);
}
@ -225,7 +243,7 @@ fn float_no_decimal() {
fn float_should_ignore_trailing_dot() {
assert_eq!(
float(b"33.rest"),
IResult::Done(".rest".as_bytes(), 33f32)
Result::Ok((".rest".as_bytes(), 33f32))
);
}
@ -233,7 +251,7 @@ fn float_should_ignore_trailing_dot() {
fn parse_duration_title() {
assert_eq!(
duration_title_tag(b"2.002,title\nrest"),
IResult::Done("rest".as_bytes(), (2.002f32, Some("title".to_string())))
Result::Ok(("rest".as_bytes(), (2.002f32, Some("title".to_string()))))
);
}