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).
This commit is contained in:
Florian Diebold 2019-01-06 23:01:33 +01:00
parent 6210e82041
commit cf49a11263
9 changed files with 98 additions and 97 deletions

View file

@ -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!(

View file

@ -1,20 +1,20 @@
[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)': ()
[22; 24) '{}': ()
[78; 231) '{ ...t &c }': &mut &f64
[227; 229) '&c': &f64
[88; 89) 'a': u32
[181; 182) 'b': i32
[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

View file

@ -1,13 +1,13 @@
[9; 10) 'a': u32
[17; 18) 'b': isize
[27; 28) 'c': !
[33; 34) 'd': &[unknown]
[88; 94) '1isize': [unknown]
[42; 121) '{ ...f32; }': ()
[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]
[76; 82) '1usize': [unknown]
[88; 94) '1isize': [unknown]
[100; 106) '"test"': [unknown]
[112; 118) '1.0f32': [unknown]

View file

@ -1,31 +1,31 @@
[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
[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
[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
[76; 77) 'y': bool
[80; 84) 'true': bool
[80; 93) 'true || false': bool
[88; 93) 'false': bool
[103; 104) 'z': bool
[60; 61) 'a': 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]

View file

@ -1,7 +1,7 @@
[21; 22) 'a': [unknown]
[52; 53) '1': usize
[11; 71) '{ ...= b; }': ()
[63; 64) 'c': usize
[21; 22) 'a': [unknown]
[25; 31) '1isize': [unknown]
[41; 42) 'b': usize
[52; 53) '1': usize
[63; 64) 'c': usize
[67; 68) 'b': usize

View file

@ -1,9 +1,9 @@
[15; 20) '{ 1 }': u32
[17; 18) '1': u32
[50; 51) '1': u32
[48; 53) '{ 1 }': u32
[82; 88) 'b::c()': 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

View file

@ -1,23 +1,23 @@
[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
[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
[81; 82) 'a': &u32
[80; 82) '&a': &&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
[73; 74) 'a': &u32
[31; 32) '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

View file

@ -1,6 +1,6 @@
[50; 54) 'self': &S
[34; 38) 'self': &S
[40; 61) '{ ... }': ()
[50; 54) 'self': &S
[75; 79) 'self': &S
[88; 109) '{ ... }': ()
[98; 102) 'self': &S
[75; 79) 'self': &S

View file

@ -1,16 +1,16 @@
[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]
[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