Skip to content

Commit b10fc3f

Browse files
committed
save
1 parent 724f8b4 commit b10fc3f

File tree

1 file changed

+113
-0
lines changed

1 file changed

+113
-0
lines changed

mdbx/cursor_test.go

Lines changed: 113 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -908,6 +908,119 @@ func TestDupCursor_EmptyKeyValues2(t *testing.T) {
908908
}
909909
}
910910

911+
func TestDupCursor_EmptyKeyValues3(t *testing.T) {
912+
t.Skip()
913+
env, _ := setup(t)
914+
915+
var db DBI
916+
err := env.Update(func(txn *Txn) (err error) {
917+
db, err = txn.OpenDBI("testingdup", Create|DupSort, nil, nil)
918+
if err != nil {
919+
return err
920+
}
921+
cur, err := txn.OpenCursor(db)
922+
if err != nil {
923+
return err
924+
}
925+
defer cur.Close()
926+
927+
// empty value - must function as valid dupsort value
928+
if err = txn.Put(db, []byte{1}, []byte{}, 0); err != nil {
929+
panic(err)
930+
}
931+
if err = txn.Put(db, []byte{1}, []byte{8}, 0); err != nil {
932+
panic(err)
933+
}
934+
935+
_, v, err := cur.Get([]byte{1}, []byte{}, GetBothRange)
936+
if err != nil {
937+
panic(err)
938+
}
939+
if !bytes.Equal(v, []byte{}) {
940+
panic(v)
941+
}
942+
_, v, err = cur.Get([]byte{1}, []byte{0}, GetBothRange)
943+
if err != nil {
944+
panic(err)
945+
}
946+
if !bytes.Equal(v, []byte{8}) {
947+
panic(v)
948+
}
949+
_, v, err = cur.Get([]byte{}, []byte{0}, GetBoth)
950+
if err == nil {
951+
panic("expecting 'not found' error")
952+
}
953+
if v != nil {
954+
panic(v)
955+
}
956+
957+
// can use empty key as valid key in non-dupsort operations
958+
k, v, err := cur.Get([]byte{}, nil, SetRange)
959+
if err != nil {
960+
panic(err)
961+
}
962+
if k == nil {
963+
panic("nil")
964+
}
965+
if !bytes.Equal(k, []byte{1}) {
966+
panic(fmt.Sprintf("%x", k))
967+
}
968+
if !bytes.Equal(v, []byte{}) {
969+
panic(fmt.Sprintf("%x", v))
970+
}
971+
k, v, err = cur.Get([]byte{}, nil, Set)
972+
if err == nil {
973+
panic("expected 'not found' error")
974+
}
975+
if k != nil {
976+
panic("nil")
977+
}
978+
979+
// empty key - must function as valid dupsort key
980+
if err = txn.Put(db, []byte{}, []byte{}, 0); err != nil {
981+
panic(err)
982+
}
983+
if err = txn.Put(db, []byte{}, []byte{2}, 0); err != nil {
984+
panic(err)
985+
}
986+
_, v, err = cur.Get([]byte{}, []byte{}, GetBothRange)
987+
if err != nil {
988+
panic(err)
989+
}
990+
if !bytes.Equal(v, []byte{}) {
991+
panic(v)
992+
}
993+
_, v, err = cur.Get([]byte{}, []byte{0}, GetBothRange)
994+
if err != nil {
995+
panic(err)
996+
}
997+
if !bytes.Equal(v, []byte{2}) {
998+
panic(v)
999+
}
1000+
_, v, err = cur.Get([]byte{}, []byte{0}, GetBoth)
1001+
if err == nil {
1002+
panic("expecting 'not found' error ")
1003+
}
1004+
if v != nil {
1005+
panic(v)
1006+
}
1007+
1008+
// non-existing key
1009+
_, v, err = cur.Get([]byte{7}, []byte{}, GetBoth)
1010+
if err == nil {
1011+
panic("expecting 'not found' error")
1012+
}
1013+
if v != nil {
1014+
panic(v)
1015+
}
1016+
1017+
return nil
1018+
})
1019+
if err != nil {
1020+
t.Error(err)
1021+
}
1022+
}
1023+
9111024
func TestDupCursor_EmptyKeyValues(t *testing.T) {
9121025
t.Skip()
9131026
env, _ := setup(t)

0 commit comments

Comments
 (0)