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.

50 lines
1.2 KiB
Go

package cmd
import (
"fmt"
"testing"
)
func TestParse(t *testing.T) {
contents := []string{
"jc2m2b1s",
"jjjjjjjjjjjj",
"c1c1c1c1c1c1c1c1c1c1",
"c5c6c7c8c9c2c3c4c1c2c3c4c5c6c2c3c4c5c6c1",
"j2jjjjjjjj",
"j",
"加入游戏",
"加入",
"没有什么意义的弹幕",
"92813182798dsjks8923kjhsddfh892h3jkl214",
"昵称为什么可以这么长",
"六十九的覅哦我就法拉盛就发链接我i苏联空军弗拉放假 ",
"一堆乱七八糟的弹幕来袭",
"不服你咬我啊?",
"红方前排速度m2b2",
"c1c2c3c4c1c2c3c4",
"m2",
"b2",
"c2",
}
p := NewCMDParser([]string{"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 BenchmarkCmd(b *testing.B) {
p := NewCMDParser([]string{"j", "c1", "c2", "c3", "c4", "b1", "b2", "b3", "s", "b2", "b3", "w", "m1", "m2", "m3", "加入", "加入游戏"})
content := "jc2m2b1s"
b.ResetTimer()
b.ReportAllocs()
for i := 0; i < b.N; i++ {
p.ParseTest(content)
}
}