mirror of
https://github.com/github/codeql.git
synced 2025-12-24 12:46:34 +01:00
31 lines
878 B
Plaintext
31 lines
878 B
Plaintext
/** This file contains test-related utility functions */
|
|
|
|
import python
|
|
|
|
/** Removes everything up to the occurrence of `sub` in the string `str` */
|
|
bindingset[str, sub]
|
|
string remove_prefix_before_substring(string str, string sub) {
|
|
exists(int index |
|
|
index = str.indexOf(sub) and
|
|
result = str.suffix(index)
|
|
)
|
|
or
|
|
not exists(str.indexOf(sub)) and
|
|
result = str
|
|
}
|
|
|
|
/**
|
|
* Removes the part of the `resources/lib` Python library path that may vary
|
|
* from machine to machine.
|
|
*/
|
|
string remove_library_prefix(Location loc) {
|
|
result = remove_prefix_before_substring(loc.toString(), "resources/lib")
|
|
}
|
|
|
|
/** Returns the location of an AST node in compact form: `basename:line:column` */
|
|
string compact_location(AstNode a) {
|
|
exists(Location l | l = a.getLocation() |
|
|
result = l.getFile().getBaseName() + ":" + l.getStartLine() + ":" + l.getStartColumn()
|
|
)
|
|
}
|