[#254] pkg/object: Rewrite unit test of MatchType enum

Avoid direct usage of naming constants where it is not necessary.

Signed-off-by: Leonard Lyubich <leonard@nspcc.ru>
This commit is contained in:
Leonard Lyubich 2021-02-01 20:54:33 +03:00 committed by Alex Vanin
parent 93e1580684
commit e9ae408c3a

View file

@ -19,15 +19,32 @@ var (
func TestMatch(t *testing.T) { func TestMatch(t *testing.T) {
t.Run("known matches", func(t *testing.T) { t.Run("known matches", func(t *testing.T) {
for i := object.MatchUnknown; i <= object.MatchStringEqual; i++ { for matchType, matchTypeV2 := range eqV2Matches {
require.Equal(t, eqV2Matches[i], i.ToV2()) require.Equal(t, matchTypeV2, matchType.ToV2())
require.Equal(t, object.SearchMatchFromV2(i.ToV2()), i) require.Equal(t, object.SearchMatchFromV2(matchTypeV2), matchType)
} }
}) })
t.Run("unknown matches", func(t *testing.T) { t.Run("unknown matches", func(t *testing.T) {
require.Equal(t, (object.MatchStringEqual + 1).ToV2(), v2object.MatchUnknown) var unknownMatchType object.SearchMatchType
require.Equal(t, object.SearchMatchFromV2(v2object.MatchStringEqual+1), object.MatchUnknown)
for matchType := range eqV2Matches {
unknownMatchType += matchType
}
unknownMatchType++
require.Equal(t, unknownMatchType.ToV2(), v2object.MatchUnknown)
var unknownMatchTypeV2 v2object.MatchType
for _, matchTypeV2 := range eqV2Matches {
unknownMatchTypeV2 += matchTypeV2
}
unknownMatchTypeV2++
require.Equal(t, object.SearchMatchFromV2(unknownMatchTypeV2), object.MatchUnknown)
}) })
} }