mirror of
https://github.com/Mrs4s/go-cqhttp.git
synced 2025-05-04 19:17:37 +08:00
58 lines
1.6 KiB
Go
58 lines
1.6 KiB
Go
package msg
|
|
|
|
import (
|
|
"fmt"
|
|
"strings"
|
|
"testing"
|
|
|
|
"github.com/Mrs4s/MiraiGo/utils"
|
|
"github.com/stretchr/testify/assert"
|
|
"github.com/tidwall/gjson"
|
|
)
|
|
|
|
func TestParseString(_ *testing.T) {
|
|
// TODO: add more text
|
|
for _, v := range ParseString(`[CQ:face,id=115,text=111][CQ:face,id=217]] [CQ:text,text=123] [`) {
|
|
fmt.Println(v)
|
|
}
|
|
}
|
|
|
|
var (
|
|
bench = `asdfqwerqwerqwer[CQ:face,id=115,text=111]asdfasdfasdfasdfasdfasdfasd[CQ:face,id=217]] 123 [`
|
|
benchArray = gjson.Parse(`[{"type":"text","data":{"text":"asdfqwerqwerqwer"}},{"type":"face","data":{"id":"115","text":"111"}},{"type":"text","data":{"text":"asdfasdfasdfasdfasdfasdfasd"}},{"type":"face","data":{"id":"217"}},{"type":"text","data":{"text":"] "}},{"type":"text","data":{"text":"123"}},{"type":"text","data":{"text":" ["}}]`)
|
|
)
|
|
|
|
func BenchmarkParseString(b *testing.B) {
|
|
for i := 0; i < b.N; i++ {
|
|
ParseString(bench)
|
|
}
|
|
b.SetBytes(int64(len(bench)))
|
|
}
|
|
|
|
func BenchmarkParseObject(b *testing.B) {
|
|
for i := 0; i < b.N; i++ {
|
|
ParseObject(benchArray)
|
|
}
|
|
b.SetBytes(int64(len(benchArray.Raw)))
|
|
}
|
|
|
|
const bText = `123456789[]&987654321[]&987654321[]&987654321[]&987654321[]&987654321[]&`
|
|
|
|
func BenchmarkCQCodeEscapeText(b *testing.B) {
|
|
for i := 0; i < b.N; i++ {
|
|
ret := bText
|
|
EscapeText(ret)
|
|
}
|
|
}
|
|
|
|
func TestCQCodeEscapeText(t *testing.T) {
|
|
for i := 0; i < 200; i++ {
|
|
rs := utils.RandomStringRange(3000, "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890[]&")
|
|
ret := rs
|
|
ret = strings.ReplaceAll(ret, "&", "&")
|
|
ret = strings.ReplaceAll(ret, "[", "[")
|
|
ret = strings.ReplaceAll(ret, "]", "]")
|
|
assert.Equal(t, ret, EscapeText(rs))
|
|
}
|
|
}
|