@@ -124,6 +124,12 @@ signature module InlineExpectationsTestSig {
124124 bindingset [ relativePath]
125125 string getStartCommentMarker ( string relativePath ) ;
126126
127+ /**
128+ * Holds if a comment can safely be appended at the end of `line` in `relativePath`.
129+ */
130+ bindingset [ relativePath, line]
131+ default predicate canAppendCommentAtEndOfLine ( string relativePath , int line ) { any ( ) }
132+
127133 /**
128134 * Gets the marker that ends a comment (for example `"-->"`) in the source file with the
129135 * given `relativePath`. Has no result by default, which is correct for languages whose
@@ -318,6 +324,7 @@ module Make<InlineExpectationsTestSig Impl> {
318324 parseRelativeUrl ( Impl:: getRelativeUrl ( comment .getLocation ( ) ) , relativePath , resultLine , _,
319325 _, _)
320326 ) and
327+ Impl:: canAppendCommentAtEndOfLine ( relativePath , resultLine ) and
321328 file = relativePath and
322329 line = resultLine and
323330 operation = "append" and
@@ -626,7 +633,8 @@ module Make<InlineExpectationsTestSig Impl> {
626633 ) and
627634 parseRelativeUrl ( Impl:: getRelativeUrl ( actualResult .getLocation ( ) ) , relativePath , line , _,
628635 line , _) and
629- text = actualResult .getExpectationText ( )
636+ text = actualResult .getExpectationText ( ) and
637+ expectationAtomRoundTrips ( actualResult .getTag ( ) , actualResult .getValue ( ) , text )
630638 )
631639 }
632640
@@ -919,6 +927,23 @@ private module ExpectationParser<InlineExpectationsTestSig Impl> {
919927 }
920928}
921929
930+ bindingset [ tag, value, text]
931+ private predicate expectationAtomRoundTrips ( string tag , string value , string text ) {
932+ exists ( string content , string parsedTag , string parsedValue |
933+ content = ( "$ " + text ) .regexpCapture ( expectationCommentPattern ( ) , 1 ) .trim ( ) and
934+ content = text and
935+ content .regexpMatch ( expectationPattern ( ) ) and
936+ parsedTag = content .regexpCapture ( expectationPattern ( ) , 1 ) and
937+ parsedTag = tag and
938+ (
939+ parsedValue = content .regexpCapture ( expectationPattern ( ) , 2 )
940+ or
941+ not exists ( content .regexpCapture ( expectationPattern ( ) , 2 ) ) and parsedValue = ""
942+ ) and
943+ parsedValue = value
944+ )
945+ }
946+
922947/**
923948 * Provides logic for creating a `@kind test-postprocess` query that checks
924949 * inline test expectations using `$ Alert` markers.
@@ -1564,21 +1589,29 @@ module TestPostProcessing {
15641589 }
15651590
15661591 /**
1567- * Renders a current-query atom in its canonical cohort form: bare when every member produces
1568- * it , otherwise qualified with the current query ID.
1592+ * Renders a current-query tag in its canonical cohort form: bare when every member produces
1593+ * the atom , otherwise qualified with the current query ID.
15691594 */
15701595 bindingset [ relativePath, line, tag, value]
1571- private string renderCohortAtom ( string relativePath , int line , string tag , string value ) {
1596+ private string renderCohortTag ( string relativePath , int line , string tag , string value ) {
15721597 (
15731598 not inCohortMode ( )
15741599 or
15751600 isCollapsedAtom ( relativePath , line , tag , value )
15761601 ) and
1577- result = renderAtom ( tag , value )
1602+ result = tag
15781603 or
15791604 inCohortMode ( ) and
15801605 not isCollapsedAtom ( relativePath , line , tag , value ) and
1581- result = renderAtom ( tag + "[" + getQueryId ( ) + "]" , value )
1606+ result = tag + "[" + getQueryId ( ) + "]"
1607+ }
1608+
1609+ /**
1610+ * Renders a current-query atom in its canonical cohort form.
1611+ */
1612+ bindingset [ relativePath, line, tag, value]
1613+ private string renderCohortAtom ( string relativePath , int line , string tag , string value ) {
1614+ result = renderAtom ( renderCohortTag ( relativePath , line , tag , value ) , value )
15821615 }
15831616
15841617 /**
@@ -1699,8 +1732,12 @@ module TestPostProcessing {
16991732 ) and
17001733 parseRelativeUrl ( actualResult .getLocation ( ) .getRelativeUrl ( ) , relativePath , endLine , _,
17011734 endLine , _) and
1702- text =
1703- renderCohortAtom ( relativePath , endLine , actualResult .getTag ( ) , actualResult .getValue ( ) )
1735+ exists ( string renderedTag |
1736+ renderedTag =
1737+ renderCohortTag ( relativePath , endLine , actualResult .getTag ( ) , actualResult .getValue ( ) ) and
1738+ text = renderAtom ( renderedTag , actualResult .getValue ( ) ) and
1739+ expectationAtomRoundTrips ( renderedTag , actualResult .getValue ( ) , text )
1740+ )
17041741 )
17051742 }
17061743
0 commit comments