diff --git a/crates/aiken-lang/src/parser/expr/record.rs b/crates/aiken-lang/src/parser/expr/record.rs index d27184f7..e8473a12 100644 --- a/crates/aiken-lang/src/parser/expr/record.rs +++ b/crates/aiken-lang/src/parser/expr/record.rs @@ -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)"#); + } +} diff --git a/crates/aiken-lang/src/parser/expr/snapshots/record_create_labeled.snap b/crates/aiken-lang/src/parser/expr/snapshots/record_create_labeled.snap new file mode 100644 index 00000000..13c2c433 --- /dev/null +++ b/crates/aiken-lang/src/parser/expr/snapshots/record_create_labeled.snap @@ -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, +} diff --git a/crates/aiken-lang/src/parser/expr/snapshots/record_create_labeled_with_field_access.snap b/crates/aiken-lang/src/parser/expr/snapshots/record_create_labeled_with_field_access.snap new file mode 100644 index 00000000..f1f46e9b --- /dev/null +++ b/crates/aiken-lang/src/parser/expr/snapshots/record_create_labeled_with_field_access.snap @@ -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, +} diff --git a/crates/aiken-lang/src/parser/expr/snapshots/record_create_unlabeled.snap b/crates/aiken-lang/src/parser/expr/snapshots/record_create_unlabeled.snap new file mode 100644 index 00000000..2f9f629c --- /dev/null +++ b/crates/aiken-lang/src/parser/expr/snapshots/record_create_unlabeled.snap @@ -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, +} diff --git a/crates/aiken-lang/src/tests/parser.rs b/crates/aiken-lang/src/tests/parser.rs index e927ac2d..54ffec99 100644 --- a/crates/aiken-lang/src/tests/parser.rs +++ b/crates/aiken-lang/src/tests/parser.rs @@ -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!( diff --git a/crates/aiken-lang/src/tests/snapshots/cargo_create_unlabeled.snap b/crates/aiken-lang/src/tests/snapshots/cargo_create_unlabeled.snap deleted file mode 100644 index 4aa1c2dd..00000000 --- a/crates/aiken-lang/src/tests/snapshots/cargo_create_unlabeled.snap +++ /dev/null @@ -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, -} diff --git a/crates/aiken-lang/src/tests/snapshots/record_create_labeled.snap b/crates/aiken-lang/src/tests/snapshots/record_create_labeled.snap deleted file mode 100644 index 1661a9c0..00000000 --- a/crates/aiken-lang/src/tests/snapshots/record_create_labeled.snap +++ /dev/null @@ -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, -} diff --git a/crates/aiken-lang/src/tests/snapshots/record_create_labeled_with_field_access.snap b/crates/aiken-lang/src/tests/snapshots/record_create_labeled_with_field_access.snap deleted file mode 100644 index 36383a8b..00000000 --- a/crates/aiken-lang/src/tests/snapshots/record_create_labeled_with_field_access.snap +++ /dev/null @@ -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, -}