test(cli): Cover extract_line

This commit is contained in:
Ed Page 2021-04-10 20:52:34 -05:00
parent d7978658d4
commit f36bdc895f

View file

@ -672,4 +672,39 @@ mod test {
); );
assert_eq!(actual, "foo happy world"); assert_eq!(actual, "foo happy world");
} }
#[test]
fn test_extract_line_single_line() {
let (line, offset) = extract_line(b"hello world", 6);
assert_eq!(line, b"hello world");
assert_eq!(offset, 6);
}
#[test]
fn test_extract_line_first() {
let (line, offset) = extract_line(b"1\n2\n3", 0);
assert_eq!(line, b"1");
assert_eq!(offset, 0);
}
#[test]
fn test_extract_line_middle() {
let (line, offset) = extract_line(b"1\n2\n3", 2);
assert_eq!(line, b"2");
assert_eq!(offset, 0);
}
#[test]
fn test_extract_line_end() {
let (line, offset) = extract_line(b"1\n2\n3", 4);
assert_eq!(line, b"3");
assert_eq!(offset, 0);
}
#[test]
fn test_extract_line_offset_change() {
let (line, offset) = extract_line(b"1\nhello world\n2", 8);
assert_eq!(line, b"hello world");
assert_eq!(offset, 6);
}
} }