@@ -148,10 +148,9 @@ static NOOP_OP: ScopeStackOp = ScopeStackOp::Noop;
148148impl < ' a > Iterator for ScopeRegionIterator < ' a > {
149149 type Item = ( & ' a str , & ' a ScopeStackOp ) ;
150150 fn next ( & mut self ) -> Option < Self :: Item > {
151- let next_str_i = if self . index >= self . ops . len ( ) {
152- if self . last_str_index >= self . line . len ( ) {
153- return None ;
154- }
151+ let next_str_i = if self . index > self . ops . len ( ) {
152+ return None ;
153+ } else if self . index == self . ops . len ( ) {
155154 self . line . len ( )
156155 } else {
157156 self . ops [ self . index ] . 0
@@ -219,4 +218,27 @@ mod tests {
219218 }
220219 assert_eq ! ( token_count, 5 ) ;
221220 }
221+
222+ #[ test]
223+ fn can_find_regions_with_trailing_newline ( ) {
224+ let ss = SyntaxSet :: load_defaults_newlines ( ) ;
225+ let mut state = ParseState :: new ( ss. find_syntax_by_extension ( "rb" ) . unwrap ( ) ) ;
226+ let lines = [ "# hello world\n " , "lol=5+2\n " ] ;
227+ let mut stack = ScopeStack :: new ( ) ;
228+
229+ for line in lines. iter ( ) {
230+ let ops = state. parse_line ( & line) ;
231+ println ! ( "{:?}" , ops) ;
232+
233+ let mut iterated_ops: Vec < & ScopeStackOp > = Vec :: new ( ) ;
234+ for ( _, op) in ScopeRegionIterator :: new ( & ops, & line) {
235+ stack. apply ( op) ;
236+ iterated_ops. push ( & op) ;
237+ println ! ( "{:?}" , op) ;
238+ }
239+
240+ let all_ops: Vec < & ScopeStackOp > = ops. iter ( ) . map ( |t|& t. 1 ) . collect ( ) ;
241+ assert_eq ! ( all_ops. len( ) , iterated_ops. len( ) - 1 ) ; // -1 because we want to ignore the NOOP
242+ }
243+ }
222244}
0 commit comments