mirror of
https://github.com/github/codeql.git
synced 2025-12-22 11:46:32 +01:00
Merge pull request #9908 from atorralba/atorralba/xml-inline-exp-test
Java: Add support for XML InlineExpectationsTest
This commit is contained in:
@@ -20,3 +20,15 @@ private class KtExpectationComment extends KtComment, ExpectationComment {
|
|||||||
|
|
||||||
override string getContents() { result = this.getText().suffix(2).trim() }
|
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
java/ql/test/library-tests/xml/Test.java
Normal file
3
java/ql/test/library-tests/xml/Test.java
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
public class Test {
|
||||||
|
|
||||||
|
}
|
||||||
2
java/ql/test/library-tests/xml/XMLTest.expected
Normal file
2
java/ql/test/library-tests/xml/XMLTest.expected
Normal file
@@ -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
java/ql/test/library-tests/xml/XMLTest.ql
Normal file
17
java/ql/test/library-tests/xml/XMLTest.ql
Normal file
@@ -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
java/ql/test/library-tests/xml/test.xml
Normal file
6
java/ql/test/library-tests/xml/test.xml
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<document>
|
||||||
|
<element attribute="value">Text</element> <!-- $ hasXmlResult -->
|
||||||
|
<element attribute="value">Text</element> <!-- Missing -->
|
||||||
|
<element>Text</element> <!-- $ hasXmlResult --> <!-- Spurious -->
|
||||||
|
</document>
|
||||||
Reference in New Issue
Block a user