leo/compiler/tests/console/mod.rs

170 lines
4.4 KiB
Rust
Raw Normal View History

2021-02-02 07:26:56 +03:00
// Copyright (C) 2019-2021 Aleo Systems Inc.
2020-09-03 04:45:48 +03:00
// 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/>.
2020-12-17 00:02:31 +03:00
use crate::{
assert_satisfied,
expect_asg_error,
expect_compiler_error,
generate_main_input,
parse_program,
parse_program_with_input,
};
2020-10-31 03:31:09 +03:00
use leo_ast::InputValue;
2020-07-10 05:23:15 +03:00
#[test]
2020-08-17 03:20:47 +03:00
fn test_log() {
2020-12-04 23:48:43 +03:00
let program_string = include_str!("log.leo");
let program = parse_program(program_string).unwrap();
2020-07-10 05:23:15 +03:00
2020-07-31 02:27:31 +03:00
assert_satisfied(program);
2020-07-10 05:23:15 +03:00
}
#[test]
2020-08-17 03:20:47 +03:00
fn test_log_fail() {
2020-12-04 23:48:43 +03:00
let program_string = include_str!("log_fail.leo");
2020-07-10 05:23:15 +03:00
2020-12-04 23:48:43 +03:00
assert!(parse_program(program_string).is_err());
2020-07-10 05:23:15 +03:00
}
#[test]
2020-08-17 03:20:47 +03:00
fn test_log_parameter() {
2020-12-04 23:48:43 +03:00
let program_string = include_str!("log_parameter.leo");
let program = parse_program(program_string).unwrap();
2020-07-10 05:23:15 +03:00
2020-07-31 02:27:31 +03:00
assert_satisfied(program);
2020-07-10 05:23:15 +03:00
}
#[test]
2020-08-17 03:20:47 +03:00
fn test_log_parameter_many() {
2020-12-04 23:48:43 +03:00
let program_string = include_str!("log_parameter_many.leo");
let program = parse_program(program_string).unwrap();
2020-07-10 05:23:15 +03:00
2020-07-31 02:27:31 +03:00
assert_satisfied(program);
2020-07-10 05:23:15 +03:00
}
2020-07-10 05:33:10 +03:00
#[test]
2020-12-17 00:02:31 +03:00
fn test_log_parameter_fail_empty() {
let program_string = include_str!("log_parameter_fail_empty.leo");
let error = parse_program(program_string).err().unwrap();
2020-07-10 05:33:10 +03:00
2020-12-17 00:02:31 +03:00
expect_asg_error(error);
2020-07-10 05:33:10 +03:00
}
2020-07-10 05:23:15 +03:00
#[test]
2020-12-17 00:02:31 +03:00
fn test_log_parameter_fail_none() {
2020-12-04 23:48:43 +03:00
let program_string = include_str!("log_parameter_fail_empty.leo");
2020-12-17 00:02:31 +03:00
let error = parse_program(program_string).err().unwrap();
2020-07-10 05:23:15 +03:00
2020-12-17 00:02:31 +03:00
expect_asg_error(error);
2020-07-10 05:23:15 +03:00
}
#[test]
2020-12-17 00:02:31 +03:00
fn test_log_parameter_fail_unknown() {
let program_string = include_str!("log_parameter_fail_unknown.leo");
let error = parse_program(program_string).err().unwrap();
2020-07-10 05:23:15 +03:00
2020-12-17 00:02:31 +03:00
expect_asg_error(error);
2020-07-10 05:23:15 +03:00
}
#[test]
2020-08-17 03:20:47 +03:00
fn test_log_input() {
2020-12-04 23:48:43 +03:00
let program_string = include_str!("log_input.leo");
let mut program = parse_program(program_string).unwrap();
2020-07-10 05:23:15 +03:00
2020-08-01 06:59:50 +03:00
let main_input = generate_main_input(vec![("a", Some(InputValue::Boolean(true)))]);
2020-07-10 05:23:15 +03:00
2020-08-01 06:59:50 +03:00
program.set_main_input(main_input);
2020-07-31 02:27:31 +03:00
assert_satisfied(program);
2020-07-10 05:23:15 +03:00
}
2021-01-04 19:34:38 +03:00
#[test]
fn test_log_conditional() {
let program_string = include_str!("log_conditional.leo");
let input_equal_string = include_str!("input/input_equal.in");
let program = parse_program_with_input(program_string, input_equal_string).unwrap();
2021-01-04 19:34:38 +03:00
assert_satisfied(program);
let input_unequal_string = include_str!("input/input_unequal.in");
let program = parse_program_with_input(program_string, input_unequal_string).unwrap();
assert_satisfied(program);
}
2020-08-17 03:20:47 +03:00
// Debug
2020-07-10 05:23:15 +03:00
#[test]
fn test_debug() {
2020-12-04 23:48:43 +03:00
let program_string = include_str!("debug.leo");
let program = parse_program(program_string).unwrap();
2020-07-10 05:23:15 +03:00
2020-07-31 02:27:31 +03:00
assert_satisfied(program);
2020-07-10 05:23:15 +03:00
}
2020-07-31 02:27:31 +03:00
2020-08-17 03:20:47 +03:00
// Error
2020-07-10 05:23:15 +03:00
#[test]
fn test_error() {
2020-12-04 23:48:43 +03:00
let program_string = include_str!("error.leo");
let program = parse_program(program_string).unwrap();
2020-07-10 05:23:15 +03:00
2020-07-31 02:27:31 +03:00
assert_satisfied(program);
2020-07-10 05:23:15 +03:00
}
2020-08-17 03:20:47 +03:00
// Assertion
#[test]
fn test_assert() {
2020-12-04 23:48:43 +03:00
let program_string = include_str!("assert.leo");
let mut program = parse_program(program_string).unwrap();
2020-08-17 03:20:47 +03:00
let main_input = generate_main_input(vec![("a", Some(InputValue::Boolean(true)))]);
program.set_main_input(main_input);
assert_satisfied(program);
2020-12-04 23:48:43 +03:00
let mut program = parse_program(program_string).unwrap();
2020-08-17 03:20:47 +03:00
let main_input = generate_main_input(vec![("a", Some(InputValue::Boolean(false)))]);
program.set_main_input(main_input);
expect_compiler_error(program);
}
2020-08-17 05:14:26 +03:00
#[test]
fn test_conditional_assert() {
2020-12-04 23:48:43 +03:00
let program_string = include_str!("conditional_assert.leo");
let mut program = parse_program(program_string).unwrap();
2020-08-17 05:14:26 +03:00
let main_input = generate_main_input(vec![("a", Some(InputValue::Boolean(true)))]);
program.set_main_input(main_input);
assert_satisfied(program);
2020-12-04 23:48:43 +03:00
let mut program = parse_program(program_string).unwrap();
2020-08-17 05:14:26 +03:00
let main_input = generate_main_input(vec![("a", Some(InputValue::Boolean(false)))]);
program.set_main_input(main_input);
assert_satisfied(program);
}