Skip to content

Commit a282efc

Browse files
committed
Rust: Add inline test expectations library
1 parent 1d6626c commit a282efc

File tree

5 files changed

+32
-4
lines changed

5 files changed

+32
-4
lines changed

rust/ql/.generated.list

Lines changed: 0 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

rust/ql/.gitattributes

Lines changed: 0 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

rust/ql/lib/codeql/rust/elements/internal/CommentImpl.qll

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
// generated by codegen, remove this comment if you wish to edit this file
21
/**
32
* This module provides a hand-modifiable wrapper around the generated class `Comment`.
43
*
@@ -12,12 +11,20 @@ private import codeql.rust.elements.internal.generated.Comment
1211
* be referenced directly.
1312
*/
1413
module Impl {
14+
// the following QLdoc is generated: if you need to edit it, do it in the schema file
1515
/**
1616
* A comment. For example:
1717
* ```rust
1818
* // this is a comment
1919
* /// This is a doc comment
2020
* ```
2121
*/
22-
class Comment extends Generated::Comment { }
22+
class Comment extends Generated::Comment {
23+
/**
24+
* Gets the text of this comment, excluding the comment marker.
25+
*/
26+
string getCommentText() {
27+
exists(string s | s = this.getText() | result = s.regexpCapture("///?\\s*(.*)", 1))
28+
}
29+
}
2330
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
/**
2+
* Inline expectation tests for Rust.
3+
* See `shared/util/codeql/util/test/InlineExpectationsTest.qll`
4+
*/
5+
6+
private import codeql.util.test.InlineExpectationsTest
7+
private import internal.InlineExpectationsTestImpl
8+
import Make<Impl>
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
private import rust as R
2+
private import R
3+
private import codeql.util.test.InlineExpectationsTest
4+
5+
module Impl implements InlineExpectationsTestSig {
6+
/**
7+
* A class representing line comments in C# used by the InlineExpectations core code
8+
*/
9+
class ExpectationComment extends R::Comment {
10+
/** Gets the contents of the given comment, _without_ the preceding comment marker (`//`). */
11+
string getContents() { result = this.getCommentText() }
12+
}
13+
14+
class Location = R::Location;
15+
}

0 commit comments

Comments
 (0)