test(parser): type alias, anon fn, record update and more

This commit is contained in:
rvcas
2023-07-03 16:44:18 -04:00
parent bd8c13c372
commit a75bcff5c8
28 changed files with 453 additions and 713 deletions

View File

@@ -87,3 +87,26 @@ pub fn param(is_validator_param: bool) -> impl Parser<Token, ast::UntypedArg, Er
arg_name,
})
}
#[cfg(test)]
mod tests {
use crate::assert_definition;
#[test]
fn function_empty() {
assert_definition!(
r#"
pub fn run() {}
"#
);
}
#[test]
fn function_non_public() {
assert_definition!(
r#"
fn run() {}
"#
);
}
}

View File

@@ -0,0 +1,45 @@
---
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"
---
Test(
Function {
arguments: [],
body: Sequence {
location: 27..55,
expressions: [
Assignment {
location: 27..46,
value: Var {
location: 41..46,
name: "False",
},
pattern: Constructor {
is_record: false,
location: 34..38,
name: "True",
arguments: [],
module: None,
constructor: (),
with_spread: false,
tipo: (),
},
kind: Expect,
annotation: None,
},
Var {
location: 50..55,
name: "False",
},
],
},
doc: None,
location: 0..22,
name: "invalid_inputs",
public: false,
return_annotation: None,
return_type: (),
end_position: 56,
can_error: true,
},
)

View File

@@ -0,0 +1,28 @@
---
source: crates/aiken-lang/src/parser/definition/function.rs
description: "Code:\n\npub fn run() {}\n"
---
Fn(
Function {
arguments: [],
body: Trace {
kind: Todo,
location: 0..15,
then: ErrorTerm {
location: 0..15,
},
text: String {
location: 0..15,
value: "aiken::todo",
},
},
doc: None,
location: 0..12,
name: "run",
public: true,
return_annotation: None,
return_type: (),
end_position: 14,
can_error: true,
},
)

View File

@@ -0,0 +1,28 @@
---
source: crates/aiken-lang/src/parser/definition/function.rs
description: "Code:\n\nfn run() {}\n"
---
Fn(
Function {
arguments: [],
body: Trace {
kind: Todo,
location: 0..11,
then: ErrorTerm {
location: 0..11,
},
text: String {
location: 0..11,
value: "aiken::todo",
},
},
doc: None,
location: 0..8,
name: "run",
public: false,
return_annotation: None,
return_type: (),
end_position: 10,
can_error: true,
},
)

View File

@@ -0,0 +1,20 @@
---
source: crates/aiken-lang/src/parser/definition/type_alias.rs
description: "Code:\n\ntype Thing = Int"
---
TypeAlias(
TypeAlias {
alias: "Thing",
annotation: Constructor {
location: 13..16,
module: None,
name: "Int",
arguments: [],
},
doc: None,
location: 0..16,
parameters: [],
public: false,
tipo: (),
},
)

View File

@@ -0,0 +1,20 @@
---
source: crates/aiken-lang/src/parser/definition/type_alias.rs
description: "Code:\n\npub type Me = String"
---
TypeAlias(
TypeAlias {
alias: "Me",
annotation: Constructor {
location: 14..20,
module: None,
name: "String",
arguments: [],
},
doc: None,
location: 0..20,
parameters: [],
public: true,
tipo: (),
},
)

View File

@@ -0,0 +1,31 @@
---
source: crates/aiken-lang/src/parser/definition/type_alias.rs
description: "Code:\n\ntype RoyaltyToken = (PolicyId, AssetName)"
---
TypeAlias(
TypeAlias {
alias: "RoyaltyToken",
annotation: Tuple {
location: 20..41,
elems: [
Constructor {
location: 21..29,
module: None,
name: "PolicyId",
arguments: [],
},
Constructor {
location: 31..40,
module: None,
name: "AssetName",
arguments: [],
},
],
},
doc: None,
location: 0..41,
parameters: [],
public: false,
tipo: (),
},
)

View File

@@ -35,3 +35,21 @@ pub fn parser() -> impl Parser<Token, ast::UntypedDefinition, Error = ParseError
})
})
}
#[cfg(test)]
mod tests {
use crate::assert_definition;
#[test]
fn test_fail() {
assert_definition!(
r#"
!test invalid_inputs() {
expect True = False
False
}
"#
);
}
}

View File

@@ -23,3 +23,32 @@ pub fn parser() -> impl Parser<Token, ast::UntypedDefinition, Error = ParseError
})
})
}
#[cfg(test)]
mod tests {
use crate::assert_definition;
#[test]
fn type_alias_tuple() {
assert_definition!(
r#"
type RoyaltyToken = (PolicyId, AssetName)"#
);
}
#[test]
fn type_alias_basic() {
assert_definition!(
r#"
type Thing = Int"#
);
}
#[test]
fn type_alias_pub() {
assert_definition!(
r#"
pub type Me = String"#
);
}
}