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