mirror of
https://github.com/itzg/mc-router.git
synced 2024-11-22 11:35:14 +01:00
38 lines
620 B
Go
38 lines
620 B
Go
package mcproto
|
|
|
|
import (
|
|
"bytes"
|
|
"testing"
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
"github.com/stretchr/testify/require"
|
|
)
|
|
|
|
func TestReadVarInt(t *testing.T) {
|
|
tests := []struct {
|
|
Name string
|
|
Input []byte
|
|
Expected int
|
|
}{
|
|
{
|
|
Name: "Single byte",
|
|
Input: []byte{0xFA, 0x00},
|
|
Expected: 0x7A,
|
|
},
|
|
{
|
|
Name: "Two byte",
|
|
Input: []byte{0x81, 0x04},
|
|
Expected: 0x0201,
|
|
},
|
|
}
|
|
|
|
for _, tt := range tests {
|
|
t.Run(tt.Name, func(t *testing.T) {
|
|
result, err := ReadVarInt(bytes.NewBuffer(tt.Input))
|
|
require.NoError(t, err)
|
|
|
|
assert.Equal(t, tt.Expected, result)
|
|
})
|
|
}
|
|
}
|