2020-07-31 01:41:03 +03:00
|
|
|
use crate::{expect_compiler_error, EdwardsTestCompiler};
|
|
|
|
use leo_compiler::errors::{CompilerError, ExpressionError, FunctionError, IntegerError, StatementError, ValueError};
|
2020-07-16 06:42:57 +03:00
|
|
|
|
|
|
|
pub trait IntegerTester {
|
2020-07-31 01:41:03 +03:00
|
|
|
/// Tests defining the smalled value that can be represented by the integer type
|
|
|
|
fn test_min();
|
2020-07-16 06:42:57 +03:00
|
|
|
|
2020-07-31 01:41:03 +03:00
|
|
|
/// Tests defining the smallest value - 1
|
|
|
|
fn test_min_fail();
|
|
|
|
|
|
|
|
/// Tests defining the largest value that can be represented by the integer type
|
|
|
|
fn test_max();
|
|
|
|
|
|
|
|
/// Tests defining the largest value + 1
|
|
|
|
fn test_max_fail();
|
|
|
|
|
|
|
|
/// Tests a non-wrapping addition
|
2020-07-16 06:42:57 +03:00
|
|
|
fn test_add();
|
|
|
|
|
2020-07-31 01:41:03 +03:00
|
|
|
/// Tests a non-wrapping subtraction
|
2020-07-16 06:42:57 +03:00
|
|
|
fn test_sub();
|
|
|
|
|
2020-07-31 01:41:03 +03:00
|
|
|
/// Tests a non-wrapping multiplication
|
2020-07-16 06:42:57 +03:00
|
|
|
fn test_mul();
|
|
|
|
|
|
|
|
/// Tests a non-wrapping division
|
|
|
|
fn test_div();
|
|
|
|
|
2020-07-31 01:41:03 +03:00
|
|
|
/// Tests a non-wrapping exponentiation
|
2020-07-16 06:42:57 +03:00
|
|
|
fn test_pow();
|
|
|
|
|
|
|
|
/// Tests == evaluation
|
|
|
|
fn test_eq();
|
|
|
|
|
2020-08-14 10:25:39 +03:00
|
|
|
/// Tests != evaluation
|
|
|
|
fn test_ne();
|
|
|
|
|
2020-07-16 06:42:57 +03:00
|
|
|
/// Tests >= evaluation
|
|
|
|
fn test_ge();
|
|
|
|
|
|
|
|
/// Tests > evaluation
|
|
|
|
fn test_gt();
|
|
|
|
|
|
|
|
/// Tests <= evaluation
|
|
|
|
fn test_le();
|
|
|
|
|
|
|
|
/// Tests < evaluation
|
|
|
|
fn test_lt();
|
|
|
|
|
|
|
|
/// Test assert equals constraint keyword
|
|
|
|
fn test_assert_eq();
|
|
|
|
|
|
|
|
/// Test ternary if bool ? num_1 : num_2;
|
|
|
|
fn test_ternary();
|
|
|
|
}
|
|
|
|
|
2020-08-01 00:06:01 +03:00
|
|
|
pub(crate) fn expect_parsing_error(program: EdwardsTestCompiler) {
|
2020-07-31 01:41:03 +03:00
|
|
|
match expect_compiler_error(program) {
|
|
|
|
CompilerError::FunctionError(FunctionError::StatementError(StatementError::ExpressionError(
|
|
|
|
ExpressionError::ValueError(ValueError::IntegerError(IntegerError::Error(_))),
|
|
|
|
))) => {}
|
2020-08-01 00:06:01 +03:00
|
|
|
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
|
|
|
|
),
|
2020-07-16 06:42:57 +03:00
|
|
|
}
|
|
|
|
}
|