leo/compiler/tests/syntax/mod.rs

84 lines
2.7 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/>.
2020-08-01 05:39:30 +03:00
use crate::{expect_compiler_error, parse_input, parse_program};
2020-06-09 03:28:09 +03:00
use leo_ast::ParserError;
2020-06-20 03:28:50 +03:00
use leo_compiler::errors::{CompilerError, ExpressionError, FunctionError, StatementError};
2020-08-01 04:49:01 +03:00
use leo_input::InputParserError;
2020-06-05 01:44:38 +03:00
pub mod identifiers;
2020-06-05 01:44:38 +03:00
#[test]
2020-08-11 00:46:36 +03:00
#[ignore]
2020-06-05 01:44:38 +03:00
fn test_semicolon() {
2020-06-09 03:28:09 +03:00
let bytes = include_bytes!("semicolon.leo");
let error = parse_program(bytes).err().unwrap();
2020-06-05 01:44:38 +03:00
match error {
2020-06-09 03:28:09 +03:00
CompilerError::ParserError(ParserError::SyntaxError(_)) => {}
_ => panic!("test_semicolon failed the wrong expected error, should be a ParserError"),
2020-06-05 01:44:38 +03:00
}
}
#[test]
2020-06-20 01:47:09 +03:00
fn test_undefined() {
let bytes = include_bytes!("undefined.leo");
let program = parse_program(bytes).unwrap();
2020-07-31 03:19:10 +03:00
let error = expect_compiler_error(program);
2020-06-20 01:47:09 +03:00
2020-06-20 03:28:50 +03:00
match error {
CompilerError::FunctionError(FunctionError::StatementError(StatementError::ExpressionError(
ExpressionError::Error(error),
))) => {
assert_eq!(
format!("{}", error),
vec![
2020-07-17 22:59:18 +03:00
" --> \"/test/src/main.leo\": 2:12",
2020-06-20 03:28:50 +03:00
" |",
2020-07-17 22:59:18 +03:00
" 2 | return a",
" | ^",
2020-06-20 03:28:50 +03:00
" |",
" = cannot find value `a` in this scope",
]
.join("\n")
);
}
_ => panic!("expected an undefined identifier error"),
}
}
2020-06-20 01:47:09 +03:00
#[test]
2020-08-11 00:46:36 +03:00
#[ignore]
2020-08-01 05:39:30 +03:00
fn input_syntax_error() {
2020-08-01 06:59:50 +03:00
let bytes = include_bytes!("input_semicolon.leo");
2020-08-01 05:39:30 +03:00
let error = parse_input(bytes).err().unwrap();
match error {
CompilerError::InputParserError(InputParserError::SyntaxError(_)) => {}
2020-08-01 06:59:50 +03:00
_ => panic!("input syntax error should be a ParserError"),
}
}
2020-08-17 11:30:13 +03:00
#[test]
fn test_compare_mismatched_types() {
let bytes = include_bytes!("compare_mismatched_types.leo");
let program = parse_program(bytes).unwrap();
// previously this bug caused a stack overflow
expect_compiler_error(program);
}