arrays 1/2

This commit is contained in:
damirka 2021-05-05 21:25:24 +03:00
parent 7f390d4d5c
commit 91c9969ff9
63 changed files with 459 additions and 766 deletions

View File

@ -2,4 +2,4 @@
a: [[u8; 2]; 3] = [[1, 2], [3, 4], [5, 6]];
[registers]
x: bool = false;
x: bool = false;

View File

@ -0,0 +1,6 @@
[main]
y: bool = true;
n: bool = false;
[registers]
r0: bool = false;

View File

@ -1,2 +1,5 @@
[main]
a: [u8; (3, 2)] = [0u8; (2, 2)];
[registers]
x: bool = false;

View File

@ -1,2 +1,5 @@
[main]
a: [u8; (3, 2)] = [[0u8; 2]; 3];
[registers]
x: bool = false;

View File

@ -1,2 +1,5 @@
[main]
a: [u8; (3, 2)] = [[0u8; 3]; 2)];
[registers]
x: bool = false;

View File

@ -1,2 +1,5 @@
[main]
a: [u8; (3, 2)] = [0u8; (3, 2)];
[registers]
x: bool = false;

View File

@ -1,2 +1,5 @@
[main]
a: [u8; (3, 2)] = [0u8; (2, 3)];
[registers]
x: bool = false;

View File

@ -1,2 +1,8 @@
[main]
a: [u8; 3] = [1, 1, 1];
[registers]
r: [u8; 3] = [1u8, 1u8, 1u8];
[registers]
x: bool = false;

View File

@ -1,2 +1,8 @@
[main]
a: [u8; 3] = [1, 1, 1]; // doesn't match arr below
[registers]
r: [u8; 3] = [0u8, 0u8, 0u8];
[registers]
x: bool = false;

View File

@ -1,2 +1,5 @@
[main]
a: [u8; 3] = [1, 1, 1];
a: [u8; 3] = [1, 1, 1];
[registers]
x: bool = false;

View File

@ -1,2 +1,5 @@
[main]
a: [[u8; 2]; 3] = [[0; 2]; 3];
[registers]
x: bool = false;

View File

@ -1,2 +1,5 @@
[main]
a: [[u8; 2]; 3] = [[0; 3]; 2]; // initializer (incorrectly reversed ordering)
[registers]
x: bool = false;

View File

@ -1,2 +1,5 @@
[main]
a: [[[u8; 2]; 3]; 4] = [[[0; 2]; 3]; 4];
[registers]
x: bool = false;

View File

@ -1,2 +1,5 @@
[main]
a: [[[u8; 2]; 3]; 4] = [[[0; 4]; 3]; 2]; // initializer (incorrectly reversed ordering)
[registers]
x: bool = false;

View File

@ -1,2 +1,5 @@
[main]
a: [[u8; 2]; 3] = [0; (3, 2)];
[registers]
x: bool = false;

View File

@ -1,2 +1,5 @@
[main]
a: [[u8; 2]; 3] = [0; (2, 3)]; // initializer (incorrectly reversed ordering)
[registers]
x: bool = false;

View File

@ -1,2 +1,5 @@
[main]
a: [[[u8; 2]; 3]; 4] = [0; (4, 3, 2)];
[registers]
x: bool = false;

View File

@ -1,2 +1,5 @@
[main]
a: [[[u8; 2]; 3]; 4] = [0; (2, 3, 4)]; // initializer (incorrectly reversed ordering)
[registers]
x: bool = false;

View File

@ -1,2 +1,5 @@
[main]
a: [u8; (3, 2)] = [[0; 2]; 3];
[registers]
x: bool = false;

View File

@ -1,2 +1,5 @@
[main]
a: [u8; (3, 2)] = [[0; 3]; 2]; // initializer (incorrectly reversed ordering)
[registers]
x: bool = false;

View File

@ -1,2 +1,5 @@
[main]
a: [u8; (4, 3, 2)] = [[[0; 2]; 3]; 4];
[registers]
x: bool = false;

View File

@ -1,2 +1,5 @@
[main]
a: [u8; (4, 3, 2)] = [[[0; 4]; 3]; 2]; // initializer (incorrectly reversed ordering)
[registers]
x: bool = false;

View File

@ -1,2 +1,5 @@
[main]
a: [u8; (3, 2)] = [0; (3, 2)];
[registers]
x: bool = false;

View File

@ -1,2 +1,5 @@
[main]
a: [u8; (3, 2)] = [0; (2, 3)]; // initializer (incorrectly reversed ordering)
[registers]
x: bool = false;

View File

@ -1,2 +1,5 @@
[main]
a: [u8; (4, 3, 2)] = [0; (4, 3, 2)];
[registers]
x: bool = false;

View File

@ -1,2 +1,5 @@
[main]
a: [u8; (4, 3, 2)] = [0; (2, 3, 4)]; // initializer (incorrectly reversed ordering)
[registers]
x: bool = false;

View File

@ -1,3 +1,9 @@
function main(a: [u8; (3, 2)]) {
console.assert(a == [[0u8; 2]; 3]);
/*
namespace: Compile
expectation: Pass
input_file: input/input_nested_3x2.in
*/
function main(a: [u8; (3, 2)]) -> bool {
return a == [[0u8; 2]; 3];
}

View File

@ -1,11 +1,9 @@
/*
namespace: Compile
expectation: Fail
input_file:
- input/six_zeros.in
- input/count_to_6.in
input_file: input/input_nested_3x2_fail.in
*/
function main(a: [u8; (3, 2)]) {
console.assert(a == [[0u8; 2]; 3)]); // This should be written the right way as this test is for the input file.
function main(a: [u8; (3, 2)]) -> bool {
return a == [[0u8; 2]; 3)]; // This should be written the right way as this test is for the input file.
}

View File

@ -1,3 +1,9 @@
function main(a: [u8; (3, 2)]) {
console.assert(a == [0u8; (3, 2)]);
/*
namespace: Compile
expectation: Pass
input_file: input/input_tuple_3x2.in
*/
function main(a: [u8; (3, 2)]) -> bool {
return a == [0u8; (3, 2)];
}

View File

@ -1,3 +1,9 @@
function main(a: [u8; (3, 2)]) {
console.assert(a == [0u8; (3, 2)]);
/*
namespace: Compile
expectation: Fail
input_file: input/input_tuple_3x2_fail.in
*/
function main(a: [u8; (3, 2)]) -> bool {
return a == [0u8; (3, 2)];
}

View File

@ -1,716 +0,0 @@
// Copyright (C) 2019-2021 Aleo Systems Inc.
// This file is part of the Leo library.
// The Leo library is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
// The Leo library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
// You should have received a copy of the GNU General Public License
// along with the Leo library. If not, see <https://www.gnu.org/licenses/>.
use crate::{
assert_satisfied,
expect_asg_error,
expect_compiler_error,
get_output,
parse_program,
parse_program_with_input,
EdwardsTestCompiler,
};
pub fn output_ones(program: EdwardsTestCompiler) {
let expected = include_bytes!("output/registers_ones.out");
let actual = get_output(program);
assert!(expected.eq(actual.bytes().as_slice()));
}
pub fn output_zeros(program: EdwardsTestCompiler) {
let expected = include_bytes!("output/registers_zeros.out");
let actual = get_output(program);
assert!(expected.eq(actual.bytes().as_slice()));
}
// Registers
#[test]
fn test_registers() {
let program_string = include_str!("registers.leo");
let ones_input_string = include_str!("input/registers_ones.in");
let zeros_input_string = include_str!("input/registers_zeros.in");
// test ones input register => ones output register
let program = parse_program_with_input(program_string, ones_input_string).unwrap();
output_ones(program);
// test zeros input register => zeros output register
let program = parse_program_with_input(program_string, zeros_input_string).unwrap();
output_zeros(program);
}
// Expressions
#[test]
fn test_inline() {
let program_string = include_str!("inline.leo");
let input_string = include_str!("input/three_ones.in");
let program = parse_program_with_input(program_string, input_string).unwrap();
assert_satisfied(program);
}
#[test]
fn test_nested() {
let program_string = include_str!("nested.leo");
let program = parse_program(program_string).unwrap();
assert_satisfied(program);
}
#[test]
fn test_inline_fail() {
let program_string = include_str!("inline.leo");
let program = parse_program(program_string).unwrap();
let _err = expect_compiler_error(program);
}
#[test]
fn test_initializer() {
let program_string = include_str!("initializer.leo");
let input_string = include_str!("input/three_ones.in");
let program = parse_program_with_input(program_string, input_string).unwrap();
assert_satisfied(program);
}
#[test]
fn test_initializer_fail() {
let program_string = include_str!("initializer_fail.leo");
let input_string = include_str!("input/three_ones.in");
let syntax_error = parse_program_with_input(program_string, input_string).is_err();
assert!(syntax_error);
}
#[test]
fn test_initializer_input() {
let program_string = include_str!("initializer_input.leo");
let input_string = include_str!("input/six_zeros.in");
let program = parse_program_with_input(program_string, input_string).unwrap();
assert_satisfied(program);
}
#[test]
fn test_initializer_input_fail() {
let program_string = include_str!("initializer_input.leo");
let input_string = include_str!("input/initializer_fail.in");
let syntax_error = parse_program_with_input(program_string, input_string).is_err();
assert!(syntax_error);
}
#[test]
fn test_input_nested_3x2() {
let program_string = include_str!("input_nested_3x2.leo");
let input_string = include_str!("input/input_nested_3x2.in");
let program = parse_program_with_input(program_string, input_string).unwrap();
assert_satisfied(program);
}
#[test]
fn test_input_nested_3x2_fail() {
let program_string = include_str!("input_nested_3x2_fail.leo");
let input_string = include_str!("input/input_nested_3x2_fail.in");
let syntax_error = parse_program_with_input(program_string, input_string).is_err();
assert!(syntax_error);
}
#[test]
fn test_input_tuple_3x2() {
let program_string = include_str!("input_tuple_3x2.leo");
let input_string = include_str!("input/input_tuple_3x2.in");
let program = parse_program_with_input(program_string, input_string).unwrap();
assert_satisfied(program);
}
#[test]
fn test_input_tuple_3x2_fail() {
let program_string = include_str!("input_tuple_3x2_fail.leo");
let input_string = include_str!("input/input_tuple_3x2_fail.in");
let syntax_error = parse_program_with_input(program_string, input_string).is_err();
assert!(syntax_error);
}
#[test]
fn test_multi_fail_initializer() {
let program_string = include_str!("multi_fail_initializer.leo");
let error = parse_program(program_string).err().unwrap();
expect_asg_error(error);
}
#[test]
fn test_multi_inline_fail() {
let program_string = include_str!("multi_fail_inline.leo");
let error = parse_program(program_string).err().unwrap();
expect_asg_error(error);
}
#[test]
fn test_multi_initializer() {
let program_string = include_str!("multi_initializer.leo");
let program = parse_program(program_string).unwrap();
assert_satisfied(program);
}
#[test]
fn test_multi_initializer_fail() {
let program_string = include_str!("multi_initializer_fail.leo");
let error = parse_program(program_string).err().unwrap();
expect_asg_error(error);
}
#[test]
fn test_nested_3x2_value() {
let program_string = include_str!("nested_3x2_value.leo");
let program = parse_program(program_string).unwrap();
assert_satisfied(program);
}
#[test]
fn test_nested_3x2_value_fail() {
let program_string = include_str!("nested_3x2_value_fail.leo");
let error = parse_program(program_string).err().unwrap();
expect_asg_error(error);
}
#[test]
fn test_tuple_3x2_value() {
let program_string = include_str!("tuple_3x2_value.leo");
let program = parse_program(program_string).unwrap();
assert_satisfied(program);
}
#[test]
fn test_tuple_3x2_value_fail() {
let program_string = include_str!("tuple_3x2_value_fail.leo");
let error = parse_program(program_string).err().unwrap();
expect_asg_error(error);
}
#[test]
fn test_spread() {
let program_string = include_str!("spread.leo");
let input_string = include_str!("input/three_ones.in");
let program = parse_program_with_input(program_string, input_string).unwrap();
assert_satisfied(program);
}
#[test]
fn test_slice() {
let program_string = include_str!("slice.leo");
let input_string = include_str!("input/three_ones.in");
let program = parse_program_with_input(program_string, input_string).unwrap();
assert_satisfied(program);
}
#[test]
fn test_slice_lower() {
let program_string = include_str!("slice_lower.leo");
let program = parse_program(program_string).unwrap();
assert_satisfied(program);
}
// Array type tests
#[test]
fn test_type_fail() {
let program_string = include_str!("type_fail.leo");
let syntax_error = parse_program(program_string).is_err();
assert!(syntax_error);
}
#[test]
fn test_type_nested_value_nested_3x2() {
let program_string = include_str!("type_nested_value_nested_3x2.leo");
let program = parse_program(program_string).unwrap();
assert_satisfied(program);
}
#[test]
fn test_type_nested_value_nested_3x2_fail() {
let program_string = include_str!("type_nested_value_nested_3x2_fail.leo");
let error = parse_program(program_string).err().unwrap();
expect_asg_error(error);
}
#[test]
fn test_type_nested_value_nested_4x3x2() {
let program_string = include_str!("type_nested_value_nested_4x3x2.leo");
let program = parse_program(program_string).unwrap();
assert_satisfied(program);
}
#[test]
fn test_type_nested_value_nested_4x3x2_fail() {
let program_string = include_str!("type_nested_value_nested_4x3x2_fail.leo");
let error = parse_program(program_string).err().unwrap();
expect_asg_error(error);
}
#[test]
fn test_type_nested_value_tuple_3x2() {
let program_string = include_str!("type_nested_value_tuple_3x2.leo");
let program = parse_program(program_string).unwrap();
assert_satisfied(program);
}
#[test]
fn test_type_nested_value_tuple_3x2_fail() {
let program_string = include_str!("type_nested_value_tuple_3x2_fail.leo");
let error = parse_program(program_string).err().unwrap();
expect_asg_error(error);
}
#[test]
fn test_type_nested_value_tuple_4x3x2() {
let program_string = include_str!("type_nested_value_tuple_4x3x2.leo");
let program = parse_program(program_string).unwrap();
assert_satisfied(program);
}
#[test]
fn test_type_nested_value_tuple_4x3x2_fail() {
let program_string = include_str!("type_nested_value_tuple_4x3x2_fail.leo");
let error = parse_program(program_string).err().unwrap();
expect_asg_error(error);
}
#[test]
fn test_type_tuple_value_nested_3x2() {
let program_string = include_str!("type_tuple_value_nested_3x2.leo");
let program = parse_program(program_string).unwrap();
assert_satisfied(program);
}
#[test]
fn test_type_tuple_value_nested_3x2_fail() {
let program_string = include_str!("type_tuple_value_nested_3x2_fail.leo");
let error = parse_program(program_string).err().unwrap();
expect_asg_error(error);
}
#[test]
fn test_type_tuple_value_nested_4x3x2() {
let program_string = include_str!("type_tuple_value_nested_4x3x2.leo");
let program = parse_program(program_string).unwrap();
assert_satisfied(program);
}
#[test]
fn test_type_tuple_value_nested_4x3x2_fail() {
let program_string = include_str!("type_tuple_value_nested_4x3x2_fail.leo");
let error = parse_program(program_string).err().unwrap();
expect_asg_error(error);
}
#[test]
fn test_type_tuple_value_tuple_3x2() {
let program_string = include_str!("type_tuple_value_tuple_3x2.leo");
let program = parse_program(program_string).unwrap();
assert_satisfied(program);
}
#[test]
fn test_type_tuple_value_tuple_3x2_fail() {
let program_string = include_str!("type_tuple_value_tuple_3x2_fail.leo");
let error = parse_program(program_string).err().unwrap();
expect_asg_error(error);
}
#[test]
fn test_type_tuple_value_tuple_4x3x2() {
let program_string = include_str!("type_tuple_value_tuple_4x3x2.leo");
let program = parse_program(program_string).unwrap();
assert_satisfied(program);
}
#[test]
fn test_type_tuple_value_tuple_4x3x2_fail() {
let program_string = include_str!("type_tuple_value_tuple_4x3x2_fail.leo");
let error = parse_program(program_string).err().unwrap();
expect_asg_error(error);
}
// Tests for nested multi-dimensional arrays as input to the program
#[test]
fn test_input_type_nested_value_nested_3x2() {
let program_string = include_str!("type_input_3x2.leo");
let input_string = include_str!("input/type_nested_value_nested_3x2.in");
let program = parse_program_with_input(program_string, input_string).unwrap();
assert_satisfied(program);
}
#[test]
fn test_input_type_nested_value_nested_3x2_fail() {
let program_string = include_str!("type_input_3x2.leo");
let input_string = include_str!("input/type_nested_value_nested_3x2_fail.in");
let syntax_error = parse_program_with_input(program_string, input_string).is_err();
assert!(syntax_error);
}
#[test]
fn test_input_type_nested_value_nested_4x3x2() {
let program_string = include_str!("type_input_4x3x2.leo");
let input_string = include_str!("input/type_nested_value_nested_4x3x2.in");
let program = parse_program_with_input(program_string, input_string).unwrap();
assert_satisfied(program);
}
#[test]
fn test_input_type_nested_value_nested_4x3x2_fail() {
let program_string = include_str!("type_input_4x3x2.leo");
let input_string = include_str!("input/type_nested_value_nested_4x3x2_fail.in");
let syntax_error = parse_program_with_input(program_string, input_string).is_err();
assert!(syntax_error);
}
#[test]
fn test_input_type_nested_value_tuple_3x2() {
let program_string = include_str!("type_input_3x2.leo");
let input_string = include_str!("input/type_nested_value_tuple_3x2.in");
let program = parse_program_with_input(program_string, input_string).unwrap();
assert_satisfied(program);
}
#[test]
fn test_input_type_nested_value_tuple_3x2_fail() {
let program_string = include_str!("type_input_3x2.leo");
let input_string = include_str!("input/type_nested_value_tuple_3x2_fail.in");
let syntax_error = parse_program_with_input(program_string, input_string).is_err();
assert!(syntax_error);
}
#[test]
fn test_input_type_nested_value_tuple_4x3x2() {
let program_string = include_str!("type_input_4x3x2.leo");
let input_string = include_str!("input/type_nested_value_tuple_4x3x2.in");
let program = parse_program_with_input(program_string, input_string).unwrap();
assert_satisfied(program)
}
#[test]
fn test_input_type_nested_value_tuple_4x3x2_fail() {
let program_string = include_str!("type_input_4x3x2.leo");
let input_string = include_str!("input/type_nested_value_tuple_4x3x2_fail.in");
let syntax_error = parse_program_with_input(program_string, input_string).is_err();
assert!(syntax_error);
}
// Tests for multi-dimensional arrays using tuple syntax as input to the program
#[test]
fn test_input_type_tuple_value_nested_3x2() {
let program_string = include_str!("type_input_3x2.leo");
let input_string = include_str!("input/type_tuple_value_nested_3x2.in");
let program = parse_program_with_input(program_string, input_string).unwrap();
assert_satisfied(program);
}
#[test]
fn test_input_type_tuple_value_nested_3x2_fail() {
let program_string = include_str!("type_input_3x2.leo");
let input_string = include_str!("input/type_tuple_value_nested_3x2_fail.in");
let syntax_error = parse_program_with_input(program_string, input_string).is_err();
assert!(syntax_error);
}
#[test]
fn test_input_type_tuple_value_nested_4x3x2() {
let program_string = include_str!("type_input_4x3x2.leo");
let input_string = include_str!("input/type_tuple_value_nested_4x3x2.in");
let program = parse_program_with_input(program_string, input_string).unwrap();
assert_satisfied(program);
}
#[test]
fn test_input_type_tuple_value_nested_4x3x2_fail() {
let program_string = include_str!("type_input_4x3x2.leo");
let input_string = include_str!("input/type_tuple_value_nested_4x3x2_fail.in");
let syntax_error = parse_program_with_input(program_string, input_string).is_err();
assert!(syntax_error);
}
#[test]
fn test_input_type_tuple_value_tuple_3x2() {
let program_string = include_str!("type_input_3x2.leo");
let input_string = include_str!("input/type_tuple_value_tuple_3x2.in");
let program = parse_program_with_input(program_string, input_string).unwrap();
assert_satisfied(program);
}
#[test]
fn test_input_type_tuple_value_tuple_3x2_fail() {
let program_string = include_str!("type_input_3x2.leo");
let input_string = include_str!("input/type_tuple_value_tuple_3x2_fail.in");
let syntax_error = parse_program_with_input(program_string, input_string).is_err();
assert!(syntax_error);
}
#[test]
fn test_input_type_tuple_value_tuple_4x3x2() {
let program_string = include_str!("type_input_4x3x2.leo");
let input_string = include_str!("input/type_tuple_value_tuple_4x3x2.in");
let program = parse_program_with_input(program_string, input_string).unwrap();
assert_satisfied(program);
}
#[test]
fn test_input_type_tuple_value_tuple_4x3x2_fail() {
let program_string = include_str!("type_input_4x3x2.leo");
let input_string = include_str!("input/type_tuple_value_tuple_4x3x2_fail.in");
let syntax_error = parse_program_with_input(program_string, input_string).is_err();
assert!(syntax_error);
}
#[test]
fn test_variable_slice_fail() {
let program_string = include_str!("variable_slice_fail.leo");
let error = parse_program(program_string).err().unwrap();
expect_asg_error(error);
}
#[test]
fn test_array_index() {
let program_string = r#"
function main(i: u32) {
let b = [1u8, 2, 3, 4];
console.assert(2 == b[i]);
console.assert(3 == b[2]);
}
"#;
let input_string = r#"
[main]
i: u32 = 1;
"#;
let program = parse_program_with_input(program_string, input_string).unwrap();
assert_satisfied(program);
}
#[test]
fn test_array_index_bounds_fail() {
let program_string = r#"
function main(i: u32) {
let b = [1u8, 2, 3, 4];
console.assert(2 == b[i]);
}
"#;
let input_string = r#"
[main]
i: u32 = 4;
"#;
let program = parse_program_with_input(program_string, input_string).unwrap();
expect_compiler_error(program);
}
#[test]
fn test_const_array_index_bounds_fail() {
let program_string = r#"
function main() {
let b = [1u8, 2, 3, 4];
const i: u32 = 4;
console.assert(2 == b[i]);
}
"#;
let error = parse_program(program_string).err().unwrap();
expect_asg_error(error);
}
#[test]
fn test_array_range_index() {
let program_string = r#"
function main(i: u32) {
let b = [1u8, 2, 3, 4];
console.assert([1u8, 2] == b[0..i]);
console.assert([3u8, 4] == b[i..4]);
}
"#;
let input_string = r#"
[main]
i: u32 = 2;
"#;
let program = parse_program_with_input(program_string, input_string).unwrap();
assert_satisfied(program);
}
#[test]
fn test_array_range_index_dyn() {
let program_string = r#"
function main(i: u32) {
let b = [1u8, 2, 3, 4];
console.assert([1u8, 2] == b[..i]);
console.assert([3u8, 4] == b[i..]);
}
"#;
let input_string = r#"
[main]
i: u32 = 2;
"#;
let program = parse_program_with_input(program_string, input_string).unwrap();
assert_satisfied(program);
}
#[test]
fn test_array_range_index_full_dyn() {
let program_string = r#"
function main(i: u32, y: u32) {
let b = [1u8, 2, 3, 4];
console.assert([3u8, 4] == b[i..y]);
}
"#;
let input_string = r#"
[main]
i: u32 = 2;
y: u32 = 4;
"#;
let program = parse_program_with_input(program_string, input_string).unwrap();
assert_satisfied(program);
}
#[test]
fn test_array_range_index_out_of_bounds_fail() {
let program_string = r#"
function main() {
let b = [1u8, 2, 3, 4];
console.assert([1, 2] == b[3..5]);
}
"#;
let error = parse_program(program_string).err().unwrap();
expect_asg_error(error);
}
#[test]
fn test_array_range_index_invalid_bounds_fail() {
let program_string = r#"
function main() {
let b = [1u8, 2, 3, 4];
console.assert([1, 2] == b[2..1]);
}
"#;
let error = parse_program(program_string).err().unwrap();
expect_asg_error(error);
}
#[test]
fn test_array_range_index_full_dyn_resized_fail() {
let program_string = r#"
function main(i: u32, y: u32) {
let b = [1u8, 2, 3, 4];
console.assert([3u8, 4] == b[i..y]);
}
"#;
let input_string = r#"
[main]
i: u32 = 1;
y: u32 = 4;
"#;
let program = parse_program_with_input(program_string, input_string).unwrap();
expect_compiler_error(program);
}
#[test]
fn test_array_range_index_full_dyn_bounds_fail() {
let program_string = r#"
function main(i: u32, y: u32) {
let b = [1u8, 2, 3, 4];
console.assert([3u8, 4] == b[i..y]);
}
"#;
let input_string = r#"
[main]
i: u32 = 3;
y: u32 = 5;
"#;
let program = parse_program_with_input(program_string, input_string).unwrap();
expect_compiler_error(program);
}

View File

@ -1,3 +1,10 @@
function main() {
/*
namespace: Compile
expectation: Fail
input_file: input/dummy.in
*/
function main() -> bool {
const arr: [u8; (2, 2)] = [[1u8; 2]; 1]; // incorrect dimensions
}
return false;
}

View File

@ -1,4 +1,11 @@
function main() {
/*
namespace: Compile
expectation: Fail
input_file: input/dummy.in
*/
function main() -> bool {
const arr: [u8; (2, 2)] = [[1u8, 1u8],
[1u8]]; // incorrect dimensions
}
return false;
}

View File

@ -1,7 +1,12 @@
function main() {
const a: [u8; (2, 2, 2)] = [1u8; (2, 2, 2)];
/*
namespace: Compile
expectation: Pass
input_file: input/dummy.in
*/
function main(y: bool) -> bool {
const a: [u8; (2, 2, 2)] = [1u8; (2, 2, 2)];
const b: [u8; (2, 2, 2)] = [[[1u8; 2]; 2]; 2];
console.assert(a == b);
}
return a == b == y;
}

View File

@ -1,3 +1,10 @@
function main() {
/*
namespace: Compile
expectation: Fail
input_file: input/dummy.in
*/
function main() -> bool {
const arr: [u8; (2, 2)] = [1u8; (2, 1)]; // incorrect dimensions
}
return false;
}

View File

@ -1,4 +1,12 @@
function main () {
/*
namespace: Compile
expectation: Pass
input_file: input/dummy.in
*/
function main(n: bool) -> bool {
const x = [false; (2, 2)];
const y: bool = x[0][0];
const z: bool = x[0][0];
return n == z;
}

View File

@ -1,8 +1,13 @@
// Multidimensional array syntax in leo
function main() {
const a = [[0u32, 0u32], [0u32, 0u32], [0u32, 0u32]]; // inline
/*
namespace: Compile
expectation: Pass
input_file: input/dummy.in
*/
// Multidimensional array syntax in leo
function main(y: bool) -> bool {
const a = [[0u32, 0u32], [0u32, 0u32], [0u32, 0u32]]; // inline
const b: [u32; (3, 2)] = [[0; 2]; 3]; // initializer
console.assert(a == b);
}
return a == b == y;
}

View File

@ -1,4 +1,12 @@
/*
namespace: Compile
expectation: Fail
input_file: input/dummy.in
*/
// Multidimensional array syntax in leo
function main() {
function main(y: bool) -> bool {
const a: [u32; (3, 2)] = [[0; 3]; 2]; // initializer (incorrectly reversed ordering)
return false;
}

View File

@ -1,3 +1,11 @@
function main() -> [u8; 3] {
return input.registers.r;
/*
namespace: Compile
expectation: Pass
input_file:
- input/registers_ones.in
- input/registers_zeros.in
*/
function main(a: [u8; 3]) -> [u8; 3] {
return input.registers.r == a ? [3,2,1] : [1,2,3];
}

View File

@ -1,6 +1,11 @@
// `{from}..{to}` copies the elements of one array into another exclusively
function main(a: [u8; 3]) {
const b = [1u8; 4];
/*
namespace: Compile
expectation: Pass
input_file: input/three_ones.in
*/
console.assert(a == b[0..3]);
// `{from}..{to}` copies the elements of one array into another exclusively
function main(a: [u8; 3]) -> bool {
const b = [1u8; 4];
return a == b[0..3];
}

View File

@ -1,8 +1,14 @@
function main() {
/*
namespace: Compile
expectation: Pass
input_file: input/dummy.in
*/
function main(y: bool) -> bool {
const arr: [u32; 9] = [0, 1, 2, 3, 4, 5, 6, 7, 8];
const expected: [u32; 2] = [0, 1];
const actual = arr[..2]; // Should produce [0, 1]
console.assert(expected == actual);
}
return expected == actual == y;
}

View File

@ -1,7 +1,13 @@
/*
namespace: Compile
expectation: Pass
input_file: input/three_ones.in
*/
// A spread operator `...` copies the elements of one array into another
function main(a: [u8; 3]) {
function main(a: [u8; 3]) -> bool {
const b = [1u8, 1u8];
const c = [1u8, ...b];
console.assert(a == c);
}
return a == c;
}

View File

@ -1,8 +1,13 @@
// Multidimensional array syntax in leo
function main() {
const a = [[0u32, 0u32], [0u32, 0u32], [0u32, 0u32]]; // inline
/*
namespace: Compile
expectation: Pass
input_file: input/dummy.in
*/
// Multidimensional array syntax in leo
function main(y: bool) -> bool {
const a = [[0u32, 0u32], [0u32, 0u32], [0u32, 0u32]]; // inline
const b: [u32; (3, 2)] = [0; (3, 2)]; // initializer
console.assert(a == b);
}
return a == b == y;
}

View File

@ -1,3 +1,8 @@
/*
namespace: Compile
expectation: Fail
*/
// Multidimensional array syntax in leo
function main() {
const a: [u32; (3, 2)] = [0; (2, 3)]; // initializer (incorrectly reversed ordering)

View File

@ -1,3 +1,9 @@
/*
namespace: Compile
expectation: Fail
*/
function main() {
const a: [u8; -2] = [0u32; 2];
}
}

View File

@ -0,0 +1,18 @@
---
namespace: Compile
expectation: Pass
outputs:
- circuit:
num_public_variables: 0
num_private_variables: 95
num_constraints: 95
at: 5884e806c47756fa1d12f47e5cc5249843d8de4e2fafcb373c5a0d67dfe22d69
bt: 983c734b40e342144d6b4d52e315da9ff9f97580f019f606403924bb977a5be7
ct: 49f0db71bd29b80dbe5f2f96573a5959b1df339c92350e16f111bade214037aa
output:
- input_file: input/input_nested_3x2.in
output:
registers:
x:
type: bool
value: "true"

View File

@ -2,4 +2,4 @@
namespace: Compile
expectation: Fail
outputs:
- " --> /Users/dam/projects/aleo/leo/test-framework/../tests/compiler/array/input_nested_3x2_fail.leo:4:37\n |\n 4 | console.assert(a == [[0u8; 2]; 3)]); // This should be written the right way as this test is for the input file.\n | ^\n |\n = expected ']' -- got ')'"
- " --> /Users/dam/projects/aleo/leo/test-framework/../tests/compiler/array/input_nested_3x2_fail.leo:4:29\n |\n 4 | return a == [[0u8; 2]; 3)]; // This should be written the right way as this test is for the input file.\n | ^\n |\n = expected ']' -- got ')'"

View File

@ -0,0 +1,18 @@
---
namespace: Compile
expectation: Pass
outputs:
- circuit:
num_public_variables: 0
num_private_variables: 95
num_constraints: 95
at: 5884e806c47756fa1d12f47e5cc5249843d8de4e2fafcb373c5a0d67dfe22d69
bt: 983c734b40e342144d6b4d52e315da9ff9f97580f019f606403924bb977a5be7
ct: 49f0db71bd29b80dbe5f2f96573a5959b1df339c92350e16f111bade214037aa
output:
- input_file: input/input_tuple_3x2.in
output:
registers:
x:
type: bool
value: "true"

View File

@ -0,0 +1,5 @@
---
namespace: Compile
expectation: Fail
outputs:
- aborting due to syntax error

View File

@ -0,0 +1,5 @@
---
namespace: Compile
expectation: Fail
outputs:
- " --> /Users/dam/projects/aleo/leo/test-framework/../tests/compiler/array/multi_fail_initializer.leo:4:31\n |\n 4 | const arr: [u8; (2, 2)] = [[1u8; 2]; 1]; // incorrect dimensions\n | ^^^^^^^^^^^^^\n |\n = unexpected type, expected: 'array of length 2', received: 'array of length 1'"

View File

@ -0,0 +1,5 @@
---
namespace: Compile
expectation: Fail
outputs:
- " --> /Users/dam/projects/aleo/leo/test-framework/../tests/compiler/array/multi_fail_inline.leo:5:35\n |\n 5 | [1u8]]; // incorrect dimensions\n | ^^^^^\n |\n = unexpected type, expected: 'array of length 2', received: 'array of length 1'"

View File

@ -0,0 +1,18 @@
---
namespace: Compile
expectation: Pass
outputs:
- circuit:
num_public_variables: 0
num_private_variables: 1
num_constraints: 1
at: 042610d0fd1fe6d6ac112138f8755752f44c7d2a00f1b5960574d6da5cda393f
bt: e97756698880ab7555a959a5fb5c6b4e15bd64612aa677adbfe2d0bd91f0a83c
ct: cf1cbb66a638b4860a516671fb74850e6ccf787fe6c4c8d29e9c04efe880bd05
output:
- input_file: input/dummy.in
output:
registers:
r0:
type: bool
value: "true"

View File

@ -0,0 +1,5 @@
---
namespace: Compile
expectation: Fail
outputs:
- " --> /Users/dam/projects/aleo/leo/test-framework/../tests/compiler/array/multi_initializer_fail.leo:4:31\n |\n 4 | const arr: [u8; (2, 2)] = [1u8; (2, 1)]; // incorrect dimensions\n | ^^^^^^^^^^^^^\n |\n = unexpected type, expected: 'array of length 2', received: 'array of length 1'"

View File

@ -0,0 +1,18 @@
---
namespace: Compile
expectation: Pass
outputs:
- circuit:
num_public_variables: 0
num_private_variables: 1
num_constraints: 1
at: 042610d0fd1fe6d6ac112138f8755752f44c7d2a00f1b5960574d6da5cda393f
bt: e97756698880ab7555a959a5fb5c6b4e15bd64612aa677adbfe2d0bd91f0a83c
ct: cf1cbb66a638b4860a516671fb74850e6ccf787fe6c4c8d29e9c04efe880bd05
output:
- input_file: input/dummy.in
output:
registers:
r0:
type: bool
value: "true"

View File

@ -0,0 +1,18 @@
---
namespace: Compile
expectation: Pass
outputs:
- circuit:
num_public_variables: 0
num_private_variables: 1
num_constraints: 1
at: 042610d0fd1fe6d6ac112138f8755752f44c7d2a00f1b5960574d6da5cda393f
bt: e97756698880ab7555a959a5fb5c6b4e15bd64612aa677adbfe2d0bd91f0a83c
ct: cf1cbb66a638b4860a516671fb74850e6ccf787fe6c4c8d29e9c04efe880bd05
output:
- input_file: input/dummy.in
output:
registers:
r0:
type: bool
value: "true"

View File

@ -0,0 +1,5 @@
---
namespace: Compile
expectation: Fail
outputs:
- " --> /Users/dam/projects/aleo/leo/test-framework/../tests/compiler/array/nested_3x2_value_fail.leo:6:30\n |\n 6 | const a: [u32; (3, 2)] = [[0; 3]; 2]; // initializer (incorrectly reversed ordering)\n | ^^^^^^^^^^^\n |\n = unexpected type, expected: 'array of length 3', received: 'array of length 2'"

View File

@ -0,0 +1,24 @@
---
namespace: Compile
expectation: Pass
outputs:
- circuit:
num_public_variables: 0
num_private_variables: 119
num_constraints: 143
at: ae3e8a95d339433e8a11fc7a54536b8f56abacc03cffa1c4f4be8fa32bc4da8b
bt: 43972815ec9d0ab821613fde2cd6a5df9ee42f50758a27a0fed6dc111b44f3ee
ct: 5ed7a755b881aa851f3d3e966a4bd18dd48ce59be71b4ada39c9c891f8297201
output:
- input_file: input/registers_ones.in
output:
registers:
r:
type: "[u8; 3]"
value: "[3, 2, 1]"
- input_file: input/registers_zeros.in
output:
registers:
r:
type: "[u8; 3]"
value: "[1, 2, 3]"

View File

@ -0,0 +1,18 @@
---
namespace: Compile
expectation: Pass
outputs:
- circuit:
num_public_variables: 0
num_private_variables: 47
num_constraints: 47
at: 9034e7c6c2ae58e279196614600093d655bcdad8237302b84a66e63ec1c2f00e
bt: f23a0442b41c8901611d5f1a9a8493a0cb03c68e183a81a1b88c5a6600fa7420
ct: ad66abc1bf940dbc76573c0a516ebf633c1411f9997101d86ded0faff025d52c
output:
- input_file: input/three_ones.in
output:
registers:
x:
type: bool
value: "true"

View File

@ -0,0 +1,18 @@
---
namespace: Compile
expectation: Pass
outputs:
- circuit:
num_public_variables: 0
num_private_variables: 1
num_constraints: 1
at: 042610d0fd1fe6d6ac112138f8755752f44c7d2a00f1b5960574d6da5cda393f
bt: e97756698880ab7555a959a5fb5c6b4e15bd64612aa677adbfe2d0bd91f0a83c
ct: cf1cbb66a638b4860a516671fb74850e6ccf787fe6c4c8d29e9c04efe880bd05
output:
- input_file: input/dummy.in
output:
registers:
r0:
type: bool
value: "true"

View File

@ -0,0 +1,18 @@
---
namespace: Compile
expectation: Pass
outputs:
- circuit:
num_public_variables: 0
num_private_variables: 47
num_constraints: 47
at: 9034e7c6c2ae58e279196614600093d655bcdad8237302b84a66e63ec1c2f00e
bt: f23a0442b41c8901611d5f1a9a8493a0cb03c68e183a81a1b88c5a6600fa7420
ct: ad66abc1bf940dbc76573c0a516ebf633c1411f9997101d86ded0faff025d52c
output:
- input_file: input/three_ones.in
output:
registers:
x:
type: bool
value: "true"

View File

@ -0,0 +1,18 @@
---
namespace: Compile
expectation: Pass
outputs:
- circuit:
num_public_variables: 0
num_private_variables: 1
num_constraints: 1
at: 042610d0fd1fe6d6ac112138f8755752f44c7d2a00f1b5960574d6da5cda393f
bt: e97756698880ab7555a959a5fb5c6b4e15bd64612aa677adbfe2d0bd91f0a83c
ct: cf1cbb66a638b4860a516671fb74850e6ccf787fe6c4c8d29e9c04efe880bd05
output:
- input_file: input/dummy.in
output:
registers:
r0:
type: bool
value: "true"

View File

@ -0,0 +1,5 @@
---
namespace: Compile
expectation: Fail
outputs:
- " --> /Users/dam/projects/aleo/leo/test-framework/../tests/compiler/array/tuple_3x2_value_fail.leo:5:30\n |\n 5 | const a: [u32; (3, 2)] = [0; (2, 3)]; // initializer (incorrectly reversed ordering)\n | ^^^^^^^^^^^\n |\n = unexpected type, expected: 'array of length 3', received: 'array of length 2'"

View File

@ -0,0 +1,5 @@
---
namespace: Compile
expectation: Fail
outputs:
- " --> /Users/dam/projects/aleo/leo/test-framework/../tests/compiler/array/type_fail.leo:5:19\n |\n 5 | const a: [u8; -2] = [0u32; 2];\n | ^\n |\n = expected '(' -- got '-'"