(t *testing.T)
| 1475 | } |
| 1476 | |
| 1477 | func TestJSON(t *testing.T) { |
| 1478 | m := &MyMessage{ |
| 1479 | Count: Int32(4), |
| 1480 | Pet: []string{"bunny", "kitty"}, |
| 1481 | Inner: &InnerMessage{ |
| 1482 | Host: String("cauchy"), |
| 1483 | }, |
| 1484 | Bikeshed: MyMessage_GREEN.Enum(), |
| 1485 | } |
| 1486 | const expected = `{"count":4,"pet":["bunny","kitty"],"inner":{"host":"cauchy"},"bikeshed":1}` |
| 1487 | |
| 1488 | b, err := json.Marshal(m) |
| 1489 | if err != nil { |
| 1490 | t.Fatalf("json.Marshal failed: %v", err) |
| 1491 | } |
| 1492 | s := string(b) |
| 1493 | if s != expected { |
| 1494 | t.Errorf("got %s\nwant %s", s, expected) |
| 1495 | } |
| 1496 | |
| 1497 | received := new(MyMessage) |
| 1498 | if err := json.Unmarshal(b, received); err != nil { |
| 1499 | t.Fatalf("json.Unmarshal failed: %v", err) |
| 1500 | } |
| 1501 | if !Equal(received, m) { |
| 1502 | t.Fatalf("got %s, want %s", received, m) |
| 1503 | } |
| 1504 | |
| 1505 | // Test unmarshalling of JSON with symbolic enum name. |
| 1506 | const old = `{"count":4,"pet":["bunny","kitty"],"inner":{"host":"cauchy"},"bikeshed":"GREEN"}` |
| 1507 | received.Reset() |
| 1508 | if err := json.Unmarshal([]byte(old), received); err != nil { |
| 1509 | t.Fatalf("json.Unmarshal failed: %v", err) |
| 1510 | } |
| 1511 | if !Equal(received, m) { |
| 1512 | t.Fatalf("got %s, want %s", received, m) |
| 1513 | } |
| 1514 | } |
| 1515 | |
| 1516 | func TestBadWireType(t *testing.T) { |
| 1517 | b := []byte{7<<3 | 6} // field 7, wire type 6 |
nothing calls this directly
no test coverage detected
searching dependent graphs…