4
4
5
5
//go:build go1.21
6
6
7
- package quic
7
+ package quicwire
8
8
9
9
import (
10
10
"bytes"
@@ -32,22 +32,22 @@ func TestConsumeVarint(t *testing.T) {
32
32
{[]byte {0x25 }, 37 , 1 },
33
33
{[]byte {0x40 , 0x25 }, 37 , 2 },
34
34
} {
35
- got , gotLen := consumeVarint (test .b )
35
+ got , gotLen := ConsumeVarint (test .b )
36
36
if got != test .want || gotLen != test .wantLen {
37
- t .Errorf ("consumeVarint (%x) = %v, %v; want %v, %v" , test .b , got , gotLen , test .want , test .wantLen )
37
+ t .Errorf ("ConsumeVarint (%x) = %v, %v; want %v, %v" , test .b , got , gotLen , test .want , test .wantLen )
38
38
}
39
39
// Extra data in the buffer is ignored.
40
40
b := append (test .b , 0 )
41
- got , gotLen = consumeVarint (b )
41
+ got , gotLen = ConsumeVarint (b )
42
42
if got != test .want || gotLen != test .wantLen {
43
- t .Errorf ("consumeVarint (%x) = %v, %v; want %v, %v" , b , got , gotLen , test .want , test .wantLen )
43
+ t .Errorf ("ConsumeVarint (%x) = %v, %v; want %v, %v" , b , got , gotLen , test .want , test .wantLen )
44
44
}
45
45
// Short buffer results in an error.
46
46
for i := 1 ; i <= len (test .b ); i ++ {
47
47
b = test .b [:len (test .b )- i ]
48
- got , gotLen = consumeVarint (b )
48
+ got , gotLen = ConsumeVarint (b )
49
49
if got != 0 || gotLen >= 0 {
50
- t .Errorf ("consumeVarint (%x) = %v, %v; want 0, -1" , b , got , gotLen )
50
+ t .Errorf ("ConsumeVarint (%x) = %v, %v; want 0, -1" , b , got , gotLen )
51
51
}
52
52
}
53
53
}
@@ -69,11 +69,11 @@ func TestAppendVarint(t *testing.T) {
69
69
{15293 , []byte {0x7b , 0xbd }},
70
70
{37 , []byte {0x25 }},
71
71
} {
72
- got := appendVarint ([]byte {}, test .v )
72
+ got := AppendVarint ([]byte {}, test .v )
73
73
if ! bytes .Equal (got , test .want ) {
74
74
t .Errorf ("AppendVarint(nil, %v) = %x, want %x" , test .v , got , test .want )
75
75
}
76
- if gotLen , wantLen := sizeVarint (test .v ), len (got ); gotLen != wantLen {
76
+ if gotLen , wantLen := SizeVarint (test .v ), len (got ); gotLen != wantLen {
77
77
t .Errorf ("SizeVarint(%v) = %v, want %v" , test .v , gotLen , wantLen )
78
78
}
79
79
}
@@ -88,8 +88,8 @@ func TestConsumeUint32(t *testing.T) {
88
88
{[]byte {0x01 , 0x02 , 0x03 , 0x04 }, 0x01020304 , 4 },
89
89
{[]byte {0x01 , 0x02 , 0x03 }, 0 , - 1 },
90
90
} {
91
- if got , n := consumeUint32 (test .b ); got != test .want || n != test .wantLen {
92
- t .Errorf ("consumeUint32 (%x) = %v, %v; want %v, %v" , test .b , got , n , test .want , test .wantLen )
91
+ if got , n := ConsumeUint32 (test .b ); got != test .want || n != test .wantLen {
92
+ t .Errorf ("ConsumeUint32 (%x) = %v, %v; want %v, %v" , test .b , got , n , test .want , test .wantLen )
93
93
}
94
94
}
95
95
}
@@ -103,8 +103,8 @@ func TestConsumeUint64(t *testing.T) {
103
103
{[]byte {0x01 , 0x02 , 0x03 , 0x04 , 0x05 , 0x06 , 0x07 , 0x08 }, 0x0102030405060708 , 8 },
104
104
{[]byte {0x01 , 0x02 , 0x03 , 0x04 , 0x05 , 0x06 , 0x07 }, 0 , - 1 },
105
105
} {
106
- if got , n := consumeUint64 (test .b ); got != test .want || n != test .wantLen {
107
- t .Errorf ("consumeUint32 (%x) = %v, %v; want %v, %v" , test .b , got , n , test .want , test .wantLen )
106
+ if got , n := ConsumeUint64 (test .b ); got != test .want || n != test .wantLen {
107
+ t .Errorf ("ConsumeUint32 (%x) = %v, %v; want %v, %v" , test .b , got , n , test .want , test .wantLen )
108
108
}
109
109
}
110
110
}
@@ -120,22 +120,22 @@ func TestConsumeVarintBytes(t *testing.T) {
120
120
{[]byte {0x04 , 0x01 , 0x02 , 0x03 , 0x04 }, []byte {0x01 , 0x02 , 0x03 , 0x04 }, 5 },
121
121
{[]byte {0x40 , 0x04 , 0x01 , 0x02 , 0x03 , 0x04 }, []byte {0x01 , 0x02 , 0x03 , 0x04 }, 6 },
122
122
} {
123
- got , gotLen := consumeVarintBytes (test .b )
123
+ got , gotLen := ConsumeVarintBytes (test .b )
124
124
if ! bytes .Equal (got , test .want ) || gotLen != test .wantLen {
125
- t .Errorf ("consumeVarintBytes (%x) = {%x}, %v; want {%x}, %v" , test .b , got , gotLen , test .want , test .wantLen )
125
+ t .Errorf ("ConsumeVarintBytes (%x) = {%x}, %v; want {%x}, %v" , test .b , got , gotLen , test .want , test .wantLen )
126
126
}
127
127
// Extra data in the buffer is ignored.
128
128
b := append (test .b , 0 )
129
- got , gotLen = consumeVarintBytes (b )
129
+ got , gotLen = ConsumeVarintBytes (b )
130
130
if ! bytes .Equal (got , test .want ) || gotLen != test .wantLen {
131
- t .Errorf ("consumeVarintBytes (%x) = {%x}, %v; want {%x}, %v" , b , got , gotLen , test .want , test .wantLen )
131
+ t .Errorf ("ConsumeVarintBytes (%x) = {%x}, %v; want {%x}, %v" , b , got , gotLen , test .want , test .wantLen )
132
132
}
133
133
// Short buffer results in an error.
134
134
for i := 1 ; i <= len (test .b ); i ++ {
135
135
b = test .b [:len (test .b )- i ]
136
- got , gotLen := consumeVarintBytes (b )
136
+ got , gotLen := ConsumeVarintBytes (b )
137
137
if len (got ) > 0 || gotLen > 0 {
138
- t .Errorf ("consumeVarintBytes (%x) = {%x}, %v; want {}, -1" , b , got , gotLen )
138
+ t .Errorf ("ConsumeVarintBytes (%x) = {%x}, %v; want {}, -1" , b , got , gotLen )
139
139
}
140
140
}
141
141
@@ -147,9 +147,9 @@ func TestConsumeVarintBytesErrors(t *testing.T) {
147
147
{0x01 },
148
148
{0x40 , 0x01 },
149
149
} {
150
- got , gotLen := consumeVarintBytes (b )
150
+ got , gotLen := ConsumeVarintBytes (b )
151
151
if len (got ) > 0 || gotLen > 0 {
152
- t .Errorf ("consumeVarintBytes (%x) = {%x}, %v; want {}, -1" , b , got , gotLen )
152
+ t .Errorf ("ConsumeVarintBytes (%x) = {%x}, %v; want {}, -1" , b , got , gotLen )
153
153
}
154
154
}
155
155
}
@@ -164,22 +164,22 @@ func TestConsumeUint8Bytes(t *testing.T) {
164
164
{[]byte {0x01 , 0x00 }, []byte {0x00 }, 2 },
165
165
{[]byte {0x04 , 0x01 , 0x02 , 0x03 , 0x04 }, []byte {0x01 , 0x02 , 0x03 , 0x04 }, 5 },
166
166
} {
167
- got , gotLen := consumeUint8Bytes (test .b )
167
+ got , gotLen := ConsumeUint8Bytes (test .b )
168
168
if ! bytes .Equal (got , test .want ) || gotLen != test .wantLen {
169
- t .Errorf ("consumeUint8Bytes (%x) = {%x}, %v; want {%x}, %v" , test .b , got , gotLen , test .want , test .wantLen )
169
+ t .Errorf ("ConsumeUint8Bytes (%x) = {%x}, %v; want {%x}, %v" , test .b , got , gotLen , test .want , test .wantLen )
170
170
}
171
171
// Extra data in the buffer is ignored.
172
172
b := append (test .b , 0 )
173
- got , gotLen = consumeUint8Bytes (b )
173
+ got , gotLen = ConsumeUint8Bytes (b )
174
174
if ! bytes .Equal (got , test .want ) || gotLen != test .wantLen {
175
- t .Errorf ("consumeUint8Bytes (%x) = {%x}, %v; want {%x}, %v" , b , got , gotLen , test .want , test .wantLen )
175
+ t .Errorf ("ConsumeUint8Bytes (%x) = {%x}, %v; want {%x}, %v" , b , got , gotLen , test .want , test .wantLen )
176
176
}
177
177
// Short buffer results in an error.
178
178
for i := 1 ; i <= len (test .b ); i ++ {
179
179
b = test .b [:len (test .b )- i ]
180
- got , gotLen := consumeUint8Bytes (b )
180
+ got , gotLen := ConsumeUint8Bytes (b )
181
181
if len (got ) > 0 || gotLen > 0 {
182
- t .Errorf ("consumeUint8Bytes (%x) = {%x}, %v; want {}, -1" , b , got , gotLen )
182
+ t .Errorf ("ConsumeUint8Bytes (%x) = {%x}, %v; want {}, -1" , b , got , gotLen )
183
183
}
184
184
}
185
185
@@ -191,35 +191,35 @@ func TestConsumeUint8BytesErrors(t *testing.T) {
191
191
{0x01 },
192
192
{0x04 , 0x01 , 0x02 , 0x03 },
193
193
} {
194
- got , gotLen := consumeUint8Bytes (b )
194
+ got , gotLen := ConsumeUint8Bytes (b )
195
195
if len (got ) > 0 || gotLen > 0 {
196
- t .Errorf ("consumeUint8Bytes (%x) = {%x}, %v; want {}, -1" , b , got , gotLen )
196
+ t .Errorf ("ConsumeUint8Bytes (%x) = {%x}, %v; want {}, -1" , b , got , gotLen )
197
197
}
198
198
}
199
199
}
200
200
201
201
func TestAppendUint8Bytes (t * testing.T ) {
202
202
var got []byte
203
- got = appendUint8Bytes (got , []byte {})
204
- got = appendUint8Bytes (got , []byte {0xaa , 0xbb })
203
+ got = AppendUint8Bytes (got , []byte {})
204
+ got = AppendUint8Bytes (got , []byte {0xaa , 0xbb })
205
205
want := []byte {
206
206
0x00 ,
207
207
0x02 , 0xaa , 0xbb ,
208
208
}
209
209
if ! bytes .Equal (got , want ) {
210
- t .Errorf ("appendUint8Bytes {}, {aabb} = {%x}; want {%x}" , got , want )
210
+ t .Errorf ("AppendUint8Bytes {}, {aabb} = {%x}; want {%x}" , got , want )
211
211
}
212
212
}
213
213
214
214
func TestAppendVarintBytes (t * testing.T ) {
215
215
var got []byte
216
- got = appendVarintBytes (got , []byte {})
217
- got = appendVarintBytes (got , []byte {0xaa , 0xbb })
216
+ got = AppendVarintBytes (got , []byte {})
217
+ got = AppendVarintBytes (got , []byte {0xaa , 0xbb })
218
218
want := []byte {
219
219
0x00 ,
220
220
0x02 , 0xaa , 0xbb ,
221
221
}
222
222
if ! bytes .Equal (got , want ) {
223
- t .Errorf ("appendVarintBytes {}, {aabb} = {%x}; want {%x}" , got , want )
223
+ t .Errorf ("AppendVarintBytes {}, {aabb} = {%x}; want {%x}" , got , want )
224
224
}
225
225
}
0 commit comments