Files
gitea/services/gitdiff/gitdiff_parse_test.go
silverwind 8abda62312 test: consolidate Go tests (#39962)
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.
2026-10-24 13:48:19 +00:00

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]))
}
})
}