Fix failed test on CLRF

This commit is contained in:
Rutger Schoorstra 2020-03-06 20:59:15 +01:00
parent ab9c554eb4
commit 100a57078a
2 changed files with 23 additions and 8 deletions

View file

@ -88,7 +88,7 @@ use nom::{IResult};
use nom::{ delimited,none_of,peek,is_not,complete,terminated,tag, use nom::{ delimited,none_of,peek,is_not,complete,terminated,tag,
alt,do_parse,opt,named,map,map_res,eof,many0,take,take_until,char}; alt,do_parse,opt,named,map,map_res,eof,many0,take,take_until,char};
use nom::combinator::map; use nom::combinator::map;
use nom::character::complete::{line_ending};
use std::str; use std::str;
use std::f32; use std::f32;
use std::string; use std::string;
@ -513,10 +513,9 @@ named!(pub unquoted<String>,
named!(pub consume_line<String>, named!(pub consume_line<String>,
do_parse!( do_parse!(
l: map_res!(is_not!("\r\n"), from_utf8_slice) line: map_res!(is_not!("\r\n"), from_utf8_slice)
>> take!(1) >> line_ending
>> >> (line)
(l)
) )
); );

View file

@ -199,13 +199,29 @@ fn quotes() {
Result::Ok(("rest".as_bytes(), "value".to_string())) Result::Ok(("rest".as_bytes(), "value".to_string()))
); );
} }
#[test]
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] #[test]
fn consume_empty_line() { fn consume_line_n() {
let line = consume_line(b"\r\nrest"); assert_eq!(
println!("{:?}", line); 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] #[test]