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