Skip to content

Commit bde4f89

Browse files
authored
test(deepseek): add unit tests for concatTextParts (#795)
1 parent 84d6e68 commit bde4f89

1 file changed

Lines changed: 50 additions & 0 deletions

File tree

components/model/deepseek/extra_test.go

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,56 @@ func TestReasoningContent(t *testing.T) {
4747
assert.Equal(t, "reasoning content", rc)
4848
}
4949

50+
func TestConcatTextParts(t *testing.T) {
51+
type part struct {
52+
typ schema.ChatMessagePartType
53+
text string
54+
}
55+
extract := func(p part) (schema.ChatMessagePartType, string) {
56+
return p.typ, p.text
57+
}
58+
59+
t.Run("empty parts", func(t *testing.T) {
60+
result, err := concatTextParts([]part{}, extract)
61+
assert.NoError(t, err)
62+
assert.Equal(t, "", result)
63+
})
64+
65+
t.Run("single text part", func(t *testing.T) {
66+
result, err := concatTextParts([]part{
67+
{typ: schema.ChatMessagePartTypeText, text: "hello"},
68+
}, extract)
69+
assert.NoError(t, err)
70+
assert.Equal(t, "hello", result)
71+
})
72+
73+
t.Run("multiple text parts", func(t *testing.T) {
74+
result, err := concatTextParts([]part{
75+
{typ: schema.ChatMessagePartTypeText, text: "hello"},
76+
{typ: schema.ChatMessagePartTypeText, text: "world"},
77+
}, extract)
78+
assert.NoError(t, err)
79+
assert.Equal(t, "hello\n\nworld", result)
80+
})
81+
82+
t.Run("unsupported type returns error", func(t *testing.T) {
83+
_, err := concatTextParts([]part{
84+
{typ: schema.ChatMessagePartTypeImageURL, text: ""},
85+
}, extract)
86+
assert.Error(t, err)
87+
assert.Contains(t, err.Error(), "does not support")
88+
assert.Contains(t, err.Error(), string(schema.ChatMessagePartTypeImageURL))
89+
})
90+
91+
t.Run("mixed types returns error", func(t *testing.T) {
92+
_, err := concatTextParts([]part{
93+
{typ: schema.ChatMessagePartTypeText, text: "hello"},
94+
{typ: schema.ChatMessagePartTypeImageURL, text: ""},
95+
}, extract)
96+
assert.Error(t, err)
97+
})
98+
}
99+
50100
func TestPrefix(t *testing.T) {
51101
msg := &schema.Message{}
52102
assert.False(t, HasPrefix(msg))

0 commit comments

Comments
 (0)