From cf49a11263c4d48720250db0c448b97dbec3d8b9 Mon Sep 17 00:00:00 2001 From: Florian Diebold Date: Sun, 6 Jan 2019 23:01:33 +0100 Subject: Sort ranges in type inference tests Also rename the files to remove the numbers (they don't serve a purpose now that there are only the data files). --- crates/ra_hir/src/ty/tests.rs | 25 ++++++++--------- crates/ra_hir/src/ty/tests/data/0001_basics.txt | 13 --------- crates/ra_hir/src/ty/tests/data/0002_let.txt | 7 ----- crates/ra_hir/src/ty/tests/data/0003_paths.txt | 9 ------- crates/ra_hir/src/ty/tests/data/0004_struct.txt | 16 ----------- crates/ra_hir/src/ty/tests/data/0005_refs.txt | 23 ---------------- crates/ra_hir/src/ty/tests/data/0006_backwards.txt | 20 -------------- crates/ra_hir/src/ty/tests/data/0007_self.txt | 6 ----- .../ra_hir/src/ty/tests/data/0008_boolean_op.txt | 31 ---------------------- crates/ra_hir/src/ty/tests/data/backwards.txt | 20 ++++++++++++++ crates/ra_hir/src/ty/tests/data/basics.txt | 13 +++++++++ crates/ra_hir/src/ty/tests/data/boolean_op.txt | 31 ++++++++++++++++++++++ crates/ra_hir/src/ty/tests/data/let.txt | 7 +++++ crates/ra_hir/src/ty/tests/data/paths.txt | 9 +++++++ crates/ra_hir/src/ty/tests/data/refs_and_ptrs.txt | 23 ++++++++++++++++ crates/ra_hir/src/ty/tests/data/self.txt | 6 +++++ crates/ra_hir/src/ty/tests/data/struct.txt | 16 +++++++++++ 17 files changed, 138 insertions(+), 137 deletions(-) delete mode 100644 crates/ra_hir/src/ty/tests/data/0001_basics.txt delete mode 100644 crates/ra_hir/src/ty/tests/data/0002_let.txt delete mode 100644 crates/ra_hir/src/ty/tests/data/0003_paths.txt delete mode 100644 crates/ra_hir/src/ty/tests/data/0004_struct.txt delete mode 100644 crates/ra_hir/src/ty/tests/data/0005_refs.txt delete mode 100644 crates/ra_hir/src/ty/tests/data/0006_backwards.txt delete mode 100644 crates/ra_hir/src/ty/tests/data/0007_self.txt delete mode 100644 crates/ra_hir/src/ty/tests/data/0008_boolean_op.txt create mode 100644 crates/ra_hir/src/ty/tests/data/backwards.txt create mode 100644 crates/ra_hir/src/ty/tests/data/basics.txt create mode 100644 crates/ra_hir/src/ty/tests/data/boolean_op.txt create mode 100644 crates/ra_hir/src/ty/tests/data/let.txt create mode 100644 crates/ra_hir/src/ty/tests/data/paths.txt create mode 100644 crates/ra_hir/src/ty/tests/data/refs_and_ptrs.txt create mode 100644 crates/ra_hir/src/ty/tests/data/self.txt create mode 100644 crates/ra_hir/src/ty/tests/data/struct.txt (limited to 'crates/ra_hir/src') diff --git a/crates/ra_hir/src/ty/tests.rs b/crates/ra_hir/src/ty/tests.rs index e46f309ae..20fb783b8 100644 --- a/crates/ra_hir/src/ty/tests.rs +++ b/crates/ra_hir/src/ty/tests.rs @@ -4,7 +4,6 @@ use std::path::{PathBuf, Path}; use std::fs; use salsa::Database; -use rustc_hash::FxHashMap; use ra_db::SyntaxDatabase; use ra_syntax::ast::{self, AstNode}; @@ -35,7 +34,7 @@ fn test(a: u32, b: isize, c: !, d: &str) { "test"; 1.0f32; }"#, - "0001_basics.txt", + "basics.txt", ); } @@ -49,7 +48,7 @@ fn test() { let c = b; } }"#, - "0002_let.txt", + "let.txt", ); } @@ -68,7 +67,7 @@ fn test() { b::c(); } }"#, - "0003_paths.txt", + "paths.txt", ); } @@ -91,7 +90,7 @@ fn test() { a.c; } "#, - "0004_struct.txt", + "struct.txt", ); } @@ -113,7 +112,7 @@ fn test(a: &u32, b: &mut u32, c: *const u32, d: *mut u32) { *d; } "#, - "0005_refs.txt", + "refs_and_ptrs.txt", ); } @@ -134,7 +133,7 @@ fn test() -> &mut &f64 { &mut &c } "#, - "0006_backwards.txt", + "backwards.txt", ); } @@ -153,7 +152,7 @@ impl S { } } "#, - "0007_self.txt", + "self.txt", ); } @@ -177,7 +176,7 @@ fn test() { 10 < 3 } "#, - "0008_boolean_op.txt", + "boolean_op.txt", ); } @@ -195,14 +194,14 @@ fn infer(content: &str) -> String { .unwrap(); let inference_result = func.infer(&db).unwrap(); let body_syntax_mapping = func.body_syntax_mapping(&db).unwrap(); - let mut types = FxHashMap::default(); + let mut types = Vec::new(); for (pat, ty) in &inference_result.type_of_pat { let syntax_ptr = if let Some(sp) = body_syntax_mapping.pat_syntax(*pat) { sp } else { continue; }; - types.insert(syntax_ptr, ty); + types.push((syntax_ptr, ty)); } for (expr, ty) in &inference_result.type_of_expr { let syntax_ptr = if let Some(sp) = body_syntax_mapping.expr_syntax(*expr) { @@ -210,8 +209,10 @@ fn infer(content: &str) -> String { } else { continue; }; - types.insert(syntax_ptr, ty); + types.push((syntax_ptr, ty)); } + // sort ranges for consistency + types.sort_by_key(|(ptr, _)| (ptr.range().start(), ptr.range().end())); for (syntax_ptr, ty) in &types { let node = syntax_ptr.resolve(&source_file); write!( diff --git a/crates/ra_hir/src/ty/tests/data/0001_basics.txt b/crates/ra_hir/src/ty/tests/data/0001_basics.txt deleted file mode 100644 index 4df6b42c9..000000000 --- a/crates/ra_hir/src/ty/tests/data/0001_basics.txt +++ /dev/null @@ -1,13 +0,0 @@ -[33; 34) 'd': &[unknown] -[88; 94) '1isize': [unknown] -[48; 49) 'a': u32 -[55; 56) 'b': isize -[112; 118) '1.0f32': [unknown] -[76; 82) '1usize': [unknown] -[9; 10) 'a': u32 -[27; 28) 'c': ! -[62; 63) 'c': ! -[17; 18) 'b': isize -[42; 121) '{ ...f32; }': () -[100; 106) '"test"': [unknown] -[69; 70) 'd': &[unknown] diff --git a/crates/ra_hir/src/ty/tests/data/0002_let.txt b/crates/ra_hir/src/ty/tests/data/0002_let.txt deleted file mode 100644 index 916ca25a1..000000000 --- a/crates/ra_hir/src/ty/tests/data/0002_let.txt +++ /dev/null @@ -1,7 +0,0 @@ -[21; 22) 'a': [unknown] -[52; 53) '1': usize -[11; 71) '{ ...= b; }': () -[63; 64) 'c': usize -[25; 31) '1isize': [unknown] -[41; 42) 'b': usize -[67; 68) 'b': usize diff --git a/crates/ra_hir/src/ty/tests/data/0003_paths.txt b/crates/ra_hir/src/ty/tests/data/0003_paths.txt deleted file mode 100644 index 2a12d264f..000000000 --- a/crates/ra_hir/src/ty/tests/data/0003_paths.txt +++ /dev/null @@ -1,9 +0,0 @@ -[15; 20) '{ 1 }': u32 -[17; 18) '1': u32 -[50; 51) '1': u32 -[48; 53) '{ 1 }': u32 -[82; 88) 'b::c()': u32 -[67; 91) '{ ...c(); }': () -[73; 74) 'a': fn() -> u32 -[73; 76) 'a()': u32 -[82; 86) 'b::c': fn() -> u32 diff --git a/crates/ra_hir/src/ty/tests/data/0004_struct.txt b/crates/ra_hir/src/ty/tests/data/0004_struct.txt deleted file mode 100644 index 6f919b332..000000000 --- a/crates/ra_hir/src/ty/tests/data/0004_struct.txt +++ /dev/null @@ -1,16 +0,0 @@ -[86; 90) 'C(1)': [unknown] -[121; 122) 'B': B -[86; 87) 'C': [unknown] -[107; 108) 'a': A -[129; 130) '1': [unknown] -[127; 128) 'C': [unknown] -[139; 142) 'a.b': B -[114; 133) 'A { b:...C(1) }': A -[148; 151) 'a.c': C -[148; 149) 'a': A -[139; 140) 'a': A -[72; 154) '{ ...a.c; }': () -[96; 97) 'B': [unknown] -[88; 89) '1': [unknown] -[82; 83) 'c': [unknown] -[127; 131) 'C(1)': C diff --git a/crates/ra_hir/src/ty/tests/data/0005_refs.txt b/crates/ra_hir/src/ty/tests/data/0005_refs.txt deleted file mode 100644 index cc32162a1..000000000 --- a/crates/ra_hir/src/ty/tests/data/0005_refs.txt +++ /dev/null @@ -1,23 +0,0 @@ -[115; 117) '&b': &&mut u32 -[88; 94) '&mut a': &mut &u32 -[146; 147) 'd': *mut u32 -[145; 147) '*d': u32 -[65; 66) 'a': &u32 -[46; 47) 'd': *mut u32 -[59; 150) '{ ... *d; }': () -[116; 117) 'b': &mut u32 -[72; 74) '*a': u32 -[131; 132) 'c': *const u32 -[130; 132) '*c': u32 -[107; 109) '*b': u32 -[108; 109) 'b': &mut u32 -[9; 10) 'a': &u32 -[18; 19) 'b': &mut u32 -[93; 94) 'a': &u32 -[100; 101) 'b': &mut u32 -[81; 82) 'a': &u32 -[80; 82) '&a': &&u32 -[123; 124) 'c': *const u32 -[73; 74) 'a': &u32 -[31; 32) 'c': *const u32 -[138; 139) 'd': *mut u32 diff --git a/crates/ra_hir/src/ty/tests/data/0006_backwards.txt b/crates/ra_hir/src/ty/tests/data/0006_backwards.txt deleted file mode 100644 index 0efae598e..000000000 --- a/crates/ra_hir/src/ty/tests/data/0006_backwards.txt +++ /dev/null @@ -1,20 +0,0 @@ -[22; 24) '{}': () -[14; 15) 'x': u32 -[142; 158) 'unknow...nction': [unknown] -[228; 229) 'c': f64 -[198; 216) 'unknow...tion()': f64 -[126; 127) 'a': u32 -[198; 214) 'unknow...nction': [unknown] -[222; 229) '&mut &c': &mut &f64 -[166; 184) 'S { i3...d: b }': S -[194; 195) 'c': f64 -[92; 110) 'unknow...tion()': u32 -[142; 160) 'unknow...tion()': i32 -[92; 108) 'unknow...nction': [unknown] -[116; 128) 'takes_u32(a)': () -[78; 231) '{ ...t &c }': &mut &f64 -[227; 229) '&c': &f64 -[88; 89) 'a': u32 -[181; 182) 'b': i32 -[116; 125) 'takes_u32': fn(u32,) -> () -[138; 139) 'b': i32 diff --git a/crates/ra_hir/src/ty/tests/data/0007_self.txt b/crates/ra_hir/src/ty/tests/data/0007_self.txt deleted file mode 100644 index db4ba17d0..000000000 --- a/crates/ra_hir/src/ty/tests/data/0007_self.txt +++ /dev/null @@ -1,6 +0,0 @@ -[50; 54) 'self': &S -[34; 38) 'self': &S -[40; 61) '{ ... }': () -[88; 109) '{ ... }': () -[98; 102) 'self': &S -[75; 79) 'self': &S diff --git a/crates/ra_hir/src/ty/tests/data/0008_boolean_op.txt b/crates/ra_hir/src/ty/tests/data/0008_boolean_op.txt deleted file mode 100644 index 0ae172914..000000000 --- a/crates/ra_hir/src/ty/tests/data/0008_boolean_op.txt +++ /dev/null @@ -1,31 +0,0 @@ -[28; 32) '0i32': i32 -[22; 34) '{ 0i32 }': i32 -[6; 7) 'x': [unknown] -[201; 205) '3i32': bool -[127; 134) 'CONST_1': [unknown] -[76; 77) 'y': bool -[60; 66) 'a && b': bool -[65; 66) 'b': bool -[229; 231) '10': [unknown] -[127; 145) 'CONST_...ONST_2': bool -[182; 183) 'd': [unknown] -[209; 222) '"hello world"': bool -[229; 235) '10 < 3': bool -[186; 187) 'b': [unknown] -[56; 57) 'x': bool -[159; 172) 'f(z || y) + 5': [unknown] -[112; 113) 'y': bool -[234; 235) '3': [unknown] -[201; 222) '3i32 &...world"': bool -[138; 145) 'CONST_2': [unknown] -[80; 93) 'true || false': bool -[46; 237) '{ ... < 3 }': bool -[197; 198) 'e': bool -[107; 113) 'x == y': bool -[88; 93) 'false': bool -[155; 156) 'c': [unknown] -[123; 124) 'h': bool -[80; 84) 'true': bool -[103; 104) 'z': bool -[60; 61) 'a': bool -[107; 108) 'x': bool diff --git a/crates/ra_hir/src/ty/tests/data/backwards.txt b/crates/ra_hir/src/ty/tests/data/backwards.txt new file mode 100644 index 000000000..b6807fb2a --- /dev/null +++ b/crates/ra_hir/src/ty/tests/data/backwards.txt @@ -0,0 +1,20 @@ +[14; 15) 'x': u32 +[22; 24) '{}': () +[78; 231) '{ ...t &c }': &mut &f64 +[88; 89) 'a': u32 +[92; 108) 'unknow...nction': [unknown] +[92; 110) 'unknow...tion()': u32 +[116; 125) 'takes_u32': fn(u32,) -> () +[116; 128) 'takes_u32(a)': () +[126; 127) 'a': u32 +[138; 139) 'b': i32 +[142; 158) 'unknow...nction': [unknown] +[142; 160) 'unknow...tion()': i32 +[166; 184) 'S { i3...d: b }': S +[181; 182) 'b': i32 +[194; 195) 'c': f64 +[198; 214) 'unknow...nction': [unknown] +[198; 216) 'unknow...tion()': f64 +[222; 229) '&mut &c': &mut &f64 +[227; 229) '&c': &f64 +[228; 229) 'c': f64 diff --git a/crates/ra_hir/src/ty/tests/data/basics.txt b/crates/ra_hir/src/ty/tests/data/basics.txt new file mode 100644 index 000000000..8ea244ba8 --- /dev/null +++ b/crates/ra_hir/src/ty/tests/data/basics.txt @@ -0,0 +1,13 @@ +[9; 10) 'a': u32 +[17; 18) 'b': isize +[27; 28) 'c': ! +[33; 34) 'd': &[unknown] +[42; 121) '{ ...f32; }': () +[48; 49) 'a': u32 +[55; 56) 'b': isize +[62; 63) 'c': ! +[69; 70) 'd': &[unknown] +[76; 82) '1usize': [unknown] +[88; 94) '1isize': [unknown] +[100; 106) '"test"': [unknown] +[112; 118) '1.0f32': [unknown] diff --git a/crates/ra_hir/src/ty/tests/data/boolean_op.txt b/crates/ra_hir/src/ty/tests/data/boolean_op.txt new file mode 100644 index 000000000..cce8d68fb --- /dev/null +++ b/crates/ra_hir/src/ty/tests/data/boolean_op.txt @@ -0,0 +1,31 @@ +[6; 7) 'x': [unknown] +[22; 34) '{ 0i32 }': i32 +[28; 32) '0i32': i32 +[46; 237) '{ ... < 3 }': bool +[56; 57) 'x': bool +[60; 61) 'a': bool +[60; 66) 'a && b': bool +[65; 66) 'b': bool +[76; 77) 'y': bool +[80; 84) 'true': bool +[80; 93) 'true || false': bool +[88; 93) 'false': bool +[103; 104) 'z': bool +[107; 108) 'x': bool +[107; 113) 'x == y': bool +[112; 113) 'y': bool +[123; 124) 'h': bool +[127; 134) 'CONST_1': [unknown] +[127; 145) 'CONST_...ONST_2': bool +[138; 145) 'CONST_2': [unknown] +[155; 156) 'c': [unknown] +[159; 172) 'f(z || y) + 5': [unknown] +[182; 183) 'd': [unknown] +[186; 187) 'b': [unknown] +[197; 198) 'e': bool +[201; 205) '3i32': bool +[201; 222) '3i32 &...world"': bool +[209; 222) '"hello world"': bool +[229; 231) '10': [unknown] +[229; 235) '10 < 3': bool +[234; 235) '3': [unknown] diff --git a/crates/ra_hir/src/ty/tests/data/let.txt b/crates/ra_hir/src/ty/tests/data/let.txt new file mode 100644 index 000000000..30f4a2cf5 --- /dev/null +++ b/crates/ra_hir/src/ty/tests/data/let.txt @@ -0,0 +1,7 @@ +[11; 71) '{ ...= b; }': () +[21; 22) 'a': [unknown] +[25; 31) '1isize': [unknown] +[41; 42) 'b': usize +[52; 53) '1': usize +[63; 64) 'c': usize +[67; 68) 'b': usize diff --git a/crates/ra_hir/src/ty/tests/data/paths.txt b/crates/ra_hir/src/ty/tests/data/paths.txt new file mode 100644 index 000000000..b22f4d4a5 --- /dev/null +++ b/crates/ra_hir/src/ty/tests/data/paths.txt @@ -0,0 +1,9 @@ +[15; 20) '{ 1 }': u32 +[17; 18) '1': u32 +[48; 53) '{ 1 }': u32 +[50; 51) '1': u32 +[67; 91) '{ ...c(); }': () +[73; 74) 'a': fn() -> u32 +[73; 76) 'a()': u32 +[82; 86) 'b::c': fn() -> u32 +[82; 88) 'b::c()': u32 diff --git a/crates/ra_hir/src/ty/tests/data/refs_and_ptrs.txt b/crates/ra_hir/src/ty/tests/data/refs_and_ptrs.txt new file mode 100644 index 000000000..afab343ea --- /dev/null +++ b/crates/ra_hir/src/ty/tests/data/refs_and_ptrs.txt @@ -0,0 +1,23 @@ +[9; 10) 'a': &u32 +[18; 19) 'b': &mut u32 +[31; 32) 'c': *const u32 +[46; 47) 'd': *mut u32 +[59; 150) '{ ... *d; }': () +[65; 66) 'a': &u32 +[72; 74) '*a': u32 +[73; 74) 'a': &u32 +[80; 82) '&a': &&u32 +[81; 82) 'a': &u32 +[88; 94) '&mut a': &mut &u32 +[93; 94) 'a': &u32 +[100; 101) 'b': &mut u32 +[107; 109) '*b': u32 +[108; 109) 'b': &mut u32 +[115; 117) '&b': &&mut u32 +[116; 117) 'b': &mut u32 +[123; 124) 'c': *const u32 +[130; 132) '*c': u32 +[131; 132) 'c': *const u32 +[138; 139) 'd': *mut u32 +[145; 147) '*d': u32 +[146; 147) 'd': *mut u32 diff --git a/crates/ra_hir/src/ty/tests/data/self.txt b/crates/ra_hir/src/ty/tests/data/self.txt new file mode 100644 index 000000000..c38029f97 --- /dev/null +++ b/crates/ra_hir/src/ty/tests/data/self.txt @@ -0,0 +1,6 @@ +[34; 38) 'self': &S +[40; 61) '{ ... }': () +[50; 54) 'self': &S +[75; 79) 'self': &S +[88; 109) '{ ... }': () +[98; 102) 'self': &S diff --git a/crates/ra_hir/src/ty/tests/data/struct.txt b/crates/ra_hir/src/ty/tests/data/struct.txt new file mode 100644 index 000000000..7b324c82f --- /dev/null +++ b/crates/ra_hir/src/ty/tests/data/struct.txt @@ -0,0 +1,16 @@ +[72; 154) '{ ...a.c; }': () +[82; 83) 'c': [unknown] +[86; 87) 'C': [unknown] +[86; 90) 'C(1)': [unknown] +[88; 89) '1': [unknown] +[96; 97) 'B': [unknown] +[107; 108) 'a': A +[114; 133) 'A { b:...C(1) }': A +[121; 122) 'B': B +[127; 128) 'C': [unknown] +[127; 131) 'C(1)': C +[129; 130) '1': [unknown] +[139; 140) 'a': A +[139; 142) 'a.b': B +[148; 149) 'a': A +[148; 151) 'a.c': C -- cgit v1.2.3