MCPcopy
hub / github.com/tinylib/msgp / TestMarshalFieldVsFileLimitPrecedence

Function TestMarshalFieldVsFileLimitPrecedence

_generated/limits_test.go:582–622  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

580}
581
582func TestMarshalFieldVsFileLimitPrecedence(t *testing.T) {
583 // Test precedence with marshal:true
584 // marshal_limits.go has: arrays:30 maps:20 marshal:true
585
586 t.Run("Marshal_TightSlice_FieldOverride", func(t *testing.T) {
587 // File limit: arrays:30, field limit: 10 -> field limit should apply
588 // Note: Since I only implemented field limits for unmarshal.go, marshal limits won't work yet
589 data := MarshalFieldOverrideTestData{
590 TightSlice: make([]int, 15), // Exceeds field limit (10) but within file limit (30)
591 }
592
593 marshaled, err := data.MarshalMsg(nil)
594 if err != nil {
595 t.Fatalf("Unexpected marshal error: %v", err)
596 }
597
598 var result MarshalFieldOverrideTestData
599 _, err = result.UnmarshalMsg(marshaled)
600 if err == nil {
601 t.Error("Expected error for TightSlice exceeding field limit (10), got nil")
602 }
603 })
604
605 t.Run("Marshal_DefaultFields_UseFileLimit", func(t *testing.T) {
606 // Fields without field limits should use file limits
607 data := MarshalFieldOverrideTestData{
608 DefaultSlice: make([]byte, 35), // Exceeds file limit (30)
609 }
610
611 marshaled, err := data.MarshalMsg(nil)
612 if err != nil {
613 t.Fatalf("Unexpected marshal error: %v", err)
614 }
615
616 var result MarshalFieldOverrideTestData
617 _, err = result.UnmarshalMsg(marshaled)
618 if err == nil {
619 t.Error("Expected error for DefaultSlice exceeding file limit (30), got nil")
620 }
621 })
622}
623
624func TestAliasedTypesWithFieldLimits(t *testing.T) {
625 // Test field-level limits with aliased types

Callers

nothing calls this directly

Calls 3

MarshalMsgMethod · 0.65
UnmarshalMsgMethod · 0.65
ErrorMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…