encoding/japanese, language: shorten very long sub-test names

Some of the generated sub-test names end up being excessively long,
which doesn't mix well with them being stored as test IDs that track
test runs over time. Replacing test case names with numbers harms
their readability, so start by trimming a few that end up being 500+
bytes in length.

Change-Id: Id3b22105efc08eb1bb51436aa257682d357d662c
Reviewed-on: https://go-review.googlesource.com/c/text/+/506416
TryBot-Result: Gopher Robot <gobot@golang.org>
Run-TryBot: Dmitri Shuralyov <dmitshur@golang.org>
Auto-Submit: Dmitri Shuralyov <dmitshur@golang.org>
Reviewed-by: Heschi Kreinick <heschi@google.com>
Reviewed-by: Dmitri Shuralyov <dmitshur@google.com>
diff --git a/encoding/japanese/all_test.go b/encoding/japanese/all_test.go
index 9cffe10..a8b53e2 100644
--- a/encoding/japanese/all_test.go
+++ b/encoding/japanese/all_test.go
@@ -8,6 +8,7 @@
 	"fmt"
 	"strings"
 	"testing"
+	"unicode/utf8"
 
 	"golang.org/x/text/encoding"
 	"golang.org/x/text/encoding/internal"
@@ -126,7 +127,7 @@
 	}
 	for _, tc := range testCases {
 		dir, tr, wantErr := tc.init(tc.e)
-		t.Run(fmt.Sprintf("%s/%v/%q", dir, tc.e, tc.src), func(t *testing.T) {
+		t.Run(fmt.Sprintf("%s/%v/%q", dir, tc.e, short(tc.src)), func(t *testing.T) {
 			dst := make([]byte, 100000)
 			src := []byte(tc.src)
 			for i := 0; i <= len(tc.src); i++ {
@@ -147,6 +148,16 @@
 	}
 }
 
+func short(s string) string {
+	if len(s) <= 50 {
+		return s
+	}
+	var i int
+	for i = 1; i < utf8.UTFMax && !utf8.RuneStart(s[50-i]); i++ {
+	}
+	return s[:50-i] + "…"
+}
+
 func TestCorrect(t *testing.T) {
 	testCases := []struct {
 		init      func(e encoding.Encoding) (string, transform.Transformer, error)
diff --git a/language/match_test.go b/language/match_test.go
index 17afc32..2a96150 100644
--- a/language/match_test.go
+++ b/language/match_test.go
@@ -13,6 +13,7 @@
 	"path/filepath"
 	"strings"
 	"testing"
+	"unicode/utf8"
 
 	"golang.org/x/text/internal/testtext"
 	"golang.org/x/text/internal/ucd"
@@ -30,11 +31,11 @@
 			t.Fatal(err)
 		}
 		ucd.Parse(r, func(p *ucd.Parser) {
-			name := strings.Replace(path.Join(p.String(0), p.String(1)), " ", "", -1)
+			name := strings.ReplaceAll(path.Join(p.String(0), p.String(1)), " ", "")
 			if skip[name] {
 				return
 			}
-			t.Run(info.Name()+"/"+name, func(t *testing.T) {
+			t.Run(info.Name()+"/"+short(name), func(t *testing.T) {
 				supported := makeTagList(p.String(0))
 				desired := makeTagList(p.String(1))
 				gotCombined, index, conf := NewMatcher(supported).Match(desired...)
@@ -56,6 +57,16 @@
 	})
 }
 
+func short(s string) string {
+	if len(s) <= 50 {
+		return s
+	}
+	var i int
+	for i = 1; i < utf8.UTFMax && !utf8.RuneStart(s[50-i]); i++ {
+	}
+	return s[:50-i] + "…"
+}
+
 var skip = map[string]bool{
 	// TODO: bugs
 	// Honor the wildcard match. This may only be useful to select non-exact