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
|
|
|
|
|
|
|
#[test]
|
|
|
|
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(_)) => {}
|
2020-06-08 08:21:31 +03:00
|
|
|
_ => panic!("test_semicolon failed the wrong expected error, should be a ParserError"),
|
2020-06-05 01:44:38 +03:00
|
|
|
}
|
|
|
|
}
|
2020-06-11 21:43:05 +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-06-11 21:43:05 +03:00
|
|
|
|
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-11 21:43:05 +03:00
|
|
|
}
|
2020-06-20 01:47:09 +03:00
|
|
|
|
2020-06-20 09:02:58 +03:00
|
|
|
#[test]
|
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();
|
2020-06-20 09:02:58 +03:00
|
|
|
|
|
|
|
match error {
|
|
|
|
CompilerError::InputParserError(InputParserError::SyntaxError(_)) => {}
|
2020-08-01 06:59:50 +03:00
|
|
|
_ => panic!("input syntax error should be a ParserError"),
|
2020-06-20 09:02:58 +03:00
|
|
|
}
|
|
|
|
}
|