Skip to content

Commit 46c414b

Browse files
author
Dave Bartolomeo
committed
C++: Document regular expressions in InlineExpectationsTest
1 parent 1277881 commit 46c414b

File tree

1 file changed

+17
-5
lines changed

1 file changed

+17
-5
lines changed

cpp/ql/test/TestUtilities/InlineExpectationsTest.qll

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -44,11 +44,12 @@
4444
* `// $tag=expected-value`
4545
*
4646
* Where `tag` is the value of the `tag` parameter from `hasActualResult()`, and `expected-value` is
47-
* the value of the `value` parameter from `hasActualResult()`. Multiple expectations may be placed
48-
* in the same comment, as long as each is prefixed by a `$`. Any actual result that appears on a
49-
* line that does not contain a matching expected result comment will be reported with a message of
50-
* the form "Unexpected result: tag=value". Any expected result comment for which there is no
51-
* matching actual result will be reported with a message of the form
47+
* the value of the `value` parameter from `hasActualResult()`. The `=expected-value` portion may be
48+
* omitted, in which case `expected-value` is treated as the empty string. Multiple expectations may
49+
* be placed in the same comment, as long as each is prefixed by a `$`. Any actual result that
50+
* appears on a line that does not contain a matching expected result comment will be reported with
51+
* a message of the form "Unexpected result: tag=value". Any expected result comment for which there
52+
* is no matching actual result will be reported with a message of the form
5253
* "Missing result: tag=expected-value".
5354
*
5455
* Example:
@@ -148,8 +149,19 @@ abstract class InlineExpectationsTest extends string {
148149
}
149150
}
150151

152+
/**
153+
* RegEx pattern to match a comment containing one or more expected results. The comment must be a
154+
* C++-style (`//`) comment with `$` as its first non-whitespace character. Any subsequent character
155+
* is treated as part of the expected results, except that the comment may contain a `//` sequence
156+
* to treat the remainder of the line as a regular (non-interpreted) comment.
157+
*/
151158
private string expectationCommentPattern() { result = "//\\s*(\\$(?:[^/]|/[^/])*)(?://.*)?" }
152159

160+
/**
161+
* RegEx pattern to match a single expected result, not including the leading `$`. It starts with an
162+
* optional `f+:` or `f-:`, followed by one or more comma-separated tags containing only letters,
163+
* `-`, and `_`, optionally followed by `=` and the expected value.
164+
*/
153165
private string expectationPattern() {
154166
result = "(?:(f(?:\\+|-)):)?((?:[A-Za-z-_]+)(?:\\s*,\\s*[A-Za-z-_]+)*)(?:=(.*))?"
155167
}

0 commit comments

Comments
 (0)