Skip to content
Merged
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
12 changes: 12 additions & 0 deletions java/ql/test/TestUtilities/InlineExpectationsTestPrivate.qll
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,15 @@ private class KtExpectationComment extends KtComment, ExpectationComment {

override string getContents() { result = this.getText().suffix(2).trim() }
}

private class XmlExpectationComment extends ExpectationComment instanceof XMLComment {
override string getContents() { result = this.(XMLComment).getText().trim() }

override Location getLocation() { result = this.(XMLComment).getLocation() }

override predicate hasLocationInfo(string path, int sl, int sc, int el, int ec) {
this.(XMLComment).hasLocationInfo(path, sl, sc, el, ec)
}

override string toString() { result = this.(XMLComment).toString() }
}
3 changes: 3 additions & 0 deletions java/ql/test/library-tests/xml/Test.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
public class Test {

}
2 changes: 2 additions & 0 deletions java/ql/test/library-tests/xml/XMLTest.expected
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
| test.xml:4:5:4:32 | attribute=value | Unexpected result: hasXmlResult= |
| test.xml:5:29:5:52 | $ hasXmlResult | Missing result:hasXmlResult= |
17 changes: 17 additions & 0 deletions java/ql/test/library-tests/xml/XMLTest.ql
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import semmle.code.xml.XML
import TestUtilities.InlineExpectationsTest

class XmlTest extends InlineExpectationsTest {
XmlTest() { this = "XmlTest" }

override string getARelevantTag() { result = "hasXmlResult" }

override predicate hasActualResult(Location location, string element, string tag, string value) {
tag = "hasXmlResult" and
exists(XMLAttribute a |
a.getLocation() = location and
element = a.toString() and
value = ""
)
}
}
6 changes: 6 additions & 0 deletions java/ql/test/library-tests/xml/test.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<document>
<element attribute="value">Text</element> <!-- $ hasXmlResult -->
Comment thread
atorralba marked this conversation as resolved.
<element attribute="value">Text</element> <!-- Missing -->
<element>Text</element> <!-- $ hasXmlResult --> <!-- Spurious -->
</document>