-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathprompt_test.go
130 lines (121 loc) · 3.61 KB
/
prompt_test.go
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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
package syndicate
import (
"encoding/json"
"fmt"
"strings"
"testing"
)
func TestCreateAndBuildSimplePrompt(t *testing.T) {
pb := NewPromptBuilder()
pb.CreateSection("Introduction")
pb.AddText("Introduction", " Welcome to the system! ")
result := pb.Build()
expected := "<Introduction>\nWelcome to the system!\n</Introduction>"
if result != expected {
t.Errorf("Expected:\n%s\ngot:\n%s", expected, result)
}
}
func TestAddSubSectionAndBuild(t *testing.T) {
pb := NewPromptBuilder()
pb.CreateSection("Main")
pb.AddText("Main", "This is the main section.")
pb.AddSubSection("Details", "Main")
pb.AddText("Details", "Some details here.")
result := pb.Build()
// Para la sección "Main", se espera:
// <Main>
// This is the main section.
// <Details>
// Some details here.
// </Details>
// </Main>
expected := "<Main>\nThis is the main section.\n <Details>\n Some details here.\n </Details>\n</Main>"
if result != expected {
t.Errorf("Expected:\n%s\ngot:\n%s", expected, result)
}
}
func TestAddTextFWithJSONConversion(t *testing.T) {
pb := NewPromptBuilder()
pb.CreateSection("Data")
data := map[string]int{"count": 10}
pb.AddTextF("Data", data)
result := pb.Build()
jsonData, _ := json.Marshal(data)
expected := fmt.Sprintf("<Data>\n%s\n</Data>", string(jsonData))
if result != expected {
t.Errorf("Expected:\n%s\ngot:\n%s", expected, result)
}
}
func TestAddListItemAndListItemF(t *testing.T) {
pb := NewPromptBuilder()
pb.CreateSection("ListSection")
pb.AddListItem("ListSection", "first item")
pb.AddListItem("ListSection", "second item")
// Con AddListItemF se convierte el valor 123 en "123".
pb.AddListItemF("ListSection", 123)
result := pb.Build()
expectedLines := []string{
"<ListSection>",
"1. first item",
"2. second item",
"3. 123",
"</ListSection>",
}
expected := strings.Join(expectedLines, "\n")
if result != expected {
t.Errorf("Expected:\n%s\ngot:\n%s", expected, result)
}
}
func TestMultipleNestedSubsections(t *testing.T) {
pb := NewPromptBuilder()
pb.CreateSection("Section1")
pb.AddText("Section1", "Line in Section1")
pb.AddSubSection("Sub1", "Section1")
pb.AddText("Sub1", "Line in Sub1")
pb.AddSubSection("SubSub1", "Sub1")
pb.AddText("SubSub1", "Deep line")
result := pb.Build()
// El comportamiento actual de buildSection es aplicar el indent al abrir la tag
// y usar el mismo indent para cada línea interna en cada nivel.
// Por lo tanto, el resultado generado es:
// <Section1>
// Line in Section1
// <Sub1>
// Line in Sub1
// <SubSub1>
// Deep line
// </SubSub1>
// </Sub1>
// </Section1>
expected := "<Section1>\nLine in Section1\n <Sub1>\n Line in Sub1\n <SubSub1>\n Deep line\n </SubSub1>\n </Sub1>\n</Section1>"
if result != expected {
t.Errorf("Expected:\n%s\ngot:\n%s", expected, result)
}
}
func TestCreateDuplicateSection(t *testing.T) {
pb := NewPromptBuilder()
pb.CreateSection("DupSection")
pb.CreateSection("DupSection")
pb.AddText("DupSection", "Only once.")
result := pb.Build()
expected := "<DupSection>\nOnly once.\n</DupSection>"
if result != expected {
t.Errorf("Expected:\n%s\ngot:\n%s", expected, result)
}
}
func TestAddTextToNonExistentSection(t *testing.T) {
pb := NewPromptBuilder()
// No se crea la sección "NonExistent", así que AddText no agrega nada.
pb.AddText("NonExistent", "Should not appear")
result := pb.Build()
if result != "" {
t.Errorf("Expected empty prompt, got: %s", result)
}
}
func TestBuildWithNoSections(t *testing.T) {
pb := NewPromptBuilder()
result := pb.Build()
if result != "" {
t.Errorf("Expected empty prompt for no sections, got: %s", result)
}
}