Skip to content

Commit

Permalink
Rust: improve modules test case
Browse files Browse the repository at this point in the history
  • Loading branch information
aibaars committed Feb 28, 2025
1 parent ae082a2 commit 2de8165
Show file tree
Hide file tree
Showing 3 changed files with 73 additions and 48 deletions.
44 changes: 22 additions & 22 deletions rust/ql/test/extractor-tests/crate_graph/crates.expected
Original file line number Diff line number Diff line change
@@ -1,23 +1,23 @@
#-----| Crate([email protected].21)
#-----| Crate([email protected].18)

#-----| Crate([email protected])
#-----| -> Crate([email protected])
#-----| -> Crate([email protected])

#-----| Crate([email protected].140)
#-----| Crate([email protected].138)
#-----| -> Crate([email protected])

#-----| Crate([email protected])
#-----| -> Crate([email protected])
#-----| -> Crate([email protected].140)
#-----| -> Crate([email protected].138)

#-----| Crate([email protected])
#-----| -> Crate([email protected])
#-----| -> Crate([email protected].140)
#-----| -> Crate([email protected].138)
#-----| -> Crate([email protected])
#-----| -> Crate([email protected])
#-----| -> Crate([email protected].2)
#-----| -> Crate([email protected].169)
#-----| -> Crate([email protected].0)
#-----| -> Crate([email protected].162)
#-----| -> Crate([email protected])
#-----| -> Crate([email protected])
#-----| -> Crate([email protected])
Expand All @@ -28,7 +28,7 @@

#-----| Crate([email protected])
#-----| -> Crate([email protected])
#-----| -> Crate([email protected].140)
#-----| -> Crate([email protected].138)
#-----| -> Crate([email protected])

#-----| Crate([email protected])
Expand All @@ -38,17 +38,17 @@

#-----| Crate([email protected])
#-----| -> Crate([email protected])
#-----| -> Crate([email protected].140)
#-----| -> Crate([email protected].138)
#-----| -> Crate([email protected])
#-----| -> Crate([email protected])

#-----| Crate([email protected].2)
#-----| -> Crate([email protected].21)
#-----| Crate([email protected].0)
#-----| -> Crate([email protected].18)
#-----| -> Crate([email protected])
#-----| -> Crate([email protected].140)
#-----| -> Crate([email protected].138)
#-----| -> Crate([email protected])

#-----| Crate([email protected].169)
#-----| Crate([email protected].162)
#-----| -> Crate([email protected])

#-----| Crate([email protected])
Expand All @@ -61,27 +61,27 @@

#-----| Crate([email protected])
#-----| -> Crate([email protected])
#-----| -> Crate([email protected].140)
#-----| -> Crate([email protected].138)

#-----| Crate([email protected])
#-----| -> Crate([email protected])
#-----| -> Crate([email protected].140)
#-----| -> Crate([email protected].138)
#-----| -> Crate([email protected])
#-----| -> Crate([email protected])
#-----| -> Crate([email protected].169)
#-----| -> Crate([email protected].162)

#-----| Crate([email protected])
#-----| -> Crate([email protected])
#-----| -> Crate([email protected].140)
#-----| -> Crate([email protected].138)
#-----| -> Crate([email protected])
#-----| -> Crate([email protected].169)
#-----| -> Crate([email protected].162)

#-----| Crate([email protected])
#-----| -> Crate([email protected])
#-----| -> Crate([email protected].140)
#-----| -> Crate([email protected].138)
#-----| -> Crate([email protected])
#-----| -> Crate([email protected])
#-----| -> Crate([email protected].169)
#-----| -> Crate([email protected].162)
#-----| -> Crate([email protected])

#-----| Crate([email protected])
Expand All @@ -90,16 +90,16 @@

#-----| Crate([email protected])
#-----| -> Crate([email protected])
#-----| -> Crate([email protected].140)
#-----| -> Crate([email protected].138)
#-----| -> Crate([email protected])
#-----| -> Crate([email protected])
#-----| -> Crate([email protected].169)
#-----| -> Crate([email protected].162)

#-----| Crate([email protected])
#-----| -> Crate([email protected])
#-----| -> Crate([email protected])
#-----| -> Crate([email protected])
#-----| -> Crate([email protected].169)
#-----| -> Crate([email protected].162)

#-----| Crate([email protected])
#-----| -> Crate([email protected])
Expand Down
43 changes: 20 additions & 23 deletions rust/ql/test/extractor-tests/crate_graph/modules.expected
Original file line number Diff line number Diff line change
@@ -1,40 +1,37 @@
#-----| fn as_string
#-----| Const

#-----| fn length
#-----| Static

#-----| fn write
#-----| enum X

#-----| fn as_string

#-----| fn as_string

#-----| fn fmt

#-----| struct X_List
#-----| fn length

#-----| Static
#-----| impl ...::Display for ...::X { ... }
#-----| -> fn fmt

#-----| impl AsString for ...::X { ... }
#-----| -> fn as_string

#-----| mod crate
#-----| -> mod module

#-----| mod module
#-----| -> Const
#-----| -> Static
#-----| -> enum X
#-----| -> fn length
#-----| -> fn write
#-----| -> impl ...::Display for ...::X { ... }
#-----| -> impl AsString for ...::X { ... }
#-----| -> struct X_List
#-----| -> Static
#-----| -> trait AsString
#-----| -> Const
#-----| -> impl AsString for ...::X { ... }
#-----| -> impl ...::Display for ...::X { ... }
#-----| -> enum X

#-----| mod crate
#-----| -> mod module
#-----| struct X_List

#-----| trait AsString
#-----| -> fn as_string

#-----| Const

#-----| impl AsString for ...::X { ... }
#-----| -> fn as_string

#-----| impl ...::Display for ...::X { ... }
#-----| -> fn fmt

#-----| enum X
34 changes: 31 additions & 3 deletions rust/ql/test/extractor-tests/crate_graph/modules.ql
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,40 @@

import rust

query predicate nodes(Item i) {
i.getParentNode*() = any(Crate m | m.getName() = "test" and m.getVersion() = "0.0.1").getModule()
predicate nodes(Item i) { i instanceof RelevantNode }

class RelevantNode extends Item {
RelevantNode() {
this.getParentNode*() =
any(Crate m | m.getName() = "test" and m.getVersion() = "0.0.1").getModule()
}
}

query predicate edges(Item container, Item element) {
predicate edges(RelevantNode container, RelevantNode element) {
element = container.(Module).getItemList().getAnItem() or
element = container.(Impl).getAssocItemList().getAnAssocItem() or
element = container.(Trait).getAssocItemList().getAnAssocItem()
}

query predicate nodes(RelevantNode node, string attr, string val) {
nodes(node) and
(
attr = "semmle.label" and
val = node.toString()
or
attr = "semmle.order" and
val =
any(int i | node = rank[i](RelevantNode n | nodes(n) | n order by n.toString())).toString()
)
}

query predicate edges(RelevantNode pred, RelevantNode succ, string attr, string val) {
edges(pred, succ) and
(
attr = "semmle.label" and
val = ""
or
attr = "semmle.order" and
val = any(int i | succ = rank[i](Item s | edges(pred, s) | s order by s.toString())).toString()
)
}

0 comments on commit 2de8165

Please sign in to comment.