diff --git a/src/lib.rs b/src/lib.rs index b635def..dc7132e 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -88,7 +88,7 @@ use nom::{IResult}; 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}; use nom::combinator::map; - +use nom::character::complete::{line_ending}; use std::str; use std::f32; use std::string; @@ -513,10 +513,9 @@ named!(pub unquoted, named!(pub consume_line, do_parse!( - l: map_res!(is_not!("\r\n"), from_utf8_slice) - >> take!(1) - >> - (l) + line: map_res!(is_not!("\r\n"), from_utf8_slice) + >> line_ending + >> (line) ) ); diff --git a/tests/lib.rs b/tests/lib.rs index 60f02c5..a41f0f1 100644 --- a/tests/lib.rs +++ b/tests/lib.rs @@ -199,13 +199,29 @@ fn quotes() { 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] -fn consume_empty_line() { - let line = consume_line(b"\r\nrest"); - println!("{:?}", line); +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]