leo/compiler/tests/array/mod.rs

179 lines
5.0 KiB
Rust
Raw Normal View History

2020-08-18 13:50:26 +03:00
// Copyright (C) 2019-2020 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::{
2020-07-30 10:56:17 +03:00
assert_satisfied,
2020-07-30 21:11:54 +03:00
expect_compiler_error,
2020-08-01 07:15:33 +03:00
get_output,
parse_program,
2020-08-01 05:39:30 +03:00
parse_program_with_input,
EdwardsTestCompiler,
};
2020-07-30 10:56:17 +03:00
pub fn output_ones(program: EdwardsTestCompiler) {
2020-08-17 05:14:26 +03:00
let expected = include_bytes!("output/registers_ones.out");
2020-08-01 07:15:33 +03:00
let actual = get_output(program);
2020-07-30 10:56:17 +03:00
assert!(expected.eq(actual.bytes().as_slice()));
}
2020-07-30 10:56:17 +03:00
pub fn output_zeros(program: EdwardsTestCompiler) {
2020-08-17 05:14:26 +03:00
let expected = include_bytes!("output/registers_zeros.out");
2020-08-01 07:15:33 +03:00
let actual = get_output(program);
2020-07-30 10:56:17 +03:00
assert!(expected.eq(actual.bytes().as_slice()));
2020-06-11 02:14:55 +03:00
}
2020-07-30 10:56:17 +03:00
// Registers
#[test]
2020-07-30 10:56:17 +03:00
fn test_registers() {
let program_bytes = include_bytes!("registers.leo");
2020-08-01 06:59:50 +03:00
let ones_input_bytes = include_bytes!("input/registers_ones.in");
let zeros_input_bytes = include_bytes!("input/registers_zeros.in");
2020-07-30 10:56:17 +03:00
// test ones input register => ones output register
2020-08-01 05:39:30 +03:00
let program = parse_program_with_input(program_bytes, ones_input_bytes).unwrap();
2020-06-09 03:51:06 +03:00
output_ones(program);
2020-07-30 10:56:17 +03:00
// test zeros input register => zeros output register
2020-08-01 05:39:30 +03:00
let program = parse_program_with_input(program_bytes, zeros_input_bytes).unwrap();
2020-06-09 03:51:06 +03:00
2020-07-30 10:56:17 +03:00
output_zeros(program);
}
2020-07-30 10:56:17 +03:00
// Expressions
#[test]
fn test_type_fail() {
let program_bytes = include_bytes!("type_fail.leo");
let syntax_error = parse_program(program_bytes).is_err();
assert!(syntax_error);
}
#[test]
2020-07-30 10:56:17 +03:00
fn test_inline() {
let program_bytes = include_bytes!("inline.leo");
2020-08-01 06:59:50 +03:00
let input_bytes = include_bytes!("input/three_ones.in");
2020-08-01 05:39:30 +03:00
let program = parse_program_with_input(program_bytes, input_bytes).unwrap();
2020-06-09 03:51:06 +03:00
2020-07-30 10:56:17 +03:00
assert_satisfied(program);
}
#[test]
2020-07-30 10:56:17 +03:00
fn test_inline_fail() {
let program_bytes = include_bytes!("inline.leo");
let program = parse_program(program_bytes).unwrap();
2020-06-09 03:51:06 +03:00
2020-07-30 21:11:54 +03:00
let _err = expect_compiler_error(program);
}
#[test]
2020-07-30 10:56:17 +03:00
fn test_initializer() {
let program_bytes = include_bytes!("initializer.leo");
2020-08-01 06:59:50 +03:00
let input_bytes = include_bytes!("input/three_ones.in");
2020-08-01 05:39:30 +03:00
let program = parse_program_with_input(program_bytes, input_bytes).unwrap();
2020-06-09 03:51:06 +03:00
2020-07-30 10:56:17 +03:00
assert_satisfied(program);
}
#[test]
fn test_initializer_fail() {
let program_bytes = include_bytes!("initializer_fail.leo");
let input_bytes = include_bytes!("input/three_ones.in");
let syntax_error = parse_program_with_input(program_bytes, input_bytes).is_err();
assert!(syntax_error);
}
2020-09-03 02:04:41 +03:00
#[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]
2020-07-30 10:56:17 +03:00
fn test_spread() {
let program_bytes = include_bytes!("spread.leo");
2020-08-01 06:59:50 +03:00
let input_bytes = include_bytes!("input/three_ones.in");
2020-08-01 05:39:30 +03:00
let program = parse_program_with_input(program_bytes, input_bytes).unwrap();
2020-06-09 03:51:06 +03:00
2020-07-30 10:56:17 +03:00
assert_satisfied(program);
}
#[test]
2020-07-30 10:56:17 +03:00
fn test_slice() {
let program_bytes = include_bytes!("slice.leo");
2020-08-01 06:59:50 +03:00
let input_bytes = include_bytes!("input/three_ones.in");
2020-08-01 05:39:30 +03:00
let program = parse_program_with_input(program_bytes, input_bytes).unwrap();
2020-06-09 03:51:06 +03:00
2020-07-30 10:56:17 +03:00
assert_satisfied(program);
}
#[test]
2020-07-30 10:56:17 +03:00
fn test_multi() {
let program_bytes = include_bytes!("multi.leo");
let program = parse_program(program_bytes).unwrap();
2020-06-09 03:51:06 +03:00
2020-07-30 10:56:17 +03:00
assert_satisfied(program);
}
2020-09-02 21:40:58 +03:00
#[test]
2020-09-03 02:49:06 +03:00
fn test_multi_fail() {
2020-09-02 21:40:58 +03:00
let program_bytes = include_bytes!("multi_fail_initializer.leo");
let program = parse_program(program_bytes).unwrap();
expect_compiler_error(program);
}
#[test]
fn test_multi_inline_fail() {
let program_bytes = include_bytes!("multi_fail_inline.leo");
let program = parse_program(program_bytes).unwrap();
expect_compiler_error(program);
}
2020-09-03 02:49:06 +03:00
#[test]
fn test_multi_initializer() {
let program_bytes = include_bytes!("multi_initializer.leo");
let program = parse_program(program_bytes).unwrap();
assert_satisfied(program);
}
#[test]
fn test_multi_initializer_fail() {
let program_bytes = include_bytes!("multi_initializer_fail.leo");
let program = parse_program(program_bytes).unwrap();
expect_compiler_error(program);
}