-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrules_test.go
More file actions
68 lines (63 loc) · 2.17 KB
/
Copy pathrules_test.go
File metadata and controls
68 lines (63 loc) · 2.17 KB
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
package main
import "testing"
// feed drives chunks through a fresh transducer chain, joining Feed outputs + End.
func feedChain(newTs func() []Transducer, chunks []string) string {
ts := newTs()
out := ""
for _, c := range chunks {
out += chainFeed(ts, c)
}
return out + chainEnd(ts)
}
func TestStripPair(t *testing.T) {
sp := func() []Transducer { return []Transducer{&stripPair{open: "<think>", close: "</think>"}} }
cases := []struct {
name string
chunks []string
want string
}{
{"single chunk", []string{"<think>hidden</think>answer"}, "answer"},
{"tags split across chunks", []string{"<thi", "nk>hid", "den</thi", "nk>vis"}, "vis"},
{"text around block", []string{"before<think>x</think>after"}, "beforeafter"},
{"passthrough", []string{"no tags here"}, "no tags here"},
{"think spans many chunks", []string{"a<think>b", "c", "d</think>e"}, "ae"},
{"unterminated think dropped", []string{"<think>only thinking, cut"}, ""},
{"trailing partial-open flushed", []string{"hello<thi"}, "hello<thi"},
}
for _, c := range cases {
if got := feedChain(sp, c.chunks); got != c.want {
t.Errorf("%s: got %q want %q", c.name, got, c.want)
}
}
}
func TestReplace(t *testing.T) {
rp := func() []Transducer { return []Transducer{&replaceRule{find: "foo", repl: "bar"}} }
cases := []struct {
chunks []string
want string
}{
{[]string{"a foo b"}, "a bar b"},
{[]string{"a fo", "o b"}, "a bar b"}, // match split across chunks
{[]string{"foofoo"}, "barbar"}, // adjacent matches
{[]string{"no match"}, "no match"}, // passthrough
{[]string{"ends in fo"}, "ends in fo"}, // partial tail flushed at End
}
for _, c := range cases {
if got := feedChain(rp, c.chunks); got != c.want {
t.Errorf("%v: got %q want %q", c.chunks, got, c.want)
}
}
}
func TestChainOrder(t *testing.T) {
// strip-pair then replace, composed over one stream
newTs := func() []Transducer {
return []Transducer{
&stripPair{open: "<think>", close: "</think>"},
&replaceRule{find: "world", repl: "there"},
}
}
got := feedChain(newTs, []string{"<think>plan</think>hello world"})
if got != "hello there" {
t.Errorf("chain: got %q want %q", got, "hello there")
}
}