7a04f298d2
- update to latest telegram layer - remove some references to fields in tg.Entities that don't exist in the schema - originally added here: https://github.com/beeper/td/commit/820929062a2ba0104397bc01235ab58a9cff780e - referenced here - https://github.com/mautrix/telegramgo/commit/124f0967ed195b5a380c9bd02e170ada9710dde3 - https://github.com/mautrix/telegramgo/commit/4205047aab2e0639217148b5d125bfaab668bd8e
56 lines
1.2 KiB
Go
56 lines
1.2 KiB
Go
package entity
|
|
|
|
import (
|
|
"encoding/hex"
|
|
"testing"
|
|
"unicode/utf8"
|
|
|
|
"github.com/stretchr/testify/require"
|
|
|
|
"go.mau.fi/mautrix-telegram/pkg/gotd/testutil"
|
|
)
|
|
|
|
func TestComputeLength(t *testing.T) {
|
|
tests := []struct {
|
|
s string
|
|
want int
|
|
}{
|
|
{string([]rune{97, 127987, 65039, 8205, 127752}), 7},
|
|
{string([]int32{97, 127987, 65039, 8205, 127752, 127987, 65039, 8205, 127752}), 13},
|
|
{string([]int32{97, 128104, 8205, 128102, 8205, 128102}), 9},
|
|
}
|
|
for _, tt := range tests {
|
|
r := []byte(tt.s)
|
|
testutil.ZeroAlloc(t, func() {
|
|
_ = ComputeLength(tt.s)
|
|
})
|
|
testutil.ZeroAlloc(t, func() {
|
|
_ = ComputeLengthBytes(r)
|
|
})
|
|
t.Run(hex.EncodeToString([]byte(tt.s)), func(t *testing.T) {
|
|
require.Equal(t, tt.want, ComputeLength(tt.s))
|
|
require.Equal(t, tt.want, ComputeLengthBytes(r))
|
|
})
|
|
}
|
|
}
|
|
|
|
func TestBuilder_Write(t *testing.T) {
|
|
var (
|
|
a = require.New(t)
|
|
b Builder
|
|
)
|
|
_, err := b.Write([]byte("abc"))
|
|
a.NoError(err)
|
|
_, err = b.WriteString("abc")
|
|
a.NoError(err)
|
|
a.NoError(b.WriteByte('\n'))
|
|
a.Equal(3+3+1, b.UTF8Len())
|
|
a.Equal(3+3+1, b.UTF16Len())
|
|
|
|
var r rune = 127987
|
|
_, err = b.WriteRune(r)
|
|
a.NoError(err)
|
|
a.Equal(3+3+1+utf8.RuneLen(r), b.UTF8Len())
|
|
a.Equal(3+3+1+utf16RuneLen(r), b.UTF16Len())
|
|
}
|