mirror of
https://github.com/Mrs4s/go-cqhttp.git
synced 2025-05-05 03:23:49 +08:00
coolq/cqcode: add a testcase for quote
May report an empty json message.
This commit is contained in:
parent
06450c66a2
commit
f3da083be9
@ -2,18 +2,31 @@ package cqcode
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
|
"encoding/json"
|
||||||
"testing"
|
"testing"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestIssue1733(t *testing.T) {
|
func jsonMarshal(s string) string {
|
||||||
const (
|
b, err := json.Marshal(s)
|
||||||
input = "\u0005"
|
if err != nil {
|
||||||
expected = `"\u0005"`
|
panic(err)
|
||||||
)
|
}
|
||||||
|
return string(b)
|
||||||
|
}
|
||||||
|
|
||||||
|
func Test_quote(t *testing.T) {
|
||||||
|
testcase := []string{
|
||||||
|
"\u0005", // issue 1773
|
||||||
|
"\v",
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, input := range testcase {
|
||||||
var b bytes.Buffer
|
var b bytes.Buffer
|
||||||
writeQuote(&b, input)
|
writeQuote(&b, input)
|
||||||
got := b.String()
|
got := b.String()
|
||||||
|
expected := jsonMarshal(input)
|
||||||
if got != expected {
|
if got != expected {
|
||||||
t.Errorf("want %v but got %v", expected, got)
|
t.Errorf("want %v but got %v", expected, got)
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user