Skip to content

Commit 3ecc4eb

Browse files
committed
Made cargo fmt
1 parent a8d0f5b commit 3ecc4eb

File tree

3 files changed

+79
-65
lines changed

3 files changed

+79
-65
lines changed

src/interpreter/statement_execute.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1145,7 +1145,7 @@ mod tests {
11451145
assert_eq!(computation, "assertfalse fail".to_string());
11461146
}
11471147
}
1148-
1148+
11491149
//TODO: Apresentar Interpretador TestDef (Tests)
11501150
mod testdef_statement_tests {
11511151
use super::*;

src/parser/parser_stmt.rs

Lines changed: 35 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ pub fn parse_statement(input: &str) -> IResult<&str, Statement> {
3333
parse_assertneq_statement,
3434
parse_assertfalse_statement,
3535
parse_asserttrue_statement,
36-
parse_test_function_definition_statement,
36+
parse_test_function_definition_statement,
3737
parse_function_definition_statement,
3838
))(input)
3939
}
@@ -310,7 +310,7 @@ fn parse_test_function_definition_statement(input: &str) -> IResult<&str, Statem
310310
preceded(multispace1, identifier),
311311
delimited(
312312
char::<&str, Error<&str>>(LEFT_PAREN),
313-
multispace0,
313+
multispace0,
314314
char::<&str, Error<&str>>(RIGHT_PAREN),
315315
),
316316
parse_block,
@@ -420,8 +420,6 @@ mod tests {
420420
assert_eq!(parsed, expected);
421421
}
422422

423-
424-
425423
#[test]
426424
#[ignore]
427425
fn test_parse_function_definition_statement() {
@@ -480,7 +478,7 @@ mod tests {
480478
//TODO: Apresentar Parser de TestDef (Testes)
481479
mod testdef_tests {
482480
use super::*;
483-
481+
484482
#[test]
485483
fn test_parse_test_function_definition_statement_valid() {
486484
let input = "test test_example(): x = 1; end";
@@ -577,7 +575,7 @@ mod tests {
577575
);
578576
}
579577
}
580-
578+
581579
//TODO: Apresentar Parser de Asserts (Testes)
582580
mod assert_tests {
583581
use super::*;
@@ -645,12 +643,13 @@ mod tests {
645643
#[test]
646644
fn test_parse_assert_statement_invalid_argnumber() {
647645
let input = "assert(False, False, \"should be false\")";
648-
649-
let result = std::panic::catch_unwind(|| {
650-
parse_assert_statement(input)
651-
});
652646

653-
assert!(result.is_err(), "Expected panic for invalid number of arguments");
647+
let result = std::panic::catch_unwind(|| parse_assert_statement(input));
648+
649+
assert!(
650+
result.is_err(),
651+
"Expected panic for invalid number of arguments"
652+
);
654653

655654
if let Err(err) = result {
656655
if let Some(s) = err.downcast_ref::<&str>() {
@@ -666,12 +665,13 @@ mod tests {
666665
#[test]
667666
fn test_parse_asserteq_statement_invalid_argnumber() {
668667
let input = "asserteq(1, 2, 3, \"msg\")";
669-
670-
let result = std::panic::catch_unwind(|| {
671-
parse_asserteq_statement(input)
672-
});
673668

674-
assert!(result.is_err(), "Expected panic for invalid number of arguments");
669+
let result = std::panic::catch_unwind(|| parse_asserteq_statement(input));
670+
671+
assert!(
672+
result.is_err(),
673+
"Expected panic for invalid number of arguments"
674+
);
675675

676676
if let Err(err) = result {
677677
if let Some(s) = err.downcast_ref::<&str>() {
@@ -687,12 +687,13 @@ mod tests {
687687
#[test]
688688
fn test_parse_assertneq_statement_invalid_argnumber() {
689689
let input = "assertneq(3, 4, 5, \"fail\")";
690-
691-
let result = std::panic::catch_unwind(|| {
692-
parse_assertneq_statement(input)
693-
});
694690

695-
assert!(result.is_err(), "Expected panic for invalid number of arguments");
691+
let result = std::panic::catch_unwind(|| parse_assertneq_statement(input));
692+
693+
assert!(
694+
result.is_err(),
695+
"Expected panic for invalid number of arguments"
696+
);
696697

697698
if let Err(err) = result {
698699
if let Some(s) = err.downcast_ref::<&str>() {
@@ -708,12 +709,13 @@ mod tests {
708709
#[test]
709710
fn test_parse_asserttrue_statement_invalid_argnumber() {
710711
let input = "asserttrue(True, True, \"should be true\")";
711-
712-
let result = std::panic::catch_unwind(|| {
713-
parse_asserttrue_statement(input)
714-
});
715712

716-
assert!(result.is_err(), "Expected panic for invalid number of arguments");
713+
let result = std::panic::catch_unwind(|| parse_asserttrue_statement(input));
714+
715+
assert!(
716+
result.is_err(),
717+
"Expected panic for invalid number of arguments"
718+
);
717719

718720
if let Err(err) = result {
719721
if let Some(s) = err.downcast_ref::<&str>() {
@@ -729,12 +731,13 @@ mod tests {
729731
#[test]
730732
fn test_parse_assertfalse_statement_invalid_argnumber() {
731733
let input = "assertfalse(False, False, \"should be false\")";
732-
733-
let result = std::panic::catch_unwind(|| {
734-
parse_assertfalse_statement(input)
735-
});
736734

737-
assert!(result.is_err(), "Expected panic for invalid number of arguments");
735+
let result = std::panic::catch_unwind(|| parse_assertfalse_statement(input));
736+
737+
assert!(
738+
result.is_err(),
739+
"Expected panic for invalid number of arguments"
740+
);
738741
if let Err(err) = result {
739742
if let Some(s) = err.downcast_ref::<&str>() {
740743
assert_eq!(*s, "AssertFalse statement requires exactly 2 arguments");
@@ -745,6 +748,5 @@ mod tests {
745748
}
746749
}
747750
}
748-
749751
}
750-
}
752+
}

src/type_checker/statement_type_checker.rs

Lines changed: 43 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)