Codebase list golang-github-gosuri-uitable / 7645362
strutil: return empty string for empty items in string join (#17) Signed-off-by: Greg Osuri <me@gregosuri.com> Greg Osuri authored 4 years ago GitHub committed 4 years ago
2 changed file(s) with 12 addition(s) and 1 deletion(s). Raw diff Collapse all Expand all
7070 return s
7171 }
7272
73 // Join joins the list of the string with the delim provided
73 // Join joins the list of the string with the delim provided.
74 // Returns an empty string for empty list
7475 func Join(list []string, delim string) string {
76 if len(list) == 0 {
77 return ""
78 }
7579 var buf bytes.Buffer
7680 for i := 0; i < len(list)-1; i++ {
7781 buf.WriteString(list[i] + delim)
3636 }
3737 }
3838
39 func TestJoin_blank(t *testing.T) {
40 got := Join([]string{}, ",")
41 if got != "" {
42 t.Fatal("want", "", "got", got)
43 }
44 }
45
3946 func TestPadRight(t *testing.T) {
4047 got := PadRight("foo", 5, '-')
4148 if got != "foo--" {