@@ -91,6 +91,18 @@ fn assert_ssr_transforms(rules: &[&str], input: &str, result: &str) {
9191 }
9292}
9393
94+ fn print_match_debug_info ( match_finder : & MatchFinder , file_id : FileId , snippet : & str ) {
95+ let debug_info = match_finder. debug_where_text_equal ( file_id, snippet) ;
96+ println ! (
97+ "Match debug info: {} nodes had text exactly equal to '{}'" ,
98+ debug_info. len( ) ,
99+ snippet
100+ ) ;
101+ for ( index, d) in debug_info. iter ( ) . enumerate ( ) {
102+ println ! ( "Node #{}\n {:#?}\n " , index, d) ;
103+ }
104+ }
105+
94106fn assert_matches ( pattern : & str , code : & str , expected : & [ & str ] ) {
95107 let ( db, file_id) = single_file ( code) ;
96108 let mut match_finder = MatchFinder :: new ( & db) ;
@@ -103,17 +115,20 @@ fn assert_matches(pattern: &str, code: &str, expected: &[&str]) {
103115 . map ( |m| m. matched_text ( ) )
104116 . collect ( ) ;
105117 if matched_strings != expected && !expected. is_empty ( ) {
106- let debug_info = match_finder. debug_where_text_equal ( file_id, & expected[ 0 ] ) ;
107- eprintln ! ( "Test is about to fail. Some possibly useful info: {} nodes had text exactly equal to '{}'" , debug_info. len( ) , & expected[ 0 ] ) ;
108- for d in debug_info {
109- eprintln ! ( "{:#?}" , d) ;
110- }
118+ print_match_debug_info ( & match_finder, file_id, & expected[ 0 ] ) ;
111119 }
112120 assert_eq ! ( matched_strings, expected) ;
113121}
114122
115123fn assert_no_match ( pattern : & str , code : & str ) {
116- assert_matches ( pattern, code, & [ ] ) ;
124+ let ( db, file_id) = single_file ( code) ;
125+ let mut match_finder = MatchFinder :: new ( & db) ;
126+ match_finder. add_search_pattern ( pattern. parse ( ) . unwrap ( ) ) ;
127+ let matches = match_finder. find_matches_in_file ( file_id) . flattened ( ) . matches ;
128+ if !matches. is_empty ( ) {
129+ print_match_debug_info ( & match_finder, file_id, & matches[ 0 ] . matched_text ( ) ) ;
130+ panic ! ( "Got {} matches when we expected none: {:#?}" , matches. len( ) , matches) ;
131+ }
117132}
118133
119134fn assert_match_failure_reason ( pattern : & str , code : & str , snippet : & str , expected_reason : & str ) {
0 commit comments