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

@@ -54,3 +54,13 @@ pub fn params() -> impl Parser<Token, ast::UntypedArg, Error = ParseError> {
arg_name,
})
}
#[cfg(test)]
mod tests {
use crate::assert_expr;
#[test]
fn anonymous_function_basic() {
assert_expr!(r#"fn (a: Int) -> Int { a + 1 }"#);
}
}

View File

@@ -43,3 +43,13 @@ fn assignment(
},
)
}
#[cfg(test)]
mod tests {
use crate::assert_expr;
#[test]
fn let_bindings() {
assert_expr!(r#"let thing = [ 1, 2, a ]"#);
}
}

View File

@@ -84,3 +84,13 @@ pub fn parser(
}
})
}
#[cfg(test)]
mod tests {
use crate::assert_expr;
#[test]
fn record_update_basic() {
assert_expr!(r#"User { ..user, name: "Aiken", age }"#);
}
}

View File

@@ -0,0 +1,51 @@
---
source: crates/aiken-lang/src/parser/expr/anonymous_function.rs
description: "Code:\n\nfn (a: Int) -> Int { a + 1 }"
---
Fn {
location: 0..28,
fn_style: Plain,
arguments: [
Arg {
arg_name: Named {
name: "a",
label: "a",
location: 4..5,
is_validator_param: false,
},
location: 4..10,
annotation: Some(
Constructor {
location: 7..10,
module: None,
name: "Int",
arguments: [],
},
),
tipo: (),
},
],
body: BinOp {
location: 21..26,
name: AddInt,
left: Var {
location: 21..22,
name: "a",
},
right: Int {
location: 25..26,
value: "1",
base: Decimal {
numeric_underscore: false,
},
},
},
return_annotation: Some(
Constructor {
location: 15..18,
module: None,
name: "Int",
arguments: [],
},
),
}

View File

@@ -0,0 +1,37 @@
---
source: crates/aiken-lang/src/parser/expr/assignment.rs
description: "Code:\n\nlet thing = [ 1, 2, a ]"
---
Assignment {
location: 0..23,
value: List {
location: 12..23,
elements: [
Int {
location: 14..15,
value: "1",
base: Decimal {
numeric_underscore: false,
},
},
Int {
location: 17..18,
value: "2",
base: Decimal {
numeric_underscore: false,
},
},
Var {
location: 20..21,
name: "a",
},
],
tail: None,
},
pattern: Var {
location: 4..9,
name: "thing",
},
kind: Let,
annotation: None,
}

View File

@@ -0,0 +1,43 @@
---
source: crates/aiken-lang/src/parser/expr/record_update.rs
description: "Code:\n\nUser { ..user, name: \"Aiken\", age }"
---
RecordUpdate {
location: 0..35,
constructor: Var {
location: 0..4,
name: "User",
},
spread: RecordUpdateSpread {
base: Var {
location: 9..13,
name: "user",
},
location: 7..13,
},
arguments: [
UntypedRecordUpdateArg {
label: "name",
location: 15..28,
value: ByteArray {
location: 21..28,
bytes: [
65,
105,
107,
101,
110,
],
preferred_format: Utf8String,
},
},
UntypedRecordUpdateArg {
label: "age",
location: 30..33,
value: Var {
location: 30..33,
name: "age",
},
},
],
}