test(parser): move over the validator tests and some misc tests to parser
This commit is contained in:
@@ -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]
|
||||
|
||||
@@ -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: [],
|
||||
},
|
||||
)
|
||||
@@ -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: [],
|
||||
},
|
||||
)
|
||||
@@ -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
|
||||
}
|
||||
}
|
||||
"#
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -49,8 +49,6 @@ pub fn parser<'a>(
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use chumsky::Parser;
|
||||
|
||||
use crate::assert_expr;
|
||||
|
||||
#[test]
|
||||
|
||||
@@ -17,8 +17,6 @@ pub fn parser() -> impl Parser<Token, UntypedExpr, Error = ParseError> {
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use chumsky::Parser;
|
||||
|
||||
use crate::assert_expr;
|
||||
|
||||
#[test]
|
||||
|
||||
@@ -30,8 +30,6 @@ pub fn parser(
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use chumsky::Parser;
|
||||
|
||||
use crate::assert_expr;
|
||||
|
||||
#[test]
|
||||
|
||||
@@ -97,6 +97,8 @@ pub fn type_name_with_args() -> impl Parser<Token, (String, Option<Vec<String>>)
|
||||
#[macro_export]
|
||||
macro_rules! assert_expr {
|
||||
($code:expr) => {
|
||||
use chumsky::Parser;
|
||||
|
||||
let $crate::parser::lexer::LexInfo { tokens, .. } = $crate::parser::lexer::run(indoc::indoc! { $code }).unwrap();
|
||||
|
||||
let stream = chumsky::Stream::from_iter($crate::ast::Span::create(tokens.len()), tokens.into_iter());
|
||||
@@ -117,7 +119,7 @@ macro_rules! assert_expr {
|
||||
macro_rules! assert_module {
|
||||
($code:expr) => {
|
||||
let (module, _) =
|
||||
parser::module(indoc::indoc!{ $code }, ast::ModuleKind::Validator).expect("Failed to parse code");
|
||||
$crate::parser::module(indoc::indoc!{ $code }, $crate::ast::ModuleKind::Validator).expect("Failed to parse code");
|
||||
|
||||
insta::with_settings!({
|
||||
description => concat!("Code:\n\n", indoc::indoc! { $code }),
|
||||
@@ -132,6 +134,8 @@ macro_rules! assert_module {
|
||||
#[macro_export]
|
||||
macro_rules! assert_definition {
|
||||
($code:expr) => {
|
||||
use chumsky::Parser;
|
||||
|
||||
let $crate::parser::lexer::LexInfo { tokens, .. } = $crate::parser::lexer::run(indoc::indoc! { $code }).unwrap();
|
||||
|
||||
let stream = chumsky::Stream::from_iter($crate::ast::Span::create(tokens.len()), tokens.into_iter());
|
||||
|
||||
Reference in New Issue
Block a user