adds check for integer parsing error vs integer computation error in tests

This commit is contained in:
collin 2020-07-31 14:06:01 -07:00
parent ae8fb1f714
commit 7137c98745
13 changed files with 30 additions and 18 deletions

View File

@ -2,7 +2,7 @@ use crate::{
assert_satisfied,
expect_synthesis_error,
generate_main_inputs,
integers::{expect_fail, IntegerTester},
integers::{expect_computation_error, expect_parsing_error, IntegerTester},
parse_program,
};
use leo_inputs::types::{I128Type, IntegerType};

View File

@ -2,7 +2,7 @@ use crate::{
assert_satisfied,
expect_synthesis_error,
generate_main_inputs,
integers::{expect_fail, IntegerTester},
integers::{expect_computation_error, expect_parsing_error, IntegerTester},
parse_program,
};
use leo_inputs::types::{I16Type, IntegerType};

View File

@ -2,7 +2,7 @@ use crate::{
assert_satisfied,
expect_synthesis_error,
generate_main_inputs,
integers::{expect_fail, IntegerTester},
integers::{expect_computation_error, expect_parsing_error, IntegerTester},
parse_program,
};
use leo_inputs::types::{I32Type, IntegerType};

View File

@ -2,7 +2,7 @@ use crate::{
assert_satisfied,
expect_synthesis_error,
generate_main_inputs,
integers::{expect_fail, IntegerTester},
integers::{expect_computation_error, expect_parsing_error, IntegerTester},
parse_program,
};
use leo_inputs::types::{I64Type, IntegerType};

View File

@ -2,7 +2,7 @@ use crate::{
assert_satisfied,
expect_synthesis_error,
generate_main_inputs,
integers::{expect_fail, IntegerTester},
integers::{expect_computation_error, expect_parsing_error, IntegerTester},
parse_program,
};
use leo_inputs::types::{I8Type, IntegerType};

View File

@ -14,7 +14,7 @@ macro_rules! test_int {
let bytes = include_bytes!("min_fail.leo");
let program = parse_program(bytes).unwrap();
expect_fail(program);
expect_parsing_error(program);
}
fn test_max() {
@ -28,7 +28,7 @@ macro_rules! test_int {
let bytes = include_bytes!("max_fail.leo");
let program = parse_program(bytes).unwrap();
expect_fail(program);
expect_parsing_error(program);
}
fn test_add() {
@ -128,11 +128,11 @@ macro_rules! test_int {
program.set_main_inputs(main_inputs);
expect_fail(program);
expect_computation_error(program);
} else {
let c = match a.checked_div(b) {
Some(valid) => valid,
None => return,
None => continue,
};
let main_inputs = generate_main_inputs(vec![

View File

@ -51,11 +51,23 @@ pub trait IntegerTester {
fn test_ternary();
}
pub(crate) fn expect_fail(program: EdwardsTestCompiler) {
pub(crate) fn expect_parsing_error(program: EdwardsTestCompiler) {
match expect_compiler_error(program) {
CompilerError::FunctionError(FunctionError::StatementError(StatementError::ExpressionError(
ExpressionError::ValueError(ValueError::IntegerError(IntegerError::Error(_))),
))) => {}
error => panic!("Expected invalid integer error, got {:?}", error),
error => panic!("Expected integer parsing error, found {:?}", error),
}
}
pub(crate) fn expect_computation_error(program: EdwardsTestCompiler) {
match expect_compiler_error(program) {
CompilerError::FunctionError(FunctionError::StatementError(StatementError::ExpressionError(
ExpressionError::IntegerError(IntegerError::Error(_)),
))) => {}
error => panic!(
"Expected integer computation error such as `DivisionByZero`, found {:?}",
error
),
}
}

View File

@ -2,7 +2,7 @@ use crate::{
assert_satisfied,
expect_synthesis_error,
generate_main_inputs,
integers::{expect_fail, IntegerTester},
integers::{expect_parsing_error, IntegerTester},
parse_program,
};
use leo_inputs::types::{IntegerType, U128Type};

View File

@ -2,7 +2,7 @@ use crate::{
assert_satisfied,
expect_synthesis_error,
generate_main_inputs,
integers::{expect_fail, IntegerTester},
integers::{expect_parsing_error, IntegerTester},
parse_program,
};
use leo_inputs::types::{IntegerType, U16Type};

View File

@ -2,7 +2,7 @@ use crate::{
assert_satisfied,
expect_synthesis_error,
generate_main_inputs,
integers::{expect_fail, IntegerTester},
integers::{expect_parsing_error, IntegerTester},
parse_program,
};
use leo_inputs::types::{IntegerType, U32Type};

View File

@ -2,7 +2,7 @@ use crate::{
assert_satisfied,
expect_synthesis_error,
generate_main_inputs,
integers::{expect_fail, IntegerTester},
integers::{expect_parsing_error, IntegerTester},
parse_program,
};
use leo_inputs::types::{IntegerType, U64Type};

View File

@ -2,7 +2,7 @@ use crate::{
assert_satisfied,
expect_synthesis_error,
generate_main_inputs,
integers::{expect_fail, IntegerTester},
integers::{expect_parsing_error, IntegerTester},
parse_program,
};
use leo_inputs::types::{IntegerType, U8Type};

View File

@ -14,7 +14,7 @@ macro_rules! test_uint {
let bytes = include_bytes!("min_fail.leo");
let program = parse_program(bytes).unwrap();
expect_fail(program);
expect_parsing_error(program);
}
fn test_max() {
@ -28,7 +28,7 @@ macro_rules! test_uint {
let bytes = include_bytes!("max_fail.leo");
let program = parse_program(bytes).unwrap();
expect_fail(program);
expect_parsing_error(program);
}
fn test_add() {