2020-07-31 03:11:58 +03:00
|
|
|
use crate::{assert_satisfied, expect_compiler_error, expect_synthesis_error, generate_main_inputs, parse_program};
|
2020-06-08 07:26:49 +03:00
|
|
|
use leo_types::InputValue;
|
2020-06-02 04:35:43 +03:00
|
|
|
|
2020-06-20 09:02:58 +03:00
|
|
|
pub mod conditional;
|
2020-06-13 12:08:21 +03:00
|
|
|
|
2020-05-21 03:08:32 +03:00
|
|
|
// Ternary if {bool}? {expression} : {expression};
|
|
|
|
|
2020-06-20 09:02:58 +03:00
|
|
|
#[test]
|
|
|
|
fn test_ternary_basic() {
|
|
|
|
let bytes = include_bytes!("ternary_basic.leo");
|
2020-07-31 03:11:58 +03:00
|
|
|
let mut program = parse_program(bytes).unwrap();
|
|
|
|
|
|
|
|
let main_inputs = generate_main_inputs(vec![
|
|
|
|
("a", Some(InputValue::Boolean(true))),
|
|
|
|
("b", Some(InputValue::Boolean(true))),
|
|
|
|
]);
|
|
|
|
|
|
|
|
program.set_main_inputs(main_inputs);
|
|
|
|
|
|
|
|
assert_satisfied(program);
|
2020-06-20 09:02:58 +03:00
|
|
|
|
2020-07-31 03:11:58 +03:00
|
|
|
let mut program = parse_program(bytes).unwrap();
|
2020-06-20 09:02:58 +03:00
|
|
|
|
2020-07-31 03:11:58 +03:00
|
|
|
let main_inputs = generate_main_inputs(vec![
|
|
|
|
("a", Some(InputValue::Boolean(false))),
|
|
|
|
("b", Some(InputValue::Boolean(false))),
|
|
|
|
]);
|
2020-06-20 09:02:58 +03:00
|
|
|
|
2020-07-31 03:11:58 +03:00
|
|
|
program.set_main_inputs(main_inputs);
|
|
|
|
|
|
|
|
assert_satisfied(program);
|
2020-06-20 09:02:58 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
// Iteration for i {start}..{stop} { statements }
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_iteration_basic() {
|
|
|
|
let bytes = include_bytes!("iteration_basic.leo");
|
|
|
|
let program = parse_program(bytes).unwrap();
|
|
|
|
|
2020-07-31 03:11:58 +03:00
|
|
|
assert_satisfied(program);
|
2020-06-20 09:02:58 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
// Assertion
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_assertion_basic() {
|
|
|
|
let bytes = include_bytes!("assertion_basic.leo");
|
2020-07-31 03:11:58 +03:00
|
|
|
let mut program = parse_program(bytes).unwrap();
|
|
|
|
|
|
|
|
let main_inputs = generate_main_inputs(vec![("a", Some(InputValue::Boolean(true)))]);
|
2020-06-20 09:02:58 +03:00
|
|
|
|
2020-07-31 03:11:58 +03:00
|
|
|
program.set_main_inputs(main_inputs);
|
2020-06-20 09:02:58 +03:00
|
|
|
|
2020-07-31 03:11:58 +03:00
|
|
|
assert_satisfied(program);
|
2020-06-20 09:02:58 +03:00
|
|
|
|
2020-07-31 03:11:58 +03:00
|
|
|
let mut program = parse_program(bytes).unwrap();
|
2020-06-20 09:02:58 +03:00
|
|
|
|
2020-07-31 03:11:58 +03:00
|
|
|
let main_inputs = generate_main_inputs(vec![("a", Some(InputValue::Boolean(false)))]);
|
2020-06-20 09:02:58 +03:00
|
|
|
|
2020-07-31 03:11:58 +03:00
|
|
|
program.set_main_inputs(main_inputs);
|
2020-06-20 09:02:58 +03:00
|
|
|
|
2020-07-31 03:11:58 +03:00
|
|
|
expect_synthesis_error(program);
|
2020-06-20 09:02:58 +03:00
|
|
|
}
|
2020-05-21 03:08:32 +03:00
|
|
|
|
|
|
|
#[test]
|
2020-06-20 05:04:13 +03:00
|
|
|
fn test_num_returns_fail() {
|
|
|
|
let bytes = include_bytes!("num_returns_fail.leo");
|
2020-06-09 04:58:41 +03:00
|
|
|
let program = parse_program(bytes).unwrap();
|
2020-05-21 03:08:32 +03:00
|
|
|
|
2020-07-31 03:11:58 +03:00
|
|
|
expect_compiler_error(program);
|
2020-05-21 03:08:32 +03:00
|
|
|
}
|