test(parser): record create
This commit is contained in:
parent
a75bcff5c8
commit
8a6c81493c
|
@ -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,
|
||||
}
|
|
@ -122,39 +122,6 @@ fn call() {
|
|||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn record_create_labeled() {
|
||||
assert_module!(
|
||||
r#"
|
||||
fn create() {
|
||||
User { name: "Aiken", age, thing: 2 }
|
||||
}
|
||||
"#
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn record_create_labeled_with_field_access() {
|
||||
assert_module!(
|
||||
r#"
|
||||
fn create() {
|
||||
some_module.User { name: "Aiken", age, thing: 2 }
|
||||
}
|
||||
"#
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn cargo_create_unlabeled() {
|
||||
assert_module!(
|
||||
r#"
|
||||
fn create() {
|
||||
some_module.Thing(1, a)
|
||||
}
|
||||
"#
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn parse_tuple() {
|
||||
assert_module!(
|
||||
|
|
|
@ -1,57 +0,0 @@
|
|||
---
|
||||
source: crates/aiken-lang/src/tests/parser.rs
|
||||
description: "Code:\n\nfn create() {\n some_module.Thing(1, a)\n}\n"
|
||||
---
|
||||
Module {
|
||||
name: "",
|
||||
docs: [],
|
||||
type_info: (),
|
||||
definitions: [
|
||||
Fn(
|
||||
Function {
|
||||
arguments: [],
|
||||
body: Call {
|
||||
arguments: [
|
||||
CallArg {
|
||||
label: None,
|
||||
location: 34..35,
|
||||
value: Int {
|
||||
location: 34..35,
|
||||
value: "1",
|
||||
base: Decimal {
|
||||
numeric_underscore: false,
|
||||
},
|
||||
},
|
||||
},
|
||||
CallArg {
|
||||
label: None,
|
||||
location: 37..38,
|
||||
value: Var {
|
||||
location: 37..38,
|
||||
name: "a",
|
||||
},
|
||||
},
|
||||
],
|
||||
fun: FieldAccess {
|
||||
location: 16..33,
|
||||
label: "Thing",
|
||||
container: Var {
|
||||
location: 16..27,
|
||||
name: "some_module",
|
||||
},
|
||||
},
|
||||
location: 16..39,
|
||||
},
|
||||
doc: None,
|
||||
location: 0..11,
|
||||
name: "create",
|
||||
public: false,
|
||||
return_annotation: None,
|
||||
return_type: (),
|
||||
end_position: 40,
|
||||
can_error: true,
|
||||
},
|
||||
),
|
||||
],
|
||||
kind: Validator,
|
||||
}
|
|
@ -1,74 +0,0 @@
|
|||
---
|
||||
source: crates/aiken-lang/src/tests/parser.rs
|
||||
description: "Code:\n\nfn create() {\n User { name: \"Aiken\", age, thing: 2 }\n}\n"
|
||||
---
|
||||
Module {
|
||||
name: "",
|
||||
docs: [],
|
||||
type_info: (),
|
||||
definitions: [
|
||||
Fn(
|
||||
Function {
|
||||
arguments: [],
|
||||
body: Call {
|
||||
arguments: [
|
||||
CallArg {
|
||||
label: Some(
|
||||
"name",
|
||||
),
|
||||
location: 23..36,
|
||||
value: ByteArray {
|
||||
location: 29..36,
|
||||
bytes: [
|
||||
65,
|
||||
105,
|
||||
107,
|
||||
101,
|
||||
110,
|
||||
],
|
||||
preferred_format: Utf8String,
|
||||
},
|
||||
},
|
||||
CallArg {
|
||||
label: Some(
|
||||
"age",
|
||||
),
|
||||
location: 38..41,
|
||||
value: Var {
|
||||
location: 38..41,
|
||||
name: "age",
|
||||
},
|
||||
},
|
||||
CallArg {
|
||||
label: Some(
|
||||
"thing",
|
||||
),
|
||||
location: 43..51,
|
||||
value: Int {
|
||||
location: 50..51,
|
||||
value: "2",
|
||||
base: Decimal {
|
||||
numeric_underscore: false,
|
||||
},
|
||||
},
|
||||
},
|
||||
],
|
||||
fun: Var {
|
||||
location: 16..20,
|
||||
name: "User",
|
||||
},
|
||||
location: 16..53,
|
||||
},
|
||||
doc: None,
|
||||
location: 0..11,
|
||||
name: "create",
|
||||
public: false,
|
||||
return_annotation: None,
|
||||
return_type: (),
|
||||
end_position: 54,
|
||||
can_error: true,
|
||||
},
|
||||
),
|
||||
],
|
||||
kind: Validator,
|
||||
}
|
|
@ -1,78 +0,0 @@
|
|||
---
|
||||
source: crates/aiken-lang/src/tests/parser.rs
|
||||
description: "Code:\n\nfn create() {\n some_module.User { name: \"Aiken\", age, thing: 2 }\n}\n"
|
||||
---
|
||||
Module {
|
||||
name: "",
|
||||
docs: [],
|
||||
type_info: (),
|
||||
definitions: [
|
||||
Fn(
|
||||
Function {
|
||||
arguments: [],
|
||||
body: Call {
|
||||
arguments: [
|
||||
CallArg {
|
||||
label: Some(
|
||||
"name",
|
||||
),
|
||||
location: 35..48,
|
||||
value: ByteArray {
|
||||
location: 41..48,
|
||||
bytes: [
|
||||
65,
|
||||
105,
|
||||
107,
|
||||
101,
|
||||
110,
|
||||
],
|
||||
preferred_format: Utf8String,
|
||||
},
|
||||
},
|
||||
CallArg {
|
||||
label: Some(
|
||||
"age",
|
||||
),
|
||||
location: 50..53,
|
||||
value: Var {
|
||||
location: 50..53,
|
||||
name: "age",
|
||||
},
|
||||
},
|
||||
CallArg {
|
||||
label: Some(
|
||||
"thing",
|
||||
),
|
||||
location: 55..63,
|
||||
value: Int {
|
||||
location: 62..63,
|
||||
value: "2",
|
||||
base: Decimal {
|
||||
numeric_underscore: false,
|
||||
},
|
||||
},
|
||||
},
|
||||
],
|
||||
fun: FieldAccess {
|
||||
location: 16..32,
|
||||
label: "User",
|
||||
container: Var {
|
||||
location: 16..27,
|
||||
name: "some_module",
|
||||
},
|
||||
},
|
||||
location: 16..65,
|
||||
},
|
||||
doc: None,
|
||||
location: 0..11,
|
||||
name: "create",
|
||||
public: false,
|
||||
return_annotation: None,
|
||||
return_type: (),
|
||||
end_position: 66,
|
||||
can_error: true,
|
||||
},
|
||||
),
|
||||
],
|
||||
kind: Validator,
|
||||
}
|
Loading…
Reference in New Issue