(t *testing.T)
| 641 | } |
| 642 | |
| 643 | func TestWriteSimpleJSONProtocolMap(t *testing.T) { |
| 644 | thetype := "map" |
| 645 | trans := NewTMemoryBuffer() |
| 646 | p := NewTSimpleJSONProtocol(trans) |
| 647 | p.WriteMapBegin(context.Background(), TType(I32), TType(DOUBLE), len(DOUBLE_VALUES)) |
| 648 | for k, value := range DOUBLE_VALUES { |
| 649 | if e := p.WriteI32(context.Background(), int32(k)); e != nil { |
| 650 | t.Fatalf("Unable to write %s key int32 value %v due to error: %s", thetype, k, e.Error()) |
| 651 | } |
| 652 | if e := p.WriteDouble(context.Background(), value); e != nil { |
| 653 | t.Fatalf("Unable to write %s value float64 value %v due to error: %s", thetype, value, e.Error()) |
| 654 | } |
| 655 | } |
| 656 | p.WriteMapEnd(context.Background()) |
| 657 | if e := p.Flush(context.Background()); e != nil { |
| 658 | t.Fatalf("Unable to write %s due to error flushing: %s", thetype, e.Error()) |
| 659 | } |
| 660 | str := trans.String() |
| 661 | if str[0] != '[' || str[len(str)-1] != ']' { |
| 662 | t.Fatalf("Bad value for %s, wrote: %v, in go: %v", thetype, str, DOUBLE_VALUES) |
| 663 | } |
| 664 | l := strings.Split(str[1:len(str)-1], ",") |
| 665 | if len(l) < 3 { |
| 666 | t.Fatal("Expected list of at least length 3 for map for metadata, but was of length ", len(l)) |
| 667 | } |
| 668 | expectedKeyType, _ := strconv.Atoi(l[0]) |
| 669 | expectedValueType, _ := strconv.Atoi(l[1]) |
| 670 | expectedSize, _ := strconv.Atoi(l[2]) |
| 671 | if expectedKeyType != I32 { |
| 672 | t.Fatal("Expected map key type ", I32, ", but was ", l[0]) |
| 673 | } |
| 674 | if expectedValueType != DOUBLE { |
| 675 | t.Fatal("Expected map value type ", DOUBLE, ", but was ", l[1]) |
| 676 | } |
| 677 | if expectedSize != len(DOUBLE_VALUES) { |
| 678 | t.Fatal("Expected map size of ", len(DOUBLE_VALUES), ", but was ", l[2]) |
| 679 | } |
| 680 | for k, value := range DOUBLE_VALUES { |
| 681 | strk := l[k*2+3] |
| 682 | strv := l[k*2+4] |
| 683 | ik, err := strconv.Atoi(strk) |
| 684 | if err != nil { |
| 685 | t.Fatalf("Bad value for %s index %v, wrote: %v, expected: %v, error: %s", thetype, k, strk, k, err.Error()) |
| 686 | } |
| 687 | if ik != k { |
| 688 | t.Fatalf("Bad value for %s index %v, wrote: %v, expected: %v", thetype, k, strk, k) |
| 689 | } |
| 690 | s := strv |
| 691 | if math.IsInf(value, 1) { |
| 692 | if s != jsonQuote(JSON_INFINITY) { |
| 693 | t.Fatalf("Bad value for %s at index %v %v, wrote: %v, expected: %v", thetype, k, value, s, jsonQuote(JSON_INFINITY)) |
| 694 | } |
| 695 | } else if math.IsInf(value, 0) { |
| 696 | if s != jsonQuote(JSON_NEGATIVE_INFINITY) { |
| 697 | t.Fatalf("Bad value for %s at index %v %v, wrote: %v, expected: %v", thetype, k, value, s, jsonQuote(JSON_NEGATIVE_INFINITY)) |
| 698 | } |
| 699 | } else if math.IsNaN(value) { |
| 700 | if s != jsonQuote(JSON_NAN) { |
nothing calls this directly
no test coverage detected