@@ -210,7 +210,7 @@ impl<'a> Node<'a> {
210210
211211 /// Return the rightmost token in the subtree of this node
212212 /// this is not tree-sitter's API
213- pub fn last_token ( & self ) -> Option < Node < ' a > > {
213+ pub fn last_node ( & self ) -> Option < Node < ' a > > {
214214 match & self . node_or_token {
215215 NodeOrToken :: Node ( node) => node. last_token ( ) . map ( |token| Node {
216216 input : self . input ,
568568 }
569569
570570 #[ test]
571- fn test_last_token_returns_rightmost_token ( ) {
571+ fn test_last_node_returns_rightmost_node ( ) {
572572 let src = "SELECT u.*, (v).id, name;" ;
573573 let tree = parse ( src) . unwrap ( ) ;
574574 let root = tree. root_node ( ) ;
@@ -578,24 +578,24 @@ from
578578 . find ( |node| node. kind ( ) == SyntaxKind :: target_list)
579579 . expect ( "should find target_list" ) ;
580580
581- // last token of the target_list is returned
582- let last_token = target_list. last_token ( ) . expect ( "should have last token " ) ;
583- assert_eq ! ( last_token . text( ) , "name" ) ;
581+ // last node of the target_list is returned
582+ let last_node = target_list. last_node ( ) . expect ( "should have last node " ) ;
583+ assert_eq ! ( last_node . text( ) , "name" ) ;
584584
585585 let target_els = target_list
586586 . children ( )
587587 . into_iter ( )
588588 . filter ( |node| node. kind ( ) == SyntaxKind :: target_el)
589589 . collect :: < Vec < _ > > ( ) ;
590590
591- let mut last_tokens = target_els
591+ let mut last_nodes = target_els
592592 . iter ( )
593- . map ( |node| node. last_token ( ) . expect ( "should have last token " ) ) ;
593+ . map ( |node| node. last_node ( ) . expect ( "should have last node " ) ) ;
594594
595- // last token of each target_el is returned
596- assert_eq ! ( last_tokens . next( ) . unwrap( ) . text( ) , "*" ) ;
597- assert_eq ! ( last_tokens . next( ) . unwrap( ) . text( ) , "id" ) ;
598- assert_eq ! ( last_tokens . next( ) . unwrap( ) . text( ) , "name" ) ;
599- assert ! ( last_tokens . next( ) . is_none( ) ) ;
595+ // last node of each target_el is returned
596+ assert_eq ! ( last_nodes . next( ) . unwrap( ) . text( ) , "*" ) ;
597+ assert_eq ! ( last_nodes . next( ) . unwrap( ) . text( ) , "id" ) ;
598+ assert_eq ! ( last_nodes . next( ) . unwrap( ) . text( ) , "name" ) ;
599+ assert ! ( last_nodes . next( ) . is_none( ) ) ;
600600 }
601601}
0 commit comments