aboutsummaryrefslogtreecommitdiff
path: root/c/cursor_test.go
diff options
context:
space:
mode:
authorMartin Kobetic <mkobetic@gmail.com>2014-04-17 21:25:03 +0000
committerMartin Kobetic <mkobetic@gmail.com>2014-04-17 21:25:03 +0000
commit194a0967b44932e62d10955d8f7643bd072b1a7e (patch)
tree5acad1a24c1307462ee1f7c4c49c9caec98713cc /c/cursor_test.go
parenttests pass (diff)
downloaddedo-194a0967b44932e62d10955d8f7643bd072b1a7e.tar.gz
dedo-194a0967b44932e62d10955d8f7643bd072b1a7e.tar.xz
hide the cursor stack details behind function calls (pop/push/current)
Diffstat (limited to 'c/cursor_test.go')
-rw-r--r--c/cursor_test.go40
1 files changed, 39 insertions, 1 deletions
diff --git a/c/cursor_test.go b/c/cursor_test.go
index 5be85de..21b6696 100644
--- a/c/cursor_test.go
+++ b/c/cursor_test.go
@@ -116,7 +116,7 @@ func TestCursor_Iterate_Leaf(t *testing.T) {
})
}
-// Ensure that a C cursor can iterate over a branches and leafs.
+// Ensure that a C cursor can iterate over branches and leafs.
func TestCursor_Iterate_Large(t *testing.T) {
withDB(func(db *bolt.DB) {
db.Update(func(tx *bolt.Tx) error {
@@ -140,6 +140,44 @@ func TestCursor_Iterate_Large(t *testing.T) {
})
}
+// Ensure that a C cursor can seek over branches and leafs.
+func TestCursor_Seek_Large(t *testing.T) {
+ withDB(func(db *bolt.DB) {
+ db.Update(func(tx *bolt.Tx) error {
+ b, _ := tx.CreateBucket([]byte("widgets"))
+ for i := 1; i < 1000; i++ {
+ b.Put([]byte(fmt.Sprintf("%05d", i*10)), []byte(fmt.Sprintf("%020d", i*10)))
+ }
+ return nil
+ })
+ db.View(func(tx *bolt.Tx) error {
+ c := NewCursor(tx.Bucket([]byte("widgets")))
+
+ // Exact match should go to the key.
+ k, v, _ := c.Seek([]byte("05000"))
+ assert.Equal(t, "05000", string(k))
+ assert.Equal(t, fmt.Sprintf("%020d", 5000), string(v))
+
+ // Inexact match should go to the next key.
+ k, v, _ = c.Seek([]byte("07495"))
+ assert.Equal(t, "07500", string(k))
+ assert.Equal(t, fmt.Sprintf("%020d", 7500), string(v))
+
+ // Low key should go to the first key.
+ k, v, _ = c.Seek([]byte("00000"))
+ assert.Equal(t, "00010", string(k))
+ assert.Equal(t, fmt.Sprintf("%020d", 10), string(v))
+
+ // High key should return no key.
+ k, v, _ = c.Seek([]byte("40000"))
+ assert.Equal(t, "", string(k))
+ assert.Equal(t, "", string(v))
+
+ return nil
+ })
+ })
+}
+
// tempfile returns a temporary path.
func tempfile() string {
f, _ := ioutil.TempFile("", "bolt-c-")