Skip to content

Commit 2de8165

Browse files
committed
Rust: improve modules test case
1 parent ae082a2 commit 2de8165

File tree

3 files changed

+73
-48
lines changed

3 files changed

+73
-48
lines changed

rust/ql/test/extractor-tests/crate_graph/crates.expected

+22-22
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,23 @@
1-
#-----| Crate([email protected].21)
1+
#-----| Crate([email protected].18)
22

33
#-----| Crate([email protected])
44
#-----| -> Crate([email protected])
55
#-----| -> Crate([email protected])
66

7-
#-----| Crate([email protected].140)
7+
#-----| Crate([email protected].138)
88
#-----| -> Crate([email protected])
99

1010
#-----| Crate([email protected])
1111
#-----| -> Crate([email protected])
12-
#-----| -> Crate([email protected].140)
12+
#-----| -> Crate([email protected].138)
1313

1414
#-----| Crate([email protected])
1515
#-----| -> Crate([email protected])
16-
#-----| -> Crate([email protected].140)
16+
#-----| -> Crate([email protected].138)
1717
#-----| -> Crate([email protected])
1818
#-----| -> Crate([email protected])
19-
#-----| -> Crate([email protected].2)
20-
#-----| -> Crate([email protected].169)
19+
#-----| -> Crate([email protected].0)
20+
#-----| -> Crate([email protected].162)
2121
#-----| -> Crate([email protected])
2222
#-----| -> Crate([email protected])
2323
#-----| -> Crate([email protected])
@@ -28,7 +28,7 @@
2828

2929
#-----| Crate([email protected])
3030
#-----| -> Crate([email protected])
31-
#-----| -> Crate([email protected].140)
31+
#-----| -> Crate([email protected].138)
3232
#-----| -> Crate([email protected])
3333

3434
#-----| Crate([email protected])
@@ -38,17 +38,17 @@
3838

3939
#-----| Crate([email protected])
4040
#-----| -> Crate([email protected])
41-
#-----| -> Crate([email protected].140)
41+
#-----| -> Crate([email protected].138)
4242
#-----| -> Crate([email protected])
4343
#-----| -> Crate([email protected])
4444

45-
#-----| Crate([email protected].2)
46-
#-----| -> Crate([email protected].21)
45+
#-----| Crate([email protected].0)
46+
#-----| -> Crate([email protected].18)
4747
#-----| -> Crate([email protected])
48-
#-----| -> Crate([email protected].140)
48+
#-----| -> Crate([email protected].138)
4949
#-----| -> Crate([email protected])
5050

51-
#-----| Crate([email protected].169)
51+
#-----| Crate([email protected].162)
5252
#-----| -> Crate([email protected])
5353

5454
#-----| Crate([email protected])
@@ -61,27 +61,27 @@
6161

6262
#-----| Crate([email protected])
6363
#-----| -> Crate([email protected])
64-
#-----| -> Crate([email protected].140)
64+
#-----| -> Crate([email protected].138)
6565

6666
#-----| Crate([email protected])
6767
#-----| -> Crate([email protected])
68-
#-----| -> Crate([email protected].140)
68+
#-----| -> Crate([email protected].138)
6969
#-----| -> Crate([email protected])
7070
#-----| -> Crate([email protected])
71-
#-----| -> Crate([email protected].169)
71+
#-----| -> Crate([email protected].162)
7272

7373
#-----| Crate([email protected])
7474
#-----| -> Crate([email protected])
75-
#-----| -> Crate([email protected].140)
75+
#-----| -> Crate([email protected].138)
7676
#-----| -> Crate([email protected])
77-
#-----| -> Crate([email protected].169)
77+
#-----| -> Crate([email protected].162)
7878

7979
#-----| Crate([email protected])
8080
#-----| -> Crate([email protected])
81-
#-----| -> Crate([email protected].140)
81+
#-----| -> Crate([email protected].138)
8282
#-----| -> Crate([email protected])
8383
#-----| -> Crate([email protected])
84-
#-----| -> Crate([email protected].169)
84+
#-----| -> Crate([email protected].162)
8585
#-----| -> Crate([email protected])
8686

8787
#-----| Crate([email protected])
@@ -90,16 +90,16 @@
9090

9191
#-----| Crate([email protected])
9292
#-----| -> Crate([email protected])
93-
#-----| -> Crate([email protected].140)
93+
#-----| -> Crate([email protected].138)
9494
#-----| -> Crate([email protected])
9595
#-----| -> Crate([email protected])
96-
#-----| -> Crate([email protected].169)
96+
#-----| -> Crate([email protected].162)
9797

9898
#-----| Crate([email protected])
9999
#-----| -> Crate([email protected])
100100
#-----| -> Crate([email protected])
101101
#-----| -> Crate([email protected])
102-
#-----| -> Crate([email protected].169)
102+
#-----| -> Crate([email protected].162)
103103

104104
#-----| Crate([email protected])
105105
#-----| -> Crate([email protected])
Original file line numberDiff line numberDiff line change
@@ -1,40 +1,37 @@
1-
#-----| fn as_string
1+
#-----| Const
22

3-
#-----| fn length
3+
#-----| Static
44

5-
#-----| fn write
5+
#-----| enum X
6+
7+
#-----| fn as_string
68

79
#-----| fn as_string
810

911
#-----| fn fmt
1012

11-
#-----| struct X_List
13+
#-----| fn length
1214

13-
#-----| Static
15+
#-----| impl ...::Display for ...::X { ... }
16+
#-----| -> fn fmt
17+
18+
#-----| impl AsString for ...::X { ... }
19+
#-----| -> fn as_string
20+
21+
#-----| mod crate
22+
#-----| -> mod module
1423

1524
#-----| mod module
25+
#-----| -> Const
26+
#-----| -> Static
27+
#-----| -> enum X
1628
#-----| -> fn length
17-
#-----| -> fn write
29+
#-----| -> impl ...::Display for ...::X { ... }
30+
#-----| -> impl AsString for ...::X { ... }
1831
#-----| -> struct X_List
19-
#-----| -> Static
2032
#-----| -> trait AsString
21-
#-----| -> Const
22-
#-----| -> impl AsString for ...::X { ... }
23-
#-----| -> impl ...::Display for ...::X { ... }
24-
#-----| -> enum X
2533

26-
#-----| mod crate
27-
#-----| -> mod module
34+
#-----| struct X_List
2835

2936
#-----| trait AsString
3037
#-----| -> 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

rust/ql/test/extractor-tests/crate_graph/modules.ql

+31-3
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,40 @@
66

77
import rust
88

9-
query predicate nodes(Item i) {
10-
i.getParentNode*() = any(Crate m | m.getName() = "test" and m.getVersion() = "0.0.1").getModule()
9+
predicate nodes(Item i) { i instanceof RelevantNode }
10+
11+
class RelevantNode extends Item {
12+
RelevantNode() {
13+
this.getParentNode*() =
14+
any(Crate m | m.getName() = "test" and m.getVersion() = "0.0.1").getModule()
15+
}
1116
}
1217

13-
query predicate edges(Item container, Item element) {
18+
predicate edges(RelevantNode container, RelevantNode element) {
1419
element = container.(Module).getItemList().getAnItem() or
1520
element = container.(Impl).getAssocItemList().getAnAssocItem() or
1621
element = container.(Trait).getAssocItemList().getAnAssocItem()
1722
}
23+
24+
query predicate nodes(RelevantNode node, string attr, string val) {
25+
nodes(node) and
26+
(
27+
attr = "semmle.label" and
28+
val = node.toString()
29+
or
30+
attr = "semmle.order" and
31+
val =
32+
any(int i | node = rank[i](RelevantNode n | nodes(n) | n order by n.toString())).toString()
33+
)
34+
}
35+
36+
query predicate edges(RelevantNode pred, RelevantNode succ, string attr, string val) {
37+
edges(pred, succ) and
38+
(
39+
attr = "semmle.label" and
40+
val = ""
41+
or
42+
attr = "semmle.order" and
43+
val = any(int i | succ = rank[i](Item s | edges(pred, s) | s order by s.toString())).toString()
44+
)
45+
}

0 commit comments

Comments
 (0)