File tree Expand file tree Collapse file tree 4 files changed +19
-19
lines changed Expand file tree Collapse file tree 4 files changed +19
-19
lines changed Original file line number Diff line number Diff line change @@ -93,7 +93,7 @@ func (w *testLoggerWriterCloser) Reset() {
93
93
func PrintCurrentTest (t testing.TB , skip ... int ) func () {
94
94
t .Helper ()
95
95
start := time .Now ()
96
- actualSkip := util .DefaultArg (skip ) + 1
96
+ actualSkip := util .OptionalArg (skip ) + 1
97
97
_ , filename , line , _ := runtime .Caller (actualSkip )
98
98
99
99
if log .CanColorStdout {
Original file line number Diff line number Diff line change @@ -230,21 +230,21 @@ func IfZero[T comparable](v, def T) T {
230
230
return v
231
231
}
232
232
233
- // DefaultArg helps the "optional argument" in Golang:
233
+ // OptionalArg helps the "optional argument" in Golang:
234
234
//
235
- // func foo(optionalArg ...int) { return DefaultArg(optionalArg ) }
236
- // calling `foo()` gets 0, calling `foo(100)` gets 100
237
- // func bar(optionalArg ...int) { return DefaultArg(optionalArg , 42) }
238
- // calling `bar()` gets 42, calling `bar(100)` gets 100
235
+ // func foo(optArg ...int) { return OptionalArg(optArg ) }
236
+ // calling `foo()` gets zero value 0, calling `foo(100)` gets 100
237
+ // func bar(optArg ...int) { return OptionalArg(optArg , 42) }
238
+ // calling `bar()` gets default value 42, calling `bar(100)` gets 100
239
239
//
240
- // Passing more than 1 item to `optionalArg ` or `def ` is undefined behavior.
241
- // At the moment it only returns the first argument .
242
- func DefaultArg [T any ](optionalArg []T , def ... T ) (ret T ) {
243
- if len (optionalArg ) >= 1 {
244
- return optionalArg [0 ]
240
+ // Passing more than 1 item to `optArg ` or `defaultValue ` is undefined behavior.
241
+ // At the moment only the first item is used .
242
+ func OptionalArg [T any ](optArg []T , defaultValue ... T ) (ret T ) {
243
+ if len (optArg ) >= 1 {
244
+ return optArg [0 ]
245
245
}
246
- if len (def ) >= 1 {
247
- return def [0 ]
246
+ if len (defaultValue ) >= 1 {
247
+ return defaultValue [0 ]
248
248
}
249
249
return ret
250
250
}
Original file line number Diff line number Diff line change @@ -242,11 +242,11 @@ func TestReserveLineBreakForTextarea(t *testing.T) {
242
242
}
243
243
244
244
func TestDefaultArg (t * testing.T ) {
245
- foo := func (other any , optionalArg ... int ) int {
246
- return DefaultArg ( optionalArg )
245
+ foo := func (other any , optArg ... int ) int {
246
+ return OptionalArg ( optArg )
247
247
}
248
- bar := func (other any , optionalArg ... int ) int {
249
- return DefaultArg ( optionalArg , 42 )
248
+ bar := func (other any , optArg ... int ) int {
249
+ return OptionalArg ( optArg , 42 )
250
250
}
251
251
assert .Equal (t , 0 , foo (nil ))
252
252
assert .Equal (t , 100 , foo (nil , 100 ))
Original file line number Diff line number Diff line change @@ -262,7 +262,7 @@ func PrepareCleanPackageData(t testing.TB) {
262
262
263
263
func PrepareTestEnv (t testing.TB , skip ... int ) func () {
264
264
t .Helper ()
265
- deferFn := PrintCurrentTest (t , util .DefaultArg (skip )+ 1 )
265
+ deferFn := PrintCurrentTest (t , util .OptionalArg (skip )+ 1 )
266
266
267
267
// load database fixtures
268
268
assert .NoError (t , unittest .LoadFixtures ())
@@ -276,7 +276,7 @@ func PrepareTestEnv(t testing.TB, skip ...int) func() {
276
276
277
277
func PrintCurrentTest (t testing.TB , skip ... int ) func () {
278
278
t .Helper ()
279
- return testlogger .PrintCurrentTest (t , util .DefaultArg (skip )+ 1 )
279
+ return testlogger .PrintCurrentTest (t , util .OptionalArg (skip )+ 1 )
280
280
}
281
281
282
282
// Printf takes a format and args and prints the string to os.Stdout
You can’t perform that action at this time.
0 commit comments