|
| 1 | +import python |
| 2 | +import semmle.python.essa.SsaCompute |
| 3 | +import TestUtilities.InlineExpectationsTest |
| 4 | + |
| 5 | +class UseTest extends InlineExpectationsTest { |
| 6 | + UseTest() { this = "UseTest" } |
| 7 | + |
| 8 | + override string getARelevantTag() { result in ["use-use", "def-use", "def"] } |
| 9 | + |
| 10 | + override predicate hasActualResult(Location location, string element, string tag, string value) { |
| 11 | + exists(location.getFile().getRelativePath()) and |
| 12 | + exists(string name | name in ["x", "y"] | |
| 13 | + exists(NameNode nodeTo, Location prevLoc | |
| 14 | + ( |
| 15 | + exists(NameNode nodeFrom | AdjacentUses::adjacentUseUse(nodeFrom, nodeTo) | |
| 16 | + prevLoc = nodeFrom.getLocation() and |
| 17 | + name = nodeFrom.getId() and |
| 18 | + tag = "use-use" |
| 19 | + ) |
| 20 | + or |
| 21 | + exists(EssaVariable var | AdjacentUses::firstUse(var, nodeTo) | |
| 22 | + prevLoc = var.getLocation() and |
| 23 | + name = var.getName() and |
| 24 | + tag = "def-use" |
| 25 | + ) |
| 26 | + ) and |
| 27 | + value = name + ":" + prevLoc.getStartLine() and |
| 28 | + location = nodeTo.getLocation() and |
| 29 | + element = nodeTo.toString() |
| 30 | + ) |
| 31 | + or |
| 32 | + exists(EssaVariable var | AdjacentUses::firstUse(var, _) | |
| 33 | + value = var.getName() and |
| 34 | + location = var.getLocation() and |
| 35 | + element = var.getName() and |
| 36 | + name = var.getName() and |
| 37 | + tag = "def" |
| 38 | + ) |
| 39 | + ) |
| 40 | + } |
| 41 | +} |
0 commit comments