2021-03-30 19:37:02 -04:00
|
|
|
package editor
|
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestTruncateString(t *testing.T) {
|
|
|
|
firstString := "abcdefghijklmnopqrstuvwxyz"
|
2021-04-01 16:17:13 -04:00
|
|
|
truncated := truncate(firstString, 13)
|
2021-03-30 19:37:02 -04:00
|
|
|
|
|
|
|
got := len(truncated)
|
|
|
|
want := 13
|
|
|
|
|
|
|
|
if got != want {
|
|
|
|
t.Errorf("Truncated length: %q, expected length: %q", got, want)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestTruncateStringNegative(t *testing.T) {
|
2021-04-01 16:17:13 -04:00
|
|
|
got := truncate("fdlkjf", -5)
|
2021-03-30 19:37:02 -04:00
|
|
|
want := ""
|
|
|
|
|
|
|
|
if got != want {
|
|
|
|
t.Errorf("Truncated value: %q, expected value: %q", got, want)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestTruncateShorterString(t *testing.T) {
|
|
|
|
str := "abcdefg"
|
|
|
|
|
2021-04-01 16:17:13 -04:00
|
|
|
got := truncate(str, 13)
|
2021-03-30 19:37:02 -04:00
|
|
|
want := str
|
|
|
|
|
|
|
|
if got != want {
|
|
|
|
t.Errorf("Truncated value: %q, expected value: %q", got, want)
|
|
|
|
}
|
|
|
|
}
|