Skip to content

Commit

Permalink
Test Weak deserialize impls
Browse files Browse the repository at this point in the history
  • Loading branch information
dtolnay committed May 7, 2018
1 parent bcb7019 commit ba0b553
Showing 1 changed file with 46 additions and 3 deletions.
49 changes: 46 additions & 3 deletions test_suite/tests/test_de.rs
Expand Up @@ -17,15 +17,15 @@ use std::ffi::{CString, OsString};
use std::net;
use std::num::Wrapping;
use std::path::{Path, PathBuf};
use std::rc::Rc;
use std::sync::Arc;
use std::rc::{Rc, Weak as RcWeak};
use std::sync::{Arc, Weak as ArcWeak};
use std::time::{Duration, UNIX_EPOCH};

#[cfg(feature = "unstable")]
use std::ffi::CStr;

extern crate serde;
use serde::Deserialize;
use serde::{Deserialize, Deserializer};

extern crate fnv;
use self::fnv::FnvHasher;
Expand Down Expand Up @@ -182,6 +182,27 @@ macro_rules! declare_error_tests {
}
}

#[derive(Debug)]
struct SkipPartialEq<T>(T);

impl<'de, T> Deserialize<'de> for SkipPartialEq<T>
where
T: Deserialize<'de>,
{
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
where
D: Deserializer<'de>,
{
T::deserialize(deserializer).map(SkipPartialEq)
}
}

impl<T> PartialEq for SkipPartialEq<T> {
fn eq(&self, _other: &Self) -> bool {
true
}
}

fn assert_de_tokens_ignore(ignorable_tokens: &[Token]) {
#[derive(PartialEq, Debug, Deserialize)]
struct IgnoreBase {
Expand Down Expand Up @@ -788,11 +809,33 @@ declare_tests! {
Token::Bool(true),
],
}
test_rc_weak_some {
SkipPartialEq(RcWeak::<bool>::new()) => &[
Token::Some,
Token::Bool(true),
],
}
test_rc_weak_none {
SkipPartialEq(RcWeak::<bool>::new()) => &[
Token::None,
],
}
test_arc {
Arc::new(true) => &[
Token::Bool(true),
],
}
test_arc_weak_some {
SkipPartialEq(ArcWeak::<bool>::new()) => &[
Token::Some,
Token::Bool(true),
],
}
test_arc_weak_none {
SkipPartialEq(ArcWeak::<bool>::new()) => &[
Token::None,
],
}
test_wrapping {
Wrapping(1usize) => &[
Token::U32(1),
Expand Down

0 comments on commit ba0b553

Please sign in to comment.