Unit: add tests for deserialization from bytes tag and content fields

This commit is contained in:
Mingun 2024-08-16 22:35:54 +05:00
parent a02da49b87
commit 6bfe1c435a

View File

@ -78,6 +78,43 @@ mod unit {
);
}
#[test]
fn map_bytes_tag_only() {
// Map: tag only
assert_de_tokens(
&AdjacentlyTagged::Unit::<u8>,
&[
Token::Struct {
name: "AdjacentlyTagged",
len: 1,
},
Token::Bytes(b"t"),
Token::UnitVariant {
name: "AdjacentlyTagged",
variant: "Unit",
},
Token::StructEnd,
],
);
// Map: tag only
assert_de_tokens(
&AdjacentlyTagged::Unit::<u8>,
&[
Token::Struct {
name: "AdjacentlyTagged",
len: 1,
},
Token::BorrowedBytes(b"t"),
Token::UnitVariant {
name: "AdjacentlyTagged",
variant: "Unit",
},
Token::StructEnd,
],
);
}
#[test]
fn map_str_tag_content() {
// Map: tag + content
@ -184,6 +221,47 @@ mod unit {
);
}
#[test]
fn map_bytes_tag_content() {
// Map: tag + content
assert_de_tokens(
&AdjacentlyTagged::Unit::<u8>,
&[
Token::Struct {
name: "AdjacentlyTagged",
len: 2,
},
Token::BorrowedBytes(b"t"),
Token::UnitVariant {
name: "AdjacentlyTagged",
variant: "Unit",
},
Token::BorrowedBytes(b"c"),
Token::Unit,
Token::StructEnd,
],
);
// Map: content + tag
assert_de_tokens(
&AdjacentlyTagged::Unit::<u8>,
&[
Token::Struct {
name: "AdjacentlyTagged",
len: 2,
},
Token::Bytes(b"c"),
Token::Unit,
Token::Bytes(b"t"),
Token::UnitVariant {
name: "AdjacentlyTagged",
variant: "Unit",
},
Token::StructEnd,
],
);
}
#[test]
fn seq_tag_content() {
// Seq: tag and content