0
0
mirror of https://github.com/thegeeklab/git-sv.git synced 2024-11-24 21:20:40 +00:00

test: add carriage return tests on parse

issue: #85
This commit is contained in:
Beatriz Vieira 2023-01-21 22:03:10 -03:00
parent 4a15a659d9
commit 12a52d9ecf

View File

@ -378,6 +378,9 @@ var completeBody = `some descriptions
jira: JIRA-123
BREAKING CHANGE: this change breaks everything`
var bodyWithCarriage = "some description\r\nmore description\r\n\r\njira: JIRA-123\r"
var expectedBodyWithCarriage = "some description\nmore description\n\njira: JIRA-123"
var issueOnlyBody = `some descriptions
jira: JIRA-456`
@ -408,11 +411,12 @@ func TestMessageProcessorImpl_Parse(t *testing.T) {
{"breaking change with exclamation mark", ccfg, "feat!: something new", "", CommitMessage{Type: "feat", Scope: "", Description: "something new", Body: "", IsBreakingChange: true, Metadata: map[string]string{}}},
{"hash metadata", ccfg, "feat: something new", hashMetadataBody, CommitMessage{Type: "feat", Scope: "", Description: "something new", Body: hashMetadataBody, IsBreakingChange: false, Metadata: map[string]string{issueMetadataKey: "JIRA-999", "refs": "#123"}}},
{"empty issue cfg", ccfgEmptyIssue, "feat: something new", hashMetadataBody, CommitMessage{Type: "feat", Scope: "", Description: "something new", Body: hashMetadataBody, IsBreakingChange: false, Metadata: map[string]string{}}},
{"carriage return on body", ccfg, "feat: something new", bodyWithCarriage, CommitMessage{Type: "feat", Scope: "", Description: "something new", Body: expectedBodyWithCarriage, IsBreakingChange: false, Metadata: map[string]string{issueMetadataKey: "JIRA-123"}}},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if got, err := NewMessageProcessor(tt.cfg, newBranchCfg(false)).Parse(tt.subject, tt.body); !reflect.DeepEqual(got, tt.want) && err == nil {
t.Errorf("MessageProcessorImpl.Parse() = %v, want %v", got, tt.want)
t.Errorf("MessageProcessorImpl.Parse() = [%+v], want [%+v]", got, tt.want)
}
})
}
@ -551,3 +555,22 @@ func Test_prepareHeader(t *testing.T) {
})
}
}
func Test_removeCarriage(t *testing.T) {
tests := []struct {
name string
commit string
want string
}{
{"normal string", "normal string", "normal string"},
{"break line", "normal\nstring", "normal\nstring"},
{"carriage return", "normal\r\nstring", "normal\nstring"},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if got := removeCarriage(tt.commit); got != tt.want {
t.Errorf("removeCarriage() = %v, want %v", got, tt.want)
}
})
}
}