|
| 1 | +import python |
| 2 | +import TestUtilities.InlineExpectationsTest |
| 3 | +private import semmle.python.regex |
| 4 | + |
| 5 | +class CharacterSetTest extends InlineExpectationsTest { |
| 6 | + CharacterSetTest() { this = "CharacterSetTest" } |
| 7 | + |
| 8 | + override string getARelevantTag() { result = "charSet" } |
| 9 | + |
| 10 | + override predicate hasActualResult(Location location, string element, string tag, string value) { |
| 11 | + exists(location.getFile().getRelativePath()) and |
| 12 | + location.getFile().getBaseName() = "charSetTest.py" and |
| 13 | + exists(Regex re, int start, int end | |
| 14 | + re.charSet(start, end) and |
| 15 | + location = re.getLocation() and |
| 16 | + element = re.toString().substring(start, end) and |
| 17 | + value = start + ":" + end and |
| 18 | + tag = "charSet" |
| 19 | + ) |
| 20 | + } |
| 21 | +} |
| 22 | + |
| 23 | +class CharacterRangeTest extends InlineExpectationsTest { |
| 24 | + CharacterRangeTest() { this = "CharacterRangeTest" } |
| 25 | + |
| 26 | + override string getARelevantTag() { result = "charRange" } |
| 27 | + |
| 28 | + override predicate hasActualResult(Location location, string element, string tag, string value) { |
| 29 | + exists(location.getFile().getRelativePath()) and |
| 30 | + location.getFile().getBaseName() = "charRangeTest.py" and |
| 31 | + exists(Regex re, int start, int lower_end, int upper_start, int end | |
| 32 | + re.charRange(_, start, lower_end, upper_start, end) and |
| 33 | + location = re.getLocation() and |
| 34 | + element = re.toString().substring(start, end) and |
| 35 | + value = start + ":" + lower_end + "-" + upper_start + ":" + end and |
| 36 | + tag = "charRange" |
| 37 | + ) |
| 38 | + } |
| 39 | +} |
| 40 | + |
| 41 | +class EscapeTest extends InlineExpectationsTest { |
| 42 | + EscapeTest() { this = "EscapeTest" } |
| 43 | + |
| 44 | + override string getARelevantTag() { result = "escapedCharacter" } |
| 45 | + |
| 46 | + override predicate hasActualResult(Location location, string element, string tag, string value) { |
| 47 | + exists(location.getFile().getRelativePath()) and |
| 48 | + location.getFile().getBaseName() = "escapedCharacterTest.py" and |
| 49 | + exists(Regex re, int start, int end | |
| 50 | + re.escapedCharacter(start, end) and |
| 51 | + location = re.getLocation() and |
| 52 | + element = re.toString().substring(start, end) and |
| 53 | + value = start + ":" + end and |
| 54 | + tag = "escapedCharacter" |
| 55 | + ) |
| 56 | + } |
| 57 | +} |
| 58 | + |
| 59 | +class GroupTest extends InlineExpectationsTest { |
| 60 | + GroupTest() { this = "GroupTest" } |
| 61 | + |
| 62 | + override string getARelevantTag() { result = "group" } |
| 63 | + |
| 64 | + override predicate hasActualResult(Location location, string element, string tag, string value) { |
| 65 | + exists(location.getFile().getRelativePath()) and |
| 66 | + location.getFile().getBaseName() = "groupTest.py" and |
| 67 | + exists(Regex re, int start, int end | |
| 68 | + re.group(start, end) and |
| 69 | + location = re.getLocation() and |
| 70 | + element = re.toString().substring(start, end) and |
| 71 | + value = start + ":" + end and |
| 72 | + tag = "group" |
| 73 | + ) |
| 74 | + } |
| 75 | +} |
0 commit comments