From 7a02d7377051e3afc07c4db628d76fdc64e8b2c2 Mon Sep 17 00:00:00 2001 From: David Tolnay Date: Sun, 12 Dec 2021 18:56:04 -0800 Subject: [PATCH] Delete disabled borrowed string deserializer test --- tests/test_visitor.rs | 101 ------------------------------------------ 1 file changed, 101 deletions(-) delete mode 100644 tests/test_visitor.rs diff --git a/tests/test_visitor.rs b/tests/test_visitor.rs deleted file mode 100644 index bb90ea11..00000000 --- a/tests/test_visitor.rs +++ /dev/null @@ -1,101 +0,0 @@ -use serde::de::{Deserialize, Deserializer, SeqAccess, Visitor}; -use serde::ser::{Serialize, Serializer}; -use std::collections::HashSet; -use std::fmt; - -#[derive(Debug, Clone, Eq, PartialEq)] -struct Names { - inner: HashSet, -} - -impl Serialize for Names { - fn serialize(&self, serializer: S) -> Result - where - S: Serializer, - { - let mut names: Vec<_> = self.inner.iter().collect(); - names.sort(); - names.serialize(serializer) - } -} - -impl<'de> Deserialize<'de> for Names { - fn deserialize(deserializer: D) -> Result - where - D: Deserializer<'de>, - { - deserializer.deserialize_any(NamesVisitor) - } -} - -struct NamesVisitor; - -impl<'de> Visitor<'de> for NamesVisitor { - type Value = Names; - - fn expecting(&self, formatter: &mut fmt::Formatter) -> fmt::Result { - formatter.write_str("names or list of names") - } - - fn visit_str(self, v: &str) -> Result - where - E: serde::de::Error, - { - let mut out = HashSet::new(); - out.insert(v.to_string()); - Ok(Names { inner: out }) - } - - fn visit_seq(self, mut seq: A) -> Result - where - A: SeqAccess<'de>, - { - let mut out: HashSet = HashSet::new(); - - // FIXME: Change `&str` to String to make the error go away - while let Some(s) = seq.next_element::<&str>()? { - out.insert(s.to_string()); - } - Ok(Names { inner: out }) - } -} - -#[test] -#[ignore] -/// This test is an almost exact replica of the "string or struct" example -/// in the [serde guide](https://serde.rs/string-or-struct.html) -/// -/// FIXME: it currently breaks. If you explicitly select `String` instead -/// of `&str` in the FIXME above, it works. -fn test_visitor() { - let single = r#" ---- -"foo" -"#; - let single_expected = Names { - inner: { - let mut i = HashSet::new(); - i.insert("foo".into()); - i - }, - }; - let multi = r#" ---- -- "foo" -- "bar" -"#; - let multi_expected = Names { - inner: { - let mut i = HashSet::new(); - i.insert("foo".into()); - i.insert("bar".into()); - i - }, - }; - - let result: Names = serde_yaml::from_str(single).expect("didn't deserialize"); - assert_eq!(result, single_expected); - - let result: Names = serde_yaml::from_str(multi).expect("didn't deserialize"); - assert_eq!(result, multi_expected); -}