feat: adjust failing test syntax
* also add a formatter test
This commit is contained in:
parent
00ac6b6c56
commit
7b3e1c6952
|
@ -118,7 +118,6 @@ fn str_to_keyword(word: &str) -> Option<Token> {
|
|||
"test" => Some(Token::Test),
|
||||
"error" => Some(Token::ErrorTerm),
|
||||
"validator" => Some(Token::Validator),
|
||||
"fail" => Some(Token::Fail),
|
||||
_ => None,
|
||||
}
|
||||
}
|
||||
|
|
|
@ -251,8 +251,17 @@ impl<'comments> Formatter<'comments> {
|
|||
arguments: args,
|
||||
body,
|
||||
end_position,
|
||||
can_error,
|
||||
..
|
||||
}) => self.definition_fn(&false, "test", name, args, &None, body, *end_position),
|
||||
}) => self.definition_fn(
|
||||
&false,
|
||||
if *can_error { "!test" } else { "test" },
|
||||
name,
|
||||
args,
|
||||
&None,
|
||||
body,
|
||||
*end_position,
|
||||
),
|
||||
|
||||
Definition::TypeAlias(TypeAlias {
|
||||
alias,
|
||||
|
|
|
@ -337,8 +337,10 @@ pub fn fn_parser() -> impl Parser<Token, ast::UntypedDefinition, Error = ParseEr
|
|||
}
|
||||
|
||||
pub fn test_parser() -> impl Parser<Token, ast::UntypedDefinition, Error = ParseError> {
|
||||
just(Token::Test)
|
||||
.ignore_then(just(Token::Fail).ignored().or_not())
|
||||
just(Token::Bang)
|
||||
.ignored()
|
||||
.or_not()
|
||||
.then_ignore(just(Token::Test))
|
||||
.then(select! {Token::Name {name} => name})
|
||||
.then_ignore(just(Token::LeftParen))
|
||||
.then_ignore(just(Token::RightParen))
|
||||
|
|
|
@ -115,7 +115,6 @@ pub fn lexer() -> impl Parser<char, Vec<(Token, Span)>, Error = ParseError> {
|
|||
"todo" => Token::Todo,
|
||||
"type" => Token::Type,
|
||||
"when" => Token::When,
|
||||
"fail" => Token::Fail,
|
||||
"validator" => Token::Validator,
|
||||
_ => {
|
||||
if s.chars().next().map_or(false, |c| c.is_uppercase()) {
|
||||
|
|
|
@ -80,7 +80,6 @@ pub enum Token {
|
|||
When,
|
||||
Trace,
|
||||
Validator,
|
||||
Fail,
|
||||
}
|
||||
|
||||
impl fmt::Display for Token {
|
||||
|
@ -165,7 +164,6 @@ impl fmt::Display for Token {
|
|||
Token::Test => "test",
|
||||
Token::ErrorTerm => "error",
|
||||
Token::Validator => "validator",
|
||||
Token::Fail => "fail",
|
||||
};
|
||||
write!(f, "\"{s}\"")
|
||||
}
|
||||
|
|
|
@ -786,3 +786,16 @@ fn match_record() {
|
|||
|
||||
assert_fmt(src, src);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_fail() {
|
||||
let src = indoc! { r#"
|
||||
!test foo() {
|
||||
expect Some(a) = bar
|
||||
|
||||
a
|
||||
}
|
||||
"#};
|
||||
|
||||
assert_fmt(src, src);
|
||||
}
|
||||
|
|
|
@ -41,7 +41,7 @@ fn windows_newline() {
|
|||
#[test]
|
||||
fn test_fail() {
|
||||
let code = indoc! {r#"
|
||||
test fail invalid_inputs() {
|
||||
!test invalid_inputs() {
|
||||
expect True = False
|
||||
|
||||
False
|
||||
|
@ -53,17 +53,17 @@ fn test_fail() {
|
|||
vec![ast::UntypedDefinition::Test(ast::Function {
|
||||
arguments: vec![],
|
||||
body: expr::UntypedExpr::Sequence {
|
||||
location: Span::new((), 31..59),
|
||||
location: Span::new((), 27..55),
|
||||
expressions: vec![
|
||||
expr::UntypedExpr::Assignment {
|
||||
location: Span::new((), 31..50),
|
||||
location: Span::new((), 27..46),
|
||||
value: Box::new(expr::UntypedExpr::Var {
|
||||
location: Span::new((), 45..50),
|
||||
location: Span::new((), 41..46),
|
||||
name: "False".to_string(),
|
||||
}),
|
||||
pattern: ast::UntypedPattern::Constructor {
|
||||
is_record: false,
|
||||
location: Span::new((), 38..42),
|
||||
location: Span::new((), 34..38),
|
||||
name: "True".to_string(),
|
||||
arguments: vec![],
|
||||
module: None,
|
||||
|
@ -75,18 +75,18 @@ fn test_fail() {
|
|||
annotation: None,
|
||||
},
|
||||
expr::UntypedExpr::Var {
|
||||
location: Span::new((), 54..59),
|
||||
location: Span::new((), 50..55),
|
||||
name: "False".to_string(),
|
||||
},
|
||||
],
|
||||
},
|
||||
doc: None,
|
||||
location: Span::new((), 0..26),
|
||||
location: Span::new((), 0..22),
|
||||
name: "invalid_inputs".to_string(),
|
||||
public: false,
|
||||
return_annotation: None,
|
||||
return_type: (),
|
||||
end_position: 60,
|
||||
end_position: 56,
|
||||
can_error: true,
|
||||
})],
|
||||
);
|
||||
|
|
Loading…
Reference in New Issue