diff options
| author | Mikko Rantanen <jubjub@jubjubnest.net> | 2019-10-03 03:55:31 +0300 |
|---|---|---|
| committer | Mikko Rantanen <jubjub@jubjubnest.net> | 2019-10-21 19:28:29 +0300 |
| commit | ff1860ad763baac652d3a43a93985e29ade805cb (patch) | |
| tree | 4c425dd8c70519e74aa630405d35019e234ee591 /src/libsyntax_pos/tests.rs | |
| parent | 2748a9fd93dd1a00a4521f4f16de5befbf77f6cd (diff) | |
| download | rust-ff1860ad763baac652d3a43a93985e29ade805cb.tar.gz rust-ff1860ad763baac652d3a43a93985e29ade805cb.zip | |
Fix the start/end byte positions in the compiler JSON output
Diffstat (limited to 'src/libsyntax_pos/tests.rs')
| -rw-r--r-- | src/libsyntax_pos/tests.rs | 31 |
1 files changed, 18 insertions, 13 deletions
diff --git a/src/libsyntax_pos/tests.rs b/src/libsyntax_pos/tests.rs index 6bd6016020a..87cc3505e38 100644 --- a/src/libsyntax_pos/tests.rs +++ b/src/libsyntax_pos/tests.rs @@ -19,20 +19,25 @@ fn test_lookup_line() { #[test] fn test_normalize_newlines() { - fn check(before: &str, after: &str) { + fn check(before: &str, after: &str, expected_positions: &[u32]) { let mut actual = before.to_string(); - normalize_newlines(&mut actual); + let mut actual_positions = vec![]; + normalize_newlines(&mut actual, &mut actual_positions); + let actual_positions : Vec<_> = actual_positions + .into_iter() + .map(|nc| nc.pos.0).collect(); assert_eq!(actual.as_str(), after); + assert_eq!(actual_positions, expected_positions); } - check("", ""); - check("\n", "\n"); - check("\r", "\r"); - check("\r\r", "\r\r"); - check("\r\n", "\n"); - check("hello world", "hello world"); - check("hello\nworld", "hello\nworld"); - check("hello\r\nworld", "hello\nworld"); - check("\r\nhello\r\nworld\r\n", "\nhello\nworld\n"); - check("\r\r\n", "\r\n"); - check("hello\rworld", "hello\rworld"); + check("", "", &[]); + check("\n", "\n", &[]); + check("\r", "\r", &[]); + check("\r\r", "\r\r", &[]); + check("\r\n", "\n", &[1]); + check("hello world", "hello world", &[]); + check("hello\nworld", "hello\nworld", &[]); + check("hello\r\nworld", "hello\nworld", &[6]); + check("\r\nhello\r\nworld\r\n", "\nhello\nworld\n", &[1, 7, 13]); + check("\r\r\n", "\r\n", &[2]); + check("hello\rworld", "hello\rworld", &[]); } |
