Skip to content

Commit 2874a87

Browse files
Update CodeMap tests after changing FileMap construction.
1 parent 8c8d733 commit 2874a87

File tree

1 file changed

+10
-61
lines changed

1 file changed

+10
-61
lines changed

src/libsyntax/codemap.rs

+10-61
Original file line numberDiff line numberDiff line change
@@ -940,51 +940,16 @@ impl FilePathMapping {
940940
#[cfg(test)]
941941
mod tests {
942942
use super::*;
943-
use std::borrow::Cow;
944943
use rustc_data_structures::sync::Lrc;
945944

946-
#[test]
947-
fn t1 () {
948-
let cm = CodeMap::new(FilePathMapping::empty());
949-
let fm = cm.new_filemap(PathBuf::from("blork.rs").into(),
950-
"first line.\nsecond line".to_string());
951-
fm.next_line(BytePos(0));
952-
// Test we can get lines with partial line info.
953-
assert_eq!(fm.get_line(0), Some(Cow::from("first line.")));
954-
// TESTING BROKEN BEHAVIOR: line break declared before actual line break.
955-
fm.next_line(BytePos(10));
956-
assert_eq!(fm.get_line(1), Some(Cow::from(".")));
957-
fm.next_line(BytePos(12));
958-
assert_eq!(fm.get_line(2), Some(Cow::from("second line")));
959-
}
960-
961-
#[test]
962-
#[should_panic]
963-
fn t2 () {
964-
let cm = CodeMap::new(FilePathMapping::empty());
965-
let fm = cm.new_filemap(PathBuf::from("blork.rs").into(),
966-
"first line.\nsecond line".to_string());
967-
// TESTING *REALLY* BROKEN BEHAVIOR:
968-
fm.next_line(BytePos(0));
969-
fm.next_line(BytePos(10));
970-
fm.next_line(BytePos(2));
971-
}
972-
973945
fn init_code_map() -> CodeMap {
974946
let cm = CodeMap::new(FilePathMapping::empty());
975-
let fm1 = cm.new_filemap(PathBuf::from("blork.rs").into(),
976-
"first line.\nsecond line".to_string());
977-
let fm2 = cm.new_filemap(PathBuf::from("empty.rs").into(),
978-
"".to_string());
979-
let fm3 = cm.new_filemap(PathBuf::from("blork2.rs").into(),
980-
"first line.\nsecond line".to_string());
981-
982-
fm1.next_line(BytePos(0));
983-
fm1.next_line(BytePos(12));
984-
fm2.next_line(fm2.start_pos);
985-
fm3.next_line(fm3.start_pos);
986-
fm3.next_line(fm3.start_pos + BytePos(12));
987-
947+
cm.new_filemap(PathBuf::from("blork.rs").into(),
948+
"first line.\nsecond line".to_string());
949+
cm.new_filemap(PathBuf::from("empty.rs").into(),
950+
"".to_string());
951+
cm.new_filemap(PathBuf::from("blork2.rs").into(),
952+
"first line.\nsecond line".to_string());
988953
cm
989954
}
990955

@@ -1037,26 +1002,10 @@ mod tests {
10371002
fn init_code_map_mbc() -> CodeMap {
10381003
let cm = CodeMap::new(FilePathMapping::empty());
10391004
// € is a three byte utf8 char.
1040-
let fm1 =
1041-
cm.new_filemap(PathBuf::from("blork.rs").into(),
1042-
"fir€st €€€€ line.\nsecond line".to_string());
1043-
let fm2 = cm.new_filemap(PathBuf::from("blork2.rs").into(),
1044-
"first line€€.\n€ second line".to_string());
1045-
1046-
fm1.next_line(BytePos(0));
1047-
fm1.next_line(BytePos(28));
1048-
fm2.next_line(fm2.start_pos);
1049-
fm2.next_line(fm2.start_pos + BytePos(20));
1050-
1051-
fm1.record_multibyte_char(BytePos(3), 3);
1052-
fm1.record_multibyte_char(BytePos(9), 3);
1053-
fm1.record_multibyte_char(BytePos(12), 3);
1054-
fm1.record_multibyte_char(BytePos(15), 3);
1055-
fm1.record_multibyte_char(BytePos(18), 3);
1056-
fm2.record_multibyte_char(fm2.start_pos + BytePos(10), 3);
1057-
fm2.record_multibyte_char(fm2.start_pos + BytePos(13), 3);
1058-
fm2.record_multibyte_char(fm2.start_pos + BytePos(18), 3);
1059-
1005+
cm.new_filemap(PathBuf::from("blork.rs").into(),
1006+
"fir€st €€€€ line.\nsecond line".to_string());
1007+
cm.new_filemap(PathBuf::from("blork2.rs").into(),
1008+
"first line€€.\n€ second line".to_string());
10601009
cm
10611010
}
10621011

0 commit comments

Comments
 (0)