MCPcopy
hub / github.com/gogo/protobuf / TestMapParsing

Function TestMapParsing

proto/text_parser_test.go:628–659  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

626}
627
628func TestMapParsing(t *testing.T) {
629 m := new(MessageWithMap)
630 const in = `name_mapping:<key:1234 value:"Feist"> name_mapping:<key:1 value:"Beatles">` +
631 `msg_mapping:<key:-4, value:<f: 2.0>,>` + // separating commas are okay
632 `msg_mapping<key:-2 value<f: 4.0>>` + // no colon after "value"
633 `msg_mapping:<value:<f: 5.0>>` + // omitted key
634 `msg_mapping:<key:1>` + // omitted value
635 `byte_mapping:<key:true value:"so be it">` +
636 `byte_mapping:<>` // omitted key and value
637 want := &MessageWithMap{
638 NameMapping: map[int32]string{
639 1: "Beatles",
640 1234: "Feist",
641 },
642 MsgMapping: map[int64]*FloatingPoint{
643 -4: {F: Float64(2.0)},
644 -2: {F: Float64(4.0)},
645 0: {F: Float64(5.0)},
646 1: nil,
647 },
648 ByteMapping: map[bool][]byte{
649 false: nil,
650 true: []byte("so be it"),
651 },
652 }
653 if err := UnmarshalText(in, m); err != nil {
654 t.Fatal(err)
655 }
656 if !Equal(m, want) {
657 t.Errorf("\n got %v\nwant %v", m, want)
658 }
659}
660
661func TestOneofParsing(t *testing.T) {
662 const in = `name:"Shrek"`

Callers

nothing calls this directly

Calls 3

Float64Function · 0.85
UnmarshalTextFunction · 0.85
EqualFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…