Skip to content

Commit fce637f

Browse files
committed
Rust: add some tests for the crate graph
1 parent 8ec8824 commit fce637f

File tree

6 files changed

+230
-0
lines changed

6 files changed

+230
-0
lines changed
Lines changed: 117 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,117 @@
1+
#-----| Crate([email protected])
2+
3+
#-----| Crate([email protected])
4+
#-----| -> Crate([email protected])
5+
#-----| -> Crate([email protected])
6+
7+
#-----| Crate([email protected])
8+
#-----| -> Crate([email protected])
9+
10+
#-----| Crate([email protected])
11+
#-----| -> Crate([email protected])
12+
#-----| -> Crate([email protected])
13+
14+
#-----| Crate([email protected])
15+
#-----| -> Crate([email protected])
16+
#-----| -> Crate([email protected])
17+
#-----| -> Crate([email protected])
18+
#-----| -> Crate([email protected])
19+
#-----| -> Crate([email protected])
20+
#-----| -> Crate([email protected])
21+
#-----| -> Crate([email protected])
22+
#-----| -> Crate([email protected])
23+
#-----| -> Crate([email protected])
24+
#-----| -> Crate([email protected])
25+
#-----| -> Crate([email protected])
26+
#-----| -> Crate([email protected])
27+
#-----| -> Crate([email protected])
28+
29+
#-----| Crate([email protected])
30+
#-----| -> Crate([email protected])
31+
#-----| -> Crate([email protected])
32+
#-----| -> Crate([email protected])
33+
34+
#-----| Crate([email protected])
35+
#-----| -> Crate([email protected])
36+
#-----| -> Crate([email protected])
37+
#-----| -> Crate([email protected])
38+
39+
#-----| Crate([email protected])
40+
#-----| -> Crate([email protected])
41+
#-----| -> Crate([email protected])
42+
#-----| -> Crate([email protected])
43+
#-----| -> Crate([email protected])
44+
45+
#-----| Crate([email protected])
46+
#-----| -> Crate([email protected])
47+
#-----| -> Crate([email protected])
48+
#-----| -> Crate([email protected])
49+
#-----| -> Crate([email protected])
50+
51+
#-----| Crate([email protected])
52+
#-----| -> Crate([email protected])
53+
54+
#-----| Crate([email protected])
55+
56+
#-----| Crate([email protected])
57+
#-----| -> Crate([email protected])
58+
59+
#-----| Crate([email protected])
60+
#-----| -> Crate([email protected])
61+
62+
#-----| Crate([email protected])
63+
#-----| -> Crate([email protected])
64+
#-----| -> Crate([email protected])
65+
66+
#-----| Crate([email protected])
67+
#-----| -> Crate([email protected])
68+
#-----| -> Crate([email protected])
69+
#-----| -> Crate([email protected])
70+
#-----| -> Crate([email protected])
71+
#-----| -> Crate([email protected])
72+
73+
#-----| Crate([email protected])
74+
#-----| -> Crate([email protected])
75+
#-----| -> Crate([email protected])
76+
#-----| -> Crate([email protected])
77+
#-----| -> Crate([email protected])
78+
79+
#-----| Crate([email protected])
80+
#-----| -> Crate([email protected])
81+
#-----| -> Crate([email protected])
82+
#-----| -> Crate([email protected])
83+
#-----| -> Crate([email protected])
84+
#-----| -> Crate([email protected])
85+
#-----| -> Crate([email protected])
86+
87+
#-----| Crate([email protected])
88+
#-----| -> Crate([email protected])
89+
#-----| -> Crate([email protected])
90+
91+
#-----| Crate([email protected])
92+
#-----| -> Crate([email protected])
93+
#-----| -> Crate([email protected])
94+
#-----| -> Crate([email protected])
95+
#-----| -> Crate([email protected])
96+
#-----| -> Crate([email protected])
97+
98+
#-----| Crate([email protected])
99+
#-----| -> Crate([email protected])
100+
#-----| -> Crate([email protected])
101+
#-----| -> Crate([email protected])
102+
#-----| -> Crate([email protected])
103+
104+
#-----| Crate([email protected])
105+
#-----| -> Crate([email protected])
106+
#-----| -> Crate([email protected])
107+
#-----| -> Crate([email protected])
108+
#-----| -> Crate([email protected])
109+
#-----| -> Crate([email protected])
110+
111+
#-----| Crate([email protected])
112+
#-----| -> Crate([email protected])
113+
#-----| -> Crate([email protected])
114+
#-----| -> Crate([email protected])
115+
#-----| -> Crate([email protected])
116+
#-----| -> Crate([email protected])
117+
#-----| -> Crate([email protected])
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
/**
2+
* @id crate-graph
3+
* @name Crate Graph
4+
* @kind graph
5+
*/
6+
7+
import rust
8+
9+
query predicate nodes(Crate c) { any() }
10+
11+
query predicate edges(Crate c1, Crate c2) { c1.getADependency() = c2 }
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
fn main() {
2+
println! {"Hello world"}
3+
}
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
use std::fmt;
2+
3+
pub enum X {
4+
A,
5+
B,
6+
}
7+
8+
pub struct X_List {
9+
x: X,
10+
tail: Option<Box<X_List>>,
11+
}
12+
13+
pub fn length(list: X_List) -> usize {
14+
match list {
15+
X_List { x: _, tail: None } => 1,
16+
X_List {
17+
x: _,
18+
tail: Some(tail),
19+
} => 1 + length(*tail),
20+
}
21+
}
22+
pub trait AsString {
23+
fn as_string(&self) -> &str;
24+
}
25+
26+
impl AsString for X {
27+
fn as_string(&self) -> &str {
28+
match self {
29+
X::A => "a",
30+
X::B => "b",
31+
}
32+
}
33+
}
34+
35+
impl fmt::Display for X {
36+
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
37+
write!(f, "{}", self.as_string())
38+
}
39+
}
40+
41+
pub const X_A: X = X::A;
42+
pub static X_B: X = X::B;
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
#-----| fn as_string
2+
3+
#-----| fn length
4+
5+
#-----| fn write
6+
7+
#-----| fn as_string
8+
9+
#-----| fn fmt
10+
11+
#-----| struct X_List
12+
13+
#-----| Static
14+
15+
#-----| mod module
16+
#-----| -> fn length
17+
#-----| -> fn write
18+
#-----| -> struct X_List
19+
#-----| -> Static
20+
#-----| -> trait AsString
21+
#-----| -> Const
22+
#-----| -> impl AsString for ...::X { ... }
23+
#-----| -> impl ...::Display for ...::X { ... }
24+
#-----| -> enum X
25+
26+
#-----| mod crate
27+
#-----| -> mod module
28+
29+
#-----| trait AsString
30+
#-----| -> fn as_string
31+
32+
#-----| Const
33+
34+
#-----| impl AsString for ...::X { ... }
35+
#-----| -> fn as_string
36+
37+
#-----| impl ...::Display for ...::X { ... }
38+
#-----| -> fn fmt
39+
40+
#-----| enum X
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
/**
2+
* @id module-graph
3+
* @name Module and Item Graph
4+
* @kind graph
5+
*/
6+
7+
import rust
8+
9+
query predicate nodes(Item i) {
10+
i.getParentNode*() = any(Crate m | m.getName() = "test" and m.getVersion() = "0.0.1").getModule()
11+
}
12+
13+
query predicate edges(Item container, Item element) {
14+
element = container.(Module).getItemList().getAnItem() or
15+
element = container.(Impl).getAssocItemList().getAnAssocItem() or
16+
element = container.(Trait).getAssocItemList().getAnAssocItem()
17+
}

0 commit comments

Comments
 (0)