| 2368 | } |
| 2369 | |
| 2370 | func TestMap(t *testing.T) { |
| 2371 | b := protopack.Message{ |
| 2372 | protopack.Tag{20, protopack.BytesType}, protopack.LengthPrefix(protopack.Message{ |
| 2373 | protopack.Tag{1, protopack.BytesType}, protopack.String("Key1"), |
| 2374 | protopack.Tag{2, protopack.BytesType}, protopack.String("Val1"), |
| 2375 | }), |
| 2376 | protopack.Tag{20, protopack.BytesType}, protopack.LengthPrefix(protopack.Message{ |
| 2377 | protopack.Tag{1, protopack.BytesType}, protopack.String("Key2"), |
| 2378 | protopack.Tag{2, protopack.BytesType}, protopack.String("Val2a"), |
| 2379 | protopack.Tag{2, protopack.BytesType}, protopack.String("Val2"), |
| 2380 | }), |
| 2381 | protopack.Tag{20, protopack.BytesType}, protopack.LengthPrefix(protopack.Message{ |
| 2382 | protopack.Tag{1, protopack.BytesType}, protopack.String("Key3"), |
| 2383 | protopack.Tag{1, protopack.Fixed32Type}, protopack.Uint32(5), |
| 2384 | protopack.Tag{2, protopack.BytesType}, protopack.String("Val3b"), |
| 2385 | protopack.Tag{3, protopack.BytesType}, protopack.Bytes("Val3a"), |
| 2386 | protopack.Tag{2, protopack.BytesType}, protopack.String("Val3"), |
| 2387 | protopack.Tag{2, protopack.Fixed32Type}, protopack.Uint32(5), |
| 2388 | }), |
| 2389 | protopack.Tag{20, protopack.BytesType}, protopack.LengthPrefix{}, |
| 2390 | protopack.Tag{20, protopack.BytesType}, protopack.LengthPrefix(protopack.Message{ |
| 2391 | protopack.Tag{1, protopack.BytesType}, protopack.String("Key4"), |
| 2392 | protopack.Tag{2, protopack.StartGroupType}, |
| 2393 | protopack.Message{ |
| 2394 | protopack.Tag{1, protopack.BytesType}, protopack.Bytes("SomeURL"), |
| 2395 | protopack.Tag{2, protopack.BytesType}, protopack.Bytes("SomeTitle"), |
| 2396 | protopack.Tag{3, protopack.BytesType}, protopack.Bytes("Snippet1"), |
| 2397 | }, |
| 2398 | protopack.Tag{2, protopack.EndGroupType}, |
| 2399 | }), |
| 2400 | }.Marshal() |
| 2401 | |
| 2402 | var m pb3.Message |
| 2403 | if err := proto.Unmarshal(b, &m); err != nil { |
| 2404 | t.Fatalf("proto.Unmarshal error: %v", err) |
| 2405 | } |
| 2406 | |
| 2407 | got := m.StringMap |
| 2408 | want := map[string]string{ |
| 2409 | "": "", |
| 2410 | "Key1": "Val1", |
| 2411 | "Key2": "Val2", |
| 2412 | "Key3": "Val3", |
| 2413 | "Key4": "", |
| 2414 | } |
| 2415 | |
| 2416 | if !reflect.DeepEqual(got, want) { |
| 2417 | t.Errorf("maps differ:\ngot %#v\nwant %#v", got, want) |
| 2418 | } |
| 2419 | } |
| 2420 | |
| 2421 | func marshalled() []byte { |
| 2422 | m := &pb3.IntMaps{} |