2020-06-12 00:40:27 +03:00
|
|
|
use crate::{boolean::output_true, parse_program};
|
|
|
|
use leo_compiler::errors::CompilerError;
|
|
|
|
use leo_inputs::InputParserError;
|
|
|
|
|
|
|
|
fn fail_input_parser(error: CompilerError) {
|
|
|
|
match error {
|
|
|
|
CompilerError::InputParserError(InputParserError::InputNotFound(_)) => {}
|
|
|
|
err => panic!("expected input parser error, got {}", err),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_inputs_pass() {
|
|
|
|
let program_bytes = include_bytes!("main.leo");
|
2020-06-20 08:07:02 +03:00
|
|
|
let input_bytes = include_bytes!("main.in");
|
2020-06-12 00:40:27 +03:00
|
|
|
let input_string = String::from_utf8_lossy(input_bytes);
|
|
|
|
|
|
|
|
let mut program = parse_program(program_bytes).unwrap();
|
2020-06-20 08:07:02 +03:00
|
|
|
program.parse_inputs(&input_string).unwrap();
|
2020-06-12 00:40:27 +03:00
|
|
|
|
|
|
|
output_true(program);
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_inputs_fail_name() {
|
|
|
|
let program_bytes = include_bytes!("main.leo");
|
2020-06-20 08:07:02 +03:00
|
|
|
let input_bytes = include_bytes!("main_fail_name.in");
|
2020-06-12 00:40:27 +03:00
|
|
|
let input_string = String::from_utf8_lossy(input_bytes);
|
|
|
|
|
|
|
|
let mut program = parse_program(program_bytes).unwrap();
|
2020-06-20 08:07:02 +03:00
|
|
|
let error = program.parse_inputs(&input_string).unwrap_err();
|
2020-06-12 00:40:27 +03:00
|
|
|
|
|
|
|
fail_input_parser(error);
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_inputs_fail_type() {
|
|
|
|
let program_bytes = include_bytes!("main.leo");
|
2020-06-20 08:07:02 +03:00
|
|
|
let input_bytes = include_bytes!("main_fail_type.in");
|
2020-06-12 00:40:27 +03:00
|
|
|
let input_string = String::from_utf8_lossy(input_bytes);
|
|
|
|
|
|
|
|
let mut program = parse_program(program_bytes).unwrap();
|
2020-06-20 08:07:02 +03:00
|
|
|
let error = program.parse_inputs(&input_string).unwrap_err();
|
2020-06-12 00:40:27 +03:00
|
|
|
|
|
|
|
fail_input_parser(error);
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_inputs_multiple() {
|
|
|
|
let program_bytes = include_bytes!("main_multiple.leo");
|
2020-06-20 08:07:02 +03:00
|
|
|
let input_bytes = include_bytes!("main_multiple.in");
|
2020-06-12 00:40:27 +03:00
|
|
|
let input_string = String::from_utf8_lossy(input_bytes);
|
|
|
|
|
|
|
|
let mut program = parse_program(program_bytes).unwrap();
|
2020-06-20 08:07:02 +03:00
|
|
|
program.parse_inputs(&input_string).unwrap();
|
2020-06-12 00:40:27 +03:00
|
|
|
|
|
|
|
output_true(program);
|
|
|
|
}
|