|
| 1 | +package git |
| 2 | + |
| 3 | +import ( |
| 4 | + "testing" |
| 5 | + |
| 6 | + "github.com/mritd/gitflow-toolkit/v3/consts" |
| 7 | +) |
| 8 | + |
| 9 | +func TestParseBranchType(t *testing.T) { |
| 10 | + tests := []struct { |
| 11 | + name string |
| 12 | + branch string |
| 13 | + expected string |
| 14 | + }{ |
| 15 | + // Standard formats with / |
| 16 | + {"feat with slash", "feat/login", consts.Feat}, |
| 17 | + {"fix with slash", "fix/bug-123", consts.Fix}, |
| 18 | + {"docs with slash", "docs/readme", consts.Docs}, |
| 19 | + {"style with slash", "style/format", consts.Style}, |
| 20 | + {"refactor with slash", "refactor/cleanup", consts.Refactor}, |
| 21 | + {"test with slash", "test/unit", consts.Test}, |
| 22 | + {"chore with slash", "chore/deps", consts.Chore}, |
| 23 | + {"perf with slash", "perf/optimize", consts.Perf}, |
| 24 | + {"hotfix with slash", "hotfix/urgent", consts.Hotfix}, |
| 25 | + |
| 26 | + // Aliases with / |
| 27 | + {"feature alias", "feature/login", consts.Feat}, |
| 28 | + {"bugfix alias", "bugfix/issue-42", consts.Fix}, |
| 29 | + {"bug alias", "bug/crash", consts.Fix}, |
| 30 | + {"doc alias", "doc/api", consts.Docs}, |
| 31 | + {"document alias", "document/guide", consts.Docs}, |
| 32 | + {"refact alias", "refact/module", consts.Refactor}, |
| 33 | + {"testing alias", "testing/e2e", consts.Test}, |
| 34 | + {"performance alias", "performance/cache", consts.Perf}, |
| 35 | + |
| 36 | + // Formats with - |
| 37 | + {"feat with dash", "feat-login", consts.Feat}, |
| 38 | + {"fix with dash", "fix-bug-123", consts.Fix}, |
| 39 | + {"feature with dash", "feature-new-ui", consts.Feat}, |
| 40 | + {"bugfix with dash", "bugfix-issue", consts.Fix}, |
| 41 | + |
| 42 | + // Formats with _ |
| 43 | + {"feat with underscore", "feat_login", consts.Feat}, |
| 44 | + {"fix with underscore", "fix_bug_123", consts.Fix}, |
| 45 | + |
| 46 | + // Case insensitivity |
| 47 | + {"uppercase FEAT", "FEAT/login", consts.Feat}, |
| 48 | + {"mixed case Feature", "Feature/login", consts.Feat}, |
| 49 | + |
| 50 | + // Non-matching branches |
| 51 | + {"main branch", "main", ""}, |
| 52 | + {"master branch", "master", ""}, |
| 53 | + {"develop branch", "develop", ""}, |
| 54 | + {"release branch", "release/v1.0", ""}, |
| 55 | + {"random branch", "random-branch", ""}, |
| 56 | + {"empty string", "", ""}, |
| 57 | + } |
| 58 | + |
| 59 | + for _, tt := range tests { |
| 60 | + t.Run(tt.name, func(t *testing.T) { |
| 61 | + result := ParseBranchType(tt.branch) |
| 62 | + if result != tt.expected { |
| 63 | + t.Errorf("ParseBranchType(%q) = %q, want %q", tt.branch, result, tt.expected) |
| 64 | + } |
| 65 | + }) |
| 66 | + } |
| 67 | +} |
0 commit comments