@@ -61,20 +61,27 @@ private static void assertDeclarations(String file, String title, String... pred
6161 private static void assertPredicatePosition (SourcePosition position , Path file , String source , String predicate )
6262 throws IOException {
6363 assertNotNull (position , "Missing refinement declaration position" );
64- int start = source .indexOf ("\" " + predicate + "\" " ) + 1 ;
65- assertTrue (start > 0 , "Predicate not found in fixture: " + predicate );
66- assertEquals (start , position .getSourceStart ());
67- assertEquals (start + predicate .length () - 1 , position .getSourceEnd ());
64+ assertTrue (position .isValidPosition (), "Invalid refinement declaration position" );
65+ int start = position .getSourceStart ();
66+ int end = position .getSourceEnd ();
67+ assertTrue (start > 0 && end >= start && end + 1 < source .length (), "Declaration outside source bounds" );
68+ assertEquals (predicate .length (), end - start + 1 );
69+ assertEquals ('"' , source .charAt (start - 1 ));
70+ assertEquals ('"' , source .charAt (end + 1 ));
6871 assertEquals (file , position .getFile ().toPath ().toRealPath ());
6972 }
7073
7174 private static void assertPredicateUnderline (LJError error , String predicate ) {
7275 String output = error .toString ().replaceAll ("\u001B \\ [[;\\ d]*m" , "" );
73- String heading = "--> Refinement declared here: \n " ;
74- assertTrue ( output .contains ( heading ), "Missing refinement declaration snippet" );
75- String snippet = output . substring ( output . indexOf ( heading ) + heading . length ()) ;
76- String indent = " " .repeat (error . getDeclarationPosition () .getColumn () - 1 );
76+ SourcePosition position = error . getDeclarationPosition () ;
77+ List < String > lines = output .lines (). toList ( );
78+ String sourceLine = position . getLine ( ) + " | " ;
79+ String indent = " " .repeat (position .getColumn () - 1 );
7780 String underline = "^" .repeat (predicate .length ());
78- assertTrue (snippet .contains (indent + underline + "\n " ), snippet );
81+ for (int i = 0 ; i + 1 < lines .size (); i ++) {
82+ if (lines .get (i ).stripLeading ().startsWith (sourceLine ) && lines .get (i + 1 ).endsWith (indent + underline ))
83+ return ;
84+ }
85+ fail ("Missing predicate underline:\n " + output );
7986 }
8087}
0 commit comments