reifydb-testing 0.6.0

Testing utilities and helpers for ReifyDB
Documentation
// SPDX-License-Identifier: AGPL-3.0-or-later
// Copyright (c) 2026 ReifyDB

// This file includes and modifies code from the toydb project (https://github.com/erikgrinaker/toydb),
// originally licensed under the Apache License, Version 2.0.
// Original copyright:
//   Copyright (c) 2024 Erik Grinaker
//
// The original Apache License can be found at:
//   http://www.apache.org/licenses/LICENSE-2.0

pub mod wait;

use std::{error::Error, ops::Bound};

use reifydb_core::util::encoding::binary::decode_binary;
use reifydb_value::util::cowvec::CowVec;

type KeyRange = (Bound<CowVec<u8>>, Bound<CowVec<u8>>);

pub fn parse_key_range(s: &str) -> Result<KeyRange, Box<dyn Error>> {
	let mut bound = (Bound::<CowVec<u8>>::Unbounded, Bound::<CowVec<u8>>::Unbounded);

	if let Some(dot_pos) = s.find("..") {
		let start_part = &s[..dot_pos];
		let end_part = &s[dot_pos + 2..];

		if !start_part.is_empty() {
			bound.0 = Bound::Included(CowVec::new(decode_binary(start_part)));
		}

		if let Some(end_str) = end_part.strip_prefix('=') {
			if !end_str.is_empty() {
				bound.1 = Bound::Included(CowVec::new(decode_binary(end_str)));
			}
		} else if !end_part.is_empty() {
			bound.1 = Bound::Excluded(CowVec::new(decode_binary(end_part)));
		}

		Ok(bound)
	} else {
		Err(format!("invalid range {s}").into())
	}
}