use super::{CursorKey, Ordering, initial_ksuf_match};
#[test]
fn test_initial_ksuf_match() {
assert!(initial_ksuf_match(Ordering::Greater, true));
assert!(initial_ksuf_match(Ordering::Greater, false));
assert!(initial_ksuf_match(Ordering::Equal, true));
assert!(!initial_ksuf_match(Ordering::Equal, false));
assert!(!initial_ksuf_match(Ordering::Less, true));
assert!(!initial_ksuf_match(Ordering::Less, false));
}
#[test]
fn test_is_duplicate_less() {
let cursor = CursorKey::from_slice(b"apple");
let slot_ikey = u64::from_be_bytes([b'b', b'a', b'n', b'a', b'n', b'a', 0, 0]);
assert_eq!(cursor.compare(slot_ikey, 6), Ordering::Less);
}
#[test]
fn test_is_duplicate_equal() {
let cursor = CursorKey::from_slice(b"hello");
let slot_ikey = u64::from_be_bytes([b'h', b'e', b'l', b'l', b'o', 0, 0, 0]);
assert_ne!(cursor.compare(slot_ikey, 5), Ordering::Less);
}
#[test]
fn test_is_duplicate_greater() {
let cursor = CursorKey::from_slice(b"zebra");
let slot_ikey = u64::from_be_bytes([b'a', b'p', b'p', b'l', b'e', 0, 0, 0]);
assert_ne!(cursor.compare(slot_ikey, 5), Ordering::Less);
}
#[test]
fn test_is_duplicate_with_suffix() {
let mut cursor = CursorKey::from_slice(b"hello world xyz");
cursor.assign_store_ikey(u64::from_be_bytes(*b"hello wo"));
let _ = cursor.assign_store_suffix(b"rld xyz");
cursor.assign_store_length(15);
assert_ne!(cursor.compare_suffix(b"rld abc"), Ordering::Less);
assert_eq!(cursor.compare_suffix(b"rld zzz"), Ordering::Less);
assert_ne!(cursor.compare_suffix(b"rld xyz"), Ordering::Less);
}