2023-04-30 11:43:26 +08:00
|
|
|
// Copyright 2023 The Gitea Authors. All rights reserved.
|
2023-09-08 09:40:02 +08:00
|
|
|
// SPDX-License-Identifier: MIT
|
2023-04-30 11:43:26 +08:00
|
|
|
|
|
|
|
package utils
|
|
|
|
|
|
|
|
import "testing"
|
|
|
|
|
|
|
|
func TestArgToIndex(t *testing.T) {
|
|
|
|
tests := []struct {
|
|
|
|
name string
|
|
|
|
arg string
|
|
|
|
want int64
|
|
|
|
wantErr bool
|
|
|
|
}{
|
|
|
|
{
|
|
|
|
name: "Valid argument",
|
|
|
|
arg: "#123",
|
|
|
|
want: 123,
|
|
|
|
wantErr: false,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "Invalid argument",
|
|
|
|
arg: "abc",
|
|
|
|
want: 0,
|
|
|
|
wantErr: true,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "Empty argument",
|
|
|
|
arg: "",
|
|
|
|
want: 0,
|
|
|
|
wantErr: true,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, tt := range tests {
|
|
|
|
t.Run(tt.name, func(t *testing.T) {
|
|
|
|
got, err := ArgToIndex(tt.arg)
|
|
|
|
if (err != nil) != tt.wantErr {
|
|
|
|
t.Errorf("ArgToIndex() error = %v, wantErr %v", err, tt.wantErr)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
if got != tt.want {
|
|
|
|
t.Errorf("ArgToIndex() = %v, want %v", got, tt.want)
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|