test(parser): record create
This commit is contained in:
@@ -150,3 +150,23 @@ pub fn parser(
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use crate::assert_expr;
|
||||
|
||||
#[test]
|
||||
fn record_create_labeled() {
|
||||
assert_expr!(r#"User { name: "Aiken", age, thing: 2 }"#);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn record_create_labeled_with_field_access() {
|
||||
assert_expr!(r#"some_module.User { name: "Aiken", age, thing: 2 }"#);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn record_create_unlabeled() {
|
||||
assert_expr!(r#"some_module.Thing(1, a)"#);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,53 @@
|
||||
---
|
||||
source: crates/aiken-lang/src/parser/expr/record.rs
|
||||
description: "Code:\n\nUser { name: \"Aiken\", age, thing: 2 }"
|
||||
---
|
||||
Call {
|
||||
arguments: [
|
||||
CallArg {
|
||||
label: Some(
|
||||
"name",
|
||||
),
|
||||
location: 7..20,
|
||||
value: ByteArray {
|
||||
location: 13..20,
|
||||
bytes: [
|
||||
65,
|
||||
105,
|
||||
107,
|
||||
101,
|
||||
110,
|
||||
],
|
||||
preferred_format: Utf8String,
|
||||
},
|
||||
},
|
||||
CallArg {
|
||||
label: Some(
|
||||
"age",
|
||||
),
|
||||
location: 22..25,
|
||||
value: Var {
|
||||
location: 22..25,
|
||||
name: "age",
|
||||
},
|
||||
},
|
||||
CallArg {
|
||||
label: Some(
|
||||
"thing",
|
||||
),
|
||||
location: 27..35,
|
||||
value: Int {
|
||||
location: 34..35,
|
||||
value: "2",
|
||||
base: Decimal {
|
||||
numeric_underscore: false,
|
||||
},
|
||||
},
|
||||
},
|
||||
],
|
||||
fun: Var {
|
||||
location: 0..4,
|
||||
name: "User",
|
||||
},
|
||||
location: 0..37,
|
||||
}
|
||||
@@ -0,0 +1,57 @@
|
||||
---
|
||||
source: crates/aiken-lang/src/parser/expr/record.rs
|
||||
description: "Code:\n\nsome_module.User { name: \"Aiken\", age, thing: 2 }"
|
||||
---
|
||||
Call {
|
||||
arguments: [
|
||||
CallArg {
|
||||
label: Some(
|
||||
"name",
|
||||
),
|
||||
location: 19..32,
|
||||
value: ByteArray {
|
||||
location: 25..32,
|
||||
bytes: [
|
||||
65,
|
||||
105,
|
||||
107,
|
||||
101,
|
||||
110,
|
||||
],
|
||||
preferred_format: Utf8String,
|
||||
},
|
||||
},
|
||||
CallArg {
|
||||
label: Some(
|
||||
"age",
|
||||
),
|
||||
location: 34..37,
|
||||
value: Var {
|
||||
location: 34..37,
|
||||
name: "age",
|
||||
},
|
||||
},
|
||||
CallArg {
|
||||
label: Some(
|
||||
"thing",
|
||||
),
|
||||
location: 39..47,
|
||||
value: Int {
|
||||
location: 46..47,
|
||||
value: "2",
|
||||
base: Decimal {
|
||||
numeric_underscore: false,
|
||||
},
|
||||
},
|
||||
},
|
||||
],
|
||||
fun: FieldAccess {
|
||||
location: 0..16,
|
||||
label: "User",
|
||||
container: Var {
|
||||
location: 0..11,
|
||||
name: "some_module",
|
||||
},
|
||||
},
|
||||
location: 0..49,
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
---
|
||||
source: crates/aiken-lang/src/parser/expr/record.rs
|
||||
description: "Code:\n\nsome_module.Thing(1, a)"
|
||||
---
|
||||
Call {
|
||||
arguments: [
|
||||
CallArg {
|
||||
label: None,
|
||||
location: 18..19,
|
||||
value: Int {
|
||||
location: 18..19,
|
||||
value: "1",
|
||||
base: Decimal {
|
||||
numeric_underscore: false,
|
||||
},
|
||||
},
|
||||
},
|
||||
CallArg {
|
||||
label: None,
|
||||
location: 21..22,
|
||||
value: Var {
|
||||
location: 21..22,
|
||||
name: "a",
|
||||
},
|
||||
},
|
||||
],
|
||||
fun: FieldAccess {
|
||||
location: 0..17,
|
||||
label: "Thing",
|
||||
container: Var {
|
||||
location: 0..11,
|
||||
name: "some_module",
|
||||
},
|
||||
},
|
||||
location: 0..23,
|
||||
}
|
||||
Reference in New Issue
Block a user