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