1+ #[ cfg( test) ]
2+ mod tests {
3+ use crate :: { LuaAstNode , LuaCallExpr , LuaIndexExpr , LuaNameExpr , LuaParser , LuaSyntaxTree , ParserConfig , PathTrait } ;
4+
5+ fn get_tree ( code : & str ) -> LuaSyntaxTree {
6+ let config = ParserConfig :: default ( ) ;
7+ let tree = LuaParser :: parse ( code, config) ;
8+ tree
9+ }
10+
11+
12+ #[ test]
13+ fn test_call_access_path ( ) {
14+ let code = "call.ddd()" ;
15+ let tree = get_tree ( code) ;
16+ let root = tree. get_chunk_node ( ) ;
17+ let call_expr = root. descendants :: < LuaCallExpr > ( ) . next ( ) . unwrap ( ) ;
18+ assert_eq ! ( call_expr. get_access_path( ) . unwrap( ) , "call.ddd" ) ;
19+ }
20+
21+ #[ test]
22+ fn test_call_access_path2 ( ) {
23+ let code = "call[1].aaa.bbb.ccc()" ;
24+ let tree = get_tree ( code) ;
25+ let root = tree. get_chunk_node ( ) ;
26+ let call_expr = root. descendants :: < LuaCallExpr > ( ) . next ( ) . unwrap ( ) ;
27+ assert_eq ! ( call_expr. get_access_path( ) . unwrap( ) , "call.1.aaa.bbb.ccc" ) ;
28+ }
29+
30+ #[ test]
31+ fn test_name_access_path ( ) {
32+ let code = "local a = name" ;
33+ let tree = get_tree ( code) ;
34+ let root = tree. get_chunk_node ( ) ;
35+ let name_expr = root. descendants :: < LuaNameExpr > ( ) . next ( ) . unwrap ( ) ;
36+ assert_eq ! ( name_expr. get_access_path( ) . unwrap( ) , "name" ) ;
37+ }
38+
39+ #[ test]
40+ fn test_index_expr_access_path ( ) {
41+ let code = "local a = name.bbb.ccc" ;
42+ let tree = get_tree ( code) ;
43+ let root = tree. get_chunk_node ( ) ;
44+ let index_expr = root. descendants :: < LuaIndexExpr > ( ) . next ( ) . unwrap ( ) ;
45+ assert_eq ! ( index_expr. get_access_path( ) . unwrap( ) , "name.bbb.ccc" ) ;
46+ }
47+
48+ #[ test]
49+ fn test_index_expr_access_path2 ( ) {
50+ let code = "local a = name[okok.yes]" ;
51+ let tree = get_tree ( code) ;
52+ let root = tree. get_chunk_node ( ) ;
53+ let index_expr = root. descendants :: < LuaIndexExpr > ( ) . next ( ) . unwrap ( ) ;
54+ assert_eq ! ( index_expr. get_access_path( ) . unwrap( ) , "name.[okok.yes]" ) ;
55+ }
56+ }
0 commit comments