Skip to content

Commit 7ca955a

Browse files
committed
Add support for XML InlineExpectationsTest
1 parent 70e6db3 commit 7ca955a

File tree

5 files changed

+36
-0
lines changed

5 files changed

+36
-0
lines changed

java/ql/test/TestUtilities/InlineExpectationsTestPrivate.qll

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,3 +20,15 @@ private class KtExpectationComment extends KtComment, ExpectationComment {
2020

2121
override string getContents() { result = this.getText().suffix(2).trim() }
2222
}
23+
24+
private class XMLExpectationComment extends ExpectationComment instanceof XMLComment {
25+
override string getContents() { result = this.(XMLComment).getText().trim() }
26+
27+
override Location getLocation() { result = this.(XMLComment).getLocation() }
28+
29+
override predicate hasLocationInfo(string path, int sl, int sc, int el, int ec) {
30+
this.(XMLComment).hasLocationInfo(path, sl, sc, el, ec)
31+
}
32+
33+
override string toString() { result = this.(XMLComment).toString() }
34+
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
public class Test {
2+
3+
}

java/ql/test/library-tests/xml/XMLTest.expected

Whitespace-only changes.
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import semmle.code.xml.XML
2+
import TestUtilities.InlineExpectationsTest
3+
4+
class XMLTest extends InlineExpectationsTest {
5+
XMLTest() { this = "XMLTest" }
6+
7+
override string getARelevantTag() { result = "hasXmlResult" }
8+
9+
override predicate hasActualResult(Location location, string element, string tag, string value) {
10+
tag = "hasXmlResult" and
11+
exists(XMLAttribute a |
12+
a.getLocation() = location and
13+
element = a.toString() and
14+
value = ""
15+
)
16+
}
17+
}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<document>
3+
<element attribute="value">Text</element> <!-- $ hasXmlResult -->
4+
</document>

0 commit comments

Comments
 (0)