leo/compiler/tests/console/mod.rs

147 lines
3.9 KiB
Rust
Raw Normal View History

2020-09-03 04:45:48 +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/>.
2020-08-01 05:39:30 +03:00
use crate::{assert_satisfied, expect_compiler_error, generate_main_input, parse_program};
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-08-17 03:20:47 +03:00
fn test_log_parameter_fail_unknown() {
2020-12-04 23:48:43 +03:00
let program_string = include_str!("log_parameter_fail_unknown.leo");
let program = parse_program(program_string).unwrap();
2020-07-10 05:33:10 +03:00
2020-07-31 02:27:31 +03:00
expect_compiler_error(program);
2020-07-10 05:33:10 +03:00
}
2020-07-10 05:23:15 +03:00
#[test]
2020-08-17 03:20:47 +03:00
fn test_log_parameter_fail_empty() {
2020-12-04 23:48:43 +03:00
let program_string = include_str!("log_parameter_fail_empty.leo");
let program = parse_program(program_string).unwrap();
2020-07-10 05:23:15 +03:00
2020-07-31 02:27:31 +03:00
expect_compiler_error(program);
2020-07-10 05:23:15 +03:00
}
#[test]
2020-08-17 03:20:47 +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");
let program = parse_program(program_string).unwrap();
2020-07-10 05:23:15 +03:00
2020-07-31 02:27:31 +03:00
expect_compiler_error(program);
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
}
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);
}