diff options
| author | Paul Buetow <paul@buetow.org> | 2026-04-21 10:45:38 +0300 |
|---|---|---|
| committer | Paul Buetow <paul@buetow.org> | 2026-04-21 10:45:38 +0300 |
| commit | 138695208e06a733d6b27673338fd3ca8de7fe62 (patch) | |
| tree | e5f0cc88c1b9ec67bb11eb735926aba9d2f4d7cf /internal/comic/comic_test.go | |
| parent | c31e91ce42fc00079e0ee23f93e337846eea00ad (diff) | |
fix o7: keep comic section splitting UTF-8 safe
Diffstat (limited to 'internal/comic/comic_test.go')
| -rw-r--r-- | internal/comic/comic_test.go | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/internal/comic/comic_test.go b/internal/comic/comic_test.go index 020fba5..0acccb0 100644 --- a/internal/comic/comic_test.go +++ b/internal/comic/comic_test.go @@ -8,6 +8,7 @@ import ( "strings" "testing" "time" + "unicode/utf8" ) func TestSlugify(t *testing.T) { @@ -55,6 +56,34 @@ func TestBuildPanelLayoutUsesFallbackExcerpt(t *testing.T) { } } +func TestSplitIntoSectionsUsesRuneBoundaries(t *testing.T) { + t.Parallel() + + text := strings.Repeat("Български текст за проверка на разделянето. ", 80) + sections := splitIntoSections(text, 4) + if len(sections) != 4 { + t.Fatalf("splitIntoSections() sections = %d, want 4", len(sections)) + } + for i, section := range sections { + if !utf8.ValidString(section) { + t.Fatalf("splitIntoSections() section %d is not valid UTF-8: %q", i, section) + } + } +} + +func TestBuildPanelLayoutTruncatesCyrillicOnRuneBoundaries(t *testing.T) { + t.Parallel() + + text := strings.Repeat("абвгдежзийклмно", 70) + got := buildPanelLayout(text, nil, 2) + if !utf8.ValidString(got) { + t.Fatalf("buildPanelLayout() returned invalid UTF-8: %q", got) + } + if !strings.Contains(got, "…") { + t.Fatalf("buildPanelLayout() = %q, want truncation ellipsis", got) + } +} + func TestParseGenerateResultUsesConfiguredDimensions(t *testing.T) { t.Parallel() |
