reprogl
1package utils2
3import (4"strconv"5"testing"6)
7
8func TestEllipticalTruncate(t *testing.T) {9tests := []struct {10text string11want string12maxLen int13}{14{15text: "a",16want: "a",17maxLen: 3,18},19{20text: "123",21want: "123",22maxLen: 3,23},24{25text: "1 2 3 4 5 6",26want: "1 2 ...",27maxLen: 7,28},29{30text: "Привет, безумный мир",31want: "Привет, безум...",32maxLen: 16,33},34}35
36for idx, item := range tests {37t.Run(strconv.Itoa(idx), func(t *testing.T) {38res := EllipticalTruncate(item.text, item.maxLen)39
40if res != item.want {41t.Errorf("%s : got %s; want %s", item.text, res, item.want)42}43})44}45}
46