Skip to content

Commit

Permalink
Add json test for identity
Browse files Browse the repository at this point in the history
  • Loading branch information
mamcx committed Nov 3, 2023
1 parent 4679945 commit d7d2507
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 5 deletions.
6 changes: 5 additions & 1 deletion crates/lib/src/identity.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ pub struct Identity {
__identity_bytes: [u8; 32],
}

impl_st!([] Identity, _ts => AlgebraicType::product([("__identity_bytes", AlgebraicType::bytes())]));
impl_st!([] Identity, _ts => Identity::get_type());

impl Identity {
/// Returns an `Identity` defined as the given `bytes` byte array.
Expand All @@ -53,6 +53,10 @@ impl Identity {
Self::from_byte_array([0; 32])
}

pub fn get_type() -> AlgebraicType {
AlgebraicType::product([("__identity_bytes", AlgebraicType::bytes())])
}

/// Returns a borrowed view of the byte array defining this `Identity`.
pub fn as_bytes(&self) -> &[u8; 32] {
&self.__identity_bytes
Expand Down
7 changes: 5 additions & 2 deletions crates/lib/tests/serde.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,14 +56,16 @@ fn test_json_mappings() {
enumm([("Hash", AlgebraicType::bytes()), ("Unit", AlgebraicType::unit())]).into(),
),
("and_peggy", AlgebraicType::option(AlgebraicType::F64)),
("identity", Identity::get_type()),
]);
let data = r#"
{
"foo": 42,
"bar": "404040FFFF0A48656C6C6F",
"baz": ["heyyyyyy", "hooo"],
"quux": { "Hash": "54a3e6d2b0959deaacf102292b1cbd6fcbb8cf237f73306e27ed82c3153878aa" },
"and_peggy": { "some": 3.141592653589793238426 }
"and_peggy": { "some": 3.141592653589793238426 },
"identity": ["0000000000000000000000000000000000000000000000000000000000000000"]
}
"#; // all of those ^^^^^^ digits are from memory
de_json_snapshot!(schema, data);
Expand All @@ -73,7 +75,8 @@ fn test_json_mappings() {
"bar": [1, 15, 44],
"baz": ["it's 🥶°C"],
"quux": { "Unit": [] },
"and_peggy": null
"and_peggy": null,
"identity": ["0000000000000000000000000000000000000000000000000000000000000000"]
}
"#;
de_json_snapshot!(schema, data);
Expand Down
5 changes: 4 additions & 1 deletion crates/lib/tests/snapshots/serde__json_mappings-2.snap
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
---
source: crates/lib/tests/serde.rs
expression: "de_json({\n \"foo\": 5654,\n \"bar\": [1, 15, 44],\n \"baz\": [\"it's 🥶°C\"],\n \"quux\": { \"Unit\": [] },\n \"and_peggy\": null\n})"
expression: "de_json({\n \"foo\": 5654,\n \"bar\": [1, 15, 44],\n \"baz\": [\"it's 🥶°C\"],\n \"quux\": { \"Unit\": [] },\n \"and_peggy\": null,\n \"identity\": [\"0000000000000000000000000000000000000000000000000000000000000000\"]\n})"
---
(
foo = 5654,
Expand All @@ -14,4 +14,7 @@ expression: "de_json({\n \"foo\": 5654,\n \"bar\": [1, 15, 44],\n \"baz
and_peggy = (
none = (),
),
identity = (
__identity_bytes = 0000000000000000000000000000000000000000000000000000000000000000,
),
)
5 changes: 4 additions & 1 deletion crates/lib/tests/snapshots/serde__json_mappings.snap
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
---
source: crates/lib/tests/serde.rs
expression: "de_json({\n \"foo\": 42,\n \"bar\": \"404040FFFF0A48656C6C6F\",\n \"baz\": [\"heyyyyyy\", \"hooo\"],\n \"quux\": { \"Hash\": \"54a3e6d2b0959deaacf102292b1cbd6fcbb8cf237f73306e27ed82c3153878aa\" },\n \"and_peggy\": { \"some\": 3.141592653589793238426 }\n})"
expression: "de_json({\n \"foo\": 42,\n \"bar\": \"404040FFFF0A48656C6C6F\",\n \"baz\": [\"heyyyyyy\", \"hooo\"],\n \"quux\": { \"Hash\": \"54a3e6d2b0959deaacf102292b1cbd6fcbb8cf237f73306e27ed82c3153878aa\" },\n \"and_peggy\": { \"some\": 3.141592653589793238426 },\n \"identity\": [\"0000000000000000000000000000000000000000000000000000000000000000\"]\n})"
---
(
foo = 42,
Expand All @@ -15,4 +15,7 @@ expression: "de_json({\n \"foo\": 42,\n \"bar\": \"404040FFFF0A48656C6C6F\
and_peggy = (
some = 3.141592653589793,
),
identity = (
__identity_bytes = 0000000000000000000000000000000000000000000000000000000000000000,
),
)

0 comments on commit d7d2507

Please sign in to comment.