summaryrefslogtreecommitdiff
path: root/internal/image/prompt_test.go
blob: 73eb30ec2018c7464fdeecd1005957dfc46a0065 (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
package image

import (
	"strings"
	"testing"
)

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

	if got := promptSubject(" apple ", "ябълка"); got != "apple" {
		t.Fatalf("promptSubject() = %q, want %q", got, "apple")
	}
}

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

	if got := promptSubject("   ", "ябълка"); got != "ябълка" {
		t.Fatalf("promptSubject() = %q, want %q", got, "ябълка")
	}
}

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

	scene := "```text\nScene: A bright apple sits centered on a wooden table.\n```"
	if got := sanitizeSceneDescription(scene); got != "A bright apple sits centered on a wooden table" {
		t.Fatalf("sanitizeSceneDescription() = %q", got)
	}
}

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

	if usableSceneDescription("A") {
		t.Fatal("usableSceneDescription() unexpectedly accepted trivial scene")
	}
	if usableSceneDescription("A single, perfectly") {
		t.Fatal("usableSceneDescription() unexpectedly accepted incomplete scene fragment")
	}
}

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

	got := fallbackVisualDirection("to indulge someone")
	if got == "" || !usableSceneDescription(got) {
		t.Fatalf("fallbackVisualDirection() returned unusable phrase direction: %q", got)
	}
}

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

	got := fallbackVisualDirection("apple")
	if got == "" || !strings.Contains(got, "single apple") {
		t.Fatalf("fallbackVisualDirection() = %q", got)
	}
}