diff options
author | Florian Diebold <[email protected]> | 2018-12-20 20:56:28 +0000 |
---|---|---|
committer | Florian Diebold <[email protected]> | 2018-12-23 12:48:04 +0000 |
commit | 3ac605e6876056fa56098231cc2f96553faab8f0 (patch) | |
tree | 82294448f696bae2ba640c4fb74dac9b929265a3 /crates/ra_hir/src/ty/tests.rs | |
parent | d77520fde3c953968beb09a3da80a0e7b17bbc04 (diff) |
Add beginnings of type infrastructure
Diffstat (limited to 'crates/ra_hir/src/ty/tests.rs')
-rw-r--r-- | crates/ra_hir/src/ty/tests.rs | 45 |
1 files changed, 45 insertions, 0 deletions
diff --git a/crates/ra_hir/src/ty/tests.rs b/crates/ra_hir/src/ty/tests.rs new file mode 100644 index 000000000..f2466dd51 --- /dev/null +++ b/crates/ra_hir/src/ty/tests.rs | |||
@@ -0,0 +1,45 @@ | |||
1 | use std::sync::Arc; | ||
2 | |||
3 | use salsa::Database; | ||
4 | use ra_db::{FilesDatabase, CrateGraph, SyntaxDatabase}; | ||
5 | use ra_syntax::{SmolStr, algo::visit::{visitor, Visitor}, ast::{self, AstNode}}; | ||
6 | use relative_path::RelativePath; | ||
7 | |||
8 | use crate::{source_binder, mock::WORKSPACE, module::ModuleSourceNode}; | ||
9 | |||
10 | use crate::{ | ||
11 | self as hir, | ||
12 | db::HirDatabase, | ||
13 | mock::MockDatabase, | ||
14 | }; | ||
15 | |||
16 | fn infer_all_fns(fixture: &str) -> () { | ||
17 | let (db, source_root) = MockDatabase::with_files(fixture); | ||
18 | for &file_id in source_root.files.values() { | ||
19 | let source_file = db.source_file(file_id); | ||
20 | for fn_def in source_file.syntax().descendants().filter_map(ast::FnDef::cast) { | ||
21 | let func = source_binder::function_from_source(&db, file_id, fn_def).unwrap().unwrap(); | ||
22 | let inference_result = func.infer(&db); | ||
23 | for (syntax_ptr, ty) in &inference_result.type_for { | ||
24 | let node = syntax_ptr.resolve(&source_file); | ||
25 | eprintln!("{} '{}': {:?}", syntax_ptr.range(), node.text(), ty); | ||
26 | } | ||
27 | } | ||
28 | } | ||
29 | } | ||
30 | |||
31 | #[test] | ||
32 | fn infer_smoke_test() { | ||
33 | let text = " | ||
34 | //- /lib.rs | ||
35 | fn foo(x: u32, y: !) -> i128 { | ||
36 | x; | ||
37 | y; | ||
38 | return 1; | ||
39 | \"hello\"; | ||
40 | 0 | ||
41 | } | ||
42 | "; | ||
43 | |||
44 | infer_all_fns(text); | ||
45 | } | ||