Skip to content

Commit

Permalink
refactor: test_amber
Browse files Browse the repository at this point in the history
  • Loading branch information
Ph0enixKM committed Dec 11, 2024
1 parent 4377b57 commit 635e21d
Showing 1 changed file with 17 additions and 12 deletions.
29 changes: 17 additions & 12 deletions src/tests/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,21 +26,26 @@ pub fn eval_amber_code(code: &str) -> Result<String, Message> {

/// Tests script output in case of success or failure
pub fn test_amber(code: &str, result: &str, target: TestOutcomeTarget) {
let evaluated = eval_amber_code(code);
match target {
TestOutcomeTarget::Success => {
match eval_amber_code(code) {
Ok(eval_result) => assert_eq!(
eval_result.trim_end_matches('\n'),
TestOutcomeTarget::Success => match evaluated {
Ok(stdout) => {
assert_eq!(
stdout.trim_end_matches('\n'),
result.trim_end_matches('\n'),
),
Err(err) => panic!("ERROR: {}", err.message.unwrap()),
}
)
},
Err(err) => {
panic!("ERROR: {}", err.message.unwrap())
},
}
TestOutcomeTarget::Failure => {
match eval_amber_code(code) {
Ok(eval_result) => panic!("Expected error, got: {}", eval_result),
Err(err) => assert_eq!(err.message.expect("Error message expected"), result),
}
TestOutcomeTarget::Failure => match evaluated {
Ok(stdout) => {
panic!("Expected error, got: {}", stdout)
},
Err(err) => {
assert_eq!(err.message.expect("Error message expected"), result)
},
}
}
}
Expand Down

0 comments on commit 635e21d

Please sign in to comment.