aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/register.rs25
1 files changed, 18 insertions, 7 deletions
diff --git a/src/register.rs b/src/register.rs
index 8fc3a6f..f04e2e2 100644
--- a/src/register.rs
+++ b/src/register.rs
@@ -318,9 +318,10 @@ impl SleepDirRegister {
impl HyperRegister for SleepDirRegister {
- fn has(&self, _index: u64) -> Result<bool> {
- // looks in bitfield
- unimplemented!()
+ /// TODO: this version only works for "dense" registers: it just checks if the index is in the
+ /// total length, instead of using the bitfield.
+ fn has(&self, index: u64) -> Result<bool> {
+ return Ok(index < self.len()?);
}
fn has_all(&self) -> Result<bool> {
@@ -482,9 +483,7 @@ fn test_sdr_open() {
fn test_sdr_create() {
use tempdir::TempDir;
-
let tmp_dir = TempDir::new("geniza-test").unwrap();
-
let mut sdr = SleepDirRegister::create(tmp_dir.path(), "dummy").unwrap();
assert_eq!(sdr.len().unwrap(), 0);
@@ -495,9 +494,7 @@ fn test_sdr_create() {
fn test_sdr_append() {
use tempdir::TempDir;
-
let tmp_dir = TempDir::new("geniza-test").unwrap();
-
let mut sdr = SleepDirRegister::create(tmp_dir.path(), "dummy").unwrap();
sdr.append("hello world!".as_bytes()).unwrap();
@@ -512,3 +509,17 @@ fn test_sdr_append() {
assert_eq!(sdr.len().unwrap(), 1+count);
assert_eq!(sdr.len_bytes().unwrap(), 12 + (count*5));
}
+
+#[test]
+fn test_sdr_has() {
+
+ use tempdir::TempDir;
+ let tmp_dir = TempDir::new("geniza-test").unwrap();
+ let mut sdr = SleepDirRegister::create(tmp_dir.path(), "dummy").unwrap();
+
+ sdr.append("hello world!".as_bytes()).unwrap();
+ sdr.check().unwrap();
+ assert_eq!(sdr.has_all().unwrap(), true);
+ assert_eq!(sdr.has(0).unwrap(), true);
+ assert_eq!(sdr.has(40).unwrap(), false);
+}