-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Rust: add some tests for the crate graph
- Loading branch information
Showing
6 changed files
with
230 additions
and
0 deletions.
There are no files selected for viewing
117 changes: 117 additions & 0 deletions
117
rust/ql/test/extractor-tests/crate_graph/crates.expected
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,117 @@ | ||
#-----| Crate([email protected]) | ||
|
||
#-----| Crate([email protected]) | ||
#-----| -> Crate([email protected]) | ||
#-----| -> Crate([email protected]) | ||
|
||
#-----| Crate([email protected]) | ||
#-----| -> Crate([email protected]) | ||
|
||
#-----| Crate([email protected]) | ||
#-----| -> Crate([email protected]) | ||
#-----| -> Crate([email protected]) | ||
|
||
#-----| Crate([email protected]) | ||
#-----| -> Crate([email protected]) | ||
#-----| -> Crate([email protected]) | ||
#-----| -> Crate([email protected]) | ||
#-----| -> Crate([email protected]) | ||
#-----| -> Crate([email protected]) | ||
#-----| -> Crate([email protected]) | ||
#-----| -> Crate([email protected]) | ||
#-----| -> Crate([email protected]) | ||
#-----| -> Crate([email protected]) | ||
#-----| -> Crate([email protected]) | ||
#-----| -> Crate([email protected]) | ||
#-----| -> Crate([email protected]) | ||
#-----| -> Crate([email protected]) | ||
|
||
#-----| Crate([email protected]) | ||
#-----| -> Crate([email protected]) | ||
#-----| -> Crate([email protected]) | ||
#-----| -> Crate([email protected]) | ||
|
||
#-----| Crate([email protected]) | ||
#-----| -> Crate([email protected]) | ||
#-----| -> Crate([email protected]) | ||
#-----| -> Crate([email protected]) | ||
|
||
#-----| Crate([email protected]) | ||
#-----| -> Crate([email protected]) | ||
#-----| -> Crate([email protected]) | ||
#-----| -> Crate([email protected]) | ||
#-----| -> Crate([email protected]) | ||
|
||
#-----| Crate([email protected]) | ||
#-----| -> Crate([email protected]) | ||
#-----| -> Crate([email protected]) | ||
#-----| -> Crate([email protected]) | ||
#-----| -> Crate([email protected]) | ||
|
||
#-----| Crate([email protected]) | ||
#-----| -> Crate([email protected]) | ||
|
||
#-----| Crate([email protected]) | ||
|
||
#-----| Crate([email protected]) | ||
#-----| -> Crate([email protected]) | ||
|
||
#-----| Crate([email protected]) | ||
#-----| -> Crate([email protected]) | ||
|
||
#-----| Crate([email protected]) | ||
#-----| -> Crate([email protected]) | ||
#-----| -> Crate([email protected]) | ||
|
||
#-----| Crate([email protected]) | ||
#-----| -> Crate([email protected]) | ||
#-----| -> Crate([email protected]) | ||
#-----| -> Crate([email protected]) | ||
#-----| -> Crate([email protected]) | ||
#-----| -> Crate([email protected]) | ||
|
||
#-----| Crate([email protected]) | ||
#-----| -> Crate([email protected]) | ||
#-----| -> Crate([email protected]) | ||
#-----| -> Crate([email protected]) | ||
#-----| -> Crate([email protected]) | ||
|
||
#-----| Crate([email protected]) | ||
#-----| -> Crate([email protected]) | ||
#-----| -> Crate([email protected]) | ||
#-----| -> Crate([email protected]) | ||
#-----| -> Crate([email protected]) | ||
#-----| -> Crate([email protected]) | ||
#-----| -> Crate([email protected]) | ||
|
||
#-----| Crate([email protected]) | ||
#-----| -> Crate([email protected]) | ||
#-----| -> Crate([email protected]) | ||
|
||
#-----| Crate([email protected]) | ||
#-----| -> Crate([email protected]) | ||
#-----| -> Crate([email protected]) | ||
#-----| -> Crate([email protected]) | ||
#-----| -> Crate([email protected]) | ||
#-----| -> Crate([email protected]) | ||
|
||
#-----| Crate([email protected]) | ||
#-----| -> Crate([email protected]) | ||
#-----| -> Crate([email protected]) | ||
#-----| -> Crate([email protected]) | ||
#-----| -> Crate([email protected]) | ||
|
||
#-----| Crate([email protected]) | ||
#-----| -> Crate([email protected]) | ||
#-----| -> Crate([email protected]) | ||
#-----| -> Crate([email protected]) | ||
#-----| -> Crate([email protected]) | ||
#-----| -> Crate([email protected]) | ||
|
||
#-----| Crate([email protected]) | ||
#-----| -> Crate([email protected]) | ||
#-----| -> Crate([email protected]) | ||
#-----| -> Crate([email protected]) | ||
#-----| -> Crate([email protected]) | ||
#-----| -> Crate([email protected]) | ||
#-----| -> Crate([email protected]) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
/** | ||
* @id crate-graph | ||
* @name Crate Graph | ||
* @kind graph | ||
*/ | ||
|
||
import rust | ||
|
||
query predicate nodes(Crate c) { any() } | ||
|
||
query predicate edges(Crate c1, Crate c2) { c1.getADependency() = c2 } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
fn main() { | ||
println! {"Hello world"} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
use std::fmt; | ||
|
||
pub enum X { | ||
A, | ||
B, | ||
} | ||
|
||
pub struct X_List { | ||
x: X, | ||
tail: Option<Box<X_List>>, | ||
} | ||
|
||
pub fn length(list: X_List) -> usize { | ||
match list { | ||
X_List { x: _, tail: None } => 1, | ||
X_List { | ||
x: _, | ||
tail: Some(tail), | ||
} => 1 + length(*tail), | ||
} | ||
} | ||
pub trait AsString { | ||
fn as_string(&self) -> &str; | ||
} | ||
|
||
impl AsString for X { | ||
fn as_string(&self) -> &str { | ||
match self { | ||
X::A => "a", | ||
X::B => "b", | ||
} | ||
} | ||
} | ||
|
||
impl fmt::Display for X { | ||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { | ||
write!(f, "{}", self.as_string()) | ||
} | ||
} | ||
|
||
pub const X_A: X = X::A; | ||
pub static X_B: X = X::B; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
#-----| fn as_string | ||
|
||
#-----| fn length | ||
|
||
#-----| fn write | ||
|
||
#-----| fn as_string | ||
|
||
#-----| fn fmt | ||
|
||
#-----| struct X_List | ||
|
||
#-----| Static | ||
|
||
#-----| mod module | ||
#-----| -> fn length | ||
#-----| -> fn write | ||
#-----| -> struct X_List | ||
#-----| -> Static | ||
#-----| -> trait AsString | ||
#-----| -> Const | ||
#-----| -> impl AsString for ...::X { ... } | ||
#-----| -> impl ...::Display for ...::X { ... } | ||
#-----| -> enum X | ||
|
||
#-----| mod crate | ||
#-----| -> mod module | ||
|
||
#-----| trait AsString | ||
#-----| -> fn as_string | ||
|
||
#-----| Const | ||
|
||
#-----| impl AsString for ...::X { ... } | ||
#-----| -> fn as_string | ||
|
||
#-----| impl ...::Display for ...::X { ... } | ||
#-----| -> fn fmt | ||
|
||
#-----| enum X |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
/** | ||
* @id module-graph | ||
* @name Module and Item Graph | ||
* @kind graph | ||
*/ | ||
|
||
import rust | ||
|
||
query predicate nodes(Item i) { | ||
i.getParentNode*() = any(Crate m | m.getName() = "test" and m.getVersion() = "0.0.1").getModule() | ||
} | ||
|
||
query predicate edges(Item container, Item element) { | ||
element = container.(Module).getItemList().getAnItem() or | ||
element = container.(Impl).getAssocItemList().getAnAssocItem() or | ||
element = container.(Trait).getAssocItemList().getAnAssocItem() | ||
} |