add tests for input array initializer

This commit is contained in:
collin 2020-09-02 16:04:41 -07:00
parent 91350a2ffe
commit bd3b465a4f
5 changed files with 26 additions and 2 deletions

View File

@ -0,0 +1,3 @@
function main(a: [u8; (3, 2)]) {
console.assert(a == [0u8; (3, 2)]);
}

View File

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

View File

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

View File

@ -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");

View File

@ -142,7 +142,7 @@ impl InputValue {
array_type: ArrayType,
initializer: ArrayInitializerExpression,
) -> Result<Self, InputParserError> {
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