Skip to content

Commit 21009e2

Browse files
committed
gentypes: option to force generate optional types
* move internal test types of gentypes to internal subpackage Closes #TNTP-3734.
1 parent 93a7028 commit 21009e2

File tree

9 files changed

+314
-40
lines changed

9 files changed

+314
-40
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ Flags:
7070
`-ext-code`: MessagePack extension code to use for custom types (must be between
7171
-128 and 127, no default value)
7272
`-verbose`: Enable verbose output (default: `false`)
73+
`-force`: Ignore absence of marshal/unmarshal methods on type (default: `false`)
7374

7475
#### Using Generated Types
7576

cmd/gentypes/generate.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
1-
//go:generate go run github.com/tarantool/go-option/cmd/gentypes -ext-code 1 -package test FullMsgpackExtType
1+
//go:generate go run github.com/tarantool/go-option/cmd/gentypes -ext-code 1 -package internal/test FullMsgpackExtType
2+
//go:generate go run github.com/tarantool/go-option/cmd/gentypes -ext-code 2 -force -package internal/test HiddenTypeAlias
23
package main

cmd/gentypes/test/fullmsgpackexttype_test.go renamed to cmd/gentypes/internal/test/fullmsgpackexttype_test.go

Lines changed: 36 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -8,26 +8,26 @@ import (
88
"github.com/stretchr/testify/require"
99
"github.com/vmihailenco/msgpack/v5"
1010

11-
td "github.com/tarantool/go-option/cmd/gentypes/test"
11+
"github.com/tarantool/go-option/cmd/gentypes/internal/test"
1212
)
1313

1414
func TestOptionalMsgpackExtType_RoundtripLL(t *testing.T) {
1515
t.Parallel()
1616

17-
input := td.FullMsgpackExtType{
17+
input := test.FullMsgpackExtType{
1818
A: 412,
1919
B: "bababa",
2020
}
2121

22-
opt := td.SomeOptionalFullMsgpackExtType(input)
22+
opt := test.SomeOptionalFullMsgpackExtType(input)
2323

2424
b := bytes.Buffer{}
2525
enc := msgpack.NewEncoder(&b)
2626
dec := msgpack.NewDecoder(&b)
2727

2828
require.NoError(t, opt.EncodeMsgpack(enc))
2929

30-
opt2 := td.NoneOptionalFullMsgpackExtType()
30+
opt2 := test.NoneOptionalFullMsgpackExtType()
3131
require.NoError(t, opt2.DecodeMsgpack(dec))
3232

3333
assert.Equal(t, opt, opt2)
@@ -37,20 +37,20 @@ func TestOptionalMsgpackExtType_RoundtripLL(t *testing.T) {
3737
func TestOptionalMsgpackExtType_RoundtripHL(t *testing.T) {
3838
t.Parallel()
3939

40-
input := td.FullMsgpackExtType{
40+
input := test.FullMsgpackExtType{
4141
A: 412,
4242
B: "bababa",
4343
}
4444

45-
opt := td.SomeOptionalFullMsgpackExtType(input)
45+
opt := test.SomeOptionalFullMsgpackExtType(input)
4646

4747
b := bytes.Buffer{}
4848
enc := msgpack.NewEncoder(&b)
4949
dec := msgpack.NewDecoder(&b)
5050

5151
require.NoError(t, enc.Encode(opt))
5252

53-
opt2 := td.NoneOptionalFullMsgpackExtType()
53+
opt2 := test.NoneOptionalFullMsgpackExtType()
5454
require.NoError(t, dec.Decode(&opt2))
5555

5656
assert.Equal(t, opt, opt2)
@@ -63,20 +63,20 @@ func TestOptionalFullMsgpackExtType_IsSome(t *testing.T) {
6363
t.Run("some", func(t *testing.T) {
6464
t.Parallel()
6565

66-
input := td.FullMsgpackExtType{
66+
input := test.FullMsgpackExtType{
6767
A: 412,
6868
B: "bababa",
6969
}
7070

71-
opt := td.SomeOptionalFullMsgpackExtType(input)
71+
opt := test.SomeOptionalFullMsgpackExtType(input)
7272

7373
assert.True(t, opt.IsSome())
7474
})
7575

7676
t.Run("none", func(t *testing.T) {
7777
t.Parallel()
7878

79-
opt := td.NoneOptionalFullMsgpackExtType()
79+
opt := test.NoneOptionalFullMsgpackExtType()
8080

8181
assert.False(t, opt.IsSome())
8282
})
@@ -88,20 +88,20 @@ func TestOptionalFullMsgpackExtType_IsZero(t *testing.T) {
8888
t.Run("some", func(t *testing.T) {
8989
t.Parallel()
9090

91-
input := td.FullMsgpackExtType{
91+
input := test.FullMsgpackExtType{
9292
A: 412,
9393
B: "bababa",
9494
}
9595

96-
opt := td.SomeOptionalFullMsgpackExtType(input)
96+
opt := test.SomeOptionalFullMsgpackExtType(input)
9797

9898
assert.False(t, opt.IsZero())
9999
})
100100

101101
t.Run("none", func(t *testing.T) {
102102
t.Parallel()
103103

104-
opt := td.NoneOptionalFullMsgpackExtType()
104+
opt := test.NoneOptionalFullMsgpackExtType()
105105

106106
assert.True(t, opt.IsZero())
107107
})
@@ -113,12 +113,12 @@ func TestOptionalFullMsgpackExtType_Get(t *testing.T) {
113113
t.Run("some", func(t *testing.T) {
114114
t.Parallel()
115115

116-
input := td.FullMsgpackExtType{
116+
input := test.FullMsgpackExtType{
117117
A: 412,
118118
B: "bababa",
119119
}
120120

121-
opt := td.SomeOptionalFullMsgpackExtType(input)
121+
opt := test.SomeOptionalFullMsgpackExtType(input)
122122

123123
val, ok := opt.Get()
124124
require.True(t, ok)
@@ -128,10 +128,10 @@ func TestOptionalFullMsgpackExtType_Get(t *testing.T) {
128128
t.Run("none", func(t *testing.T) {
129129
t.Parallel()
130130

131-
opt := td.NoneOptionalFullMsgpackExtType()
131+
opt := test.NoneOptionalFullMsgpackExtType()
132132
val, ok := opt.Get()
133133
require.False(t, ok)
134-
assert.Equal(t, td.NewEmptyFullMsgpackExtType(), val)
134+
assert.Equal(t, test.NewEmptyFullMsgpackExtType(), val)
135135
})
136136
}
137137

@@ -141,14 +141,14 @@ func TestOptionalFullMsgpackExtType_MustGet(t *testing.T) {
141141
t.Run("some", func(t *testing.T) {
142142
t.Parallel()
143143

144-
input := td.FullMsgpackExtType{
144+
input := test.FullMsgpackExtType{
145145
A: 412,
146146
B: "bababa",
147147
}
148148

149-
opt := td.SomeOptionalFullMsgpackExtType(input)
149+
opt := test.SomeOptionalFullMsgpackExtType(input)
150150

151-
var val td.FullMsgpackExtType
151+
var val test.FullMsgpackExtType
152152

153153
require.NotPanics(t, func() {
154154
val = opt.MustGet()
@@ -159,7 +159,7 @@ func TestOptionalFullMsgpackExtType_MustGet(t *testing.T) {
159159
t.Run("none", func(t *testing.T) {
160160
t.Parallel()
161161

162-
opt := td.NoneOptionalFullMsgpackExtType()
162+
opt := test.NoneOptionalFullMsgpackExtType()
163163

164164
require.Panics(t, func() { opt.MustGet() })
165165
})
@@ -171,21 +171,21 @@ func TestOptionalFullMsgpackExtType_Unwrap(t *testing.T) {
171171
t.Run("some", func(t *testing.T) {
172172
t.Parallel()
173173

174-
input := td.FullMsgpackExtType{
174+
input := test.FullMsgpackExtType{
175175
A: 412,
176176
B: "bababa",
177177
}
178178

179-
opt := td.SomeOptionalFullMsgpackExtType(input)
179+
opt := test.SomeOptionalFullMsgpackExtType(input)
180180

181181
assert.Equal(t, input, opt.Unwrap())
182182
})
183183

184184
t.Run("none", func(t *testing.T) {
185185
t.Parallel()
186186

187-
opt := td.NoneOptionalFullMsgpackExtType()
188-
assert.Equal(t, td.NewEmptyFullMsgpackExtType(), opt.Unwrap())
187+
opt := test.NoneOptionalFullMsgpackExtType()
188+
assert.Equal(t, test.NewEmptyFullMsgpackExtType(), opt.Unwrap())
189189
})
190190
}
191191

@@ -195,25 +195,25 @@ func TestOptionalFullMsgpackExtType_UnwrapOr(t *testing.T) {
195195
t.Run("some", func(t *testing.T) {
196196
t.Parallel()
197197

198-
input := td.FullMsgpackExtType{
198+
input := test.FullMsgpackExtType{
199199
A: 412,
200200
B: "bababa",
201201
}
202202

203-
opt := td.SomeOptionalFullMsgpackExtType(input)
203+
opt := test.SomeOptionalFullMsgpackExtType(input)
204204

205-
assert.Equal(t, input, opt.UnwrapOr(td.NewEmptyFullMsgpackExtType()))
205+
assert.Equal(t, input, opt.UnwrapOr(test.NewEmptyFullMsgpackExtType()))
206206
})
207207

208208
t.Run("none", func(t *testing.T) {
209209
t.Parallel()
210210

211-
alt := td.FullMsgpackExtType{
211+
alt := test.FullMsgpackExtType{
212212
A: 1,
213213
B: "b",
214214
}
215215

216-
opt := td.NoneOptionalFullMsgpackExtType()
216+
opt := test.NoneOptionalFullMsgpackExtType()
217217
assert.Equal(t, alt, opt.UnwrapOr(alt))
218218
})
219219
}
@@ -224,27 +224,27 @@ func TestOptionalFullMsgpackExtType_UnwrapOrElse(t *testing.T) {
224224
t.Run("some", func(t *testing.T) {
225225
t.Parallel()
226226

227-
input := td.FullMsgpackExtType{
227+
input := test.FullMsgpackExtType{
228228
A: 412,
229229
B: "bababa",
230230
}
231231

232-
opt := td.SomeOptionalFullMsgpackExtType(input)
232+
opt := test.SomeOptionalFullMsgpackExtType(input)
233233

234-
assert.Equal(t, input, opt.UnwrapOrElse(td.NewEmptyFullMsgpackExtType))
234+
assert.Equal(t, input, opt.UnwrapOrElse(test.NewEmptyFullMsgpackExtType))
235235
})
236236

237237
t.Run("none", func(t *testing.T) {
238238
t.Parallel()
239239

240-
alt := td.FullMsgpackExtType{
240+
alt := test.FullMsgpackExtType{
241241
A: 1,
242242
B: "b",
243243
}
244244

245-
opt := td.NoneOptionalFullMsgpackExtType()
245+
opt := test.NoneOptionalFullMsgpackExtType()
246246

247-
assert.Equal(t, alt, opt.UnwrapOrElse(func() td.FullMsgpackExtType {
247+
assert.Equal(t, alt, opt.UnwrapOrElse(func() test.FullMsgpackExtType {
248248
return alt
249249
}))
250250
})
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
package test
2+
3+
import (
4+
"github.com/tarantool/go-option/cmd/gentypes/internal/test/subpackage"
5+
)
6+
7+
// HiddenTypeAlias is a hidden type alias to test.
8+
type HiddenTypeAlias = subpackage.Hidden

0 commit comments

Comments
 (0)