snapshot of https://github.com/go-gitea/gitea.git (main, 2026-09-15; blobs > 131072B omitted)
Some checks failed
cache-seeder / prune (push) Has been skipped
cache-seeder / frontend (push) Failing after 3s
cache-seeder / python (push) Failing after 3s
cache-seeder / gobuild (push) Failing after 4s
cache-seeder / lint (bindata, lint-backend) (push) Failing after 3s
giteabot backport / giteabot (push) Has been skipped
giteabot / giteabot (push) Has been skipped
cache-prune / prune (push) Has been skipped
release-nightly-snapcraft / build-and-publish (ubuntu-24.04) (push) Has been cancelled
release-nightly-snapcraft / build-and-publish (ubuntu-24.04-arm) (push) Has been cancelled
release-nightly / nightly-binary (push) Has been cancelled
release-nightly / nightly-container (push) Has been cancelled
cron-renovate / cron-renovate (push) Has been skipped
Some checks failed
cache-seeder / prune (push) Has been skipped
cache-seeder / frontend (push) Failing after 3s
cache-seeder / python (push) Failing after 3s
cache-seeder / gobuild (push) Failing after 4s
cache-seeder / lint (bindata, lint-backend) (push) Failing after 3s
giteabot backport / giteabot (push) Has been skipped
giteabot / giteabot (push) Has been skipped
cache-prune / prune (push) Has been skipped
release-nightly-snapcraft / build-and-publish (ubuntu-24.04) (push) Has been cancelled
release-nightly-snapcraft / build-and-publish (ubuntu-24.04-arm) (push) Has been cancelled
release-nightly / nightly-binary (push) Has been cancelled
release-nightly / nightly-container (push) Has been cancelled
cron-renovate / cron-renovate (push) Has been skipped
This commit is contained in:
48
services/gitdiff/gitdiff_parse_test.go
Normal file
48
services/gitdiff/gitdiff_parse_test.go
Normal file
@@ -0,0 +1,48 @@
|
||||
// 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) {
|
||||
s := "🌞a🌛"
|
||||
assert.Equal(t, s[:1], tryFixTruncatedString(s[:1]))
|
||||
assert.Equal(t, s[:2], tryFixTruncatedString(s[:2]))
|
||||
assert.Equal(t, s[:3], tryFixTruncatedString(s[:3]))
|
||||
assert.Equal(t, "🌞", tryFixTruncatedString(s[:4]))
|
||||
assert.Equal(t, "🌞a", tryFixTruncatedString(s[:5]))
|
||||
assert.Equal(t, "🌞a", tryFixTruncatedString(s[:6]))
|
||||
assert.Equal(t, "🌞a", tryFixTruncatedString(s[:7]))
|
||||
assert.Equal(t, "🌞a", tryFixTruncatedString(s[:8]))
|
||||
assert.Equal(t, "🌞a🌛", tryFixTruncatedString(s[:9]))
|
||||
|
||||
s = "a🌞🌛"
|
||||
assert.Equal(t, "a", tryFixTruncatedString(s[:1]))
|
||||
assert.Equal(t, "a", tryFixTruncatedString(s[:2]))
|
||||
assert.Equal(t, "a", tryFixTruncatedString(s[:3]))
|
||||
assert.Equal(t, "a", tryFixTruncatedString(s[:4]))
|
||||
assert.Equal(t, "a🌞", tryFixTruncatedString(s[:5]))
|
||||
assert.Equal(t, "a🌞", tryFixTruncatedString(s[:6]))
|
||||
})
|
||||
|
||||
t.Run("Non-UTF8", func(t *testing.T) {
|
||||
s := "\xff\xee\xff\xeeb\xff\xee\xff\xee"
|
||||
assert.Equal(t, "\xff", tryFixTruncatedString(s[:1]))
|
||||
assert.Equal(t, "\xff\xee", tryFixTruncatedString(s[:2]))
|
||||
assert.Equal(t, "\xff\xee\xff", tryFixTruncatedString(s[:3]))
|
||||
assert.Equal(t, "\xff\xee\xff\xee", tryFixTruncatedString(s[:4]))
|
||||
assert.Equal(t, "\xff\xee\xff\xeeb", tryFixTruncatedString(s[:5]))
|
||||
assert.Equal(t, "\xff\xee\xff\xeeb", tryFixTruncatedString(s[:6]))
|
||||
assert.Equal(t, "\xff\xee\xff\xeeb", tryFixTruncatedString(s[:7]))
|
||||
assert.Equal(t, "\xff\xee\xff\xeeb", tryFixTruncatedString(s[:8]))
|
||||
assert.Equal(t, "\xff\xee\xff\xeeb\xff\xee\xff\xee", tryFixTruncatedString(s[:9]))
|
||||
})
|
||||
}
|
||||
Reference in New Issue
Block a user