move gotd fork into repo. (#111)

- 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
This commit is contained in:
Adam Van Ymeren
2025-06-27 20:03:37 -07:00
committed by GitHub
parent 0952df0244
commit 7a04f298d2
19264 changed files with 1539697 additions and 84 deletions
+65
View File
@@ -0,0 +1,65 @@
package bin
import (
"bytes"
"io"
"strings"
"testing"
"github.com/stretchr/testify/require"
)
func TestStringDecodeEncode(t *testing.T) {
t.Run("Valid", func(t *testing.T) {
a := require.New(t)
for _, s := range []string{
strings.Repeat("abcd", 100),
strings.Repeat("abc", 102),
strings.Repeat("de", 103),
strings.Repeat("z", 104),
strings.Repeat("b", 105),
"foo",
"b",
"ba",
"what are you doing?",
"кек",
strings.Repeat("a", 253),
} {
buf := encodeString(nil, s)
a.True(len(buf)%4 == 0, "bad align")
n, v, err := decodeString(buf)
a.NoError(err)
a.Equal(s, v)
a.NotZero(n, "zero bytes read return")
}
})
t.Run("ErrUnexpectedEOF", func(t *testing.T) {
a := require.New(t)
_, _, err := decodeString(nil)
a.ErrorIs(err, io.ErrUnexpectedEOF)
_, _, err = decodeString([]byte{firstLongStringByte})
a.ErrorIs(err, io.ErrUnexpectedEOF)
_, _, err = decodeString([]byte{firstLongStringByte, 0, 0, 255, 0})
a.ErrorIs(err, io.ErrUnexpectedEOF)
_, _, err = decodeString(encodeString(nil, "foo bar")[:2])
a.ErrorIs(err, io.ErrUnexpectedEOF)
_, _, err = decodeString(encodeString(nil, strings.Repeat("b", 105))[:10])
a.ErrorIs(err, io.ErrUnexpectedEOF)
})
t.Run("InvalidLength", func(t *testing.T) {
a := require.New(t)
_, _, err := decodeString(bytes.Repeat([]byte{255}, 256))
var e *InvalidLengthError
a.ErrorAs(err, &e)
a.Equal("string", e.Where)
a.Contains(e.Error(), "string")
})
}