just/src/testing.rs

50 lines
1.3 KiB
Rust
Raw Normal View History

use crate::common::*;
2017-11-16 23:30:08 -08:00
pub fn parse_success(text: &str) -> Justfile {
2017-11-18 03:36:02 -08:00
match Parser::parse(text) {
2017-11-16 23:30:08 -08:00
Ok(justfile) => justfile,
Err(error) => panic!("Expected successful parse but got error:\n{}", error),
}
}
macro_rules! compilation_error_test {
(
name: $name:ident,
input: $input:expr,
index: $index:expr,
line: $line:expr,
column: $column:expr,
width: $width:expr,
kind: $kind:expr,
) => {
#[test]
fn $name() {
let input = $input;
2017-11-17 17:28:06 -08:00
let expected = crate::compilation_error::CompilationError {
text: input,
index: $index,
line: $line,
column: $column,
width: $width,
kind: $kind,
};
let tokens = crate::lexer::Lexer::lex(input).unwrap();
let parser = crate::parser::Parser::new(input, tokens);
if let Err(error) = parser.justfile() {
assert_eq!(error.text, expected.text);
assert_eq!(error.index, expected.index);
assert_eq!(error.line, expected.line);
assert_eq!(error.column, expected.column);
assert_eq!(error.width, expected.width);
assert_eq!(error.kind, expected.kind);
assert_eq!(error, expected);
} else {
panic!("parse succeeded but expected: {}\n{}", expected, input);
}
}
};
2017-11-16 23:30:08 -08:00
}