| 1 | // Copyright 2009 The Go Authors. All rights reserved. |
| 2 | // Use of this source code is governed by a BSD-style |
| 3 | // license that can be found in the LICENSE file. |
| 4 | |
| 5 | package utilscip-go gomod github.com/syndtr/goleveldb . `github.com/syndtr/goleveldb/leveldb/util`/ |
| 6 | |
| 7 | import ( |
| 8 | "bytesscip-go gomod github.com/golang/go/src go1.14 bytes/" |
| 9 | "ioscip-go gomod github.com/golang/go/src go1.14 io/" |
| 10 | "math/randscip-go gomod github.com/golang/go/src go1.14 `math/rand`/" |
| 11 | "runtimescip-go gomod github.com/golang/go/src go1.14 runtime/" |
| 12 | "testingscip-go gomod github.com/golang/go/src go1.14 testing/" |
| 13 | ) |
| 14 | |
| 15 | const Nscip-go gomod github.com/syndtr/goleveldb . `github.com/syndtr/goleveldb/leveldb/util`/N. = 10000 // make this bigger for a larger (and slower) test |
| 16 | var datascip-go gomod github.com/syndtr/goleveldb . `github.com/syndtr/goleveldb/leveldb/util`/data. string // test data for write tests |
| 17 | var testBytesscip-go gomod github.com/syndtr/goleveldb . `github.com/syndtr/goleveldb/leveldb/util`/testBytes. []byte // test data; same as data but as a slice. |
| 18 | |
| 19 | func initscip-go gomod github.com/syndtr/goleveldb . `github.com/syndtr/goleveldb/leveldb/util`/init().() { |
| 20 | testBytesscip-go gomod github.com/syndtr/goleveldb . `github.com/syndtr/goleveldb/leveldb/util`/testBytes. = make([]byte, Nscip-go gomod github.com/syndtr/goleveldb . `github.com/syndtr/goleveldb/leveldb/util`/N.) |
| 21 | for i := 0; i < Nscip-go gomod github.com/syndtr/goleveldb . `github.com/syndtr/goleveldb/leveldb/util`/N.; i++ { |
| 22 | testBytesscip-go gomod github.com/syndtr/goleveldb . `github.com/syndtr/goleveldb/leveldb/util`/testBytes.[i] = 'a' + byte(i%26) |
| 23 | } |
| 24 | datascip-go gomod github.com/syndtr/goleveldb . `github.com/syndtr/goleveldb/leveldb/util`/data. = string(testBytesscip-go gomod github.com/syndtr/goleveldb . `github.com/syndtr/goleveldb/leveldb/util`/testBytes.) |
| 25 | } |
| 26 | |
| 27 | // Verify that contents of buf match the string s. |
| 28 | func checkscip-go gomod github.com/syndtr/goleveldb . `github.com/syndtr/goleveldb/leveldb/util`/check().(t *testingscip-go gomod github.com/golang/go/src go1.14 testing/.Tscip-go gomod github.com/golang/go/src go1.14 testing/T#, testname string, buf *Bufferscip-go gomod github.com/syndtr/goleveldb . `github.com/syndtr/goleveldb/leveldb/util`/Buffer#, s string) { |
| 29 | bytes := buf.Bytesscip-go gomod github.com/syndtr/goleveldb . `github.com/syndtr/goleveldb/leveldb/util`/Buffer#Bytes().() |
| 30 | str := buf.Stringscip-go gomod github.com/syndtr/goleveldb . `github.com/syndtr/goleveldb/leveldb/util`/Buffer#String().() |
| 31 | if buf.Lenscip-go gomod github.com/syndtr/goleveldb . `github.com/syndtr/goleveldb/leveldb/util`/Buffer#Len().() != len(bytes) { |
| 32 | t.Errorfscip-go gomod github.com/golang/go/src go1.14 testing/common#Errorf().("%s: buf.Len() == %d, len(buf.Bytes()) == %d", testname, buf.Lenscip-go gomod github.com/syndtr/goleveldb . `github.com/syndtr/goleveldb/leveldb/util`/Buffer#Len().(), len(bytes)) |
| 33 | } |
| 34 | |
| 35 | if buf.Lenscip-go gomod github.com/syndtr/goleveldb . `github.com/syndtr/goleveldb/leveldb/util`/Buffer#Len().() != len(str) { |
| 36 | t.Errorfscip-go gomod github.com/golang/go/src go1.14 testing/common#Errorf().("%s: buf.Len() == %d, len(buf.String()) == %d", testname, buf.Lenscip-go gomod github.com/syndtr/goleveldb . `github.com/syndtr/goleveldb/leveldb/util`/Buffer#Len().(), len(str)) |
| 37 | } |
| 38 | |
| 39 | if buf.Lenscip-go gomod github.com/syndtr/goleveldb . `github.com/syndtr/goleveldb/leveldb/util`/Buffer#Len().() != len(s) { |
| 40 | t.Errorfscip-go gomod github.com/golang/go/src go1.14 testing/common#Errorf().("%s: buf.Len() == %d, len(s) == %d", testname, buf.Lenscip-go gomod github.com/syndtr/goleveldb . `github.com/syndtr/goleveldb/leveldb/util`/Buffer#Len().(), len(s)) |
| 41 | } |
| 42 | |
| 43 | if string(bytes) != s { |
| 44 | t.Errorfscip-go gomod github.com/golang/go/src go1.14 testing/common#Errorf().("%s: string(buf.Bytes()) == %q, s == %q", testname, string(bytes), s) |
| 45 | } |
| 46 | } |
| 47 | |
| 48 | // Fill buf through n writes of byte slice fub. |
| 49 | // The initial contents of buf corresponds to the string s; |
| 50 | // the result is the final contents of buf returned as a string. |
| 51 | func fillBytesscip-go gomod github.com/syndtr/goleveldb . `github.com/syndtr/goleveldb/leveldb/util`/fillBytes().(t *testingscip-go gomod github.com/golang/go/src go1.14 testing/.Tscip-go gomod github.com/golang/go/src go1.14 testing/T#, testname string, buf *Bufferscip-go gomod github.com/syndtr/goleveldb . `github.com/syndtr/goleveldb/leveldb/util`/Buffer#, s string, n int, fub []byte) string { |
| 52 | checkscip-go gomod github.com/syndtr/goleveldb . `github.com/syndtr/goleveldb/leveldb/util`/check().(t, testname+" (fill 1)", buf, s) |
| 53 | for ; n > 0; n-- { |
| 54 | m, err := buf.Writescip-go gomod github.com/syndtr/goleveldb . `github.com/syndtr/goleveldb/leveldb/util`/Buffer#Write().(fub) |
| 55 | if m != len(fub) { |
| 56 | t.Errorfscip-go gomod github.com/golang/go/src go1.14 testing/common#Errorf().(testname+" (fill 2): m == %d, expected %d", m, len(fub)) |
| 57 | } |
| 58 | if err != nil { |
| 59 | t.Errorfscip-go gomod github.com/golang/go/src go1.14 testing/common#Errorf().(testname+" (fill 3): err should always be nil, found err == %s", err) |
| 60 | } |
| 61 | s += string(fub) |
| 62 | checkscip-go gomod github.com/syndtr/goleveldb . `github.com/syndtr/goleveldb/leveldb/util`/check().(t, testname+" (fill 4)", buf, s) |
| 63 | } |
| 64 | return s |
| 65 | } |
| 66 | |
| 67 | func TestNewBufferscip-go gomod github.com/syndtr/goleveldb . `github.com/syndtr/goleveldb/leveldb/util`/TestNewBuffer().(t *testingscip-go gomod github.com/golang/go/src go1.14 testing/.Tscip-go gomod github.com/golang/go/src go1.14 testing/T#) { |
| 68 | buf := NewBufferscip-go gomod github.com/syndtr/goleveldb . `github.com/syndtr/goleveldb/leveldb/util`/NewBuffer().(testBytesscip-go gomod github.com/syndtr/goleveldb . `github.com/syndtr/goleveldb/leveldb/util`/testBytes.) |
| 69 | checkscip-go gomod github.com/syndtr/goleveldb . `github.com/syndtr/goleveldb/leveldb/util`/check().(t, "NewBuffer", buf, datascip-go gomod github.com/syndtr/goleveldb . `github.com/syndtr/goleveldb/leveldb/util`/data.) |
| 70 | } |
| 71 | |
| 72 | // Empty buf through repeated reads into fub. |
| 73 | // The initial contents of buf corresponds to the string s. |
| 74 | func emptyscip-go gomod github.com/syndtr/goleveldb . `github.com/syndtr/goleveldb/leveldb/util`/empty().(t *testingscip-go gomod github.com/golang/go/src go1.14 testing/.Tscip-go gomod github.com/golang/go/src go1.14 testing/T#, testname string, buf *Bufferscip-go gomod github.com/syndtr/goleveldb . `github.com/syndtr/goleveldb/leveldb/util`/Buffer#, s string, fub []byte) { |
| 75 | checkscip-go gomod github.com/syndtr/goleveldb . `github.com/syndtr/goleveldb/leveldb/util`/check().(t, testname+" (empty 1)", buf, s) |
| 76 | |
| 77 | for { |
| 78 | n, err := buf.Readscip-go gomod github.com/syndtr/goleveldb . `github.com/syndtr/goleveldb/leveldb/util`/Buffer#Read().(fub) |
| 79 | if n == 0 { |
| 80 | break |
| 81 | } |
| 82 | if err != nil { |
| 83 | t.Errorfscip-go gomod github.com/golang/go/src go1.14 testing/common#Errorf().(testname+" (empty 2): err should always be nil, found err == %s", err) |
| 84 | } |
| 85 | s = s[n:] |
| 86 | checkscip-go gomod github.com/syndtr/goleveldb . `github.com/syndtr/goleveldb/leveldb/util`/check().(t, testname+" (empty 3)", buf, s) |
| 87 | } |
| 88 | |
| 89 | checkscip-go gomod github.com/syndtr/goleveldb . `github.com/syndtr/goleveldb/leveldb/util`/check().(t, testname+" (empty 4)", buf, "") |
| 90 | } |
| 91 | |
| 92 | func TestBasicOperationsscip-go gomod github.com/syndtr/goleveldb . `github.com/syndtr/goleveldb/leveldb/util`/TestBasicOperations().(t *testingscip-go gomod github.com/golang/go/src go1.14 testing/.Tscip-go gomod github.com/golang/go/src go1.14 testing/T#) { |
| 93 | var buf Bufferscip-go gomod github.com/syndtr/goleveldb . `github.com/syndtr/goleveldb/leveldb/util`/Buffer# |
| 94 | |
| 95 | for i := 0; i < 5; i++ { |
| 96 | checkscip-go gomod github.com/syndtr/goleveldb . `github.com/syndtr/goleveldb/leveldb/util`/check().(t, "TestBasicOperations (1)", &buf, "") |
| 97 | |
| 98 | buf.Resetscip-go gomod github.com/syndtr/goleveldb . `github.com/syndtr/goleveldb/leveldb/util`/Buffer#Reset().() |
| 99 | checkscip-go gomod github.com/syndtr/goleveldb . `github.com/syndtr/goleveldb/leveldb/util`/check().(t, "TestBasicOperations (2)", &buf, "") |
| 100 | |
| 101 | buf.Truncatescip-go gomod github.com/syndtr/goleveldb . `github.com/syndtr/goleveldb/leveldb/util`/Buffer#Truncate().(0) |
| 102 | checkscip-go gomod github.com/syndtr/goleveldb . `github.com/syndtr/goleveldb/leveldb/util`/check().(t, "TestBasicOperations (3)", &buf, "") |
| 103 | |
| 104 | n, err := buf.Writescip-go gomod github.com/syndtr/goleveldb . `github.com/syndtr/goleveldb/leveldb/util`/Buffer#Write().([]byte(datascip-go gomod github.com/syndtr/goleveldb . `github.com/syndtr/goleveldb/leveldb/util`/data.[0:1])) |
| 105 | if n != 1 { |
| 106 | t.Errorfscip-go gomod github.com/golang/go/src go1.14 testing/common#Errorf().("wrote 1 byte, but n == %d", n) |
| 107 | } |
| 108 | if err != nil { |
| 109 | t.Errorfscip-go gomod github.com/golang/go/src go1.14 testing/common#Errorf().("err should always be nil, but err == %s", err) |
| 110 | } |
| 111 | checkscip-go gomod github.com/syndtr/goleveldb . `github.com/syndtr/goleveldb/leveldb/util`/check().(t, "TestBasicOperations (4)", &buf, "a") |
| 112 | |
| 113 | buf.WriteBytescip-go gomod github.com/syndtr/goleveldb . `github.com/syndtr/goleveldb/leveldb/util`/Buffer#WriteByte().(datascip-go gomod github.com/syndtr/goleveldb . `github.com/syndtr/goleveldb/leveldb/util`/data.[1]) |
| 114 | checkscip-go gomod github.com/syndtr/goleveldb . `github.com/syndtr/goleveldb/leveldb/util`/check().(t, "TestBasicOperations (5)", &buf, "ab") |
| 115 | |
| 116 | n, err = buf.Writescip-go gomod github.com/syndtr/goleveldb . `github.com/syndtr/goleveldb/leveldb/util`/Buffer#Write().([]byte(datascip-go gomod github.com/syndtr/goleveldb . `github.com/syndtr/goleveldb/leveldb/util`/data.[2:26])) |
| 117 | if n != 24 { |
| 118 | t.Errorfscip-go gomod github.com/golang/go/src go1.14 testing/common#Errorf().("wrote 25 bytes, but n == %d", n) |
| 119 | } |
| 120 | checkscip-go gomod github.com/syndtr/goleveldb . `github.com/syndtr/goleveldb/leveldb/util`/check().(t, "TestBasicOperations (6)", &buf, string(datascip-go gomod github.com/syndtr/goleveldb . `github.com/syndtr/goleveldb/leveldb/util`/data.[0:26])) |
| 121 | |
| 122 | buf.Truncatescip-go gomod github.com/syndtr/goleveldb . `github.com/syndtr/goleveldb/leveldb/util`/Buffer#Truncate().(26) |
| 123 | checkscip-go gomod github.com/syndtr/goleveldb . `github.com/syndtr/goleveldb/leveldb/util`/check().(t, "TestBasicOperations (7)", &buf, string(datascip-go gomod github.com/syndtr/goleveldb . `github.com/syndtr/goleveldb/leveldb/util`/data.[0:26])) |
| 124 | |
| 125 | buf.Truncatescip-go gomod github.com/syndtr/goleveldb . `github.com/syndtr/goleveldb/leveldb/util`/Buffer#Truncate().(20) |
| 126 | checkscip-go gomod github.com/syndtr/goleveldb . `github.com/syndtr/goleveldb/leveldb/util`/check().(t, "TestBasicOperations (8)", &buf, string(datascip-go gomod github.com/syndtr/goleveldb . `github.com/syndtr/goleveldb/leveldb/util`/data.[0:20])) |
| 127 | |
| 128 | emptyscip-go gomod github.com/syndtr/goleveldb . `github.com/syndtr/goleveldb/leveldb/util`/empty().(t, "TestBasicOperations (9)", &buf, string(datascip-go gomod github.com/syndtr/goleveldb . `github.com/syndtr/goleveldb/leveldb/util`/data.[0:20]), make([]byte, 5)) |
| 129 | emptyscip-go gomod github.com/syndtr/goleveldb . `github.com/syndtr/goleveldb/leveldb/util`/empty().(t, "TestBasicOperations (10)", &buf, "", make([]byte, 100)) |
| 130 | |
| 131 | buf.WriteBytescip-go gomod github.com/syndtr/goleveldb . `github.com/syndtr/goleveldb/leveldb/util`/Buffer#WriteByte().(datascip-go gomod github.com/syndtr/goleveldb . `github.com/syndtr/goleveldb/leveldb/util`/data.[1]) |
| 132 | c, err := buf.ReadBytescip-go gomod github.com/syndtr/goleveldb . `github.com/syndtr/goleveldb/leveldb/util`/Buffer#ReadByte().() |
| 133 | if err != nil { |
| 134 | t.Errorscip-go gomod github.com/golang/go/src go1.14 testing/common#Error().("ReadByte unexpected eof") |
| 135 | } |
| 136 | if c != datascip-go gomod github.com/syndtr/goleveldb . `github.com/syndtr/goleveldb/leveldb/util`/data.[1] { |
| 137 | t.Errorfscip-go gomod github.com/golang/go/src go1.14 testing/common#Errorf().("ReadByte wrong value c=%v", c) |
| 138 | } |
| 139 | c, err = buf.ReadBytescip-go gomod github.com/syndtr/goleveldb . `github.com/syndtr/goleveldb/leveldb/util`/Buffer#ReadByte().() |
| 140 | if err == nil { |
| 141 | t.Errorscip-go gomod github.com/golang/go/src go1.14 testing/common#Error().("ReadByte unexpected not eof") |
| 142 | } |
| 143 | } |
| 144 | } |
| 145 | |
| 146 | func TestLargeByteWritesscip-go gomod github.com/syndtr/goleveldb . `github.com/syndtr/goleveldb/leveldb/util`/TestLargeByteWrites().(t *testingscip-go gomod github.com/golang/go/src go1.14 testing/.Tscip-go gomod github.com/golang/go/src go1.14 testing/T#) { |
| 147 | var buf Bufferscip-go gomod github.com/syndtr/goleveldb . `github.com/syndtr/goleveldb/leveldb/util`/Buffer# |
| 148 | limit := 30 |
| 149 | if testingscip-go gomod github.com/golang/go/src go1.14 testing/.Shortscip-go gomod github.com/golang/go/src go1.14 testing/Short().() { |
| 150 | limit = 9 |
| 151 | } |
| 152 | for i := 3; i < limit; i += 3 { |
| 153 | s := fillBytesscip-go gomod github.com/syndtr/goleveldb . `github.com/syndtr/goleveldb/leveldb/util`/fillBytes().(t, "TestLargeWrites (1)", &buf, "", 5, testBytesscip-go gomod github.com/syndtr/goleveldb . `github.com/syndtr/goleveldb/leveldb/util`/testBytes.) |
| 154 | emptyscip-go gomod github.com/syndtr/goleveldb . `github.com/syndtr/goleveldb/leveldb/util`/empty().(t, "TestLargeByteWrites (2)", &buf, s, make([]byte, len(datascip-go gomod github.com/syndtr/goleveldb . `github.com/syndtr/goleveldb/leveldb/util`/data.)/i)) |
| 155 | } |
| 156 | checkscip-go gomod github.com/syndtr/goleveldb . `github.com/syndtr/goleveldb/leveldb/util`/check().(t, "TestLargeByteWrites (3)", &buf, "") |
| 157 | } |
| 158 | |
| 159 | func TestLargeByteReadsscip-go gomod github.com/syndtr/goleveldb . `github.com/syndtr/goleveldb/leveldb/util`/TestLargeByteReads().(t *testingscip-go gomod github.com/golang/go/src go1.14 testing/.Tscip-go gomod github.com/golang/go/src go1.14 testing/T#) { |
| 160 | var buf Bufferscip-go gomod github.com/syndtr/goleveldb . `github.com/syndtr/goleveldb/leveldb/util`/Buffer# |
| 161 | for i := 3; i < 30; i += 3 { |
| 162 | s := fillBytesscip-go gomod github.com/syndtr/goleveldb . `github.com/syndtr/goleveldb/leveldb/util`/fillBytes().(t, "TestLargeReads (1)", &buf, "", 5, testBytesscip-go gomod github.com/syndtr/goleveldb . `github.com/syndtr/goleveldb/leveldb/util`/testBytes.[0:len(testBytesscip-go gomod github.com/syndtr/goleveldb . `github.com/syndtr/goleveldb/leveldb/util`/testBytes.)/i]) |
| 163 | emptyscip-go gomod github.com/syndtr/goleveldb . `github.com/syndtr/goleveldb/leveldb/util`/empty().(t, "TestLargeReads (2)", &buf, s, make([]byte, len(datascip-go gomod github.com/syndtr/goleveldb . `github.com/syndtr/goleveldb/leveldb/util`/data.))) |
| 164 | } |
| 165 | checkscip-go gomod github.com/syndtr/goleveldb . `github.com/syndtr/goleveldb/leveldb/util`/check().(t, "TestLargeByteReads (3)", &buf, "") |
| 166 | } |
| 167 | |
| 168 | func TestMixedReadsAndWritesscip-go gomod github.com/syndtr/goleveldb . `github.com/syndtr/goleveldb/leveldb/util`/TestMixedReadsAndWrites().(t *testingscip-go gomod github.com/golang/go/src go1.14 testing/.Tscip-go gomod github.com/golang/go/src go1.14 testing/T#) { |
| 169 | var buf Bufferscip-go gomod github.com/syndtr/goleveldb . `github.com/syndtr/goleveldb/leveldb/util`/Buffer# |
| 170 | s := "" |
| 171 | for i := 0; i < 50; i++ { |
| 172 | wlen := randscip-go gomod github.com/golang/go/src go1.14 `math/rand`/.Intnscip-go gomod github.com/golang/go/src go1.14 `math/rand`/Intn().(len(datascip-go gomod github.com/syndtr/goleveldb . `github.com/syndtr/goleveldb/leveldb/util`/data.)) |
| 173 | s = fillBytesscip-go gomod github.com/syndtr/goleveldb . `github.com/syndtr/goleveldb/leveldb/util`/fillBytes().(t, "TestMixedReadsAndWrites (1)", &buf, s, 1, testBytesscip-go gomod github.com/syndtr/goleveldb . `github.com/syndtr/goleveldb/leveldb/util`/testBytes.[0:wlen]) |
| 174 | rlen := randscip-go gomod github.com/golang/go/src go1.14 `math/rand`/.Intnscip-go gomod github.com/golang/go/src go1.14 `math/rand`/Intn().(len(datascip-go gomod github.com/syndtr/goleveldb . `github.com/syndtr/goleveldb/leveldb/util`/data.)) |
| 175 | fub := make([]byte, rlen) |
| 176 | n, _ := buf.Readscip-go gomod github.com/syndtr/goleveldb . `github.com/syndtr/goleveldb/leveldb/util`/Buffer#Read().(fub) |
| 177 | s = s[n:] |
| 178 | } |
| 179 | emptyscip-go gomod github.com/syndtr/goleveldb . `github.com/syndtr/goleveldb/leveldb/util`/empty().(t, "TestMixedReadsAndWrites (2)", &buf, s, make([]byte, buf.Lenscip-go gomod github.com/syndtr/goleveldb . `github.com/syndtr/goleveldb/leveldb/util`/Buffer#Len().())) |
| 180 | } |
| 181 | |
| 182 | func TestNilscip-go gomod github.com/syndtr/goleveldb . `github.com/syndtr/goleveldb/leveldb/util`/TestNil().(t *testingscip-go gomod github.com/golang/go/src go1.14 testing/.Tscip-go gomod github.com/golang/go/src go1.14 testing/T#) { |
| 183 | var b *Bufferscip-go gomod github.com/syndtr/goleveldb . `github.com/syndtr/goleveldb/leveldb/util`/Buffer# |
| 184 | if b.Stringscip-go gomod github.com/syndtr/goleveldb . `github.com/syndtr/goleveldb/leveldb/util`/Buffer#String().() != "<nil>" { |
| 185 | t.Errorfscip-go gomod github.com/golang/go/src go1.14 testing/common#Errorf().("expected <nil>; got %q", b.Stringscip-go gomod github.com/syndtr/goleveldb . `github.com/syndtr/goleveldb/leveldb/util`/Buffer#String().()) |
| 186 | } |
| 187 | } |
| 188 | |
| 189 | func TestReadFromscip-go gomod github.com/syndtr/goleveldb . `github.com/syndtr/goleveldb/leveldb/util`/TestReadFrom().(t *testingscip-go gomod github.com/golang/go/src go1.14 testing/.Tscip-go gomod github.com/golang/go/src go1.14 testing/T#) { |
| 190 | var buf Bufferscip-go gomod github.com/syndtr/goleveldb . `github.com/syndtr/goleveldb/leveldb/util`/Buffer# |
| 191 | for i := 3; i < 30; i += 3 { |
| 192 | s := fillBytesscip-go gomod github.com/syndtr/goleveldb . `github.com/syndtr/goleveldb/leveldb/util`/fillBytes().(t, "TestReadFrom (1)", &buf, "", 5, testBytesscip-go gomod github.com/syndtr/goleveldb . `github.com/syndtr/goleveldb/leveldb/util`/testBytes.[0:len(testBytesscip-go gomod github.com/syndtr/goleveldb . `github.com/syndtr/goleveldb/leveldb/util`/testBytes.)/i]) |
| 193 | var b Bufferscip-go gomod github.com/syndtr/goleveldb . `github.com/syndtr/goleveldb/leveldb/util`/Buffer# |
| 194 | b.ReadFromscip-go gomod github.com/syndtr/goleveldb . `github.com/syndtr/goleveldb/leveldb/util`/Buffer#ReadFrom().(&buf) |
| 195 | emptyscip-go gomod github.com/syndtr/goleveldb . `github.com/syndtr/goleveldb/leveldb/util`/empty().(t, "TestReadFrom (2)", &b, s, make([]byte, len(datascip-go gomod github.com/syndtr/goleveldb . `github.com/syndtr/goleveldb/leveldb/util`/data.))) |
| 196 | } |
| 197 | } |
| 198 | |
| 199 | func TestWriteToscip-go gomod github.com/syndtr/goleveldb . `github.com/syndtr/goleveldb/leveldb/util`/TestWriteTo().(t *testingscip-go gomod github.com/golang/go/src go1.14 testing/.Tscip-go gomod github.com/golang/go/src go1.14 testing/T#) { |
| 200 | var buf Bufferscip-go gomod github.com/syndtr/goleveldb . `github.com/syndtr/goleveldb/leveldb/util`/Buffer# |
| 201 | for i := 3; i < 30; i += 3 { |
| 202 | s := fillBytesscip-go gomod github.com/syndtr/goleveldb . `github.com/syndtr/goleveldb/leveldb/util`/fillBytes().(t, "TestWriteTo (1)", &buf, "", 5, testBytesscip-go gomod github.com/syndtr/goleveldb . `github.com/syndtr/goleveldb/leveldb/util`/testBytes.[0:len(testBytesscip-go gomod github.com/syndtr/goleveldb . `github.com/syndtr/goleveldb/leveldb/util`/testBytes.)/i]) |
| 203 | var b Bufferscip-go gomod github.com/syndtr/goleveldb . `github.com/syndtr/goleveldb/leveldb/util`/Buffer# |
| 204 | buf.WriteToscip-go gomod github.com/syndtr/goleveldb . `github.com/syndtr/goleveldb/leveldb/util`/Buffer#WriteTo().(&b) |
| 205 | emptyscip-go gomod github.com/syndtr/goleveldb . `github.com/syndtr/goleveldb/leveldb/util`/empty().(t, "TestWriteTo (2)", &b, s, make([]byte, len(datascip-go gomod github.com/syndtr/goleveldb . `github.com/syndtr/goleveldb/leveldb/util`/data.))) |
| 206 | } |
| 207 | } |
| 208 | |
| 209 | func TestNextscip-go gomod github.com/syndtr/goleveldb . `github.com/syndtr/goleveldb/leveldb/util`/TestNext().(t *testingscip-go gomod github.com/golang/go/src go1.14 testing/.Tscip-go gomod github.com/golang/go/src go1.14 testing/T#) { |
| 210 | b := []byte{0, 1, 2, 3, 4} |
| 211 | tmp := make([]byte, 5) |
| 212 | for i := 0; i <= 5; i++ { |
| 213 | for j := i; j <= 5; j++ { |
| 214 | for k := 0; k <= 6; k++ { |
| 215 | // 0 <= i <= j <= 5; 0 <= k <= 6 |
| 216 | // Check that if we start with a buffer |
| 217 | // of length j at offset i and ask for |
| 218 | // Next(k), we get the right bytes. |
| 219 | buf := NewBufferscip-go gomod github.com/syndtr/goleveldb . `github.com/syndtr/goleveldb/leveldb/util`/NewBuffer().(b[0:j]) |
| 220 | n, _ := buf.Readscip-go gomod github.com/syndtr/goleveldb . `github.com/syndtr/goleveldb/leveldb/util`/Buffer#Read().(tmp[0:i]) |
| 221 | if n != i { |
| 222 | t.Fatalfscip-go gomod github.com/golang/go/src go1.14 testing/common#Fatalf().("Read %d returned %d", i, n) |
| 223 | } |
| 224 | bb := buf.Nextscip-go gomod github.com/syndtr/goleveldb . `github.com/syndtr/goleveldb/leveldb/util`/Buffer#Next().(k) |
| 225 | want := k |
| 226 | if want > j-i { |
| 227 | want = j - i |
| 228 | } |
| 229 | if len(bb) != want { |
| 230 | t.Fatalfscip-go gomod github.com/golang/go/src go1.14 testing/common#Fatalf().("in %d,%d: len(Next(%d)) == %d", i, j, k, len(bb)) |
| 231 | } |
| 232 | for l, v := range bb { |
| 233 | if v != byte(l+i) { |
| 234 | t.Fatalfscip-go gomod github.com/golang/go/src go1.14 testing/common#Fatalf().("in %d,%d: Next(%d)[%d] = %d, want %d", i, j, k, l, v, l+i) |
| 235 | } |
| 236 | } |
| 237 | } |
| 238 | } |
| 239 | } |
| 240 | } |
| 241 | |
| 242 | var readBytesTestsscip-go gomod github.com/syndtr/goleveldb . `github.com/syndtr/goleveldb/leveldb/util`/readBytesTests. = []struct { |
| 243 | bufferscip-go gomod github.com/syndtr/goleveldb . `github.com/syndtr/goleveldb/leveldb/util`/readBytesTests:buffer. string |
| 244 | delimscip-go gomod github.com/syndtr/goleveldb . `github.com/syndtr/goleveldb/leveldb/util`/readBytesTests:delim. byte |
| 245 | expectedscip-go gomod github.com/syndtr/goleveldb . `github.com/syndtr/goleveldb/leveldb/util`/readBytesTests:expected. []string |
| 246 | errscip-go gomod github.com/syndtr/goleveldb . `github.com/syndtr/goleveldb/leveldb/util`/readBytesTests:err. error |
| 247 | }{ |
| 248 | {"", 0, []string{""}, ioscip-go gomod github.com/golang/go/src go1.14 io/.EOFscip-go gomod github.com/golang/go/src go1.14 io/EOF.}, |
| 249 | {"a\x00", 0, []string{"a\x00"}, nil}, |
| 250 | {"abbbaaaba", 'b', []string{"ab", "b", "b", "aaab"}, nil}, |
| 251 | {"hello\x01world", 1, []string{"hello\x01"}, nil}, |
| 252 | {"foo\nbar", 0, []string{"foo\nbar"}, ioscip-go gomod github.com/golang/go/src go1.14 io/.EOFscip-go gomod github.com/golang/go/src go1.14 io/EOF.}, |
| 253 | {"alpha\nbeta\ngamma\n", '\n', []string{"alpha\n", "beta\n", "gamma\n"}, nil}, |
| 254 | {"alpha\nbeta\ngamma", '\n', []string{"alpha\n", "beta\n", "gamma"}, ioscip-go gomod github.com/golang/go/src go1.14 io/.EOFscip-go gomod github.com/golang/go/src go1.14 io/EOF.}, |
| 255 | } |
| 256 | |
| 257 | func TestReadBytesscip-go gomod github.com/syndtr/goleveldb . `github.com/syndtr/goleveldb/leveldb/util`/TestReadBytes().(t *testingscip-go gomod github.com/golang/go/src go1.14 testing/.Tscip-go gomod github.com/golang/go/src go1.14 testing/T#) { |
| 258 | for _, test := range readBytesTestsscip-go gomod github.com/syndtr/goleveldb . `github.com/syndtr/goleveldb/leveldb/util`/readBytesTests. { |
| 259 | buf := NewBufferscip-go gomod github.com/syndtr/goleveldb . `github.com/syndtr/goleveldb/leveldb/util`/NewBuffer().([]byte(test.bufferscip-go gomod github.com/syndtr/goleveldb . `github.com/syndtr/goleveldb/leveldb/util`/readBytesTests:buffer.)) |
| 260 | var err error |
| 261 | for _, expected := range test.expectedscip-go gomod github.com/syndtr/goleveldb . `github.com/syndtr/goleveldb/leveldb/util`/readBytesTests:expected. { |
| 262 | var bytes []byte |
| 263 | bytes, err = buf.ReadBytesscip-go gomod github.com/syndtr/goleveldb . `github.com/syndtr/goleveldb/leveldb/util`/Buffer#ReadBytes().(test.delimscip-go gomod github.com/syndtr/goleveldb . `github.com/syndtr/goleveldb/leveldb/util`/readBytesTests:delim.) |
| 264 | if string(bytes) != expected { |
| 265 | t.Errorfscip-go gomod github.com/golang/go/src go1.14 testing/common#Errorf().("expected %q, got %q", expected, bytes) |
| 266 | } |
| 267 | if err != nil { |
| 268 | break |
| 269 | } |
| 270 | } |
| 271 | if err != test.errscip-go gomod github.com/syndtr/goleveldb . `github.com/syndtr/goleveldb/leveldb/util`/readBytesTests:err. { |
| 272 | t.Errorfscip-go gomod github.com/golang/go/src go1.14 testing/common#Errorf().("expected error %v, got %v", test.errscip-go gomod github.com/syndtr/goleveldb . `github.com/syndtr/goleveldb/leveldb/util`/readBytesTests:err., err) |
| 273 | } |
| 274 | } |
| 275 | } |
| 276 | |
| 277 | func TestGrowscip-go gomod github.com/syndtr/goleveldb . `github.com/syndtr/goleveldb/leveldb/util`/TestGrow().(t *testingscip-go gomod github.com/golang/go/src go1.14 testing/.Tscip-go gomod github.com/golang/go/src go1.14 testing/T#) { |
| 278 | x := []byte{'x'} |
| 279 | y := []byte{'y'} |
| 280 | tmp := make([]byte, 72) |
| 281 | for _, startLen := range []int{0, 100, 1000, 10000, 100000} { |
| 282 | xBytes := bytesscip-go gomod github.com/golang/go/src go1.14 bytes/.Repeatscip-go gomod github.com/golang/go/src go1.14 bytes/Repeat().(x, startLen) |
| 283 | for _, growLen := range []int{0, 100, 1000, 10000, 100000} { |
| 284 | buf := NewBufferscip-go gomod github.com/syndtr/goleveldb . `github.com/syndtr/goleveldb/leveldb/util`/NewBuffer().(xBytes) |
| 285 | // If we read, this affects buf.off, which is good to test. |
| 286 | readBytes, _ := buf.Readscip-go gomod github.com/syndtr/goleveldb . `github.com/syndtr/goleveldb/leveldb/util`/Buffer#Read().(tmp) |
| 287 | buf.Growscip-go gomod github.com/syndtr/goleveldb . `github.com/syndtr/goleveldb/leveldb/util`/Buffer#Grow().(growLen) |
| 288 | yBytes := bytesscip-go gomod github.com/golang/go/src go1.14 bytes/.Repeatscip-go gomod github.com/golang/go/src go1.14 bytes/Repeat().(y, growLen) |
| 289 | // Check no allocation occurs in write, as long as we're single-threaded. |
| 290 | var m1, m2 runtimescip-go gomod github.com/golang/go/src go1.14 runtime/.MemStatsscip-go gomod github.com/golang/go/src go1.14 runtime/MemStats# |
| 291 | runtimescip-go gomod github.com/golang/go/src go1.14 runtime/.ReadMemStatsscip-go gomod github.com/golang/go/src go1.14 runtime/ReadMemStats().(&m1) |
| 292 | buf.Writescip-go gomod github.com/syndtr/goleveldb . `github.com/syndtr/goleveldb/leveldb/util`/Buffer#Write().(yBytes) |
| 293 | runtimescip-go gomod github.com/golang/go/src go1.14 runtime/.ReadMemStatsscip-go gomod github.com/golang/go/src go1.14 runtime/ReadMemStats().(&m2) |
| 294 | if runtimescip-go gomod github.com/golang/go/src go1.14 runtime/.GOMAXPROCSscip-go gomod github.com/golang/go/src go1.14 runtime/GOMAXPROCS().(-1) == 1 && m1.Mallocsscip-go gomod github.com/golang/go/src go1.14 runtime/MemStats#Mallocs. != m2.Mallocsscip-go gomod github.com/golang/go/src go1.14 runtime/MemStats#Mallocs. { |
| 295 | t.Errorfscip-go gomod github.com/golang/go/src go1.14 testing/common#Errorf().("allocation occurred during write") |
| 296 | } |
| 297 | // Check that buffer has correct data. |
| 298 | if !bytesscip-go gomod github.com/golang/go/src go1.14 bytes/.Equalscip-go gomod github.com/golang/go/src go1.14 bytes/Equal().(buf.Bytesscip-go gomod github.com/syndtr/goleveldb . `github.com/syndtr/goleveldb/leveldb/util`/Buffer#Bytes().()[0:startLen-readBytes], xBytes[readBytes:]) { |
| 299 | t.Errorfscip-go gomod github.com/golang/go/src go1.14 testing/common#Errorf().("bad initial data at %d %d", startLen, growLen) |
| 300 | } |
| 301 | if !bytesscip-go gomod github.com/golang/go/src go1.14 bytes/.Equalscip-go gomod github.com/golang/go/src go1.14 bytes/Equal().(buf.Bytesscip-go gomod github.com/syndtr/goleveldb . `github.com/syndtr/goleveldb/leveldb/util`/Buffer#Bytes().()[startLen-readBytes:startLen-readBytes+growLen], yBytes) { |
| 302 | t.Errorfscip-go gomod github.com/golang/go/src go1.14 testing/common#Errorf().("bad written data at %d %d", startLen, growLen) |
| 303 | } |
| 304 | } |
| 305 | } |
| 306 | } |
| 307 | |
| 308 | // TestReadEmptyAtEOF: Was a bug: used to give EOF reading empty slice at EOF. |
| 309 | func TestReadEmptyAtEOFscip-go gomod github.com/syndtr/goleveldb . `github.com/syndtr/goleveldb/leveldb/util`/TestReadEmptyAtEOF().(t *testingscip-go gomod github.com/golang/go/src go1.14 testing/.Tscip-go gomod github.com/golang/go/src go1.14 testing/T#) { |
| 310 | b := new(Bufferscip-go gomod github.com/syndtr/goleveldb . `github.com/syndtr/goleveldb/leveldb/util`/Buffer#) |
| 311 | slice := make([]byte, 0) |
| 312 | n, err := b.Readscip-go gomod github.com/syndtr/goleveldb . `github.com/syndtr/goleveldb/leveldb/util`/Buffer#Read().(slice) |
| 313 | if err != nil { |
| 314 | t.Errorfscip-go gomod github.com/golang/go/src go1.14 testing/common#Errorf().("read error: %v", err) |
| 315 | } |
| 316 | if n != 0 { |
| 317 | t.Errorfscip-go gomod github.com/golang/go/src go1.14 testing/common#Errorf().("wrong count; got %d want 0", n) |
| 318 | } |
| 319 | } |
| 320 | |
| 321 | // TestBufferGrowth tests that we occasionally compact. Issue 5154. |
| 322 | func TestBufferGrowthscip-go gomod github.com/syndtr/goleveldb . `github.com/syndtr/goleveldb/leveldb/util`/TestBufferGrowth().(t *testingscip-go gomod github.com/golang/go/src go1.14 testing/.Tscip-go gomod github.com/golang/go/src go1.14 testing/T#) { |
| 323 | var b Bufferscip-go gomod github.com/syndtr/goleveldb . `github.com/syndtr/goleveldb/leveldb/util`/Buffer# |
| 324 | buf := make([]byte, 1024) |
| 325 | b.Writescip-go gomod github.com/syndtr/goleveldb . `github.com/syndtr/goleveldb/leveldb/util`/Buffer#Write().(buf[0:1]) |
| 326 | var cap0 int |
| 327 | for i := 0; i < 5<<10; i++ { |
| 328 | b.Writescip-go gomod github.com/syndtr/goleveldb . `github.com/syndtr/goleveldb/leveldb/util`/Buffer#Write().(buf) |
| 329 | b.Readscip-go gomod github.com/syndtr/goleveldb . `github.com/syndtr/goleveldb/leveldb/util`/Buffer#Read().(buf) |
| 330 | if i == 0 { |
| 331 | cap0 = cap(b.bufscip-go gomod github.com/syndtr/goleveldb . `github.com/syndtr/goleveldb/leveldb/util`/Buffer#buf.) |
| 332 | } |
| 333 | } |
| 334 | cap1 := cap(b.bufscip-go gomod github.com/syndtr/goleveldb . `github.com/syndtr/goleveldb/leveldb/util`/Buffer#buf.) |
| 335 | // (*Buffer).grow allows for 2x capacity slop before sliding, |
| 336 | // so set our error threshold at 3x. |
| 337 | if cap1 > cap0*3 { |
| 338 | t.Errorfscip-go gomod github.com/golang/go/src go1.14 testing/common#Errorf().("buffer cap = %d; too big (grew from %d)", cap1, cap0) |
| 339 | } |
| 340 | } |
| 341 | |
| 342 | func BenchmarkWriteBytescip-go gomod github.com/syndtr/goleveldb . `github.com/syndtr/goleveldb/leveldb/util`/BenchmarkWriteByte().(b *testingscip-go gomod github.com/golang/go/src go1.14 testing/.Bscip-go gomod github.com/golang/go/src go1.14 testing/B#) { |
| 343 | const n = 4 << 10 |
| 344 | b.SetBytesscip-go gomod github.com/golang/go/src go1.14 testing/B#SetBytes().(n) |
| 345 | buf := NewBufferscip-go gomod github.com/syndtr/goleveldb . `github.com/syndtr/goleveldb/leveldb/util`/NewBuffer().(make([]byte, n)) |
| 346 | for i := 0; i < b.Nscip-go gomod github.com/golang/go/src go1.14 testing/B#N.; i++ { |
| 347 | buf.Resetscip-go gomod github.com/syndtr/goleveldb . `github.com/syndtr/goleveldb/leveldb/util`/Buffer#Reset().() |
| 348 | for i := 0; i < n; i++ { |
| 349 | buf.WriteBytescip-go gomod github.com/syndtr/goleveldb . `github.com/syndtr/goleveldb/leveldb/util`/Buffer#WriteByte().('x') |
| 350 | } |
| 351 | } |
| 352 | } |
| 353 | |
| 354 | func BenchmarkAllocscip-go gomod github.com/syndtr/goleveldb . `github.com/syndtr/goleveldb/leveldb/util`/BenchmarkAlloc().(b *testingscip-go gomod github.com/golang/go/src go1.14 testing/.Bscip-go gomod github.com/golang/go/src go1.14 testing/B#) { |
| 355 | const n = 4 << 10 |
| 356 | b.SetBytesscip-go gomod github.com/golang/go/src go1.14 testing/B#SetBytes().(n) |
| 357 | buf := NewBufferscip-go gomod github.com/syndtr/goleveldb . `github.com/syndtr/goleveldb/leveldb/util`/NewBuffer().(make([]byte, n)) |
| 358 | for i := 0; i < b.Nscip-go gomod github.com/golang/go/src go1.14 testing/B#N.; i++ { |
| 359 | buf.Resetscip-go gomod github.com/syndtr/goleveldb . `github.com/syndtr/goleveldb/leveldb/util`/Buffer#Reset().() |
| 360 | for i := 0; i < n; i++ { |
| 361 | buf.Allocscip-go gomod github.com/syndtr/goleveldb . `github.com/syndtr/goleveldb/leveldb/util`/Buffer#Alloc().(1) |
| 362 | } |
| 363 | } |
| 364 | } |
| 365 | |
| 366 | // BenchmarkBufferNotEmptyWriteRead: From Issue 5154. |
| 367 | func BenchmarkBufferNotEmptyWriteReadscip-go gomod github.com/syndtr/goleveldb . `github.com/syndtr/goleveldb/leveldb/util`/BenchmarkBufferNotEmptyWriteRead().(b *testingscip-go gomod github.com/golang/go/src go1.14 testing/.Bscip-go gomod github.com/golang/go/src go1.14 testing/B#) { |
| 368 | buf := make([]byte, 1024) |
| 369 | for i := 0; i < b.Nscip-go gomod github.com/golang/go/src go1.14 testing/B#N.; i++ { |
| 370 | var b Bufferscip-go gomod github.com/syndtr/goleveldb . `github.com/syndtr/goleveldb/leveldb/util`/Buffer# |
| 371 | b.Writescip-go gomod github.com/syndtr/goleveldb . `github.com/syndtr/goleveldb/leveldb/util`/Buffer#Write().(buf[0:1]) |
| 372 | for i := 0; i < 5<<10; i++ { |
| 373 | b.Writescip-go gomod github.com/syndtr/goleveldb . `github.com/syndtr/goleveldb/leveldb/util`/Buffer#Write().(buf) |
| 374 | b.Readscip-go gomod github.com/syndtr/goleveldb . `github.com/syndtr/goleveldb/leveldb/util`/Buffer#Read().(buf) |
| 375 | } |
| 376 | } |
| 377 | } |
| 378 | |
| 379 | // BenchmarkBufferFullSmallReads checks that we don't compact too often. From Issue 5154. |
| 380 | func BenchmarkBufferFullSmallReadsscip-go gomod github.com/syndtr/goleveldb . `github.com/syndtr/goleveldb/leveldb/util`/BenchmarkBufferFullSmallReads().(b *testingscip-go gomod github.com/golang/go/src go1.14 testing/.Bscip-go gomod github.com/golang/go/src go1.14 testing/B#) { |
| 381 | buf := make([]byte, 1024) |
| 382 | for i := 0; i < b.Nscip-go gomod github.com/golang/go/src go1.14 testing/B#N.; i++ { |
| 383 | var b Bufferscip-go gomod github.com/syndtr/goleveldb . `github.com/syndtr/goleveldb/leveldb/util`/Buffer# |
| 384 | b.Writescip-go gomod github.com/syndtr/goleveldb . `github.com/syndtr/goleveldb/leveldb/util`/Buffer#Write().(buf) |
| 385 | for b.Lenscip-go gomod github.com/syndtr/goleveldb . `github.com/syndtr/goleveldb/leveldb/util`/Buffer#Len().()+20 < cap(b.bufscip-go gomod github.com/syndtr/goleveldb . `github.com/syndtr/goleveldb/leveldb/util`/Buffer#buf.) { |
| 386 | b.Writescip-go gomod github.com/syndtr/goleveldb . `github.com/syndtr/goleveldb/leveldb/util`/Buffer#Write().(buf[:10]) |
| 387 | } |
| 388 | for i := 0; i < 5<<10; i++ { |
| 389 | b.Readscip-go gomod github.com/syndtr/goleveldb . `github.com/syndtr/goleveldb/leveldb/util`/Buffer#Read().(buf[:1]) |
| 390 | b.Writescip-go gomod github.com/syndtr/goleveldb . `github.com/syndtr/goleveldb/leveldb/util`/Buffer#Write().(buf[:1]) |
| 391 | } |
| 392 | } |
| 393 | } |