2021-04-18 12:35:30 -04:00
|
|
|
package test
|
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
"github.com/mgechev/revive/lint"
|
|
|
|
"github.com/mgechev/revive/rule"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestStringFormat(t *testing.T) {
|
2024-11-11 13:39:10 +02:00
|
|
|
testRule(t, "string_format", &rule.StringFormatRule{}, &lint.RuleConfig{
|
2021-04-18 12:35:30 -04:00
|
|
|
Arguments: lint.Arguments{
|
2023-09-24 08:44:02 +02:00
|
|
|
[]any{
|
2021-04-18 12:35:30 -04:00
|
|
|
"stringFormatMethod1", // The first argument is checked by default
|
|
|
|
"/^[A-Z]/",
|
|
|
|
"must start with a capital letter"},
|
|
|
|
|
2023-09-24 08:44:02 +02:00
|
|
|
[]any{
|
2021-04-18 12:35:30 -04:00
|
|
|
"stringFormatMethod2[2].d",
|
|
|
|
"/[^\\.]$/"}, // Must not end with a period
|
2023-09-24 08:44:02 +02:00
|
|
|
[]any{
|
2021-04-18 12:35:30 -04:00
|
|
|
"s.Method3[2]",
|
2022-10-24 20:48:41 +02:00
|
|
|
"!/^[Tt][Hh]/",
|
2023-07-29 06:27:07 -03:00
|
|
|
"must not start with 'th'"},
|
2023-09-24 08:44:02 +02:00
|
|
|
[]any{
|
2023-07-29 06:27:07 -03:00
|
|
|
"s.Method4", // same as before, but called from a struct
|
|
|
|
"!/^[Ot][Tt]/",
|
|
|
|
"must not start with 'ot'"}}})
|
2021-04-18 12:35:30 -04:00
|
|
|
}
|
|
|
|
|
2024-11-04 09:19:29 -03:00
|
|
|
func TestStringFormatDuplicatedStrings(t *testing.T) {
|
2024-11-11 13:39:10 +02:00
|
|
|
testRule(t, "string_format_issue_1063", &rule.StringFormatRule{}, &lint.RuleConfig{
|
2024-11-04 09:19:29 -03:00
|
|
|
Arguments: lint.Arguments{[]any{
|
|
|
|
"fmt.Errorf[0],errors.New[0]",
|
|
|
|
"/^([^A-Z]|$)/",
|
|
|
|
"must not start with a capital letter",
|
|
|
|
}},
|
|
|
|
})
|
|
|
|
}
|