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