-
Notifications
You must be signed in to change notification settings - Fork 1
/
main_test.go
170 lines (121 loc) · 3.17 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
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
package gg_test
import (
"strconv"
"github.com/mitranim/gg"
)
func init() { gg.TraceBaseDir = gg.Cwd() }
var void struct{}
// Adapted from `reflect.ValueOf`.
func esc(val any) any {
if trap.false {
trap.val = val
}
return val
}
var trap struct {
false bool
val any
}
type IntSet = gg.Set[int]
type IntMap = map[int]int
type SomeKey int64
type SomeModel struct {
Id SomeKey `json:"id"`
Name string `json:"name"`
}
func (self SomeModel) Pk() SomeKey { return self.Id }
type StructDirect struct {
Public0 int
Public1 string
private *string
}
//nolint:unused
type StructIndirect struct {
Public0 int
Public1 *string
private *string
}
type Outer struct {
OuterId int
OuterName string
Embed
Inner *Inner
}
type Embed struct {
EmbedId int
EmbedName string
}
type Inner struct {
InnerId *int
InnerName *string
}
type SomeJsonDbMapper struct {
SomeName string `json:"someName" db:"some_name"`
SomeValue string `json:"someValue" db:"some_value"`
SomeJson string `json:"someJson"`
SomeDb string `db:"some_db"`
}
type SomeColl = gg.Coll[SomeKey, SomeModel]
type SomeLazyColl = gg.LazyColl[SomeKey, SomeModel]
type IsZeroAlwaysTrue string
func (IsZeroAlwaysTrue) IsZero() bool { return true }
type IsZeroAlwaysFalse string
func (IsZeroAlwaysFalse) IsZero() bool { return false }
type FatStruct struct {
_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, Id int
_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, Name string
}
type FatStructNonComparable struct {
FatStruct
_ []byte
}
func ComparerOf[A gg.LesserPrim](val A) Comparer[A] { return Comparer[A]{val} }
type Comparer[A gg.LesserPrim] [1]A
func (self Comparer[A]) Less(val Comparer[A]) bool { return self[0] < val[0] }
func (self Comparer[A]) Get() A { return self[0] }
func ToPair[A gg.Num](val A) (A, A) { return val - 1, val + 1 }
func True1[A any](A) bool { return true }
func False1[A any](A) bool { return false }
func Id1True[A any](val A) (A, bool) { return val, true }
func Id1False[A any](val A) (A, bool) { return val, false }
type ParserStr string
func (self *ParserStr) Parse(val string) error {
*self = ParserStr(val)
return nil
}
type UnmarshalerBytes []byte
func (self *UnmarshalerBytes) UnmarshalText(val []byte) error {
*self = val
return nil
}
// Implements `error` on the pointer type, not on the value type.
type PtrErrStr string
func (self *PtrErrStr) Error() string { return gg.PtrGet((*string)(self)) }
type StrsParser []string
func (self *StrsParser) Parse(src string) error {
gg.Append(self, src)
return nil
}
type IntsValue []int
func (self *IntsValue) Set(src string) error {
return gg.ParseCatch(src, gg.AppendPtrZero(self))
}
/*
Defined as a struct to verify that the flag parser supports slices of arbitrary
types implementing `flag.Value`, even if they're not typedefs of text types,
and not something normally compatible with `gg.Parse`.
*/
type IntValue struct{ Val int }
func (self *IntValue) Set(src string) error {
return gg.ParseCatch(src, &self.Val)
}
func intStrPair(src int) []string {
return []string{strconv.Itoa(src - 1), strconv.Itoa(src + 1)}
}
func intPair(src int) []int {
return []int{src - 1, src + 1}
}
type Cyclic struct {
Id int
Cyclic *Cyclic
}