Skip to content

Instantly share code, notes, and snippets.

@weiznich
Last active April 5, 2016 22:11
Show Gist options
  • Save weiznich/eef28628d21a8ff5140bae5f84340ff1 to your computer and use it in GitHub Desktop.
Save weiznich/eef28628d21a8ff5140bae5f84340ff1 to your computer and use it in GitHub Desktop.
#[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