@@ -39,22 +39,40 @@ func Test_UncommittedChangeCount(t *testing.T) {
3939}
4040
4141func Test_CurrentBranch (t * testing.T ) {
42- cs , teardown := test .InitCmdStubber ()
43- defer teardown ()
44-
45- expected := "branch-name"
46-
47- cs .Stub (expected )
48-
49- result , err := CurrentBranch ()
50- if err != nil {
51- t .Errorf ("got unexpected error: %w" , err )
42+ type c struct {
43+ Stub string
44+ Expected string
5245 }
53- if len (cs .Calls ) != 1 {
54- t .Errorf ("expected 1 git call, saw %d" , len (cs .Calls ))
46+ cases := []c {
47+ {
48+ Stub : "branch-name\n " ,
49+ Expected : "branch-name" ,
50+ },
51+ {
52+ Stub : "refs/heads/branch-name\n " ,
53+ Expected : "branch-name" ,
54+ },
55+ {
56+ Stub : "refs/heads/branch\u00A0 with\u00A0 non\u00A0 breaking\u00A0 space\n " ,
57+ Expected : "branch\u00A0 with\u00A0 non\u00A0 breaking\u00A0 space" ,
58+ },
5559 }
56- if result != expected {
57- t .Errorf ("unexpected branch name: %s instead of %s" , result , expected )
60+
61+ for _ , v := range cases {
62+ cs , teardown := test .InitCmdStubber ()
63+ cs .Stub (v .Stub )
64+
65+ result , err := CurrentBranch ()
66+ if err != nil {
67+ t .Errorf ("got unexpected error: %w" , err )
68+ }
69+ if len (cs .Calls ) != 1 {
70+ t .Errorf ("expected 1 git call, saw %d" , len (cs .Calls ))
71+ }
72+ if result != v .Expected {
73+ t .Errorf ("unexpected branch name: %s instead of %s" , result , v .Expected )
74+ }
75+ teardown ()
5876 }
5977}
6078
0 commit comments