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:
@@ -0,0 +1,67 @@
|
||||
package tljson
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/go-faster/jx"
|
||||
"github.com/stretchr/testify/require"
|
||||
|
||||
"go.mau.fi/mautrix-telegram/pkg/gotd/tg"
|
||||
)
|
||||
|
||||
func TestDecodeEncodeDecode(t *testing.T) {
|
||||
tests := []struct {
|
||||
name string
|
||||
input string
|
||||
wantErr bool
|
||||
expect tg.JSONValueClass
|
||||
}{
|
||||
{"Empty", "", true, nil},
|
||||
{"InvalidNull", "nul", true, nil},
|
||||
{"InvalidTrue", "tru", true, nil},
|
||||
{"InvalidFalse", "falsy", true, nil},
|
||||
{"InvalidInt", `[1a]"`, true, nil},
|
||||
{"InvalidFloat", "1.", true, nil},
|
||||
{"InvalidString", `"hello`, true, nil},
|
||||
{"InvalidArray", "[1, 2, 3.]", true, nil},
|
||||
{"InvalidObject", `{"abc":"def}`, true, nil},
|
||||
|
||||
{"Null", "null", false, nil},
|
||||
{"True", "true", false, nil},
|
||||
{"False", "false", false, nil},
|
||||
{"Int", "10", false, nil},
|
||||
{"Float", "1.1", false, nil},
|
||||
{"String", `"hello"`, false, nil},
|
||||
{"EmptyArray", "[]", false, nil},
|
||||
{"Array", "[1, 2, 3]", false, nil},
|
||||
{"EmptyObject", `{}`, false, nil},
|
||||
{"Object", `{"abc":"def"}`, false, nil},
|
||||
{"Tree", `{"a":1,"b":true,"c":null,"sub":{"abc":"def"}}`, false, nil},
|
||||
}
|
||||
for _, tt := range tests {
|
||||
tt := tt
|
||||
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
a := require.New(t)
|
||||
|
||||
// Decode.
|
||||
d := jx.DecodeStr(tt.input)
|
||||
obj, err := Decode(d)
|
||||
if tt.wantErr {
|
||||
a.Error(err)
|
||||
return
|
||||
}
|
||||
a.NoError(err)
|
||||
|
||||
// Encode.
|
||||
e := jx.GetEncoder()
|
||||
Encode(obj, e)
|
||||
|
||||
// Decode.
|
||||
d.ResetBytes(e.Bytes())
|
||||
obj2, err := Decode(d)
|
||||
a.NoError(err)
|
||||
a.Equal(obj, obj2)
|
||||
})
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user