From 1b6a2b55d4ad09bdb8c72d1b9f08ba826fd0d4f4 Mon Sep 17 00:00:00 2001 From: collin Date: Thu, 30 Jul 2020 14:38:31 -0700 Subject: [PATCH] fix inputs tests --- compiler/tests/inputs/inputs/main.in | 2 + .../inputs/{ => inputs}/main_fail_name.in | 0 .../tests/inputs/inputs/main_fail_type.in | 2 + compiler/tests/inputs/inputs/main_multiple.in | 3 ++ compiler/tests/inputs/main.in | 2 - compiler/tests/inputs/main.leo | 4 +- compiler/tests/inputs/main_fail_type.in | 2 - compiler/tests/inputs/main_multiple.in | 3 -- compiler/tests/inputs/main_multiple.leo | 5 ++- compiler/tests/inputs/mod.rs | 43 ++++++++----------- compiler/tests/mod.rs | 2 +- 11 files changed, 30 insertions(+), 38 deletions(-) create mode 100644 compiler/tests/inputs/inputs/main.in rename compiler/tests/inputs/{ => inputs}/main_fail_name.in (100%) create mode 100644 compiler/tests/inputs/inputs/main_fail_type.in create mode 100644 compiler/tests/inputs/inputs/main_multiple.in delete mode 100644 compiler/tests/inputs/main.in delete mode 100644 compiler/tests/inputs/main_fail_type.in delete mode 100644 compiler/tests/inputs/main_multiple.in diff --git a/compiler/tests/inputs/inputs/main.in b/compiler/tests/inputs/inputs/main.in new file mode 100644 index 0000000000..16ba5231af --- /dev/null +++ b/compiler/tests/inputs/inputs/main.in @@ -0,0 +1,2 @@ +[main] +a: bool = true; \ No newline at end of file diff --git a/compiler/tests/inputs/main_fail_name.in b/compiler/tests/inputs/inputs/main_fail_name.in similarity index 100% rename from compiler/tests/inputs/main_fail_name.in rename to compiler/tests/inputs/inputs/main_fail_name.in diff --git a/compiler/tests/inputs/inputs/main_fail_type.in b/compiler/tests/inputs/inputs/main_fail_type.in new file mode 100644 index 0000000000..a5cf30c8cc --- /dev/null +++ b/compiler/tests/inputs/inputs/main_fail_type.in @@ -0,0 +1,2 @@ +[main] +a: u8 = 1; \ No newline at end of file diff --git a/compiler/tests/inputs/inputs/main_multiple.in b/compiler/tests/inputs/inputs/main_multiple.in new file mode 100644 index 0000000000..546c971bf8 --- /dev/null +++ b/compiler/tests/inputs/inputs/main_multiple.in @@ -0,0 +1,3 @@ +[main] +a: bool = true; +b: bool = false; diff --git a/compiler/tests/inputs/main.in b/compiler/tests/inputs/main.in deleted file mode 100644 index b40103724a..0000000000 --- a/compiler/tests/inputs/main.in +++ /dev/null @@ -1,2 +0,0 @@ -[main] -b: bool = true; \ No newline at end of file diff --git a/compiler/tests/inputs/main.leo b/compiler/tests/inputs/main.leo index 7e2a1c7e0c..8a8ab02f28 100644 --- a/compiler/tests/inputs/main.leo +++ b/compiler/tests/inputs/main.leo @@ -1,3 +1,3 @@ -function main(b: bool) -> bool { - return b +function main(a: bool) { + assert_eq!(a, true); } \ No newline at end of file diff --git a/compiler/tests/inputs/main_fail_type.in b/compiler/tests/inputs/main_fail_type.in deleted file mode 100644 index 04cd884d05..0000000000 --- a/compiler/tests/inputs/main_fail_type.in +++ /dev/null @@ -1,2 +0,0 @@ -[main] -b: u8 = 1; \ No newline at end of file diff --git a/compiler/tests/inputs/main_multiple.in b/compiler/tests/inputs/main_multiple.in deleted file mode 100644 index 85ee0349ec..0000000000 --- a/compiler/tests/inputs/main_multiple.in +++ /dev/null @@ -1,3 +0,0 @@ -[main] -b: bool = true; -a: bool = false; \ No newline at end of file diff --git a/compiler/tests/inputs/main_multiple.leo b/compiler/tests/inputs/main_multiple.leo index e2231f14bc..49ad704a2f 100644 --- a/compiler/tests/inputs/main_multiple.leo +++ b/compiler/tests/inputs/main_multiple.leo @@ -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); } \ No newline at end of file diff --git a/compiler/tests/inputs/mod.rs b/compiler/tests/inputs/mod.rs index da5bf9836d..8ecec380c3 100644 --- a/compiler/tests/inputs/mod.rs +++ b/compiler/tests/inputs/mod.rs @@ -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); } diff --git a/compiler/tests/mod.rs b/compiler/tests/mod.rs index 5e4ea9bee9..e61dff1666 100644 --- a/compiler/tests/mod.rs +++ b/compiler/tests/mod.rs @@ -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;