Skip to content

Commit

Permalink
test(cli): extract_line tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Ed Page committed Apr 11, 2021
1 parent d797865 commit 246b4c9
Showing 1 changed file with 35 additions and 0 deletions.
35 changes: 35 additions & 0 deletions src/file.rs
Original file line number Diff line number Diff line change
Expand Up @@ -672,4 +672,39 @@ mod test {
);
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);
}
}

0 comments on commit 246b4c9

Please sign in to comment.