Skip to content
This repository has been archived by the owner on Nov 6, 2020. It is now read-only.

Commit

Permalink
test for passing closure as query
Browse files Browse the repository at this point in the history
  • Loading branch information
rphmeier committed Jan 5, 2017
1 parent dcf7881 commit 3f3d1a5
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
2 changes: 1 addition & 1 deletion util/src/trie/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ impl<'a> Query for &'a mut Recorder {
}
}

impl<F, T> Query for F where F: FnOnce(&[u8]) -> T {
impl<F, T> Query for F where F: for<'a> FnOnce(&'a [u8]) -> T {
type Item = T;

fn decode(self, value: &[u8]) -> T { (self)(value) }
Expand Down
20 changes: 20 additions & 0 deletions util/src/trie/triedb.rs
Original file line number Diff line number Diff line change
Expand Up @@ -426,3 +426,23 @@ fn iterator_seek() {
iter.seek(b"C").unwrap();
assert_eq!(&d[4..], &iter.map(|x| x.unwrap().1).collect::<Vec<_>>()[..]);
}

#[test]
fn get_len() {
use memorydb::*;
use super::TrieMut;
use super::triedbmut::*;

let mut memdb = MemoryDB::new();
let mut root = H256::new();
{
let mut t = TrieDBMut::new(&mut memdb, &mut root);
t.insert(b"A", b"ABC").unwrap();
t.insert(b"B", b"ABCBA").unwrap();
}

let t = TrieDB::new(&memdb, &root).unwrap();
assert_eq!(t.get_with(b"A", |x: &[u8]| x.len()), Ok(Some(3)));
assert_eq!(t.get_with(b"B", |x: &[u8]| x.len()), Ok(Some(5)));
assert_eq!(t.get_with(b"C", |x: &[u8]| x.len()), Ok(None));
}

0 comments on commit 3f3d1a5

Please sign in to comment.