Allow prop test argument to be (optionally) annotated.

This commit is contained in:
KtorZ
2024-03-02 11:19:21 +01:00
parent 93347d8e7b
commit cf61387a41
6 changed files with 87 additions and 6 deletions

View File

@@ -12,12 +12,13 @@ Test(
location: 9..10,
is_validator_param: false,
},
location: 9..16,
location: 9..10,
via: Var {
location: 15..16,
name: "f",
},
tipo: (),
annotation: None,
},
ArgVia {
arg_name: Named {
@@ -26,12 +27,13 @@ Test(
location: 18..19,
is_validator_param: false,
},
location: 18..25,
location: 18..19,
via: Var {
location: 24..25,
name: "g",
},
tipo: (),
annotation: None,
},
],
body: Var {

View File

@@ -12,7 +12,7 @@ Test(
location: 9..10,
is_validator_param: false,
},
location: 9..27,
location: 9..10,
via: FieldAccess {
location: 15..27,
label: "any_int",
@@ -22,6 +22,7 @@ Test(
},
},
tipo: (),
annotation: None,
},
],
body: Var {

View File

@@ -0,0 +1,55 @@
---
source: crates/aiken-lang/src/parser/definition/test.rs
description: "Code:\n\ntest foo(x: Int via foo()) {\n True\n}\n"
---
Test(
Function {
arguments: [
ArgVia {
arg_name: Named {
name: "x",
label: "x",
location: 9..10,
is_validator_param: false,
},
location: 9..15,
via: Call {
arguments: [],
fun: Var {
location: 20..23,
name: "foo",
},
location: 20..25,
},
tipo: (),
annotation: Some(
Constructor {
location: 12..15,
module: None,
name: "Int",
arguments: [],
},
),
},
],
body: Var {
location: 33..37,
name: "True",
},
doc: None,
location: 0..26,
name: "foo",
public: false,
return_annotation: Some(
Constructor {
location: 0..39,
module: None,
name: "Bool",
arguments: [],
},
),
return_type: (),
end_position: 38,
can_error: false,
},
)

View File

@@ -4,6 +4,7 @@ use crate::{
ast,
expr::UntypedExpr,
parser::{
annotation,
chain::{call::parser as call, field_access, tuple_index::parser as tuple_index, Chain},
error::ParseError,
expr::{self, var},
@@ -67,11 +68,13 @@ pub fn via() -> impl Parser<Token, ast::UntypedArgVia, Error = ParseError> {
}
}),
))
.then(just(Token::Colon).ignore_then(annotation()).or_not())
.then_ignore(just(Token::Via))
.then(fuzzer())
.map_with_span(|(arg_name, via), location| ast::ArgVia {
.map_with_span(|((arg_name, annotation), via), location| ast::ArgVia {
arg_name,
via,
annotation,
tipo: (),
location,
})
@@ -144,4 +147,15 @@ mod tests {
"#
);
}
#[test]
fn def_property_test_annotated_fuzzer() {
assert_definition!(
r#"
test foo(x: Int via foo()) {
True
}
"#
);
}
}