1 use super::*;
2 
3 #[test]
test_lookup_line()4 fn test_lookup_line() {
5     let lines = &[BytePos(3), BytePos(17), BytePos(28)];
6 
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);
10 
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);
14 
15     assert_eq!(lookup_line(lines, BytePos(28)), 2);
16     assert_eq!(lookup_line(lines, BytePos(29)), 2);
17 }
18 
19 #[test]
test_normalize_newlines()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);
28     }
29     check("", "", &[]);
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", &[]);
40 }
41