fix tests on stable
This commit is contained in:
parent
dced4416a7
commit
b860d3cb1f
@ -70,9 +70,11 @@ use super::{
|
||||
Error,
|
||||
Serialize,
|
||||
Serializer,
|
||||
IteratorSerializer,
|
||||
};
|
||||
|
||||
#[cfg(feature = "unstable")]
|
||||
use super::IteratorSerializer;
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
macro_rules! impl_visit {
|
||||
|
@ -18,7 +18,9 @@ use error;
|
||||
#[cfg(all(feature = "collections", not(feature = "std")))]
|
||||
use collections::String;
|
||||
|
||||
#[cfg(feature = "unstable")]
|
||||
use core::marker::PhantomData;
|
||||
#[cfg(feature = "unstable")]
|
||||
use core::cell::RefCell;
|
||||
|
||||
pub mod impls;
|
||||
@ -418,12 +420,14 @@ pub trait Serializer {
|
||||
/// A wrapper type for iterators that implements `Serialize` for iterators whose items implement
|
||||
/// `Serialize`. Don't use multiple times. Create new versions of this with the `iterator` function
|
||||
/// every time you want to serialize an iterator.
|
||||
#[cfg(feature = "unstable")]
|
||||
pub struct IteratorSerializer<I>(RefCell<Option<I>>)
|
||||
where <I as Iterator>::Item: Serialize,
|
||||
I: Iterator;
|
||||
|
||||
/// Creates a temporary type that can be passed to any function expecting a `Serialize` and will
|
||||
/// serialize the given iterator as a sequence
|
||||
#[cfg(feature = "unstable")]
|
||||
pub fn iterator<I>(iter: I) -> IteratorSerializer<I>
|
||||
where <I as Iterator>::Item: Serialize,
|
||||
I: Iterator
|
||||
|
@ -15,6 +15,7 @@ use self::serde_test::{
|
||||
extern crate fnv;
|
||||
use self::fnv::FnvHasher;
|
||||
|
||||
#[cfg(feature = "unstable")]
|
||||
use serde::ser::iterator;
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
@ -100,45 +101,6 @@ declare_ser_tests! {
|
||||
Token::I32(1),
|
||||
],
|
||||
}
|
||||
test_iterator {
|
||||
iterator([0; 0].iter()) => &[
|
||||
Token::SeqStart(Some(0)),
|
||||
Token::SeqEnd,
|
||||
],
|
||||
iterator([1, 2, 3].iter()) => &[
|
||||
Token::SeqStart(Some(3)),
|
||||
Token::SeqSep,
|
||||
Token::I32(1),
|
||||
|
||||
Token::SeqSep,
|
||||
Token::I32(2),
|
||||
|
||||
Token::SeqSep,
|
||||
Token::I32(3),
|
||||
Token::SeqEnd,
|
||||
],
|
||||
iterator([1, 2, 3].iter().map(|x| x * 2)) => &[
|
||||
Token::SeqStart(Some(3)),
|
||||
Token::SeqSep,
|
||||
Token::I32(2),
|
||||
|
||||
Token::SeqSep,
|
||||
Token::I32(4),
|
||||
|
||||
Token::SeqSep,
|
||||
Token::I32(6),
|
||||
Token::SeqEnd,
|
||||
],
|
||||
iterator([1, 2, 3].iter().filter(|&x| x % 2 != 0)) => &[
|
||||
Token::SeqStart(None),
|
||||
Token::SeqSep,
|
||||
Token::I32(1),
|
||||
|
||||
Token::SeqSep,
|
||||
Token::I32(3),
|
||||
Token::SeqEnd,
|
||||
],
|
||||
}
|
||||
test_slice {
|
||||
&[0][..0] => &[
|
||||
Token::SeqStart(Some(0)),
|
||||
@ -410,6 +372,49 @@ declare_ser_tests! {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
#[cfg(feature = "unstable")]
|
||||
#[test]
|
||||
fn test_iterator() {
|
||||
assert_ser_tokens(iterator([0; 0].iter()), &[
|
||||
Token::SeqStart(Some(0)),
|
||||
Token::SeqEnd,
|
||||
]);
|
||||
assert_ser_tokens(iterator([1, 2, 3].iter()), &[
|
||||
Token::SeqStart(Some(3)),
|
||||
Token::SeqSep,
|
||||
Token::I32(1),
|
||||
|
||||
Token::SeqSep,
|
||||
Token::I32(2),
|
||||
|
||||
Token::SeqSep,
|
||||
Token::I32(3),
|
||||
Token::SeqEnd,
|
||||
]);
|
||||
assert_ser_tokens(iterator([1, 2, 3].iter().map(|x| x * 2)), &[
|
||||
Token::SeqStart(Some(3)),
|
||||
Token::SeqSep,
|
||||
Token::I32(2),
|
||||
|
||||
Token::SeqSep,
|
||||
Token::I32(4),
|
||||
|
||||
Token::SeqSep,
|
||||
Token::I32(6),
|
||||
Token::SeqEnd,
|
||||
]);
|
||||
assert_ser_tokens(iterator([1, 2, 3].iter().filter(|&x| x % 2 != 0)), &[
|
||||
Token::SeqStart(None),
|
||||
Token::SeqSep,
|
||||
Token::I32(1),
|
||||
|
||||
Token::SeqSep,
|
||||
Token::I32(3),
|
||||
Token::SeqEnd,
|
||||
]);
|
||||
}
|
||||
|
||||
#[cfg(feature = "unstable")]
|
||||
#[test]
|
||||
fn test_net_ipaddr() {
|
||||
|
Loading…
x
Reference in New Issue
Block a user