Skip to content

Commit 8f026b1

Browse files
committed
Allow inline expectation comments in more file formats
1 parent c3a0b65 commit 8f026b1

1 file changed

Lines changed: 42 additions & 4 deletions

File tree

csharp/ql/lib/utils/test/internal/InlineExpectationsTestImpl.qll

Lines changed: 42 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,51 @@
11
private import csharp as CS
2+
private import semmle.code.asp.AspNet as ASP
23
private import codeql.util.test.InlineExpectationsTest
34

45
module Impl implements InlineExpectationsTestSig {
6+
private newtype TExpectationComment =
7+
TCSharpComment(CS::SinglelineComment c) or
8+
TXmlComment(CS::XmlComment c) or
9+
TAspComment(ASP::AspComment c)
10+
511
/**
6-
* A class representing line comments in C# used by the InlineExpectations core code
12+
* A class representing comments that may contain inline expectations.
13+
* Supports C# single-line comments (`//`), XML comments (`<!-- -->`), and
14+
* ASP.NET comments (`<!-- -->` and `<%-- --%>`) in their respective file types.
715
*/
8-
class ExpectationComment extends CS::SinglelineComment {
9-
/** Gets the contents of the given comment, _without_ the preceding comment marker (`//`). */
10-
string getContents() { result = this.getText() }
16+
class ExpectationComment extends TExpectationComment {
17+
CS::SinglelineComment asCSharpComment() { this = TCSharpComment(result) }
18+
19+
CS::XmlComment asXmlComment() { this = TXmlComment(result) }
20+
21+
ASP::AspComment asAspComment() { this = TAspComment(result) }
22+
23+
/** Gets the contents of this comment, _without_ the preceding comment marker. */
24+
string getContents() {
25+
result = this.asCSharpComment().getText()
26+
or
27+
result = this.asXmlComment().getText()
28+
or
29+
result = this.asAspComment().getBody()
30+
}
31+
32+
/** Gets the location of this comment. */
33+
Location getLocation() {
34+
result = this.asCSharpComment().getLocation()
35+
or
36+
result = this.asXmlComment().getLocation()
37+
or
38+
result = this.asAspComment().getLocation()
39+
}
40+
41+
/** Gets a textual representation of this comment. */
42+
string toString() {
43+
result = this.asCSharpComment().toString()
44+
or
45+
result = this.asXmlComment().toString()
46+
or
47+
result = this.asAspComment().toString()
48+
}
1149
}
1250

1351
class Location = CS::Location;

0 commit comments

Comments
 (0)