Skip to content

Commit

Permalink
save test
Browse files Browse the repository at this point in the history
  • Loading branch information
awskii committed Nov 1, 2023
1 parent d1fe18f commit 78263b9
Showing 1 changed file with 72 additions and 0 deletions.
72 changes: 72 additions & 0 deletions mdbx/cursor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package mdbx

import (
"bytes"
"encoding/binary"
"encoding/hex"
"fmt"
"os"
Expand Down Expand Up @@ -730,6 +731,59 @@ func TestCursor_Del(t *testing.T) {
}
}

func TestDupCursor_SharedPRefix00(t *testing.T) {
env, _ := setup(t)

var db DBI
err := env.Update(func(txn *Txn) (err error) {
db, err = txn.OpenDBI("testingdup", Create|DupSort, nil, nil)
if err != nil {
return err
}
cur, err := txn.OpenCursor(db)
if err != nil {
return err
}
defer cur.Close()

// key with 00 prefix
tk := make([]byte, 10)
binary.BigEndian.PutUint64(tk[2:], 11)
if err = txn.Put(db, tk, []byte{4, 4, 0}, 0); err != nil {
panic(err)
}
if err = txn.Put(db, tk[2:], []byte{4, 7, 0}, 0); err != nil {
panic(err)
}

k, v, err := cur.Get([]byte{}, []byte{}, First)
if err != nil {
panic(err)
}
if !bytes.Equal(k, tk[2:]) {
panic(fmt.Sprintf("unexpected first key %x", k))
}
if !bytes.Equal(v, []byte{4, 7, 0}) {
panic(v)
}

k, v, err = cur.Get([]byte{}, []byte{}, SetRange)
if err != nil {
panic(err)
}
if !bytes.Equal(k, tk[2:]) {
panic(fmt.Sprintf("unexpected first key %x", k))
}
if !bytes.Equal(v, []byte{4, 7, 0}) {
panic(v)
}
return nil
})
if err != nil {
t.Error(err)
}
}

func TestDupCursor_EmptyKeyValues(t *testing.T) {
env, _ := setup(t)

Expand Down Expand Up @@ -826,6 +880,24 @@ func TestDupCursor_EmptyKeyValues(t *testing.T) {
panic(v)
}

if err = txn.Put(db, []byte{0}, []byte{4}, 0); err != nil {
panic(err)
}
_, v, err = cur.Get([]byte{0}, []byte{}, SetRange)
if err != nil {
panic(err)
}
if !bytes.Equal(v, []byte{4}) {
panic(v)
}
_, v, err = cur.Get([]byte{}, []byte{}, First)
if err != nil {
panic(err)
}
if !bytes.Equal(v, []byte{}) {
panic(v)
}

// non-existing key
_, v, err = cur.Get([]byte{7}, []byte{}, GetBoth)
if err == nil {
Expand Down

0 comments on commit 78263b9

Please sign in to comment.