@@ -17,6 +17,7 @@ import (
1717 "testing"
1818 "time"
1919
20+ "github.com/cockroachdb/crlib/crstrings"
2021 "github.com/cockroachdb/datadriven"
2122 "github.com/cockroachdb/errors"
2223 "github.com/cockroachdb/pebble/batchrepr"
@@ -965,17 +966,15 @@ func TestBatchIter(t *testing.T) {
965966 b = newBatch (nil )
966967 }
967968
968- for _ , key := range strings .Split (d .Input , "\n " ) {
969- j := strings .Index (key , ":" )
970- ikey := base .ParseInternalKey (key [:j ])
971- value := []byte (key [j + 1 :])
972- b .Set (ikey .UserKey , value , nil )
969+ for _ , line := range crstrings .Lines (d .Input ) {
970+ kv := base .ParseInternalKV (line )
971+ require .NoError (t , b .Set (kv .K .UserKey , kv .InPlaceValue (), nil ))
973972 }
974973
975974 switch method {
976975 case "apply" :
977976 tmp := newIndexedBatch (nil , DefaultComparer )
978- tmp .Apply (b , nil )
977+ require . NoError ( t , tmp .Apply (b , nil ) )
979978 b = tmp
980979 }
981980 return ""
@@ -1111,11 +1110,11 @@ func TestFlushableBatchIter(t *testing.T) {
11111110 switch d .Cmd {
11121111 case "define" :
11131112 batch := newBatch (nil )
1114- for _ , key := range strings . Split (d .Input , " \n " ) {
1115- j := strings . Index ( key , ":" )
1116- ikey := base . ParseInternalKey ( key [: j ])
1117- value := []byte (fmt . Sprint ( ikey .SeqNum ()))
1118- batch .Set (ikey . UserKey , value , nil )
1113+ for _ , line := range crstrings . Lines (d .Input ) {
1114+ kv := base . ParseInternalKV ( line )
1115+ // Ignore any value in the test.
1116+ value := []byte (kv . K .SeqNum (). String ( ))
1117+ require . NoError ( t , batch .Set (kv . K . UserKey , value , nil ) )
11191118 }
11201119 var err error
11211120 b , err = newFlushableBatch (batch , DefaultComparer )
@@ -1139,30 +1138,29 @@ func TestFlushableBatch(t *testing.T) {
11391138 switch d .Cmd {
11401139 case "define" :
11411140 batch := newBatch (nil )
1142- for _ , key := range strings .Split (d .Input , "\n " ) {
1143- j := strings .Index (key , ":" )
1144- ikey := base .ParseInternalKey (key [:j ])
1145- value := []byte (key [j + 1 :])
1141+ for _ , line := range crstrings .Lines (d .Input ) {
1142+ kv := base .ParseInternalKV (line )
1143+ value := kv .InPlaceValue ()
11461144 if len (value ) == 0 {
1147- value = []byte (fmt . Sprintf ( "%d" , ikey .SeqNum ()))
1145+ value = []byte (kv . K .SeqNum (). String ( ))
11481146 }
1149- switch ikey .Kind () {
1147+ switch kv . K .Kind () {
11501148 case InternalKeyKindDelete :
1151- require .NoError (t , batch .Delete (ikey .UserKey , nil ))
1149+ require .NoError (t , batch .Delete (kv . K .UserKey , nil ))
11521150 case InternalKeyKindSet :
1153- require .NoError (t , batch .Set (ikey .UserKey , value , nil ))
1151+ require .NoError (t , batch .Set (kv . K .UserKey , value , nil ))
11541152 case InternalKeyKindMerge :
1155- require .NoError (t , batch .Merge (ikey .UserKey , value , nil ))
1153+ require .NoError (t , batch .Merge (kv . K .UserKey , value , nil ))
11561154 case InternalKeyKindLogData :
1157- require .NoError (t , batch .LogData (ikey .UserKey , nil ))
1155+ require .NoError (t , batch .LogData (kv . K .UserKey , nil ))
11581156 case InternalKeyKindRangeDelete :
1159- require .NoError (t , batch .DeleteRange (ikey .UserKey , value , nil ))
1157+ require .NoError (t , batch .DeleteRange (kv . K .UserKey , value , nil ))
11601158 case InternalKeyKindRangeKeyDelete :
1161- require .NoError (t , batch .RangeKeyDelete (ikey .UserKey , value , nil ))
1159+ require .NoError (t , batch .RangeKeyDelete (kv . K .UserKey , value , nil ))
11621160 case InternalKeyKindRangeKeySet :
1163- require .NoError (t , batch .RangeKeySet (ikey .UserKey , value , value , value , nil ))
1161+ require .NoError (t , batch .RangeKeySet (kv . K .UserKey , value , value , value , nil ))
11641162 case InternalKeyKindRangeKeyUnset :
1165- require .NoError (t , batch .RangeKeyUnset (ikey .UserKey , value , value , nil ))
1163+ require .NoError (t , batch .RangeKeyUnset (kv . K .UserKey , value , value , nil ))
11661164 }
11671165 }
11681166 var err error
0 commit comments