mirror of
https://github.com/go-gitea/gitea.git
synced 2026-10-26 06:16:56 +09:00
Consolidate all Go tests. Coverage is identical to before. Go tests are around 5% faster while being 7% smaller. No non-test code is touched.
39 lines
1.1 KiB
Go
39 lines
1.1 KiB
Go
// Copyright 2026 The Gitea Authors. All rights reserved.
|
|
// SPDX-License-Identifier: MIT
|
|
|
|
package gitdiff
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
)
|
|
|
|
func TestTryFixTruncatedString(t *testing.T) {
|
|
assert.Equal(t, "", tryFixTruncatedString(""))
|
|
|
|
t.Run("UTF8", func(t *testing.T) {
|
|
for _, test := range []struct {
|
|
input string
|
|
expected []string
|
|
}{
|
|
{"🌞a🌛", []string{"🌞"[:1], "🌞"[:2], "🌞"[:3], "🌞", "🌞a", "🌞a", "🌞a", "🌞a", "🌞a🌛"}},
|
|
{"a🌞🌛", []string{"a", "a", "a", "a", "a🌞", "a🌞"}},
|
|
} {
|
|
for i, expected := range test.expected {
|
|
assert.Equal(t, expected, tryFixTruncatedString(test.input[:i+1]))
|
|
}
|
|
}
|
|
})
|
|
|
|
t.Run("Non-UTF8", func(t *testing.T) {
|
|
s := "\xff\xee\xff\xeeb\xff\xee\xff\xee"
|
|
for i, expected := range []string{
|
|
"\xff", "\xff\xee", "\xff\xee\xff", "\xff\xee\xff\xee",
|
|
"\xff\xee\xff\xeeb", "\xff\xee\xff\xeeb", "\xff\xee\xff\xeeb", "\xff\xee\xff\xeeb", "\xff\xee\xff\xeeb\xff\xee\xff\xee",
|
|
} {
|
|
assert.Equal(t, expected, tryFixTruncatedString(s[:i+1]))
|
|
}
|
|
})
|
|
}
|