Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
| Test.java | 3 | append | 0 | 0 | // $ java-direct=safe |
| Test.java | 4 | replace | 25 | 37 | // $ foreign java-direct=safe |
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
class Test {
void target() {} // $ java-direct
void safeAppend() {}
void safeReplace() {} // $ foreign
void unsafeHash() {}
void unsafeSpace() {} // $ foreign
void unsafeNewline() {} // $ foreign
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import java
import utils.test.InlineExpectationsTest

module DirectTest implements TestSig {
string getARelevantTag() { result = "java-direct" }

predicate tagIsIgnored(string expectedTag) { expectedTag = "foreign" }

predicate hasActualResult(Location location, string element, string tag, string value) {
exists(Method method |
method.getName() =
["target", "safeAppend", "safeReplace", "unsafeHash", "unsafeSpace", "unsafeNewline"] and
method.fromSource() and
location = method.getLocation() and
element = method.toString() and
tag = "java-direct" and
if method.getName() = "unsafeHash"
then value = "a#b"
else
if method.getName() = "unsafeSpace"
then value = "hello world"
else
if method.getName() = "unsafeNewline"
then value = "hello\nworld"
else
if method.getName() = ["safeAppend", "safeReplace"]
then value = "safe"
else value = ""
)
}
}

private module Test = MakeTest<DirectTest>;

from string file, int line, string operation, int startColumn, int endColumn, string text
where Test::learnEdits(file, line, operation, startColumn, endColumn, text)
select file, line, operation, startColumn, endColumn, text
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,8 @@ module Impl implements InlineExpectationsTestSig {
relativePath.regexpMatch(".*\\.(py|pyi)") and
result = "#"
}

// Python source lines are not available here, so an explicit `\` continuation cannot be excluded.
bindingset[relativePath, line]
predicate canAppendCommentAtEndOfLine(string relativePath, int line) { none() }
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import python
import utils.test.InlineExpectationsTest

module DirectTest implements TestSig {
string getARelevantTag() { result = "direct" }

string getARelevantExpectedTag() { result = ["direct", "direct[alias]"] }

bindingset[expectedTag, actualTag]
predicate tagMatches(string expectedTag, string actualTag) {
expectedTag = ["direct", "direct[alias]"] and actualTag = "direct"
}

predicate hasActualResult(Location location, string element, string tag, string value) {
exists(Name name |
name.getId() = ["target", "target_continuation"] and
location = name.getLocation() and
element = name.toString() and
tag = "direct" and
value = ""
)
}
}

private module Test = MakeTest<DirectTest>;

from string file, int line, string operation, int startColumn, int endColumn, string text
where Test::learnEdits(file, line, operation, startColumn, endColumn, text)
select file, line, operation, startColumn, endColumn, text
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
target = 1 # $ direct[alias] foreign
target_continuation = 1 \
+ 1
Loading
Loading