-
Notifications
You must be signed in to change notification settings - Fork 0
/
cable_test.go
73 lines (69 loc) · 1.52 KB
/
cable_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
package simp
import (
"fmt"
"strings"
"testing"
"github.com/google/go-cmp/cmp"
)
func TestParseCable(t *testing.T) {
const (
system = "system"
user = "user"
asst = "assistant"
)
var (
all = func(msg ...Message) []Message { return msg }
msg = func(role, s string, ann ...string) Message {
a := ""
if ann != nil {
a = ann[0]
}
return Message{Role: role, Content: s, Annotation: a}
}
)
var tests = []struct {
Source string
Want []Message
Error error
Whitespace string
}{
{
Source: "a\n\t>>>\nb",
Want: all(msg(system, "a"), msg(user, "b")),
Whitespace: "\t",
},
{
Source: " >>>>\na",
Want: all(msg(user, "a")),
Whitespace: " ",
},
{
Source: "\n\t>>>>>\na",
Want: all(msg(user, "a")),
Whitespace: "\t",
},
{
Source: "a\n\t\t>>>\nb\n\t<<< gpt-4\nc",
Want: all(msg(system, "a"), msg(user, "b"), msg(asst, "c", "gpt-4")),
Whitespace: "\t\t",
},
}
for i, test := range tests {
t.Run(fmt.Sprintf("%d", i), func(t *testing.T) {
s := test.Source
s_ := strings.ReplaceAll(s, "\t", "TAB")
s_ = strings.ReplaceAll(s_, " ", "_")
t.Logf("source:\n%s", s_)
got, err := ParseCable(s)
if err != nil {
t.Error(err)
}
if diff := cmp.Diff(test.Want, got.Thread); diff != "" {
t.Errorf("mismatch (-want +got):\n%v", diff)
}
// if got.Whitespace != test.Whitespace {
// t.Errorf("whitespace mismatch: want %q, got %q", test.Whitespace, got.Whitespace)
// }
})
}
}