@@ -2,6 +2,7 @@ package tgapi
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"strings"
|
||||
"testing"
|
||||
)
|
||||
@@ -266,3 +267,28 @@ func TestUnmarshalRichBlockRejectsMalformedFields(t *testing.T) {
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestUnmarshalRichMessageStrict(t *testing.T) {
|
||||
for _, raw := range []string{`null`, `{}`, `{"blocks":null}`, `{"blocks":{}}`} {
|
||||
t.Run(raw, func(t *testing.T) {
|
||||
if _, err := UnmarshalRichMessageStrict([]byte(raw)); err == nil {
|
||||
t.Fatal("expected strict decoder error")
|
||||
}
|
||||
})
|
||||
}
|
||||
if _, err := UnmarshalRichMessageStrict([]byte(`{"blocks":[]}`)); err != nil {
|
||||
t.Fatalf("strict decoder rejected an empty blocks array: %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestRichJSONStructuralLimits(t *testing.T) {
|
||||
deep := strings.Repeat("[", maximumRichJSONDepth+1) + `"x"` + strings.Repeat("]", maximumRichJSONDepth+1)
|
||||
if _, err := UnmarshalRichText([]byte(deep)); !errors.Is(err, ErrRichJSONDepth) {
|
||||
t.Fatalf("expected ErrRichJSONDepth, got %v", err)
|
||||
}
|
||||
|
||||
wide := "[" + strings.Repeat("0,", maximumRichJSONNodes) + "0]"
|
||||
if _, err := UnmarshalRichText([]byte(wide)); !errors.Is(err, ErrRichJSONNodes) {
|
||||
t.Fatalf("expected ErrRichJSONNodes, got %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user