]> git.lizzy.rs Git - rust.git/blob - src/libsyntax_pos/tests.rs
Rollup merge of #65775 - matthewjasper:reempty, r=pnkfelix
[rust.git] / src / libsyntax_pos / tests.rs
1 use super::*;
2
3 #[test]
4 fn test_lookup_line() {
5
6     let lines = &[BytePos(3), BytePos(17), BytePos(28)];
7
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);
11
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);
15
16     assert_eq!(lookup_line(lines, BytePos(28)), 2);
17     assert_eq!(lookup_line(lines, BytePos(29)), 2);
18 }
19
20 #[test]
21 fn test_normalize_newlines() {
22     fn check(before: &str, after: &str) {
23         let mut actual = before.to_string();
24         normalize_newlines(&mut actual);
25         assert_eq!(actual.as_str(), after);
26     }
27     check("", "");
28     check("\n", "\n");
29     check("\r", "\r");
30     check("\r\r", "\r\r");
31     check("\r\n", "\n");
32     check("hello world", "hello world");
33     check("hello\nworld", "hello\nworld");
34     check("hello\r\nworld", "hello\nworld");
35     check("\r\nhello\r\nworld\r\n", "\nhello\nworld\n");
36     check("\r\r\n", "\r\n");
37     check("hello\rworld", "hello\rworld");
38 }