feat: update syntax for failing test to be more consistent
This commit is contained in:
parent
0be09cd9e5
commit
03e7d6e944
|
@ -239,6 +239,7 @@ impl<'comments> Formatter<'comments> {
|
|||
return_annotation,
|
||||
body,
|
||||
*end_position,
|
||||
false,
|
||||
),
|
||||
|
||||
Definition::Validator(Validator {
|
||||
|
@ -258,12 +259,13 @@ impl<'comments> Formatter<'comments> {
|
|||
..
|
||||
}) => self.definition_fn(
|
||||
&false,
|
||||
if *can_error { "!test" } else { "test" },
|
||||
"test",
|
||||
name,
|
||||
args,
|
||||
&None,
|
||||
body,
|
||||
*end_position,
|
||||
*can_error,
|
||||
),
|
||||
|
||||
Definition::TypeAlias(TypeAlias {
|
||||
|
@ -483,13 +485,15 @@ impl<'comments> Formatter<'comments> {
|
|||
return_annotation: &'a Option<Annotation>,
|
||||
body: &'a UntypedExpr,
|
||||
end_location: usize,
|
||||
can_error: bool,
|
||||
) -> Document<'a> {
|
||||
// Fn name and args
|
||||
let head = pub_(*public)
|
||||
.append(keyword)
|
||||
.append(" ")
|
||||
.append(name)
|
||||
.append(wrap_args(args.iter().map(|e| (self.fn_arg(e), false))));
|
||||
.append(wrap_args(args.iter().map(|e| (self.fn_arg(e), false))))
|
||||
.append(if can_error { " fail" } else { "" });
|
||||
|
||||
// Add return annotation
|
||||
let head = match return_annotation {
|
||||
|
@ -532,6 +536,7 @@ impl<'comments> Formatter<'comments> {
|
|||
&fun.return_annotation,
|
||||
&fun.body,
|
||||
fun.end_position,
|
||||
false,
|
||||
)
|
||||
.group();
|
||||
let first_fn = commented(fun_doc_comments.append(first_fn).group(), fun_comments);
|
||||
|
@ -551,6 +556,7 @@ impl<'comments> Formatter<'comments> {
|
|||
&other.return_annotation,
|
||||
&other.body,
|
||||
other.end_position,
|
||||
false,
|
||||
)
|
||||
.group();
|
||||
|
||||
|
|
|
@ -1,22 +1,22 @@
|
|||
---
|
||||
source: crates/aiken-lang/src/parser/definition/test.rs
|
||||
description: "Code:\n\n!test invalid_inputs() {\n expect True = False\n\n False\n}\n"
|
||||
description: "Code:\n\ntest invalid_inputs() fail {\n expect True = False\n\n False\n}\n"
|
||||
---
|
||||
Test(
|
||||
Function {
|
||||
arguments: [],
|
||||
body: Sequence {
|
||||
location: 27..55,
|
||||
location: 31..59,
|
||||
expressions: [
|
||||
Assignment {
|
||||
location: 27..46,
|
||||
location: 31..50,
|
||||
value: Var {
|
||||
location: 41..46,
|
||||
location: 45..50,
|
||||
name: "False",
|
||||
},
|
||||
pattern: Constructor {
|
||||
is_record: false,
|
||||
location: 34..38,
|
||||
location: 38..42,
|
||||
name: "True",
|
||||
arguments: [],
|
||||
module: None,
|
||||
|
@ -28,18 +28,18 @@ Test(
|
|||
annotation: None,
|
||||
},
|
||||
Var {
|
||||
location: 50..55,
|
||||
location: 54..59,
|
||||
name: "False",
|
||||
},
|
||||
],
|
||||
},
|
||||
doc: None,
|
||||
location: 0..22,
|
||||
location: 0..26,
|
||||
name: "invalid_inputs",
|
||||
public: false,
|
||||
return_annotation: None,
|
||||
return_type: (),
|
||||
end_position: 56,
|
||||
end_position: 60,
|
||||
can_error: true,
|
||||
},
|
||||
)
|
|
@ -7,20 +7,18 @@ use crate::{
|
|||
};
|
||||
|
||||
pub fn parser() -> impl Parser<Token, ast::UntypedDefinition, Error = ParseError> {
|
||||
just(Token::Bang)
|
||||
.ignored()
|
||||
.or_not()
|
||||
.then_ignore(just(Token::Test))
|
||||
.then(select! {Token::Name {name} => name})
|
||||
just(Token::Test)
|
||||
.ignore_then(select! {Token::Name {name} => name})
|
||||
.then_ignore(just(Token::LeftParen))
|
||||
.then_ignore(just(Token::RightParen))
|
||||
.then(just(Token::Fail).ignored().or_not())
|
||||
.map_with_span(|name, span| (name, span))
|
||||
.then(
|
||||
expr::sequence()
|
||||
.or_not()
|
||||
.delimited_by(just(Token::LeftBrace), just(Token::RightBrace)),
|
||||
)
|
||||
.map_with_span(|(((fail, name), span_end), body), span| {
|
||||
.map_with_span(|(((name, fail), span_end), body), span| {
|
||||
ast::UntypedDefinition::Test(ast::Function {
|
||||
arguments: vec![],
|
||||
body: body.unwrap_or_else(|| UntypedExpr::todo(None, span)),
|
||||
|
@ -41,10 +39,10 @@ mod tests {
|
|||
use crate::assert_definition;
|
||||
|
||||
#[test]
|
||||
fn test_fail() {
|
||||
fn def_test_fail() {
|
||||
assert_definition!(
|
||||
r#"
|
||||
!test invalid_inputs() {
|
||||
test invalid_inputs() fail {
|
||||
expect True = False
|
||||
|
||||
False
|
||||
|
|
|
@ -507,7 +507,7 @@ fn test_format_match_record() {
|
|||
fn test_format_fail() {
|
||||
assert_format!(
|
||||
r#"
|
||||
!test foo() {
|
||||
test foo() fail {
|
||||
expect Some(a) = bar
|
||||
|
||||
a
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
---
|
||||
source: crates/aiken-lang/src/tests/format.rs
|
||||
description: "Code:\n\n!test foo() {\n expect Some(a) = bar\n\n a\n}\n"
|
||||
description: "Code:\n\ntest foo() fail {\n expect Some(a) = bar\n\n a\n}\n"
|
||||
---
|
||||
!test foo() {
|
||||
test foo() fail {
|
||||
expect Some(a) = bar
|
||||
|
||||
a
|
||||
|
|
Loading…
Reference in New Issue