1
This repository has been archived on 2025-08-19. You can view files and clone it, but cannot push or open issues or pull requests.
Files
go-commitlint/internal/commitlint/validator/validator_test.go
Voomra af99bebf91 add: import code
портирован код из старого репозитория https://di9.ru/git/Voomra/Conventional-Commits
2025-07-30 18:44:50 +03:00

84 lines
1.7 KiB
Go

package validator
import (
"commitlint/internal/commitlint/configuration"
"github.com/stretchr/testify/assert"
"regexp"
"testing"
)
func TestValidateFirstLine(t *testing.T) {
pConfig, err := configuration.CreateConfig(nil)
if err != nil {
panic(err)
}
pConfig.Contexts = append(pConfig.Contexts, "git")
pConfig.Excludes = append(pConfig.Excludes, regexp.MustCompile("(?i)^wip$"))
testTab := []struct {
line string
excepted *ValidateError
}{
{
line: "incorrect line",
excepted: &ValidateError{Result: IncorrectPattern, Line: 1},
},
{
line: "zed: message",
excepted: &ValidateError{Result: UnknownType, Line: 1, UnknownType: "zed"},
},
{
line: "fix(zed): message",
excepted: &ValidateError{Result: UnknownContext, Line: 1, UnknownContext: "zed"},
},
{
line: "fix: message",
excepted: nil,
},
{
line: "fix(git): message",
excepted: nil,
},
{
line: "WIP",
excepted: nil,
},
}
for _, test := range testTab {
pResult := validateFirstLine(test.line, *pConfig)
assert.Equal(t, test.excepted, pResult)
}
}
func TestValidateBody(t *testing.T) {
pConfig, err := configuration.CreateConfig(nil)
if err != nil {
panic(err)
}
pConfig.MaxLengthLine = 10
testTab := []struct {
lines []string
excepted *ValidateError
}{
{
lines: []string{" ", "Some Body"},
excepted: &ValidateError{Result: BlankLine, Line: 2},
},
{
lines: []string{"", "Some Body 1234567890"},
excepted: &ValidateError{Result: OverlongLine, Line: 3},
},
{
lines: []string{"", "Some Body"},
excepted: nil,
},
}
for _, test := range testTab {
pResult := validateBody(test.lines, *pConfig)
assert.Equal(t, test.excepted, pResult)
}
}