Skip to content

Commit 593ce01

Browse files
authored
Merge pull request #9908 from atorralba/atorralba/xml-inline-exp-test
Java: Add support for XML InlineExpectationsTest
2 parents 48e93b3 + ec03ebb commit 593ce01

File tree

5 files changed

+40
-0
lines changed

5 files changed

+40
-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+
}
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
| test.xml:4:5:4:32 | attribute=value | Unexpected result: hasXmlResult= |
2+
| test.xml:5:29:5:52 | $ hasXmlResult | Missing result:hasXmlResult= |
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: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<document>
3+
<element attribute="value">Text</element> <!-- $ hasXmlResult -->
4+
<element attribute="value">Text</element> <!-- Missing -->
5+
<element>Text</element> <!-- $ hasXmlResult --> <!-- Spurious -->
6+
</document>

0 commit comments

Comments
 (0)