Fixed tests

This commit is contained in:
arkpar
2016-01-27 16:58:22 +01:00
parent 40314614f7
commit 60e2b53a1d
4 changed files with 33 additions and 22 deletions

View File

@@ -87,7 +87,7 @@ pub fn decode<T>(bytes: &[u8]) -> T where T: Decodable {
///
/// fn main () {
/// let animal = "cat";
/// let out = encode(&animal);
/// let out = encode(&animal).to_vec();
/// assert_eq!(out, vec![0x83, b'c', b'a', b't']);
/// }
/// ```
@@ -105,7 +105,7 @@ pub fn encode<E>(object: &E) -> ElasticArray1024<u8> where E: Encodable {
///
/// fn main () {
/// let animals = vec!["cat", "dog"];
/// let out = encode_list(&animals);
/// let out = encode_list(&animals).to_vec();
/// assert_eq!(out, vec![0xc8, 0x83, b'c', b'a', b't', 0x83, b'd', b'o', b'g']);
/// }
/// ```

View File

@@ -69,8 +69,9 @@ impl Stream for RlpStream {
let items = list.deref();
self.begin_list(items.len());
for el in items.iter() {
self.append(el);
el.rlp_append(self);
}
self.note_appended(items.len());
self
}
@@ -240,7 +241,7 @@ impl<T> ByteEncodable for T where T: ToBytes {
impl<'a> ByteEncodable for &'a[u8] {
fn to_bytes<V: VecLike<u8>>(&self, out: &mut V) {
out.extend(self)
out.vec_extend(self)
}
fn bytes_len(&self) -> usize {
@@ -250,7 +251,7 @@ impl<'a> ByteEncodable for &'a[u8] {
impl ByteEncodable for Vec<u8> {
fn to_bytes<V: VecLike<u8>>(&self, out: &mut V) {
out.extend(self.deref())
out.vec_extend(self.deref())
}
fn bytes_len(&self) -> usize {

View File

@@ -286,10 +286,10 @@ pub trait Stream: Sized {
/// use util::rlp::*;
///
/// fn main () {
/// let mut stream = RlpStream::new_list(2);
/// stream.begin_list([&"cat", &"dog"]);
/// let out = stream.out();
/// assert_eq!(out, vec![0xca, 0xc8, 0x83, b'c', b'a', b't', 0x83, b'd', b'o', b'g', 0x80]);
/// let mut stream = RlpStream::new_list(1);
/// stream.append_list(&vec!["cat", "dog"]);
/// let out = stream.out().to_vec();
/// assert_eq!(out, vec![0xc9, 0xc8, 0x83, b'c', b'a', b't', 0x83, b'd', b'o', b'g']);
/// }
/// ```
fn append_list<I, E>(&mut self, list: &I) -> &mut Self where I: Deref<Target = [E]>, E: Encodable;