test(parser): move over the validator tests and some misc tests to parser

This commit is contained in:
rvcas
2023-07-03 15:09:31 -04:00
parent 6b05d6a91e
commit bd8c13c372
15 changed files with 227 additions and 272 deletions

View File

@@ -58,8 +58,6 @@ pub fn parser() -> impl Parser<Token, ast::UntypedDefinition, Error = ParseError
#[cfg(test)]
mod tests {
use chumsky::Parser;
use crate::assert_definition;
#[test]

View File

@@ -0,0 +1,101 @@
---
source: crates/aiken-lang/src/parser/definition/validator.rs
description: "Code:\n\nvalidator {\n fn foo(datum, rdmr, ctx) {\n True\n }\n\n fn bar(rdmr, ctx) {\n True\n }\n}\n"
---
Validator(
Validator {
doc: None,
end_position: 90,
fun: Function {
arguments: [
Arg {
arg_name: Named {
name: "datum",
label: "datum",
location: 21..26,
is_validator_param: false,
},
location: 21..26,
annotation: None,
tipo: (),
},
Arg {
arg_name: Named {
name: "rdmr",
label: "rdmr",
location: 28..32,
is_validator_param: false,
},
location: 28..32,
annotation: None,
tipo: (),
},
Arg {
arg_name: Named {
name: "ctx",
label: "ctx",
location: 34..37,
is_validator_param: false,
},
location: 34..37,
annotation: None,
tipo: (),
},
],
body: Var {
location: 45..49,
name: "True",
},
doc: None,
location: 14..38,
name: "foo",
public: false,
return_annotation: None,
return_type: (),
end_position: 52,
can_error: true,
},
other_fun: Some(
Function {
arguments: [
Arg {
arg_name: Named {
name: "rdmr",
label: "rdmr",
location: 64..68,
is_validator_param: false,
},
location: 64..68,
annotation: None,
tipo: (),
},
Arg {
arg_name: Named {
name: "ctx",
label: "ctx",
location: 70..73,
is_validator_param: false,
},
location: 70..73,
annotation: None,
tipo: (),
},
],
body: Var {
location: 81..85,
name: "True",
},
doc: None,
location: 57..74,
name: "bar",
public: false,
return_annotation: None,
return_type: (),
end_position: 88,
can_error: true,
},
),
location: 0..9,
params: [],
},
)

View File

@@ -0,0 +1,62 @@
---
source: crates/aiken-lang/src/parser/definition/validator.rs
description: "Code:\n\nvalidator {\n fn foo(datum, rdmr, ctx) {\n True\n }\n}\n"
---
Validator(
Validator {
doc: None,
end_position: 54,
fun: Function {
arguments: [
Arg {
arg_name: Named {
name: "datum",
label: "datum",
location: 21..26,
is_validator_param: false,
},
location: 21..26,
annotation: None,
tipo: (),
},
Arg {
arg_name: Named {
name: "rdmr",
label: "rdmr",
location: 28..32,
is_validator_param: false,
},
location: 28..32,
annotation: None,
tipo: (),
},
Arg {
arg_name: Named {
name: "ctx",
label: "ctx",
location: 34..37,
is_validator_param: false,
},
location: 34..37,
annotation: None,
tipo: (),
},
],
body: Var {
location: 45..49,
name: "True",
},
doc: None,
location: 14..38,
name: "foo",
public: false,
return_annotation: None,
return_type: (),
end_position: 52,
can_error: true,
},
other_fun: None,
location: 0..9,
params: [],
},
)

View File

@@ -58,3 +58,38 @@ pub fn parser() -> impl Parser<Token, ast::UntypedDefinition, Error = ParseError
})
})
}
#[cfg(test)]
mod tests {
use crate::assert_definition;
#[test]
fn validator() {
assert_definition!(
r#"
validator {
fn foo(datum, rdmr, ctx) {
True
}
}
"#
);
}
#[test]
fn double_validator() {
assert_definition!(
r#"
validator {
fn foo(datum, rdmr, ctx) {
True
}
fn bar(rdmr, ctx) {
True
}
}
"#
);
}
}