MCPcopy Create free account
hub / github.com/google/go-querystring / TestValues_CustomEncodingPointer

Function TestValues_CustomEncodingPointer

query/encode_test.go:598–662  ·  view source on GitHub ↗

Test behavior when encoding is defined for a pointer of a custom type. Custom type should be able to encode values for nil pointers.

(t *testing.T)

Source from the content-addressed store, hash-verified

596// Test behavior when encoding is defined for a pointer of a custom type.
597// Custom type should be able to encode values for nil pointers.
598func TestValues_CustomEncodingPointer(t *testing.T) {
599 var zero customEncodedIntPtr = 0
600 var one customEncodedIntPtr = 1
601 tests := []struct {
602 input interface{}
603 want url.Values
604 }{
605 // non-pointer values do not get the custom encoding because
606 // they don't implement the encoder interface.
607 {
608 struct {
609 V customEncodedIntPtr `url:"v"`
610 }{},
611 url.Values{"v": {"0"}},
612 },
613 {
614 struct {
615 V customEncodedIntPtr `url:"v,omitempty"`
616 }{},
617 url.Values{},
618 },
619 {
620 struct {
621 V customEncodedIntPtr `url:"v"`
622 }{one},
623 url.Values{"v": {"1"}},
624 },
625
626 // pointers to custom encoded types.
627 {
628 struct {
629 V *customEncodedIntPtr `url:"v"`
630 }{},
631 url.Values{"v": {"undefined"}},
632 },
633 {
634 struct {
635 V *customEncodedIntPtr `url:"v,omitempty"`
636 }{},
637 url.Values{},
638 },
639 {
640 struct {
641 V *customEncodedIntPtr `url:"v"`
642 }{&zero},
643 url.Values{"v": {"_0"}},
644 },
645 {
646 struct {
647 V *customEncodedIntPtr `url:"v,omitempty"`
648 }{&zero},
649 url.Values{"v": {"_0"}},
650 },
651 {
652 struct {
653 V *customEncodedIntPtr `url:"v"`
654 }{&one},
655 url.Values{"v": {"_1"}},

Callers

nothing calls this directly

Calls 1

testValueFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…