From bd3b465a4f6e54a15436385d79488471955d4ad6 Mon Sep 17 00:00:00 2001 From: collin Date: Wed, 2 Sep 2020 16:04:41 -0700 Subject: [PATCH] add tests for input array initializer --- compiler/tests/array/initializer_input.leo | 3 +++ .../tests/array/input/initializer_fail.in | 2 ++ compiler/tests/array/input/six_zeros.in | 2 +- compiler/tests/array/mod.rs | 19 +++++++++++++++++++ typed/src/input/input_value.rs | 2 +- 5 files changed, 26 insertions(+), 2 deletions(-) create mode 100644 compiler/tests/array/initializer_input.leo create mode 100644 compiler/tests/array/input/initializer_fail.in diff --git a/compiler/tests/array/initializer_input.leo b/compiler/tests/array/initializer_input.leo new file mode 100644 index 0000000000..4b886159dc --- /dev/null +++ b/compiler/tests/array/initializer_input.leo @@ -0,0 +1,3 @@ +function main(a: [u8; (3, 2)]) { + console.assert(a == [0u8; (3, 2)]); +} \ No newline at end of file diff --git a/compiler/tests/array/input/initializer_fail.in b/compiler/tests/array/input/initializer_fail.in new file mode 100644 index 0000000000..cf991c79b6 --- /dev/null +++ b/compiler/tests/array/input/initializer_fail.in @@ -0,0 +1,2 @@ +[main] +a: [u8; (3, 2)] = [0; (2, 2)]; \ No newline at end of file diff --git a/compiler/tests/array/input/six_zeros.in b/compiler/tests/array/input/six_zeros.in index b6f6bd4b65..9f9880807c 100644 --- a/compiler/tests/array/input/six_zeros.in +++ b/compiler/tests/array/input/six_zeros.in @@ -1,2 +1,2 @@ [main] -a: [u8; (3, 2)] = [[0; 3]; 2]; \ No newline at end of file +a: [u8; (3, 2)] = [0; (3, 2)]; \ No newline at end of file diff --git a/compiler/tests/array/mod.rs b/compiler/tests/array/mod.rs index e97e487047..76db81cfb8 100644 --- a/compiler/tests/array/mod.rs +++ b/compiler/tests/array/mod.rs @@ -18,6 +18,7 @@ use crate::{ assert_satisfied, expect_compiler_error, get_output, + integers::{expect_computation_error, expect_parsing_error}, parse_program, parse_program_with_input, EdwardsTestCompiler, @@ -101,6 +102,24 @@ fn test_initializer_fail() { assert!(syntax_error); } +#[test] +fn test_initializer_input() { + let program_bytes = include_bytes!("initializer_input.leo"); + let input_bytes = include_bytes!("input/six_zeros.in"); + let program = parse_program_with_input(program_bytes, input_bytes).unwrap(); + + assert_satisfied(program); +} + +#[test] +fn test_initializer_input_fail() { + let program_bytes = include_bytes!("initializer_input.leo"); + let input_bytes = include_bytes!("input/initializer_fail.in"); + let syntax_error = parse_program_with_input(program_bytes, input_bytes).is_err(); + + assert!(syntax_error); +} + #[test] fn test_spread() { let program_bytes = include_bytes!("spread.leo"); diff --git a/typed/src/input/input_value.rs b/typed/src/input/input_value.rs index 6f23861860..6f9ad83eee 100644 --- a/typed/src/input/input_value.rs +++ b/typed/src/input/input_value.rs @@ -142,7 +142,7 @@ impl InputValue { array_type: ArrayType, initializer: ArrayInitializerExpression, ) -> Result { - let mut array_dimensions = TypedExpression::get_input_array_dimensions(array_type.dimensions.clone()); + let array_dimensions = TypedExpression::get_input_array_dimensions(array_type.dimensions.clone()); let initializer_dimensions = TypedExpression::get_input_array_dimensions(initializer.dimensions.clone()); // Return an error if the array type does not equal the array expression