fix inputs tests

This commit is contained in:
collin 2020-07-30 14:38:31 -07:00
parent 4566ac8e03
commit 1b6a2b55d4
11 changed files with 30 additions and 38 deletions

View File

@ -0,0 +1,2 @@
[main]
a: bool = true;

View File

@ -0,0 +1,2 @@
[main]
a: u8 = 1;

View File

@ -0,0 +1,3 @@
[main]
a: bool = true;
b: bool = false;

View File

@ -1,2 +0,0 @@
[main]
b: bool = true;

View File

@ -1,3 +1,3 @@
function main(b: bool) -> bool {
return b
function main(a: bool) {
assert_eq!(a, true);
}

View File

@ -1,2 +0,0 @@
[main]
b: u8 = 1;

View File

@ -1,3 +0,0 @@
[main]
b: bool = true;
a: bool = false;

View File

@ -1,3 +1,4 @@
function main(a: bool, b: bool) -> bool {
return a || b
function main(a: bool, b: bool) {
assert_eq!(a, true);
assert_eq!(b, false);
}

View File

@ -1,58 +1,49 @@
use crate::{boolean::output_true, parse_program};
use crate::{assert_satisfied, expect_compiler_error, parse_program_with_inputs, EdwardsTestCompiler};
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),
fn expect_fail(program: EdwardsTestCompiler) {
match expect_compiler_error(program) {
CompilerError::FunctionError(_) => {}
err => panic!("expected input parser error, got {:?}", err),
}
}
#[test]
fn test_inputs_pass() {
let program_bytes = include_bytes!("main.leo");
let input_bytes = include_bytes!("main.in");
let input_string = String::from_utf8_lossy(input_bytes);
let input_bytes = include_bytes!("inputs/main.in");
let mut program = parse_program(program_bytes).unwrap();
program.parse_inputs(&input_string).unwrap();
let program = parse_program_with_inputs(program_bytes, input_bytes).unwrap();
output_true(program);
assert_satisfied(program);
}
#[test]
fn test_inputs_fail_name() {
let program_bytes = include_bytes!("main.leo");
let input_bytes = include_bytes!("main_fail_name.in");
let input_string = String::from_utf8_lossy(input_bytes);
let input_bytes = include_bytes!("inputs/main_fail_name.in");
let mut program = parse_program(program_bytes).unwrap();
let error = program.parse_inputs(&input_string).unwrap_err();
let program = parse_program_with_inputs(program_bytes, input_bytes).unwrap();
fail_input_parser(error);
expect_fail(program);
}
#[test]
fn test_inputs_fail_type() {
let program_bytes = include_bytes!("main.leo");
let input_bytes = include_bytes!("main_fail_type.in");
let input_string = String::from_utf8_lossy(input_bytes);
let input_bytes = include_bytes!("inputs/main_fail_type.in");
let mut program = parse_program(program_bytes).unwrap();
let error = program.parse_inputs(&input_string).unwrap_err();
let program = parse_program_with_inputs(program_bytes, input_bytes).unwrap();
fail_input_parser(error);
expect_fail(program);
}
#[test]
fn test_inputs_multiple() {
let program_bytes = include_bytes!("main_multiple.leo");
let input_bytes = include_bytes!("main_multiple.in");
let input_string = String::from_utf8_lossy(input_bytes);
let input_bytes = include_bytes!("inputs/main_multiple.in");
let mut program = parse_program(program_bytes).unwrap();
program.parse_inputs(&input_string).unwrap();
let program = parse_program_with_inputs(program_bytes, input_bytes).unwrap();
output_true(program);
assert_satisfied(program);
}

View File

@ -6,7 +6,7 @@ pub mod field;
pub mod function;
pub mod group;
pub mod import;
// pub mod inputs;
pub mod inputs;
// pub mod integers;
// pub mod macros;
// pub mod mutability;