77
88func TestGenerateName (t * testing.T ) {
99 type args struct {
10- num int
10+ id string
1111 title string
1212 }
1313 for _ , tt := range []struct {
@@ -18,27 +18,45 @@ func TestGenerateName(t *testing.T) {
1818 want string
1919 }{
2020 {
21- name : "negative index " ,
21+ name : "id empty " ,
2222 args : args {
23- num : - 1 ,
23+ id : "" ,
2424 title : "a-title" ,
2525 },
2626 want : "" ,
2727 wantErr : true ,
2828 },
2929 {
30- name : "zero index " ,
30+ name : "id blank " ,
3131 args : args {
32- num : 0 ,
32+ id : " " ,
3333 title : "a-title" ,
3434 },
3535 want : "" ,
3636 wantErr : true ,
3737 },
38+ {
39+ name : "id starting with an hyphen -" ,
40+ args : args {
41+ id : "-1" ,
42+ title : "a-title" ,
43+ },
44+ want : "1-a-title" ,
45+ wantErr : false ,
46+ },
47+ {
48+ name : "any other id" ,
49+ args : args {
50+ id : "myId" ,
51+ title : "a-title" ,
52+ },
53+ want : "myid-a-title" ,
54+ wantErr : false ,
55+ },
3856 {
3957 name : "empty title" ,
4058 args : args {
41- num : 33 ,
59+ id : "33" ,
4260 title : "" ,
4361 },
4462 want : "" ,
@@ -47,7 +65,7 @@ func TestGenerateName(t *testing.T) {
4765 {
4866 name : "blank title" ,
4967 args : args {
50- num : 33 ,
68+ id : "33" ,
5169 title : " " ,
5270 },
5371 want : "" ,
@@ -56,7 +74,7 @@ func TestGenerateName(t *testing.T) {
5674 {
5775 name : "dot title" ,
5876 args : args {
59- num : 33 ,
77+ id : "33" ,
6078 title : "." ,
6179 },
6280 want : "" ,
@@ -65,7 +83,7 @@ func TestGenerateName(t *testing.T) {
6583 {
6684 name : "branch name should not end with replacement if title already ends with it" ,
6785 args : args {
68- num : 1 ,
86+ id : "1" ,
6987 title : "-" ,
7088 },
7189 want : "1" ,
@@ -74,7 +92,7 @@ func TestGenerateName(t *testing.T) {
7492 {
7593 name : "branch name should not end with replacement if title already ends with it" ,
7694 args : args {
77- num : 1 ,
95+ id : "1" ,
7896 title : "something-ending-with-hyphen-" ,
7997 },
8098 want : "1-something-ending-with-hyphen" ,
@@ -83,7 +101,7 @@ func TestGenerateName(t *testing.T) {
83101 {
84102 name : "branch name should not have non-alphanumeric character" ,
85103 args : args {
86- num : 777 ,
104+ id : " 777" ,
87105 title : "[Feature request] an awesome feature for `tool`" ,
88106 },
89107 want : "777-feature-request-an-awesome-feature-for-tool" ,
@@ -92,7 +110,7 @@ func TestGenerateName(t *testing.T) {
92110 {
93111 name : "ending dot should be ignored" ,
94112 args : args {
95- num : 1234 ,
113+ id : " 1234" ,
96114 title : "Bug when running something." ,
97115 },
98116 want : "1234-bug-when-running-something" ,
@@ -101,15 +119,15 @@ func TestGenerateName(t *testing.T) {
101119 {
102120 name : "branch name should be all lowercase" ,
103121 args : args {
104- num : 2345 ,
122+ id : " 2345" ,
105123 title : "THIS IS AN IMPROVEMENT SUGGESTION :-) !!!" ,
106124 },
107125 want : "2345-this-is-an-improvement-suggestion" ,
108126 wantErr : false ,
109127 },
110128 } {
111129 t .Run (tt .name , func (t * testing.T ) {
112- got , err := GenerateName (tt .num , tt .title )
130+ got , err := GenerateName (tt .id , tt .title )
113131 if (err != nil ) != tt .wantErr {
114132 t .Errorf ("got err: %v, but wanted err set to %v" , err , tt .wantErr )
115133 }
0 commit comments