Last active
April 5, 2016 22:11
-
-
Save weiznich/eef28628d21a8ff5140bae5f84340ff1 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#[macro_use] | |
extern crate nom; | |
#[cfg(test)] | |
mod tests { | |
use nom::*; | |
use nom::IResult::*; | |
#[test] | |
fn till_line_ending_unix() { | |
let input = b"abc\n"; | |
let output = not_line_ending(input); | |
assert_eq!(output, Done(&b"\n"[..], &b"abc"[..])); | |
} | |
#[test] | |
fn till_line_ending_windows() { | |
let input = b"abc\r\n"; | |
let output = not_line_ending(input); | |
assert_eq!(output, Done(&b"\r\n"[..], &b"abc"[..])); | |
} | |
named!(take_full_line<(&[u8], &[u8])>, tuple!(not_line_ending, line_ending)); | |
#[test] | |
fn full_line_windows() { | |
let input = b"abc\r\n"; | |
let output = take_full_line(input); | |
assert_eq!(output, Done(&b""[..], (&b"abc"[..], &b"\r\n"[..]))); | |
} | |
#[test] | |
fn full_line_unix() { | |
let input = b"abc\n"; | |
let output = take_full_line(input); | |
assert_eq!(output, Done(&b""[..], (&b"abc"[..], &b"\n"[..]))); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment