leo/compiler/tests/syntax/mod.rs

55 lines
1.7 KiB
Rust
Raw Normal View History

use crate::{get_error, parse_inputs, 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};
use leo_inputs::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(_)) => {}
_ => 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-06-20 01:47:09 +03:00
let error = get_error(program);
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-06-23 08:32:57 +03:00
" --> \"/test/src/main.leo\": 2:10",
2020-06-20 03:28:50 +03:00
" |",
" 2 | return a",
" | ^",
" |",
" = cannot find value `a` in this scope",
]
.join("\n")
);
}
_ => panic!("expected an undefined identifier error"),
}
}
2020-06-20 01:47:09 +03:00
#[test]
fn inputs_syntax_error() {
let bytes = include_bytes!("inputs_semicolon.leo");
let error = parse_inputs(bytes).err().unwrap();
match error {
CompilerError::InputParserError(InputParserError::SyntaxError(_)) => {}
_ => panic!("inputs syntax error should be a ParserError"),
}
}