diff options
author | Aleksey Kladov <[email protected]> | 2019-11-03 20:35:48 +0000 |
---|---|---|
committer | Aleksey Kladov <[email protected]> | 2019-11-03 20:35:48 +0000 |
commit | 6fba51c5fc05264abcbf971dcf28142746588d74 (patch) | |
tree | edbdbf98b279802ee8dc03f35e941943e1e20e10 /crates/ra_hir/src/nameres/tests/incremental.rs | |
parent | 0933d914a37c4ab57fda6fe95464d194dab6f80c (diff) |
move crate_def_map tests to hir_def
Diffstat (limited to 'crates/ra_hir/src/nameres/tests/incremental.rs')
-rw-r--r-- | crates/ra_hir/src/nameres/tests/incremental.rs | 140 |
1 files changed, 0 insertions, 140 deletions
diff --git a/crates/ra_hir/src/nameres/tests/incremental.rs b/crates/ra_hir/src/nameres/tests/incremental.rs deleted file mode 100644 index 723ece7b0..000000000 --- a/crates/ra_hir/src/nameres/tests/incremental.rs +++ /dev/null | |||
@@ -1,140 +0,0 @@ | |||
1 | use std::sync::Arc; | ||
2 | |||
3 | use ra_db::{SourceDatabase, SourceDatabaseExt}; | ||
4 | |||
5 | use super::*; | ||
6 | |||
7 | fn check_def_map_is_not_recomputed(initial: &str, file_change: &str) { | ||
8 | let (mut db, pos) = MockDatabase::with_position(initial); | ||
9 | let krate = db.crate_graph().iter().next().unwrap(); | ||
10 | { | ||
11 | let events = db.log_executed(|| { | ||
12 | db.crate_def_map(krate); | ||
13 | }); | ||
14 | assert!(format!("{:?}", events).contains("crate_def_map"), "{:#?}", events) | ||
15 | } | ||
16 | db.set_file_text(pos.file_id, Arc::new(file_change.to_string())); | ||
17 | |||
18 | { | ||
19 | let events = db.log_executed(|| { | ||
20 | db.crate_def_map(krate); | ||
21 | }); | ||
22 | assert!(!format!("{:?}", events).contains("crate_def_map"), "{:#?}", events) | ||
23 | } | ||
24 | } | ||
25 | |||
26 | #[test] | ||
27 | fn typing_inside_a_function_should_not_invalidate_def_map() { | ||
28 | check_def_map_is_not_recomputed( | ||
29 | " | ||
30 | //- /lib.rs | ||
31 | mod foo;<|> | ||
32 | |||
33 | use crate::foo::bar::Baz; | ||
34 | |||
35 | fn foo() -> i32 { | ||
36 | 1 + 1 | ||
37 | } | ||
38 | //- /foo/mod.rs | ||
39 | pub mod bar; | ||
40 | |||
41 | //- /foo/bar.rs | ||
42 | pub struct Baz; | ||
43 | ", | ||
44 | " | ||
45 | mod foo; | ||
46 | |||
47 | use crate::foo::bar::Baz; | ||
48 | |||
49 | fn foo() -> i32 { 92 } | ||
50 | ", | ||
51 | ); | ||
52 | } | ||
53 | |||
54 | #[test] | ||
55 | fn adding_inner_items_should_not_invalidate_def_map() { | ||
56 | check_def_map_is_not_recomputed( | ||
57 | " | ||
58 | //- /lib.rs | ||
59 | struct S { a: i32} | ||
60 | enum E { A } | ||
61 | trait T { | ||
62 | fn a() {} | ||
63 | } | ||
64 | mod foo;<|> | ||
65 | impl S { | ||
66 | fn a() {} | ||
67 | } | ||
68 | use crate::foo::bar::Baz; | ||
69 | //- /foo/mod.rs | ||
70 | pub mod bar; | ||
71 | |||
72 | //- /foo/bar.rs | ||
73 | pub struct Baz; | ||
74 | ", | ||
75 | " | ||
76 | struct S { a: i32, b: () } | ||
77 | enum E { A, B } | ||
78 | trait T { | ||
79 | fn a() {} | ||
80 | fn b() {} | ||
81 | } | ||
82 | mod foo;<|> | ||
83 | impl S { | ||
84 | fn a() {} | ||
85 | fn b() {} | ||
86 | } | ||
87 | use crate::foo::bar::Baz; | ||
88 | ", | ||
89 | ); | ||
90 | } | ||
91 | |||
92 | #[test] | ||
93 | fn typing_inside_a_macro_should_not_invalidate_def_map() { | ||
94 | let (mut db, pos) = MockDatabase::with_position( | ||
95 | " | ||
96 | //- /lib.rs | ||
97 | macro_rules! m { | ||
98 | ($ident:ident) => { | ||
99 | fn f() { | ||
100 | $ident + $ident; | ||
101 | }; | ||
102 | } | ||
103 | } | ||
104 | mod foo; | ||
105 | |||
106 | //- /foo/mod.rs | ||
107 | pub mod bar; | ||
108 | |||
109 | //- /foo/bar.rs | ||
110 | <|> | ||
111 | m!(X); | ||
112 | ", | ||
113 | ); | ||
114 | { | ||
115 | let events = db.log_executed(|| { | ||
116 | let src = crate::Source { | ||
117 | file_id: pos.file_id.into(), | ||
118 | ast: crate::ModuleSource::new(&db, Some(pos.file_id), None), | ||
119 | }; | ||
120 | let module = crate::Module::from_definition(&db, src).unwrap(); | ||
121 | let decls = module.declarations(&db); | ||
122 | assert_eq!(decls.len(), 18); | ||
123 | }); | ||
124 | assert!(format!("{:?}", events).contains("crate_def_map"), "{:#?}", events) | ||
125 | } | ||
126 | db.set_file_text(pos.file_id, Arc::new("m!(Y);".to_string())); | ||
127 | |||
128 | { | ||
129 | let events = db.log_executed(|| { | ||
130 | let src = crate::Source { | ||
131 | file_id: pos.file_id.into(), | ||
132 | ast: crate::ModuleSource::new(&db, Some(pos.file_id), None), | ||
133 | }; | ||
134 | let module = crate::Module::from_definition(&db, src).unwrap(); | ||
135 | let decls = module.declarations(&db); | ||
136 | assert_eq!(decls.len(), 18); | ||
137 | }); | ||
138 | assert!(!format!("{:?}", events).contains("crate_def_map"), "{:#?}", events) | ||
139 | } | ||
140 | } | ||