From 2a3262c75792d90341e21c241b2f95ef8cdccb23 Mon Sep 17 00:00:00 2001 From: Hirokazu Hata Date: Sun, 13 Jan 2019 22:46:52 +0900 Subject: Add infer array test --- crates/ra_hir/src/ty/tests.rs | 23 +++++++++++++++++++ crates/ra_hir/src/ty/tests/data/array.txt | 38 +++++++++++++++++++++++++++++++ 2 files changed, 61 insertions(+) create mode 100644 crates/ra_hir/src/ty/tests/data/array.txt (limited to 'crates/ra_hir') 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) { ); } +#[test] +fn infer_array() { + check_inference( + r#" +fn test(x: &str, y: isize) { + let a = [x]; + let b = [a, a]; + let c = [b, b]; + + let d = [y]; + let e = [d, d]; + let f = [e, e]; + + // we have not infered these case yet. + let g = [1, 2]; + let h = ["a", "b"]; + let b = [a, ["b"]]; +} +"#, + "array.txt", + ); +} + fn infer(content: &str) -> String { let (db, _, file_id) = MockDatabase::with_single_file(content); 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 @@ +[9; 10) 'x': &str +[18; 19) 'y': isize +[28; 258) '{ ..."]]; }': () +[38; 39) 'a': [&str,] +[42; 45) '[x]': [&str,] +[43; 44) 'x': &str +[55; 56) 'b': [[&str,], [&str,]] +[59; 65) '[a, a]': [[&str,], [&str,]] +[60; 61) 'a': [&str,] +[63; 64) 'a': [&str,] +[75; 76) 'c': [[[&str,], [&str,]], [[&str,], [&str,]]] +[79; 85) '[b, b]': [[[&str,], [&str,]], [[&str,], [&str,]]] +[80; 81) 'b': [[&str,], [&str,]] +[83; 84) 'b': [[&str,], [&str,]] +[96; 97) 'd': [isize,] +[100; 103) '[y]': [isize,] +[101; 102) 'y': isize +[113; 114) 'e': [[isize,], [isize,]] +[117; 123) '[d, d]': [[isize,], [isize,]] +[118; 119) 'd': [isize,] +[121; 122) 'd': [isize,] +[133; 134) 'f': [[[isize,], [isize,]], [[isize,], [isize,]]] +[137; 143) '[e, e]': [[[isize,], [isize,]], [[isize,], [isize,]]] +[138; 139) 'e': [[isize,], [isize,]] +[141; 142) 'e': [[isize,], [isize,]] +[197; 198) 'g': [_, _] +[201; 207) '[1, 2]': [_, _] +[202; 203) '1': [unknown] +[205; 206) '2': [unknown] +[217; 218) 'h': [_, _] +[221; 231) '["a", "b"]': [_, _] +[222; 225) '"a"': [unknown] +[227; 230) '"b"': [unknown] +[241; 242) 'b': [[&str,], [_,]] +[245; 255) '[a, ["b"]]': [[&str,], [_,]] +[246; 247) 'a': [&str,] +[249; 254) '["b"]': [_,] +[250; 253) '"b"': [unknown] -- cgit v1.2.3