-
-
Notifications
You must be signed in to change notification settings - Fork 2
/
main_test.go
140 lines (115 loc) · 2.61 KB
/
main_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
// Copyright (c) 2022-2024 Xelaj Software
//
// This file is a part of tl package.
// See https://github.com/xelaj/tl/blob/master/LICENSE_README.md for details.
//revive:disable:function-length // who cares for test files
package tl_test
import (
"bytes"
"encoding/hex"
"fmt"
"io"
"os"
"testing"
"github.com/stretchr/testify/assert"
. "github.com/xelaj/tl"
)
func tearup() {
RegisterObjectDefault[*MultipleChats]()
RegisterObjectDefault[*Chat]()
RegisterObjectDefault[*AuthSentCode]()
RegisterObjectDefault[*SomeNullStruct]()
RegisterObjectDefault[*AuthSentCodeTypeApp]()
RegisterObjectDefault[*Rights]()
RegisterObjectDefault[*PollResults]()
RegisterObjectDefault[*PollAnswerVoters]()
RegisterObjectDefault[*AccountInstallThemeParams]()
RegisterObjectDefault[*InputThemeObj]()
RegisterObjectDefault[*AccountUnregisterDeviceParams]()
RegisterObjectDefault[*InvokeWithLayerParams]()
RegisterObjectDefault[*InitConnectionParams]()
RegisterObjectDefault[*ResPQ]()
RegisterObjectDefault[*ResPQRaw]()
RegisterObjectDefault[*AnyStructWithAnyType]()
RegisterObjectDefault[*AnyStructWithAnyObject]()
RegisterObjectDefault[*Poll]()
RegisterObjectDefault[*PollAnswer]()
RegisterObjectDefault[*DHParamsOk]()
RegisterEnumDefault[AuthCodeType](
AuthCodeTypeSms,
AuthCodeTypeCall,
AuthCodeTypeFlashCall,
)
}
func teardown() {}
func TestMain(m *testing.M) {
tearup()
code := m.Run()
teardown()
os.Exit(code)
}
func Hexed(in string) []byte {
reader := bytes.NewReader([]byte(in))
buf := []rune{}
for {
r, ok := readByte(reader)
if !ok {
break
}
if r != 0 {
buf = append(buf, r)
}
}
return checkFunc(hex.DecodeString(string(buf)))
}
func readByte(reader *bytes.Reader) (rune, bool) {
r, ok := readAndCheck(reader)
if !ok {
return 0, false
}
switch r {
case ' ', '\n', '\t':
return 0, true
case '/':
if r, ok := readAndCheck(reader); !ok || r != '/' {
panic("expected comment")
}
skipComment(reader)
return 0, true
default:
return r, true
}
}
func skipComment(reader *bytes.Reader) {
for {
r, ok := readAndCheck(reader)
if !ok || r == '\n' {
break
}
}
}
func readAndCheck(reader *bytes.Reader) (r rune, ok bool) {
r, _, err := reader.ReadRune()
if err == io.EOF {
return 0, false
}
check(err)
return r, true
}
func checkFunc[T any](res T, err error) T {
check(err)
return res
}
func check(err error) {
if err != nil {
panic(fmt.Sprintf("%+v", err))
}
}
func noErrAsDefault(e assert.ErrorAssertionFunc) assert.ErrorAssertionFunc {
if e == nil {
return assert.NoError
}
return e
}
func ptr[T any](value T) *T { return &value }
type null = struct{}