Skip to content

Commit ed63ad9

Browse files
committed
chore(cmd): use vars and add util tests
1 parent ae9e2ac commit ed63ad9

File tree

2 files changed

+32
-1
lines changed

2 files changed

+32
-1
lines changed

cmd/lk/app.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,7 @@ func listTemplates(ctx context.Context, cmd *cli.Command) error {
196196
for _, t := range templates {
197197
table.Row(
198198
t.Name,
199-
strings.Join(wrapToLines(t.Desc, 40), "\n"),
199+
strings.Join(wrapToLines(t.Desc, maxDescLength), "\n"),
200200
strings.Join(t.Tags, ", "),
201201
)
202202
}

cmd/lk/utils_test.go

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,3 +56,34 @@ func TestMapStrings(t *testing.T) {
5656
t.Error("mapStrings should apply the function to all elements")
5757
}
5858
}
59+
60+
func TestEllipziseTo(t *testing.T) {
61+
str := "This is some long string that should be ellipsized"
62+
ellipsized := ellipsizeTo(str, 12)
63+
if len(ellipsized) != 12 {
64+
t.Error("ellipsizeTo should return a string of the specified length")
65+
}
66+
if ellipsized != "This is s..." {
67+
t.Error("ellipsizeTo should ellipsize the string")
68+
}
69+
}
70+
71+
func TestWrapToLines(t *testing.T) {
72+
str := "This is a long string that should be wrapped to multiple lines"
73+
wrapped := wrapToLines(str, 10)
74+
if len(wrapped) != 8 {
75+
t.Error("wrapToLines should return a slice of lines")
76+
}
77+
if !slices.Equal([]string{
78+
"This is a",
79+
"long",
80+
"string",
81+
"that",
82+
"should be",
83+
"wrapped to",
84+
"multiple",
85+
"lines",
86+
}, wrapped) {
87+
t.Error("wrapToLines should wrap the string to the specified width")
88+
}
89+
}

0 commit comments

Comments
 (0)