2019-04-11 15:23:14 -07:00
|
|
|
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),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-04-15 22:40:02 -07:00
|
|
|
pub fn token_summary(tokens: &[Token]) -> String {
|
|
|
|
use TokenKind::*;
|
|
|
|
|
|
|
|
tokens
|
|
|
|
.iter()
|
|
|
|
.map(|t| match t.kind {
|
|
|
|
At => "@",
|
|
|
|
Backtick => "`",
|
|
|
|
Colon => ":",
|
|
|
|
Comma => ",",
|
|
|
|
Comment => "#",
|
|
|
|
Dedent => "<",
|
|
|
|
Eof => ".",
|
|
|
|
Eol => "$",
|
|
|
|
Equals => "=",
|
|
|
|
Indent => ">",
|
|
|
|
InterpolationEnd => "}",
|
|
|
|
InterpolationStart => "{",
|
|
|
|
Line => "^",
|
|
|
|
Name => "N",
|
|
|
|
ParenL => "(",
|
|
|
|
ParenR => ")",
|
|
|
|
Plus => "+",
|
|
|
|
StringRaw => "'",
|
|
|
|
StringCooked => "\"",
|
|
|
|
Text => "_",
|
|
|
|
Whitespace => " ",
|
|
|
|
})
|
|
|
|
.collect::<Vec<&str>>()
|
|
|
|
.join("")
|
|
|
|
}
|
|
|
|
|
2017-11-18 01:44:59 -08:00
|
|
|
macro_rules! compilation_error_test {
|
|
|
|
(
|
2019-04-15 22:40:02 -07:00
|
|
|
name: $name:ident,
|
|
|
|
input: $input:expr,
|
|
|
|
offset: $offset:expr,
|
|
|
|
line: $line:expr,
|
|
|
|
column: $column:expr,
|
|
|
|
width: $width:expr,
|
|
|
|
kind: $kind:expr,
|
2017-11-18 01:44:59 -08:00
|
|
|
) => {
|
|
|
|
#[test]
|
|
|
|
fn $name() {
|
|
|
|
let input = $input;
|
2017-11-17 17:28:06 -08:00
|
|
|
|
2019-04-11 15:23:14 -07:00
|
|
|
let expected = crate::compilation_error::CompilationError {
|
2018-12-08 14:29:41 -08:00
|
|
|
text: input,
|
2019-04-15 22:40:02 -07:00
|
|
|
offset: $offset,
|
2018-12-08 14:29:41 -08:00
|
|
|
line: $line,
|
2017-11-18 01:44:59 -08:00
|
|
|
column: $column,
|
2018-12-08 14:29:41 -08:00
|
|
|
width: $width,
|
|
|
|
kind: $kind,
|
2017-11-18 01:44:59 -08:00
|
|
|
};
|
|
|
|
|
2019-04-15 22:40:02 -07:00
|
|
|
let mut tokens = Lexer::lex(input).unwrap();
|
|
|
|
|
|
|
|
tokens.retain(|token| token.kind != TokenKind::Whitespace);
|
|
|
|
|
2019-04-11 15:23:14 -07:00
|
|
|
let parser = crate::parser::Parser::new(input, tokens);
|
2017-11-18 01:44:59 -08:00
|
|
|
|
|
|
|
if let Err(error) = parser.justfile() {
|
2018-12-08 14:29:41 -08:00
|
|
|
assert_eq!(error.text, expected.text);
|
2019-04-15 22:40:02 -07:00
|
|
|
assert_eq!(error.offset, expected.offset);
|
2018-12-08 14:29:41 -08:00
|
|
|
assert_eq!(error.line, expected.line);
|
2017-11-18 01:44:59 -08:00
|
|
|
assert_eq!(error.column, expected.column);
|
2018-12-08 14:29:41 -08:00
|
|
|
assert_eq!(error.width, expected.width);
|
|
|
|
assert_eq!(error.kind, expected.kind);
|
|
|
|
assert_eq!(error, expected);
|
2017-11-18 01:44:59 -08:00
|
|
|
} else {
|
|
|
|
panic!("parse succeeded but expected: {}\n{}", expected, input);
|
|
|
|
}
|
|
|
|
}
|
2018-12-08 14:29:41 -08:00
|
|
|
};
|
2017-11-16 23:30:08 -08:00
|
|
|
}
|