aboutsummaryrefslogtreecommitdiffhomepage
path: root/cmd/git-extract-issue/main_test.go
blob: dbf88c5eb5de8440c765a4a9966403396826408a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
package main

import "testing"

func TestExtractIssueNumberFromBranchName(t *testing.T) {
	tests := []struct {
		name       string
		branchName string
		expected   string
	}{
		{"numeric only", "123", "#123"},
		{"numeric with suffix", "123-suffix", "#123"},

		{"feature prefix", "feature/123", "#123"},
		{"feature prefix with suffix", "feature/123-suffix", "#123"},

		{"project prefix", "feature/prefix-123", "prefix-123"},
		{"project prefix with suffix", "feature/prefix-123-suffix", "prefix-123"},

		{"bugfix prefix", "bugfix/123", "#123"},
		{"hotfix prefix", "hotfix/456-fix", "#456"},

		{"no number", "feature/no-number", ""},
		{"empty string", "", ""},
	}

	for _, tt := range tests {
		t.Run(tt.name, func(t *testing.T) {
			actual := extractIssueNumberFromBranchName(tt.branchName)
			if actual != tt.expected {
				t.Errorf("extractIssueNumberFromBranchName(%q) = %q, expected %q", tt.branchName, actual, tt.expected)
			}
		})
	}
}