You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

100 lines
2.3 KiB
Go

package cmd
import (
"fmt"
"testing"
)
var p = NewCMDParser(Pattern{
Prefix: "j",
Alias: []string{"加入", "加入游戏", "加入蓝方", "加入红方"},
ContentMaxLen: 0,
}, Pattern{
Prefix: "c",
Alias: []string{"切换"},
ContentMaxLen: 1,
}, Pattern{
Prefix: "w",
Alias: []string{"我在哪"},
ContentMaxLen: 0,
}, Pattern{
Prefix: "s",
ContentMaxLen: 1,
}, Pattern{
Prefix: "m",
ContentMaxLen: 1,
}, Pattern{
Prefix: "r",
ContentMaxLen: 1,
}, Pattern{
Prefix: "dq",
Alias: []string{"购买粮草", "买粮草"},
ContentMaxLen: 4,
}, Pattern{
Prefix: "dw",
Alias: []string{"购买精英"},
ContentMaxLen: 1,
}, Pattern{
Prefix: "zw",
Alias: []string{"使用精英"},
ContentMaxLen: 1,
}, Pattern{
Prefix: "zz",
Alias: []string{"使用称号"},
ContentMaxLen: 1,
})
func TestParse(t *testing.T) {
//contents := []string{
// "jc2m2b1s",
// "jjjjjjjjjjjj",
// "c1c1c1c1c1c1c1c1c1c1",
// "c5c6c7c8c9c2c3c4c1c2c3c4c5c6c2c3c4c5c6c1",
// "j2jjjjjjjj",
// "j",
// "加入游戏",
// "加入",
// "没有什么意义的弹幕",
// "92813182798dsjks8923kjhsddfh892h3jkl214",
// "昵称为什么可以这么长",
// "六十九的覅哦我就法拉盛就发链接我i苏联空军弗拉放假 ",
// "一堆乱七八糟的弹幕来袭",
// "不服你咬我啊?",
// "红方前排速度m2b2",
// "c1c2c3c4c1c2c3c4",
// "m2",
// "b2",
// "c2",
//}
//p := NewCMDParser(true, "j", "c1", "c2", "c3", "c4", "b1", "b2", "b3", "s", "b2", "b3", "w", "m1", "m2", "m3", "加入", "加入游戏")
//
//for _, content := range contents {
// cmdStruct := p.Parse(content)
// fmt.Printf("弹幕: [%s] 是命令否? [%v]\n", content, cmdStruct.IsCMD)
// fmt.Printf("清洗后的真实命令为:%s len:%d\n\n", cmdStruct.Arr, len(cmdStruct.Arr))
//}
}
func TestA(t *testing.T) {
p.SetDistinct(false)
cmd := p.Parse("jc2j加入c2jc2加入游戏dq4654购买粮草9999购买精英1m1r2zz1zw2wss1")
fmt.Println(cmd.IsCMD)
for _, match := range cmd.Matches {
fmt.Printf("prefix: %s, content: %s\n", match.Prefix, string(match.Content))
}
}
func BenchmarkCmd(b *testing.B) {
content := "jc2"
b.ResetTimer()
b.ReportAllocs()
for i := 0; i < b.N; i++ {
go func() {
p.Parse(content)
}()
}
}