Skip to content

Commit

Permalink
add bug repr test
Browse files Browse the repository at this point in the history
  • Loading branch information
breathx committed Oct 10, 2024
1 parent c850327 commit 63dbd4f
Showing 1 changed file with 22 additions and 8 deletions.
30 changes: 22 additions & 8 deletions ethexe/db/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -109,18 +109,32 @@ mod tests {
}

pub fn kv_iter_prefix<DB: KVDatabase>(db: DB) {
let testcase = |prefix: &str, expectations: &[(&str, &str)]| {
let actual: BTreeSet<_> = db.iter_prefix(prefix.as_bytes()).collect();
let expected: BTreeSet<_> = expectations
.iter()
.map(|(k, v)| (k.as_bytes().to_vec(), v.as_bytes().to_vec()))
.collect();
assert_eq!(actual, expected);
};

db.put(b"prefix_foo", b"hello".to_vec());
db.put(b"prefix_bar", b"world".to_vec());

let values: BTreeSet<(Vec<u8>, Vec<u8>)> = db.iter_prefix(b"prefix_").collect();
assert_eq!(
values,
[
(b"prefix_foo".to_vec(), b"hello".to_vec()),
(b"prefix_bar".to_vec(), b"world".to_vec()),
]
.into(),
testcase(
"prefix_",
&[("prefix_foo", "hello"), ("prefix_bar", "world")],
);

testcase("", &[("prefix_foo", "hello"), ("prefix_bar", "world")]);

testcase("0", &[]);

testcase("prefix_foobar", &[]);

testcase("prefix_foo", &[("prefix_foo", "hello")]);

testcase("prefix_bar", &[("prefix_bar", "world")]);
}

pub fn cas_multi_thread<DB: CASDatabase>(db: DB) {
Expand Down

0 comments on commit 63dbd4f

Please sign in to comment.