Skip to content

Commit

Permalink
Allow borrowed and owned strings and bytes and u8, u16, u64 for varia…
Browse files Browse the repository at this point in the history
…nt keys in serde_test
  • Loading branch information
Mingun committed Oct 22, 2020
1 parent 0737474 commit e805717
Show file tree
Hide file tree
Showing 2 changed files with 68 additions and 0 deletions.
28 changes: 28 additions & 0 deletions serde_test/src/de.rs
Expand Up @@ -168,14 +168,42 @@ impl<'de, 'a> de::Deserializer<'de> for &'a mut Deserializer<'de> {
self.next_token();
visitor.visit_str(variant)
}
(Token::BorrowedStr(variant), Token::Unit) => {
self.next_token();
visitor.visit_borrowed_str(variant)
}
(Token::String(variant), Token::Unit) => {
self.next_token();
visitor.visit_string(variant.to_string())
}
(Token::Bytes(variant), Token::Unit) => {
self.next_token();
visitor.visit_bytes(variant)
}
(Token::BorrowedBytes(variant), Token::Unit) => {
self.next_token();
visitor.visit_borrowed_bytes(variant)
}
(Token::ByteBuf(variant), Token::Unit) => {
self.next_token();
visitor.visit_byte_buf(variant.to_vec())
}
(Token::U8(variant), Token::Unit) => {
self.next_token();
visitor.visit_u8(variant)
}
(Token::U16(variant), Token::Unit) => {
self.next_token();
visitor.visit_u16(variant)
}
(Token::U32(variant), Token::Unit) => {
self.next_token();
visitor.visit_u32(variant)
}
(Token::U64(variant), Token::Unit) => {
self.next_token();
visitor.visit_u64(variant)
}
(variant, Token::Unit) => unexpected!(variant),
(variant, _) => {
visitor.visit_map(EnumMapVisitor::new(self, variant, EnumFormat::Any))
Expand Down
40 changes: 40 additions & 0 deletions test_suite/tests/test_de.rs
Expand Up @@ -693,6 +693,46 @@ declare_tests! {
Token::SeqEnd,
],
}
test_struct_borrowed_keys {
Struct { a: 1, b: 2, c: 0 } => &[
Token::Map { len: Some(3) },
Token::BorrowedStr("a"),
Token::I32(1),

Token::BorrowedStr("b"),
Token::I32(2),
Token::MapEnd,
],
Struct { a: 1, b: 2, c: 0 } => &[
Token::Struct { name: "Struct", len: 2 },
Token::BorrowedStr("a"),
Token::I32(1),

Token::BorrowedStr("b"),
Token::I32(2),
Token::StructEnd,
],
}
test_struct_owned_keys {
Struct { a: 1, b: 2, c: 0 } => &[
Token::Map { len: Some(3) },
Token::String("a"),
Token::I32(1),

Token::String("b"),
Token::I32(2),
Token::MapEnd,
],
Struct { a: 1, b: 2, c: 0 } => &[
Token::Struct { name: "Struct", len: 2 },
Token::String("a"),
Token::I32(1),

Token::String("b"),
Token::I32(2),
Token::StructEnd,
],
}
test_struct_with_skip {
Struct { a: 1, b: 2, c: 0 } => &[
Token::Map { len: Some(3) },
Expand Down

0 comments on commit e805717

Please sign in to comment.