diff options
author | Hirokazu Hata <[email protected]> | 2019-01-13 13:46:52 +0000 |
---|---|---|
committer | Hirokazu Hata <[email protected]> | 2019-01-16 14:35:06 +0000 |
commit | 2a3262c75792d90341e21c241b2f95ef8cdccb23 (patch) | |
tree | 3eba7d4770bb2a2d77f475c1747e531828768d09 /crates/ra_hir | |
parent | d665acbbec39ffd26eb56b1194653459a0c495e7 (diff) |
Add infer array test
Diffstat (limited to 'crates/ra_hir')
-rw-r--r-- | crates/ra_hir/src/ty/tests.rs | 23 | ||||
-rw-r--r-- | crates/ra_hir/src/ty/tests/data/array.txt | 38 |
2 files changed, 61 insertions, 0 deletions
diff --git a/crates/ra_hir/src/ty/tests.rs b/crates/ra_hir/src/ty/tests.rs index 5d7bc25cc..09c8644f7 100644 --- a/crates/ra_hir/src/ty/tests.rs +++ b/crates/ra_hir/src/ty/tests.rs | |||
@@ -334,6 +334,29 @@ fn test(x: &str, y: isize) { | |||
334 | ); | 334 | ); |
335 | } | 335 | } |
336 | 336 | ||
337 | #[test] | ||
338 | fn infer_array() { | ||
339 | check_inference( | ||
340 | r#" | ||
341 | fn test(x: &str, y: isize) { | ||
342 | let a = [x]; | ||
343 | let b = [a, a]; | ||
344 | let c = [b, b]; | ||
345 | |||
346 | let d = [y]; | ||
347 | let e = [d, d]; | ||
348 | let f = [e, e]; | ||
349 | |||
350 | // we have not infered these case yet. | ||
351 | let g = [1, 2]; | ||
352 | let h = ["a", "b"]; | ||
353 | let b = [a, ["b"]]; | ||
354 | } | ||
355 | "#, | ||
356 | "array.txt", | ||
357 | ); | ||
358 | } | ||
359 | |||
337 | fn infer(content: &str) -> String { | 360 | fn infer(content: &str) -> String { |
338 | let (db, _, file_id) = MockDatabase::with_single_file(content); | 361 | let (db, _, file_id) = MockDatabase::with_single_file(content); |
339 | let source_file = db.source_file(file_id); | 362 | let source_file = db.source_file(file_id); |
diff --git a/crates/ra_hir/src/ty/tests/data/array.txt b/crates/ra_hir/src/ty/tests/data/array.txt new file mode 100644 index 000000000..7711e378b --- /dev/null +++ b/crates/ra_hir/src/ty/tests/data/array.txt | |||
@@ -0,0 +1,38 @@ | |||
1 | [9; 10) 'x': &str | ||
2 | [18; 19) 'y': isize | ||
3 | [28; 258) '{ ..."]]; }': () | ||
4 | [38; 39) 'a': [&str,] | ||
5 | [42; 45) '[x]': [&str,] | ||
6 | [43; 44) 'x': &str | ||
7 | [55; 56) 'b': [[&str,], [&str,]] | ||
8 | [59; 65) '[a, a]': [[&str,], [&str,]] | ||
9 | [60; 61) 'a': [&str,] | ||
10 | [63; 64) 'a': [&str,] | ||
11 | [75; 76) 'c': [[[&str,], [&str,]], [[&str,], [&str,]]] | ||
12 | [79; 85) '[b, b]': [[[&str,], [&str,]], [[&str,], [&str,]]] | ||
13 | [80; 81) 'b': [[&str,], [&str,]] | ||
14 | [83; 84) 'b': [[&str,], [&str,]] | ||
15 | [96; 97) 'd': [isize,] | ||
16 | [100; 103) '[y]': [isize,] | ||
17 | [101; 102) 'y': isize | ||
18 | [113; 114) 'e': [[isize,], [isize,]] | ||
19 | [117; 123) '[d, d]': [[isize,], [isize,]] | ||
20 | [118; 119) 'd': [isize,] | ||
21 | [121; 122) 'd': [isize,] | ||
22 | [133; 134) 'f': [[[isize,], [isize,]], [[isize,], [isize,]]] | ||
23 | [137; 143) '[e, e]': [[[isize,], [isize,]], [[isize,], [isize,]]] | ||
24 | [138; 139) 'e': [[isize,], [isize,]] | ||
25 | [141; 142) 'e': [[isize,], [isize,]] | ||
26 | [197; 198) 'g': [_, _] | ||
27 | [201; 207) '[1, 2]': [_, _] | ||
28 | [202; 203) '1': [unknown] | ||
29 | [205; 206) '2': [unknown] | ||
30 | [217; 218) 'h': [_, _] | ||
31 | [221; 231) '["a", "b"]': [_, _] | ||
32 | [222; 225) '"a"': [unknown] | ||
33 | [227; 230) '"b"': [unknown] | ||
34 | [241; 242) 'b': [[&str,], [_,]] | ||
35 | [245; 255) '[a, ["b"]]': [[&str,], [_,]] | ||
36 | [246; 247) 'a': [&str,] | ||
37 | [249; 254) '["b"]': [_,] | ||
38 | [250; 253) '"b"': [unknown] | ||