rubydex 0.1.0.beta11 → 0.1.0.beta13
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/LICENSE.txt +23 -23
- data/README.md +125 -125
- data/THIRD_PARTY_LICENSES.html +2018 -945
- data/exe/rdx +47 -47
- data/ext/rubydex/declaration.c +453 -388
- data/ext/rubydex/declaration.h +23 -23
- data/ext/rubydex/definition.c +284 -197
- data/ext/rubydex/definition.h +28 -28
- data/ext/rubydex/diagnostic.c +6 -6
- data/ext/rubydex/diagnostic.h +11 -11
- data/ext/rubydex/document.c +97 -98
- data/ext/rubydex/document.h +10 -10
- data/ext/rubydex/extconf.rb +146 -127
- data/ext/rubydex/graph.c +701 -512
- data/ext/rubydex/graph.h +10 -10
- data/ext/rubydex/handle.h +44 -44
- data/ext/rubydex/location.c +22 -22
- data/ext/rubydex/location.h +15 -15
- data/ext/rubydex/reference.c +123 -104
- data/ext/rubydex/reference.h +15 -16
- data/ext/rubydex/rubydex.c +22 -22
- data/ext/rubydex/utils.c +108 -86
- data/ext/rubydex/utils.h +34 -28
- data/lib/rubydex/comment.rb +17 -17
- data/lib/rubydex/declaration.rb +11 -0
- data/lib/rubydex/diagnostic.rb +21 -21
- data/lib/rubydex/failures.rb +15 -15
- data/lib/rubydex/graph.rb +98 -92
- data/lib/rubydex/keyword.rb +17 -0
- data/lib/rubydex/keyword_parameter.rb +13 -0
- data/lib/rubydex/location.rb +90 -90
- data/lib/rubydex/mixin.rb +22 -0
- data/lib/rubydex/version.rb +5 -5
- data/lib/rubydex.rb +24 -20
- data/rbi/rubydex.rbi +425 -310
- data/rust/Cargo.lock +1851 -1851
- data/rust/Cargo.toml +29 -29
- data/rust/about.toml +10 -10
- data/rust/{about.hbs → about_templates/about.hbs} +81 -78
- data/rust/about_templates/mingw_licenses.hbs +1071 -0
- data/rust/rubydex/Cargo.toml +42 -42
- data/rust/rubydex/src/compile_assertions.rs +13 -13
- data/rust/rubydex/src/diagnostic.rs +110 -109
- data/rust/rubydex/src/errors.rs +28 -28
- data/rust/rubydex/src/indexing/local_graph.rs +224 -224
- data/rust/rubydex/src/indexing/rbs_indexer.rs +1551 -1554
- data/rust/rubydex/src/indexing/ruby_indexer.rs +2329 -6753
- data/rust/rubydex/src/indexing/ruby_indexer_tests.rs +4962 -0
- data/rust/rubydex/src/indexing.rs +210 -210
- data/rust/rubydex/src/integrity.rs +279 -278
- data/rust/rubydex/src/job_queue.rs +199 -205
- data/rust/rubydex/src/lib.rs +17 -17
- data/rust/rubydex/src/listing.rs +371 -272
- data/rust/rubydex/src/main.rs +160 -160
- data/rust/rubydex/src/model/built_in.rs +83 -0
- data/rust/rubydex/src/model/comment.rs +24 -24
- data/rust/rubydex/src/model/declaration.rs +679 -588
- data/rust/rubydex/src/model/definitions.rs +1682 -1602
- data/rust/rubydex/src/model/document.rs +222 -252
- data/rust/rubydex/src/model/encoding.rs +22 -22
- data/rust/rubydex/src/model/graph.rs +3782 -3556
- data/rust/rubydex/src/model/id.rs +110 -110
- data/rust/rubydex/src/model/identity_maps.rs +58 -58
- data/rust/rubydex/src/model/ids.rs +60 -38
- data/rust/rubydex/src/model/keywords.rs +256 -256
- data/rust/rubydex/src/model/name.rs +298 -298
- data/rust/rubydex/src/model/references.rs +111 -111
- data/rust/rubydex/src/model/string_ref.rs +50 -50
- data/rust/rubydex/src/model/visibility.rs +41 -41
- data/rust/rubydex/src/model.rs +15 -14
- data/rust/rubydex/src/offset.rs +147 -147
- data/rust/rubydex/src/position.rs +6 -6
- data/rust/rubydex/src/query.rs +1841 -1700
- data/rust/rubydex/src/resolution.rs +1852 -5895
- data/rust/rubydex/src/resolution_tests.rs +4701 -0
- data/rust/rubydex/src/stats/memory.rs +71 -71
- data/rust/rubydex/src/stats/orphan_report.rs +264 -263
- data/rust/rubydex/src/stats/timer.rs +127 -127
- data/rust/rubydex/src/stats.rs +11 -11
- data/rust/rubydex/src/test_utils/context.rs +226 -226
- data/rust/rubydex/src/test_utils/graph_test.rs +730 -679
- data/rust/rubydex/src/test_utils/local_graph_test.rs +602 -602
- data/rust/rubydex/src/test_utils.rs +52 -52
- data/rust/rubydex/src/visualization/dot.rs +192 -176
- data/rust/rubydex/src/visualization.rs +6 -6
- data/rust/rubydex/tests/cli.rs +185 -167
- data/rust/rubydex-mcp/Cargo.toml +28 -28
- data/rust/rubydex-mcp/src/main.rs +48 -48
- data/rust/rubydex-mcp/src/server.rs +1145 -1145
- data/rust/rubydex-mcp/src/tools.rs +49 -49
- data/rust/rubydex-mcp/tests/mcp.rs +302 -302
- data/rust/rubydex-sys/Cargo.toml +20 -20
- data/rust/rubydex-sys/build.rs +14 -14
- data/rust/rubydex-sys/cbindgen.toml +12 -12
- data/rust/rubydex-sys/src/declaration_api.rs +485 -469
- data/rust/rubydex-sys/src/definition_api.rs +443 -352
- data/rust/rubydex-sys/src/diagnostic_api.rs +99 -99
- data/rust/rubydex-sys/src/document_api.rs +85 -54
- data/rust/rubydex-sys/src/graph_api.rs +1017 -700
- data/rust/rubydex-sys/src/lib.rs +79 -9
- data/rust/rubydex-sys/src/location_api.rs +79 -79
- data/rust/rubydex-sys/src/name_api.rs +187 -135
- data/rust/rubydex-sys/src/reference_api.rs +267 -195
- data/rust/rubydex-sys/src/utils.rs +70 -70
- data/rust/rustfmt.toml +2 -2
- metadata +16 -9
- data/lib/rubydex/librubydex_sys.so +0 -0
|
@@ -1,278 +1,279 @@
|
|
|
1
|
-
use std::fmt;
|
|
2
|
-
|
|
3
|
-
use crate::model::{
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
let
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
.
|
|
120
|
-
.
|
|
121
|
-
|
|
122
|
-
let
|
|
123
|
-
document.
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
_ => return
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
use
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
assert_eq!(errors
|
|
188
|
-
assert_eq!(errors[0].
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
let
|
|
195
|
-
let
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
assert_eq!(errors
|
|
208
|
-
assert_eq!(errors[0].
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
assert_eq!(errors
|
|
244
|
-
assert_eq!(errors[0].
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
let
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
.
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
}
|
|
1
|
+
use std::fmt;
|
|
2
|
+
|
|
3
|
+
use crate::model::{
|
|
4
|
+
built_in::{BASIC_OBJECT_ID, OBJECT_ID},
|
|
5
|
+
declaration::{Declaration, Namespace},
|
|
6
|
+
graph::Graph,
|
|
7
|
+
ids::DeclarationId,
|
|
8
|
+
};
|
|
9
|
+
|
|
10
|
+
#[derive(Debug, PartialEq, Eq)]
|
|
11
|
+
pub enum IntegrityErrorKind {
|
|
12
|
+
/// A declaration's owner is not a namespace (module, class, or singleton class)
|
|
13
|
+
OwnerIsNotNamespace,
|
|
14
|
+
/// A declaration's owner does not exist in the graph
|
|
15
|
+
OwnerDoesNotExist,
|
|
16
|
+
/// A singleton class chain never resolves to a non-singleton namespace
|
|
17
|
+
SingletonClassChainDoesNotTerminate,
|
|
18
|
+
/// A non-root declaration unexpectedly owns itself
|
|
19
|
+
UnexpectedSelfOwnership,
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
/// An integrity error found during graph validation
|
|
23
|
+
#[derive(Debug, PartialEq, Eq)]
|
|
24
|
+
pub struct IntegrityError {
|
|
25
|
+
kind: IntegrityErrorKind,
|
|
26
|
+
declaration_name: String,
|
|
27
|
+
uris: Vec<String>,
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
impl fmt::Display for IntegrityError {
|
|
31
|
+
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
|
32
|
+
let message = match self.kind {
|
|
33
|
+
IntegrityErrorKind::OwnerIsNotNamespace => {
|
|
34
|
+
format!("Declaration `{}` is owned by a non-namespace", self.declaration_name)
|
|
35
|
+
}
|
|
36
|
+
IntegrityErrorKind::OwnerDoesNotExist => {
|
|
37
|
+
format!(
|
|
38
|
+
"Declaration `{}` has an owner that does not exist in the graph",
|
|
39
|
+
self.declaration_name
|
|
40
|
+
)
|
|
41
|
+
}
|
|
42
|
+
IntegrityErrorKind::SingletonClassChainDoesNotTerminate => {
|
|
43
|
+
format!(
|
|
44
|
+
"Singleton class `{}` does not eventually attach to a non-singleton namespace",
|
|
45
|
+
self.declaration_name
|
|
46
|
+
)
|
|
47
|
+
}
|
|
48
|
+
IntegrityErrorKind::UnexpectedSelfOwnership => {
|
|
49
|
+
format!("Declaration `{}` unexpectedly owns itself", self.declaration_name)
|
|
50
|
+
}
|
|
51
|
+
};
|
|
52
|
+
|
|
53
|
+
write!(f, "{message}. Defined in: {}", self.uris.join(", "))
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
impl std::error::Error for IntegrityError {}
|
|
58
|
+
|
|
59
|
+
/// Checks the integrity of the graph data
|
|
60
|
+
#[must_use]
|
|
61
|
+
pub fn check_integrity(graph: &Graph) -> Vec<IntegrityError> {
|
|
62
|
+
let mut errors = Vec::new();
|
|
63
|
+
let self_owners = [*OBJECT_ID, *BASIC_OBJECT_ID];
|
|
64
|
+
|
|
65
|
+
for (id, declaration) in graph.declarations() {
|
|
66
|
+
let owner_id = declaration.owner_id();
|
|
67
|
+
|
|
68
|
+
// Check for constants that own themselves. Only `Object` and `BasicObject` own themselves and no other constant
|
|
69
|
+
if *id == *owner_id {
|
|
70
|
+
if self_owners.contains(id) {
|
|
71
|
+
continue;
|
|
72
|
+
}
|
|
73
|
+
errors.push(IntegrityError {
|
|
74
|
+
kind: IntegrityErrorKind::UnexpectedSelfOwnership,
|
|
75
|
+
declaration_name: declaration.name().to_string(),
|
|
76
|
+
uris: collect_uris(graph, declaration),
|
|
77
|
+
});
|
|
78
|
+
continue;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
// Check that the owner exists
|
|
82
|
+
let Some(owner) = graph.declarations().get(owner_id) else {
|
|
83
|
+
errors.push(IntegrityError {
|
|
84
|
+
kind: IntegrityErrorKind::OwnerDoesNotExist,
|
|
85
|
+
declaration_name: declaration.name().to_string(),
|
|
86
|
+
uris: collect_uris(graph, declaration),
|
|
87
|
+
});
|
|
88
|
+
continue;
|
|
89
|
+
};
|
|
90
|
+
|
|
91
|
+
// Check that the owner is a namespace
|
|
92
|
+
if owner.as_namespace().is_none() {
|
|
93
|
+
errors.push(IntegrityError {
|
|
94
|
+
kind: IntegrityErrorKind::OwnerIsNotNamespace,
|
|
95
|
+
declaration_name: declaration.name().to_string(),
|
|
96
|
+
uris: collect_uris(graph, declaration),
|
|
97
|
+
});
|
|
98
|
+
continue;
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
// Check singleton class chain termination
|
|
102
|
+
if let Declaration::Namespace(Namespace::SingletonClass(_)) = declaration
|
|
103
|
+
&& !singleton_chain_terminates(graph, *owner_id)
|
|
104
|
+
{
|
|
105
|
+
errors.push(IntegrityError {
|
|
106
|
+
kind: IntegrityErrorKind::SingletonClassChainDoesNotTerminate,
|
|
107
|
+
declaration_name: declaration.name().to_string(),
|
|
108
|
+
uris: collect_uris(graph, declaration),
|
|
109
|
+
});
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
errors
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
/// Collects the URIs where a declaration is defined, sorted and deduplicated
|
|
117
|
+
fn collect_uris(graph: &Graph, declaration: &Declaration) -> Vec<String> {
|
|
118
|
+
declaration
|
|
119
|
+
.definitions()
|
|
120
|
+
.iter()
|
|
121
|
+
.map(|def_id| {
|
|
122
|
+
let definition = graph.definitions().get(def_id).unwrap();
|
|
123
|
+
let document = graph.documents().get(definition.uri_id()).unwrap();
|
|
124
|
+
document.uri().to_string()
|
|
125
|
+
})
|
|
126
|
+
.collect()
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
/// Walks the singleton class chain to verify that it eventually finds a module or class as its attached object
|
|
130
|
+
fn singleton_chain_terminates(graph: &Graph, start_owner_id: DeclarationId) -> bool {
|
|
131
|
+
const MAX_SINGLETON_DEPTH: usize = 128;
|
|
132
|
+
let mut current_id = start_owner_id;
|
|
133
|
+
|
|
134
|
+
for _ in 0..MAX_SINGLETON_DEPTH {
|
|
135
|
+
let Some(current) = graph.declarations().get(¤t_id) else {
|
|
136
|
+
return false;
|
|
137
|
+
};
|
|
138
|
+
|
|
139
|
+
match current {
|
|
140
|
+
Declaration::Namespace(Namespace::SingletonClass(_)) => {
|
|
141
|
+
current_id = *current.owner_id();
|
|
142
|
+
}
|
|
143
|
+
Declaration::Namespace(_) => return true,
|
|
144
|
+
_ => return false,
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
false
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
#[cfg(test)]
|
|
152
|
+
mod tests {
|
|
153
|
+
use super::*;
|
|
154
|
+
use crate::model::declaration::{ClassDeclaration, MethodDeclaration, SingletonClassDeclaration};
|
|
155
|
+
|
|
156
|
+
#[test]
|
|
157
|
+
fn test_unexpected_self_ownership() {
|
|
158
|
+
let mut graph = Graph::new();
|
|
159
|
+
|
|
160
|
+
// Object and BasicObject are exempt from self-ownership
|
|
161
|
+
graph.declarations_mut().insert(
|
|
162
|
+
*OBJECT_ID,
|
|
163
|
+
Declaration::Namespace(Namespace::Class(Box::new(ClassDeclaration::new(
|
|
164
|
+
"Object".to_string(),
|
|
165
|
+
*OBJECT_ID,
|
|
166
|
+
)))),
|
|
167
|
+
);
|
|
168
|
+
graph.declarations_mut().insert(
|
|
169
|
+
*BASIC_OBJECT_ID,
|
|
170
|
+
Declaration::Namespace(Namespace::Class(Box::new(ClassDeclaration::new(
|
|
171
|
+
"BasicObject".to_string(),
|
|
172
|
+
*BASIC_OBJECT_ID,
|
|
173
|
+
)))),
|
|
174
|
+
);
|
|
175
|
+
|
|
176
|
+
// Foo owns itself — should be an error
|
|
177
|
+
let foo_id = DeclarationId::from("Foo");
|
|
178
|
+
graph.declarations_mut().insert(
|
|
179
|
+
foo_id,
|
|
180
|
+
Declaration::Namespace(Namespace::Class(Box::new(ClassDeclaration::new(
|
|
181
|
+
"Foo".to_string(),
|
|
182
|
+
foo_id,
|
|
183
|
+
)))),
|
|
184
|
+
);
|
|
185
|
+
|
|
186
|
+
let errors = check_integrity(&graph);
|
|
187
|
+
assert_eq!(errors.len(), 1);
|
|
188
|
+
assert_eq!(errors[0].kind, IntegrityErrorKind::UnexpectedSelfOwnership);
|
|
189
|
+
assert_eq!(errors[0].declaration_name, "Foo");
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
#[test]
|
|
193
|
+
fn test_owner_does_not_exist() {
|
|
194
|
+
let mut graph = Graph::new();
|
|
195
|
+
let foo_id = DeclarationId::from("Foo");
|
|
196
|
+
let bogus_owner = DeclarationId::from("NonExistent");
|
|
197
|
+
|
|
198
|
+
graph.declarations_mut().insert(
|
|
199
|
+
foo_id,
|
|
200
|
+
Declaration::Namespace(Namespace::Class(Box::new(ClassDeclaration::new(
|
|
201
|
+
"Foo".to_string(),
|
|
202
|
+
bogus_owner,
|
|
203
|
+
)))),
|
|
204
|
+
);
|
|
205
|
+
|
|
206
|
+
let errors = check_integrity(&graph);
|
|
207
|
+
assert_eq!(errors.len(), 1);
|
|
208
|
+
assert_eq!(errors[0].kind, IntegrityErrorKind::OwnerDoesNotExist);
|
|
209
|
+
assert_eq!(errors[0].declaration_name, "Foo");
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
#[test]
|
|
213
|
+
fn test_owner_is_not_namespace() {
|
|
214
|
+
let mut graph = Graph::new();
|
|
215
|
+
|
|
216
|
+
// Object (self-owned, exempt)
|
|
217
|
+
graph.declarations_mut().insert(
|
|
218
|
+
*OBJECT_ID,
|
|
219
|
+
Declaration::Namespace(Namespace::Class(Box::new(ClassDeclaration::new(
|
|
220
|
+
"Object".to_string(),
|
|
221
|
+
*OBJECT_ID,
|
|
222
|
+
)))),
|
|
223
|
+
);
|
|
224
|
+
|
|
225
|
+
// A method owned by Object (valid)
|
|
226
|
+
let method_id = DeclarationId::from("Object#foo");
|
|
227
|
+
graph.declarations_mut().insert(
|
|
228
|
+
method_id,
|
|
229
|
+
Declaration::Method(Box::new(MethodDeclaration::new("Object#foo".to_string(), *OBJECT_ID))),
|
|
230
|
+
);
|
|
231
|
+
|
|
232
|
+
// A class owned by the method (invalid — owner is not a namespace)
|
|
233
|
+
let bar_id = DeclarationId::from("Bar");
|
|
234
|
+
graph.declarations_mut().insert(
|
|
235
|
+
bar_id,
|
|
236
|
+
Declaration::Namespace(Namespace::Class(Box::new(ClassDeclaration::new(
|
|
237
|
+
"Bar".to_string(),
|
|
238
|
+
method_id,
|
|
239
|
+
)))),
|
|
240
|
+
);
|
|
241
|
+
|
|
242
|
+
let errors = check_integrity(&graph);
|
|
243
|
+
assert_eq!(errors.len(), 1);
|
|
244
|
+
assert_eq!(errors[0].kind, IntegrityErrorKind::OwnerIsNotNamespace);
|
|
245
|
+
assert_eq!(errors[0].declaration_name, "Bar");
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
#[test]
|
|
249
|
+
fn test_singleton_class_chain_does_not_terminate() {
|
|
250
|
+
let mut graph = Graph::new();
|
|
251
|
+
|
|
252
|
+
// Two singleton classes that own each other, forming a cycle
|
|
253
|
+
let s1_id = DeclarationId::from("<Class:Foo>");
|
|
254
|
+
let s2_id = DeclarationId::from("<Class:Bar>");
|
|
255
|
+
|
|
256
|
+
graph.declarations_mut().insert(
|
|
257
|
+
s1_id,
|
|
258
|
+
Declaration::Namespace(Namespace::SingletonClass(Box::new(SingletonClassDeclaration::new(
|
|
259
|
+
"<Class:Foo>".to_string(),
|
|
260
|
+
s2_id,
|
|
261
|
+
)))),
|
|
262
|
+
);
|
|
263
|
+
graph.declarations_mut().insert(
|
|
264
|
+
s2_id,
|
|
265
|
+
Declaration::Namespace(Namespace::SingletonClass(Box::new(SingletonClassDeclaration::new(
|
|
266
|
+
"<Class:Bar>".to_string(),
|
|
267
|
+
s1_id,
|
|
268
|
+
)))),
|
|
269
|
+
);
|
|
270
|
+
|
|
271
|
+
let errors = check_integrity(&graph);
|
|
272
|
+
assert_eq!(errors.len(), 2);
|
|
273
|
+
assert!(
|
|
274
|
+
errors
|
|
275
|
+
.iter()
|
|
276
|
+
.all(|e| e.kind == IntegrityErrorKind::SingletonClassChainDoesNotTerminate)
|
|
277
|
+
);
|
|
278
|
+
}
|
|
279
|
+
}
|