@@ -41,13 +41,13 @@ pub fn check_block(
4141 Statement :: Block ( stmts) => {
4242 let mut block_env = env. clone ( ) ;
4343 block_env. push ( ) ;
44-
44+
4545 for s in stmts {
4646 block_env = check_stmt ( s, & block_env) ?;
47- }
48- block_env. pop ( ) ;
47+ }
48+ block_env. pop ( ) ;
4949 Ok ( block_env)
50- }
50+ }
5151 _ => Err ( "Expected a block statement" . to_string ( ) ) ,
5252 }
5353}
@@ -354,7 +354,10 @@ fn check_test_function_stmt(
354354 env : & Environment < Type > ,
355355) -> Result < Environment < Type > , ErrorMessage > {
356356 if env. lookup_test ( & function. name ) . is_some ( ) {
357- return Err ( format ! ( "[Type Error] Test function '{}' already exists." , function. name) ) ;
357+ return Err ( format ! (
358+ "[Type Error] Test function '{}' already exists." ,
359+ function. name
360+ ) ) ;
358361 }
359362 if !function. params . is_empty ( ) {
360363 return Err ( "[Type Error] Test functions must not have parameters." . into ( ) ) ;
@@ -408,7 +411,7 @@ fn merge_environments(
408411 }
409412 }
410413 }
411-
414+
412415 //TODO: should we merge ADTs and functions?
413416
414417 Ok ( merged)
@@ -996,7 +999,7 @@ mod tests {
996999 //TODO: Apresentar TypeChecker de TestDef (Testes)
9971000 mod testdef_tests {
9981001 use super :: * ;
999-
1002+
10001003 #[ test]
10011004 fn test_check_valid_test_function ( ) {
10021005 let env: Environment < Type > = Environment :: new ( ) ;
@@ -1010,16 +1013,16 @@ mod tests {
10101013 Statement :: AssertEQ (
10111014 Box :: new( Expression :: Add (
10121015 Box :: new( Expression :: Var ( "a" . to_string( ) ) ) ,
1013- Box :: new( Expression :: Var ( "b" . to_string( ) ) )
1016+ Box :: new( Expression :: Var ( "b" . to_string( ) ) ) ,
10141017 ) ) ,
10151018 Box :: new( Expression :: CInt ( 15 ) ) ,
1016- Box :: new( Expression :: CString ( "A soma deveria ser 15" . to_string( ) ) )
1017- )
1019+ Box :: new( Expression :: CString ( "A soma deveria ser 15" . to_string( ) ) ) ,
1020+ ) ,
10181021 ] ) ) ) ,
10191022 } ) ;
10201023 assert ! ( check_stmt( stmt, & env) . is_ok( ) ) ;
10211024 }
1022-
1025+
10231026 #[ test]
10241027 fn test_check_test_function_with_params ( ) {
10251028 let env: Environment < Type > = Environment :: new ( ) ;
@@ -1032,43 +1035,49 @@ mod tests {
10321035
10331036 assert ! ( check_stmt( stmt. clone( ) , & env) . is_err( ) ) ;
10341037
1035- let error = match check_stmt ( stmt, & env) {
1038+ let error = match check_stmt ( stmt, & env) {
10361039 Ok ( _) => "Expected an error, but got Ok" . to_string ( ) ,
10371040 Err ( error) => error,
10381041 } ;
10391042
1040- assert_eq ! ( error, "[Type Error] Test functions must not have parameters." . to_string( ) ) ;
1043+ assert_eq ! (
1044+ error,
1045+ "[Type Error] Test functions must not have parameters." . to_string( )
1046+ ) ;
10411047 }
10421048
10431049 #[ test]
10441050 fn test_check_test_function_with_non_void_return ( ) {
10451051 let env: Environment < Type > = Environment :: new ( ) ;
10461052 let stmt = TestDef ( Function {
10471053 name : "invalid_function" . to_string ( ) ,
1048- kind : Type :: TInteger , // Must be TVoid!
1054+ kind : Type :: TInteger , // Must be TVoid!
10491055 params : vec ! [ ] ,
10501056 body : Some ( Box :: new ( Block ( vec ! [
10511057 Statement :: VarDeclaration ( "a" . to_string( ) , Box :: new( Expression :: CInt ( 10 ) ) ) ,
10521058 Statement :: VarDeclaration ( "b" . to_string( ) , Box :: new( Expression :: CInt ( 5 ) ) ) ,
10531059 Statement :: AssertEQ (
10541060 Box :: new( Expression :: Add (
10551061 Box :: new( Expression :: Var ( "a" . to_string( ) ) ) ,
1056- Box :: new( Expression :: Var ( "b" . to_string( ) ) )
1062+ Box :: new( Expression :: Var ( "b" . to_string( ) ) ) ,
10571063 ) ) ,
10581064 Box :: new( Expression :: CInt ( 15 ) ) ,
1059- Box :: new( Expression :: CString ( "A soma deveria ser 15" . to_string( ) ) )
1060- )
1065+ Box :: new( Expression :: CString ( "A soma deveria ser 15" . to_string( ) ) ) ,
1066+ ) ,
10611067 ] ) ) ) ,
10621068 } ) ;
1063-
1069+
10641070 assert ! ( check_stmt( stmt. clone( ) , & env) . is_err( ) ) ;
10651071
1066- let error = match check_stmt ( stmt, & env) {
1072+ let error = match check_stmt ( stmt, & env) {
10671073 Ok ( _) => "Expected an error, but got Ok" . to_string ( ) ,
10681074 Err ( error) => error,
10691075 } ;
10701076
1071- assert_eq ! ( error, "[Type Error] Test functions must return void." . to_string( ) ) ;
1077+ assert_eq ! (
1078+ error,
1079+ "[Type Error] Test functions must return void." . to_string( )
1080+ ) ;
10721081 }
10731082
10741083 #[ test]
@@ -1084,16 +1093,16 @@ mod tests {
10841093 Statement :: AssertEQ (
10851094 Box :: new( Expression :: Add (
10861095 Box :: new( Expression :: Var ( "a" . to_string( ) ) ) ,
1087- Box :: new( Expression :: Var ( "b" . to_string( ) ) )
1096+ Box :: new( Expression :: Var ( "b" . to_string( ) ) ) ,
10881097 ) ) ,
10891098 Box :: new( Expression :: CInt ( 15 ) ) ,
1090- Box :: new( Expression :: CString ( "A soma deveria ser 15" . to_string( ) ) )
1091- )
1099+ Box :: new( Expression :: CString ( "A soma deveria ser 15" . to_string( ) ) ) ,
1100+ ) ,
10921101 ] ) ) ) ,
10931102 } ) ;
1094-
1103+
10951104 env = check_stmt ( first_func, & env) . unwrap ( ) ;
1096-
1105+
10971106 let stmt = TestDef ( Function {
10981107 name : "duplicate" . to_string ( ) ,
10991108 kind : Type :: TVoid ,
@@ -1104,22 +1113,25 @@ mod tests {
11041113 Statement :: AssertEQ (
11051114 Box :: new( Expression :: Add (
11061115 Box :: new( Expression :: Var ( "a" . to_string( ) ) ) ,
1107- Box :: new( Expression :: Var ( "b" . to_string( ) ) )
1116+ Box :: new( Expression :: Var ( "b" . to_string( ) ) ) ,
11081117 ) ) ,
11091118 Box :: new( Expression :: CInt ( 15 ) ) ,
1110- Box :: new( Expression :: CString ( "A soma deveria ser 15" . to_string( ) ) )
1111- )
1119+ Box :: new( Expression :: CString ( "A soma deveria ser 15" . to_string( ) ) ) ,
1120+ ) ,
11121121 ] ) ) ) ,
11131122 } ) ;
1114-
1123+
11151124 assert ! ( check_stmt( stmt. clone( ) , & env) . is_err( ) ) ;
11161125
1117- let error = match check_stmt ( stmt, & env) {
1126+ let error = match check_stmt ( stmt, & env) {
11181127 Ok ( _) => "Expected an error, but got Ok" . to_string ( ) ,
11191128 Err ( error) => error,
11201129 } ;
11211130
1122- assert_eq ! ( error, "[Type Error] Test function 'duplicate' already exists." . to_string( ) ) ;
1131+ assert_eq ! (
1132+ error,
1133+ "[Type Error] Test function 'duplicate' already exists." . to_string( )
1134+ ) ;
11231135 }
11241136 }
11251137}
0 commit comments