@@ -192,40 +192,30 @@ private int getEndOfColumnPosition(int start, string content) {
192192 result = content .length ( )
193193}
194194
195- private string getAnExpectation ( LineComment comment , TColumn column ) {
195+ private predicate getAnExpectation (
196+ LineComment comment , TColumn column , string expectation , string tags , string value
197+ ) {
196198 exists ( string content |
197199 content = comment .getContents ( ) .regexpCapture ( expectationCommentPattern ( ) , 1 ) and
198200 (
199201 column = TDefaultColumn ( ) and
200202 exists ( int end |
201203 end = getEndOfColumnPosition ( 0 , content ) and
202- result = content .prefix ( end ) .splitAt ( " " ) .trim ( )
204+ expectation = content .prefix ( end ) .regexpFind ( expectationPattern ( ) , _ , _ ) .trim ( )
203205 )
204206 or
205207 exists ( string name , int start , int end |
206208 column = TNamedColumn ( name ) and
207209 start = content .indexOf ( name + ":" ) + name .length ( ) + 1 and
208210 end = getEndOfColumnPosition ( start , content ) and
209- result = content .substring ( start , end ) .splitAt ( " " ) .trim ( )
211+ expectation = content .substring ( start , end ) .regexpFind ( expectationPattern ( ) , _ , _ ) .trim ( )
210212 )
211- ) and
212- result != ""
213- )
214- }
215-
216- bindingset [ expectation]
217- private string getATag ( string expectation ) {
218- (
219- result = expectation .prefix ( expectation .indexOf ( "=" ) ) .splitAt ( "," ) .trim ( )
220- or
221- not exists ( expectation .indexOf ( "=" ) ) and
222- result = expectation .splitAt ( "," ) .trim ( )
223- )
224- }
225-
226- bindingset [ expectation]
227- private string getValueForTag ( string expectation ) {
228- result = expectation .suffix ( expectation .indexOf ( "=" ) + 1 )
213+ )
214+ ) and
215+ tags = expectation .regexpCapture ( expectationPattern ( ) , 1 ) and
216+ if exists ( expectation .regexpCapture ( expectationPattern ( ) , 2 ) )
217+ then value = expectation .regexpCapture ( expectationPattern ( ) , 2 )
218+ else value = ""
229219}
230220
231221private string getColumnString ( TColumn column ) {
@@ -236,11 +226,16 @@ private string getColumnString(TColumn column) {
236226
237227/**
238228 * RegEx pattern to match a single expected result, not including the leading `$`. It consists of one or
239- * more comma-separated tags containing only letters, `-`, and `_`, optionally followed by `=` and the
240- * expected value.
229+ * more comma-separated tags containing only letters, digits, `-` and `_` (note that the first character
230+ * must not be a digit), optionally followed by `=` and the expected value.
241231 */
242232private string expectationPattern ( ) {
243- result = "((?:[A-Za-z-_]+)(?:\\s*,\\s*[A-Za-z-_]+)*)(?:=(.*))?"
233+ exists ( string tag , string tags , string value |
234+ tag = "[A-Za-z-_][A-Za-z-_0-9]*" and
235+ tags = "((?:" + tag + ")(?:\\s*,\\s*" + tag + ")*)" and
236+ value = "((?:\"[^\"]*\"|\\S+)*)" and
237+ result = tags + "(?:=" + value + ")?"
238+ )
244239}
245240
246241private newtype TFailureLocatable =
@@ -250,19 +245,14 @@ private newtype TFailureLocatable =
250245 test .hasActualResult ( location , element , tag , value )
251246 } or
252247 TValidExpectation ( LineComment comment , string tag , string value , string knownFailure ) {
253- exists ( string expectation , TColumn column |
254- expectation = getAnExpectation ( comment , column ) and
255- tag = getATag ( expectation ) and
256- (
257- if exists ( getValueForTag ( expectation ) )
258- then value = getValueForTag ( expectation )
259- else value = ""
260- ) and
248+ exists ( TColumn column , string tags |
249+ getAnExpectation ( comment , column , _, tags , value ) and
250+ tag = tags .splitAt ( "," ) and
261251 knownFailure = getColumnString ( column )
262252 )
263253 } or
264254 TInvalidExpectation ( LineComment comment , string expectation ) {
265- expectation = getAnExpectation ( comment , _) and
255+ getAnExpectation ( comment , _ , expectation , _ , _) and
266256 not expectation .regexpMatch ( expectationPattern ( ) )
267257 }
268258
0 commit comments