-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
added progress message support (#42)
- Loading branch information
Showing
7 changed files
with
438 additions
and
38 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
package termite | ||
|
||
import ( | ||
"fmt" | ||
) | ||
|
||
// TruncateString returns a string that is at most maxLen long. | ||
// If s is longer than maxLen, it is trimmed to (maxLen - 2) and three dots are appended. | ||
func TruncateString(s string, maxLen int) string { | ||
if len(s) > maxLen { | ||
if maxLen > 1 { | ||
return fmt.Sprintf("%s..", s[:maxLen-2]) | ||
} | ||
return "" | ||
} | ||
return s | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
package termite | ||
|
||
import "testing" | ||
|
||
func TestTruncateString(t *testing.T) { | ||
type args struct { | ||
s string | ||
maxLen int | ||
} | ||
tests := []struct { | ||
name string | ||
args args | ||
want string | ||
}{ | ||
{name: "below threshold", args: args{s: "hello world!", maxLen: 20}, want: "hello world!"}, | ||
{name: "above threshold", args: args{s: "hello world!", maxLen: 6}, want: "hell.."}, | ||
{name: "zero length", args: args{s: "hello", maxLen: 0}, want: ""}, | ||
} | ||
for _, tt := range tests { | ||
t.Run(tt.name, func(t *testing.T) { | ||
if got := TruncateString(tt.args.s, tt.args.maxLen); got != tt.want { | ||
t.Errorf("TruncateString() = %v, want %v", got, tt.want) | ||
} | ||
}) | ||
} | ||
} |