1
0
mirror of https://github.com/mgechev/revive.git synced 2024-11-24 08:32:22 +02:00

refactor: move lint.Name to name.go file (#1084)

This commit is contained in:
Oleksandr Redko 2024-10-28 14:22:36 +02:00 committed by GitHub
parent a213a5f7f6
commit 14babf2824
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 44 additions and 41 deletions

44
lint/name_test.go Normal file
View File

@ -0,0 +1,44 @@
package lint
import "testing"
// TestName tests Name function
func TestName(t *testing.T) { //revive:disable-line:exported
tests := []struct {
name, want string
}{
{"foo_bar", "fooBar"},
{"foo_bar_baz", "fooBarBaz"},
{"Foo_bar", "FooBar"},
{"foo_WiFi", "fooWiFi"},
{"id", "id"},
{"Id", "ID"},
{"foo_id", "fooID"},
{"fooId", "fooID"},
{"fooUid", "fooUID"},
{"idFoo", "idFoo"},
{"uidFoo", "uidFoo"},
{"midIdDle", "midIDDle"},
{"APIProxy", "APIProxy"},
{"ApiProxy", "APIProxy"},
{"apiProxy", "apiProxy"},
{"_Leading", "_Leading"},
{"___Leading", "_Leading"},
{"trailing_", "trailing"},
{"trailing___", "trailing"},
{"a_b", "aB"},
{"a__b", "aB"},
{"a___b", "aB"},
{"Rpc1150", "RPC1150"},
{"case3_1", "case3_1"},
{"case3__1", "case3_1"},
{"IEEE802_16bit", "IEEE802_16bit"},
{"IEEE802_16Bit", "IEEE802_16Bit"},
}
for _, test := range tests {
got := Name(test.name, nil, nil)
if got != test.want {
t.Errorf("Name(%q) = %q, want %q", test.name, got, test.want)
}
}
}

View File

@ -288,47 +288,6 @@ func TestLine(t *testing.T) { //revive:disable-line:exported
} }
} }
// TestLintName tests lint.Name function
func TestLintName(t *testing.T) { //revive:disable-line:exported
tests := []struct {
name, want string
}{
{"foo_bar", "fooBar"},
{"foo_bar_baz", "fooBarBaz"},
{"Foo_bar", "FooBar"},
{"foo_WiFi", "fooWiFi"},
{"id", "id"},
{"Id", "ID"},
{"foo_id", "fooID"},
{"fooId", "fooID"},
{"fooUid", "fooUID"},
{"idFoo", "idFoo"},
{"uidFoo", "uidFoo"},
{"midIdDle", "midIDDle"},
{"APIProxy", "APIProxy"},
{"ApiProxy", "APIProxy"},
{"apiProxy", "apiProxy"},
{"_Leading", "_Leading"},
{"___Leading", "_Leading"},
{"trailing_", "trailing"},
{"trailing___", "trailing"},
{"a_b", "aB"},
{"a__b", "aB"},
{"a___b", "aB"},
{"Rpc1150", "RPC1150"},
{"case3_1", "case3_1"},
{"case3__1", "case3_1"},
{"IEEE802_16bit", "IEEE802_16bit"},
{"IEEE802_16Bit", "IEEE802_16Bit"},
}
for _, test := range tests {
got := lint.Name(test.name, nil, nil)
if got != test.want {
t.Errorf("lintName(%q) = %q, want %q", test.name, got, test.want)
}
}
}
// exportedType reports whether typ is an exported type. // exportedType reports whether typ is an exported type.
// It is imprecise, and will err on the side of returning true, // It is imprecise, and will err on the side of returning true,
// such as for composite types. // such as for composite types.