summaryrefslogtreecommitdiff
path: root/internal/comic/localization_test.go
blob: 9da0f11a6bb20f02d132d3313ac18f972b699b19 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
package comic

import (
	"strings"
	"testing"
)

func TestLocalizedBrandName(t *testing.T) {
	t.Parallel()

	if got, want := localizedBrandName("Bulgarian", "Cyrillic"), "КомиксФордж Приключения"; got != want {
		t.Fatalf("localizedBrandName() = %q, want %q", got, want)
	}
	if got, want := localizedBrandName("English", "Latin"), "ComicForge Adventures"; got != want {
		t.Fatalf("localizedBrandName() = %q, want %q", got, want)
	}
}

func TestValidateTextScript(t *testing.T) {
	t.Parallel()

	if err := validateTextScript("title", "Заглавие", "Cyrillic"); err != nil {
		t.Fatalf("validateTextScript() error = %v", err)
	}
	if err := validateTextScript("title", "Title", "Cyrillic"); err == nil {
		t.Fatal("validateTextScript() error = nil, want Latin rejection")
	}
	if err := validateTextScript("title", "Title", "Latin"); err != nil {
		t.Fatalf("validateTextScript() error = %v", err)
	}
	if err := validateTextScript("title", "Заглавие", "Latin"); err == nil {
		t.Fatal("validateTextScript() error = nil, want Cyrillic rejection")
	}
}

func TestValidateNoPromptLeakage(t *testing.T) {
	t.Parallel()

	if err := validateNoPromptLeakage("story", "A calm story without artifacts."); err != nil {
		t.Fatalf("validateNoPromptLeakage() error = %v", err)
	}
	if err := validateNoPromptLeakage("story", "Words to include:\n- ябълка"); err == nil {
		t.Fatal("validateNoPromptLeakage() error = nil, want prompt leakage rejection")
	}
}

func TestFindImageLeakMarker(t *testing.T) {
	t.Parallel()

	if marker, ok := findImageLeakMarker("calm text"); ok || marker != "" {
		t.Fatalf("findImageLeakMarker() = %q, %v, want no match", marker, ok)
	}
	if marker, ok := findImageLeakMarker("mandatory language rule"); !ok || marker != "mandatory language rule" {
		t.Fatalf("findImageLeakMarker() = %q, %v, want mandatory language rule match", marker, ok)
	}
}

func TestFindEnglishLeakWord(t *testing.T) {
	t.Parallel()

	if word, ok := findEnglishLeakWord("спокойна сцена"); ok || word != "" {
		t.Fatalf("findEnglishLeakWord() = %q, %v, want no match", word, ok)
	}
	if word, ok := findEnglishLeakWord("page 1 of 5"); !ok || word != "page" {
		t.Fatalf("findEnglishLeakWord() = %q, %v, want page match", word, ok)
	}
}

func TestComicStylesStayComic(t *testing.T) {
	t.Parallel()

	for _, style := range comicStyles {
		if strings.Contains(strings.ToLower(style), "ultra realistic") || strings.Contains(strings.ToLower(style), "photograph") {
			t.Fatalf("comicStyles contains hybrid or photorealistic style: %q", style)
		}
	}
}

func TestContainsLatinLetters(t *testing.T) {
	t.Parallel()

	if containsLatinLetters("Здравей") {
		t.Fatal("containsLatinLetters() = true for Cyrillic text")
	}
	if !containsLatinLetters("Page 4 of 5") {
		t.Fatal("containsLatinLetters() = false for Latin text")
	}
}

func TestLocalizedStylePrompt(t *testing.T) {
	t.Parallel()

	got := localizedStylePrompt("classic American comic book with bold ink outlines, halftone dots, and primary colors", "Bulgarian", "Cyrillic")
	if containsLatinLetters(got) {
		t.Fatalf("localizedStylePrompt() = %q, want no Latin letters", got)
	}
	if got == "" {
		t.Fatal("localizedStylePrompt() returned empty string")
	}
}