Include chat, weather, image, travel, streaming ASR and text examples, shared model initialization, documentation, and existing tests. Co-authored-by: TRAE CLI <traecli@bytedance.com>
40 lines
1006 B
Go
40 lines
1006 B
Go
package terminal
|
|
|
|
import (
|
|
"context"
|
|
"errors"
|
|
"io"
|
|
"strings"
|
|
"testing"
|
|
)
|
|
|
|
func TestConfirmImage(t *testing.T) {
|
|
for _, tt := range []struct {
|
|
name, input string
|
|
approved bool
|
|
err error
|
|
}{
|
|
{name: "确认", input: "y\n继续\n", approved: true},
|
|
{name: "拒绝", input: "n\n继续\n"},
|
|
{name: "默认拒绝", input: "\n继续\n"},
|
|
{name: "纠正输入", input: "maybe\n确认\n继续\n", approved: true},
|
|
{name: "输入结束", err: io.EOF},
|
|
} {
|
|
t.Run(tt.name, func(t *testing.T) {
|
|
ctx, cancel := context.WithCancel(context.Background())
|
|
defer cancel()
|
|
input := newInput(ctx, strings.NewReader(tt.input))
|
|
approved, err := confirmImage(ctx, input, "画一只猫")
|
|
if approved != tt.approved || !errors.Is(err, tt.err) {
|
|
t.Fatalf("确认结果 = %v,错误 = %v", approved, err)
|
|
}
|
|
if err == nil {
|
|
line, err := input.next(ctx)
|
|
if err != nil || line != "继续" {
|
|
t.Fatal("确认不应吞掉下一条聊天输入")
|
|
}
|
|
}
|
|
})
|
|
}
|
|
}
|