@@ -94,6 +94,7 @@ pub fn iterate_assertions(
9494 let mut actual_highlights = Vec :: < & String > :: new ( ) ;
9595 for Assertion {
9696 position,
97+ negative,
9798 expected_capture_name : expected_highlight,
9899 } in assertions
99100 {
@@ -117,12 +118,13 @@ pub fn iterate_assertions(
117118 break ' highlight_loop;
118119 }
119120
120- // If the highlight matches the assertion, this test passes. Otherwise,
121+ // If the highlight matches the assertion, or if the highlight doesn't
122+ // match the assertion but it's negative, this test passes. Otherwise,
121123 // add this highlight to the list of actual highlights that span the
122124 // assertion's position, in order to generate an error message in the event
123125 // of a failure.
124126 let highlight_name = & highlight_names[ ( highlight. 2 ) . 0 ] ;
125- if * highlight_name == * expected_highlight {
127+ if ( * highlight_name == * expected_highlight) == !negative {
126128 passed = true ;
127129 break ' highlight_loop;
128130 } else {
@@ -162,68 +164,7 @@ pub fn test_highlight(
162164 let assertions =
163165 parse_position_comments ( highlighter. parser ( ) , highlight_config. language , source) ?;
164166
165- iterate_assertions ( & assertions, & highlights, & highlight_names) ?;
166-
167- // Iterate through all of the highlighting assertions, checking each one against the
168- // actual highlights.
169- let mut i = 0 ;
170- let mut actual_highlights = Vec :: < & String > :: new ( ) ;
171- for Assertion {
172- position,
173- expected_capture_name : expected_highlight,
174- } in & assertions
175- {
176- let mut passed = false ;
177- actual_highlights. clear ( ) ;
178-
179- ' highlight_loop: loop {
180- // The assertions are ordered by position, so skip past all of the highlights that
181- // end at or before this assertion's position.
182- if let Some ( highlight) = highlights. get ( i) {
183- if highlight. 1 <= * position {
184- i += 1 ;
185- continue ;
186- }
187-
188- // Iterate through all of the highlights that start at or before this assertion's,
189- // position, looking for one that matches the assertion.
190- let mut j = i;
191- while let ( false , Some ( highlight) ) = ( passed, highlights. get ( j) ) {
192- if highlight. 0 > * position {
193- break ' highlight_loop;
194- }
195-
196- // If the highlight matches the assertion, this test passes. Otherwise,
197- // add this highlight to the list of actual highlights that span the
198- // assertion's position, in order to generate an error message in the event
199- // of a failure.
200- let highlight_name = & highlight_names[ ( highlight. 2 ) . 0 ] ;
201- if * highlight_name == * expected_highlight {
202- passed = true ;
203- break ' highlight_loop;
204- } else {
205- actual_highlights. push ( highlight_name) ;
206- }
207-
208- j += 1 ;
209- }
210- } else {
211- break ;
212- }
213- }
214-
215- if !passed {
216- return Err ( Failure {
217- row : position. row ,
218- column : position. column ,
219- expected_highlight : expected_highlight. clone ( ) ,
220- actual_highlights : actual_highlights. into_iter ( ) . cloned ( ) . collect ( ) ,
221- }
222- . into ( ) ) ;
223- }
224- }
225-
226- Ok ( assertions. len ( ) )
167+ iterate_assertions ( & assertions, & highlights, & highlight_names)
227168}
228169
229170pub fn get_highlight_positions (
0 commit comments