11use crate :: executor:: ast:: Expression :: * ;
2- use crate :: executor:: ast:: SourceUnitPart :: Statement ;
2+ use crate :: executor:: ast:: SourceUnitPart :: Statement as Stmt ;
33use crate :: executor:: ast:: Statement :: * ;
44use crate :: executor:: ast:: * ;
55use crate :: lexer:: tokens:: TokenType ;
@@ -28,28 +28,28 @@ fn parser_test() {
2828 println ! ( "{:?}" , parsed) ;
2929 let expected = SourceUnit (
3030 [
31- Statement ( Assignment (
31+ Stmt ( Assignment (
3232 ( 9 , 13 ) ,
3333 Symbol ( ( 9 , 9 ) , TokenType :: Symbol ( 1 ) ) ,
3434 Integer ( ( 11 , 12 ) , TokenType :: Integer ( 0 ) ) ,
3535 ) ) ,
36- Statement ( Conditional (
36+ Stmt ( Conditional (
3737 ( 22 , 126 ) ,
3838 NotEquals (
3939 ( 32 , 43 ) ,
4040 Box :: new ( Symbol ( ( 22 , 22 ) , TokenType :: Symbol ( 1 ) ) ) ,
4141 Box :: new ( Integer ( ( 27 , 28 ) , TokenType :: Integer ( 0 ) ) ) ,
4242 ) ,
4343 SourceUnit (
44- [ Statement ( Assignment (
44+ [ Stmt ( Assignment (
4545 ( 65 , 72 ) ,
4646 Symbol ( ( 65 , 65 ) , TokenType :: Symbol ( 1 ) ) ,
4747 Integer ( ( 69 , 71 ) , TokenType :: Integer ( 10 ) ) ,
4848 ) ) ]
4949 . to_vec ( ) ,
5050 ) ,
5151 Some ( SourceUnit (
52- [ Statement ( Assignment (
52+ [ Stmt ( Assignment (
5353 ( 109 , 116 ) ,
5454 Symbol ( ( 109 , 109 ) , TokenType :: Symbol ( 1 ) ) ,
5555 UnaryMinus (
@@ -60,15 +60,15 @@ fn parser_test() {
6060 . to_vec ( ) ,
6161 ) ) ,
6262 ) ) ,
63- Statement ( Loop (
63+ Stmt ( Loop (
6464 ( 135 , 208 ) ,
6565 NotEquals (
6666 ( 145 , 156 ) ,
6767 Box :: new ( Symbol ( ( 135 , 135 ) , TokenType :: Symbol ( 1 ) ) ) ,
6868 Box :: new ( Integer ( ( 140 , 141 ) , TokenType :: Integer ( 0 ) ) ) ,
6969 ) ,
7070 SourceUnit (
71- [ Statement ( Assignment (
71+ [ Stmt ( Assignment (
7272 ( 190 , 198 ) ,
7373 Symbol ( ( 190 , 190 ) , TokenType :: Symbol ( 1 ) ) ,
7474 Subtract (
@@ -80,9 +80,37 @@ fn parser_test() {
8080 . to_vec ( ) ,
8181 ) ,
8282 ) ) ,
83- Statement ( Write ( ( 217 , 228 ) , Symbol ( ( 217 , 217 ) , TokenType :: Symbol ( 1 ) ) ) ) ,
83+ Stmt ( Write ( ( 217 , 228 ) , Symbol ( ( 217 , 217 ) , TokenType :: Symbol ( 1 ) ) ) ) ,
8484 ]
8585 . to_vec ( ) ,
8686 ) ;
8787 assert_eq ! ( expected, parsed. unwrap( ) ) ;
8888}
89+
90+ #[ test]
91+ fn parser_import_test ( ) {
92+ let code = "
93+ math:operations m ennu ulppeduthuka;
94+ math:utils ulppeduthuka;
95+ " ;
96+ let mut lex = Lexer :: new ( & code, HashMap :: new ( ) , 0 ) ;
97+ let parsed = parse ( & code, & mut lex) ;
98+ assert ! ( parsed. is_ok( ) ) ;
99+
100+ let unit = parsed. unwrap ( ) ;
101+ assert_eq ! ( unit. 0 . len( ) , 2 ) ;
102+
103+ if let SourceUnitPart :: Statement ( Statement :: Import ( _, path, alias) ) = & unit. 0 [ 0 ] {
104+ assert_eq ! ( path. len( ) , 2 ) ;
105+ assert ! ( alias. is_some( ) ) ;
106+ } else {
107+ panic ! ( "Expected import statement with alias" ) ;
108+ }
109+
110+ if let SourceUnitPart :: Statement ( Statement :: Import ( _, path, alias) ) = & unit. 0 [ 1 ] {
111+ assert_eq ! ( path. len( ) , 2 ) ;
112+ assert ! ( alias. is_none( ) ) ;
113+ } else {
114+ panic ! ( "Expected import statement without alias" ) ;
115+ }
116+ }
0 commit comments