aienux
Aienux, the AienOS kernel: boot, scheduling, IPC and capability boundaries. Pre-alpha; host, emulator and physical evidence are labelled separately.
Brought by drakestapleton
aienux / vendor / serde_json / tests / regression / issue979.rs
| 1 | use serde::de::{Deserializer, EnumAccess, VariantAccess, Visitor}; |
| 2 | use std::fmt; |
| 3 | |
| 4 | struct EnumVisitor; |
| 5 | |
| 6 | impl<'de> Visitor<'de> for EnumVisitor { |
| 7 | type Value = (Vec<bool>, ()); |
| 8 | |
| 9 | fn expecting(&self, formatter: &mut fmt::Formatter) -> fmt::Result { |
| 10 | formatter.write_str("enum") |
| 11 | } |
| 12 | |
| 13 | fn visit_enum<A>(self, data: A) -> Result<Self::Value, A::Error> |
| 14 | where |
| 15 | A: EnumAccess<'de>, |
| 16 | { |
| 17 | let (key, variant) = data.variant()?; |
| 18 | variant.newtype_variant::<()>()?; |
| 19 | Ok((key, ())) |
| 20 | } |
| 21 | } |
| 22 | |
| 23 | #[test] |
| 24 | fn test() { |
| 25 | let mut de = serde_json::Deserializer::from_str("{[true]: null}"); |
| 26 | let err = de.deserialize_enum("name", &[], EnumVisitor).unwrap_err(); |
| 27 | |
| 28 | assert!(err.to_string().contains("key must be a string")); |
| 29 | } |