4 fn test_lookup_line() {
5 let lines = &[BytePos(3), BytePos(17), BytePos(28)];
7 assert_eq!(lookup_line(lines, BytePos(0)), -1);
8 assert_eq!(lookup_line(lines, BytePos(3)), 0);
9 assert_eq!(lookup_line(lines, BytePos(4)), 0);
11 assert_eq!(lookup_line(lines, BytePos(16)), 0);
12 assert_eq!(lookup_line(lines, BytePos(17)), 1);
13 assert_eq!(lookup_line(lines, BytePos(18)), 1);
15 assert_eq!(lookup_line(lines, BytePos(28)), 2);
16 assert_eq!(lookup_line(lines, BytePos(29)), 2);
20 fn test_normalize_newlines() {
21 fn check(before: &str, after: &str, expected_positions: &[u32]) {
22 let mut actual = before.to_string();
23 let mut actual_positions = vec![];
24 normalize_newlines(&mut actual, &mut actual_positions);
25 let actual_positions: Vec<_> = actual_positions.into_iter().map(|nc| nc.pos.0).collect();
26 assert_eq!(actual.as_str(), after);
27 assert_eq!(actual_positions, expected_positions);
30 check("\n", "\n", &[]);
31 check("\r", "\r", &[]);
32 check("\r\r", "\r\r", &[]);
33 check("\r\n", "\n", &[1]);
34 check("hello world", "hello world", &[]);
35 check("hello\nworld", "hello\nworld", &[]);
36 check("hello\r\nworld", "hello\nworld", &[6]);
37 check("\r\nhello\r\nworld\r\n", "\nhello\nworld\n", &[1, 7, 13]);
38 check("\r\r\n", "\r\n", &[2]);
39 check("hello\rworld", "hello\rworld", &[]);