test(parser): move over the validator tests and some misc tests to parser
This commit is contained in:
parent
6b05d6a91e
commit
bd8c13c372
|
@ -38,3 +38,24 @@ pub fn module(
|
|||
|
||||
Ok((module, extra))
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use crate::assert_module;
|
||||
|
||||
#[test]
|
||||
fn windows_newline() {
|
||||
assert_module!("use aiken/list\r\n");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn can_handle_comments_at_end_of_file() {
|
||||
assert_module!(
|
||||
r#"
|
||||
use aiken
|
||||
|
||||
// some comment
|
||||
// more comments"#
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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());
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
---
|
||||
source: crates/aiken-lang/src/tests/parser.rs
|
||||
source: crates/aiken-lang/src/parser.rs
|
||||
description: "Code:\n\nuse aiken\n\n// some comment\n// more comments"
|
||||
---
|
||||
Module {
|
|
@ -1,5 +1,5 @@
|
|||
---
|
||||
source: crates/aiken-lang/src/tests/parser.rs
|
||||
source: crates/aiken-lang/src/parser.rs
|
||||
description: "Code:\n\nuse aiken/list\r\n"
|
||||
---
|
||||
Module {
|
|
@ -1,20 +1,4 @@
|
|||
use crate::{assert_module, ast, parser};
|
||||
|
||||
#[test]
|
||||
fn windows_newline() {
|
||||
assert_module!("use aiken/list\r\n");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn can_handle_comments_at_end_of_file() {
|
||||
assert_module!(
|
||||
r#"
|
||||
use aiken
|
||||
|
||||
// some comment
|
||||
// more comments"#
|
||||
);
|
||||
}
|
||||
use crate::assert_module;
|
||||
|
||||
#[test]
|
||||
fn type_annotation_with_module_prefix() {
|
||||
|
@ -42,45 +26,6 @@ fn test_fail() {
|
|||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn validator() {
|
||||
assert_module!(
|
||||
r#"
|
||||
validator {
|
||||
fn foo(datum, rdmr, ctx) {
|
||||
True
|
||||
}
|
||||
}
|
||||
"#
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn double_validator() {
|
||||
assert_module!(
|
||||
r#"
|
||||
validator {
|
||||
fn foo(datum, rdmr, ctx) {
|
||||
True
|
||||
}
|
||||
|
||||
fn bar(rdmr, ctx) {
|
||||
True
|
||||
}
|
||||
}
|
||||
"#
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn import_alias() {
|
||||
assert_module!(
|
||||
r#"
|
||||
use std/tx as t
|
||||
"#
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn custom_type() {
|
||||
assert_module!(
|
||||
|
|
|
@ -1,109 +0,0 @@
|
|||
---
|
||||
source: crates/aiken-lang/src/tests/parser.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"
|
||||
---
|
||||
Module {
|
||||
name: "",
|
||||
docs: [],
|
||||
type_info: (),
|
||||
definitions: [
|
||||
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: [],
|
||||
},
|
||||
),
|
||||
],
|
||||
kind: Validator,
|
||||
}
|
|
@ -1,26 +0,0 @@
|
|||
---
|
||||
source: crates/aiken-lang/src/tests/parser.rs
|
||||
description: "Code:\n\nuse std/tx as t\n"
|
||||
---
|
||||
Module {
|
||||
name: "",
|
||||
docs: [],
|
||||
type_info: (),
|
||||
definitions: [
|
||||
Use(
|
||||
Use {
|
||||
as_name: Some(
|
||||
"t",
|
||||
),
|
||||
location: 0..15,
|
||||
module: [
|
||||
"std",
|
||||
"tx",
|
||||
],
|
||||
package: (),
|
||||
unqualified: [],
|
||||
},
|
||||
),
|
||||
],
|
||||
kind: Validator,
|
||||
}
|
|
@ -1,70 +0,0 @@
|
|||
---
|
||||
source: crates/aiken-lang/src/tests/parser.rs
|
||||
description: "Code:\n\nvalidator {\n fn foo(datum, rdmr, ctx) {\n True\n }\n}\n"
|
||||
---
|
||||
Module {
|
||||
name: "",
|
||||
docs: [],
|
||||
type_info: (),
|
||||
definitions: [
|
||||
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: [],
|
||||
},
|
||||
),
|
||||
],
|
||||
kind: Validator,
|
||||
}
|
Loading…
Reference in New Issue