Skip to content

Commit 7bf69d9

Browse files
authored
Merge pull request #2 from hvitved/js/source-on-same-line
Test: Remove location parsing
2 parents fc1d36f + fc04ad1 commit 7bf69d9

File tree

1 file changed

+25
-42
lines changed

1 file changed

+25
-42
lines changed

Diff for: shared/util/codeql/util/test/InlineExpectationsTest.qll

+25-42
Original file line numberDiff line numberDiff line change
@@ -645,29 +645,21 @@ module TestPostProcessing {
645645
private import InlineExpectationsTest as InlineExpectationsTest
646646
private import InlineExpectationsTest::Make<Input>
647647

648-
bindingset[loc]
649-
private predicate parseLocation(
650-
string loc, string file, int startLine, int startColumn, int endLine, int endColumn
651-
) {
652-
exists(string regexp |
653-
regexp = "(.*):(-?\\d+):(-?\\d+):(-?\\d+):(-?\\d+)" and
654-
file = loc.regexpCapture(regexp, 1) and
655-
startLine = loc.regexpCapture(regexp, 2).toInt() and
656-
startColumn = loc.regexpCapture(regexp, 3).toInt() and
657-
endLine = loc.regexpCapture(regexp, 4).toInt() and
658-
endColumn = loc.regexpCapture(regexp, 5).toInt()
659-
)
660-
}
661-
662-
/** Holds if the given location strings refer to the same lines, but possibly with different column numbers. */
648+
/** Holds if the given locations refer to the same lines, but possibly with different column numbers. */
663649
bindingset[loc1, loc2]
664-
private predicate sameLineInfo(string loc1, string loc2) {
650+
pragma[inline_late]
651+
private predicate sameLineInfo(Input::Location loc1, Input::Location loc2) {
665652
exists(string file, int line1, int line2 |
666-
parseLocation(loc1, file, line1, _, line2, _) and
667-
parseLocation(loc2, file, line1, _, line2, _)
653+
loc1.hasLocationInfo(file, line1, _, line2, _) and
654+
loc2.hasLocationInfo(file, line1, _, line2, _)
668655
)
669656
}
670657

658+
pragma[nomagic]
659+
private predicate mainQueryResult(int row, int column, Input::Location loc) {
660+
queryResults(mainResultSet(), row, column, Input2::getRelativeUrl(loc))
661+
}
662+
671663
/**
672664
* Gets the tag to be used for the path-problem source at result row `row`.
673665
*
@@ -676,9 +668,9 @@ module TestPostProcessing {
676668
*/
677669
private string getSourceTag(int row) {
678670
getQueryKind() = "path-problem" and
679-
exists(string sourceLoc, string selectLoc |
680-
queryResults(mainResultSet(), row, 0, selectLoc) and
681-
queryResults(mainResultSet(), row, 2, sourceLoc) and
671+
exists(Input::Location sourceLoc, Input::Location selectLoc |
672+
mainQueryResult(row, 0, selectLoc) and
673+
mainQueryResult(row, 2, sourceLoc) and
682674
if sameLineInfo(selectLoc, sourceLoc) then result = "Alert" else result = "Source"
683675
)
684676
}
@@ -744,13 +736,10 @@ module TestPostProcessing {
744736
int row, Input::Location location, string element, string tag, string value
745737
) {
746738
getQueryKind() = "path-problem" and
747-
exists(string loc |
748-
queryResults(mainResultSet(), row, 2, loc) and
749-
queryResults(mainResultSet(), row, 3, element) and
750-
tag = getSourceTag(row) and
751-
value = "" and
752-
Input2::getRelativeUrl(location) = loc
753-
)
739+
mainQueryResult(row, 2, location) and
740+
queryResults(mainResultSet(), row, 3, element) and
741+
tag = getSourceTag(row) and
742+
value = ""
754743
}
755744

756745
predicate hasActualResult(Input::Location location, string element, string tag, string value) {
@@ -784,24 +773,18 @@ module TestPostProcessing {
784773
int row, Input::Location location, string element, string tag
785774
) {
786775
getQueryKind() = "path-problem" and
787-
exists(string loc |
788-
queryResults(mainResultSet(), row, 4, loc) and
789-
queryResults(mainResultSet(), row, 5, element) and
790-
tag = getSinkTag(row) and
791-
Input2::getRelativeUrl(location) = loc
792-
)
776+
mainQueryResult(row, 4, location) and
777+
queryResults(mainResultSet(), row, 5, element) and
778+
tag = getSinkTag(row)
793779
}
794780

795781
private predicate hasAlert(int row, Input::Location location, string element, string tag) {
796782
getQueryKind() = ["problem", "path-problem"] and
797-
exists(string loc |
798-
queryResults(mainResultSet(), row, 0, loc) and
799-
queryResults(mainResultSet(), row, 2, element) and
800-
tag = "Alert" and
801-
Input2::getRelativeUrl(location) = loc and
802-
not hasPathProblemSource(row, location, _, _, _) and
803-
not hasPathProblemSink(row, location, _, _)
804-
)
783+
mainQueryResult(row, 0, location) and
784+
queryResults(mainResultSet(), row, 2, element) and
785+
tag = "Alert" and
786+
not hasPathProblemSource(row, location, _, _, _) and
787+
not hasPathProblemSink(row, location, _, _)
805788
}
806789

807790
/**

0 commit comments

Comments
 (0)