MCPcopy
hub / github.com/grpc/grpc-go / ExampleAttributes_String

Function ExampleAttributes_String

attributes/attributes_test.go:68–96  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

66}
67
68func ExampleAttributes_String() {
69 type key struct{}
70 var typedNil *stringerVal
71 a1 := attributes.New(key{}, typedNil) // typed nil implements [fmt.Stringer]
72 a2 := attributes.New(key{}, (*stringerVal)(nil)) // typed nil implements [fmt.Stringer]
73 a3 := attributes.New(key{}, (*stringVal)(nil)) // typed nil not implements [fmt.Stringer]
74 a4 := attributes.New(key{}, nil) // untyped nil
75 a5 := attributes.New(key{}, 1)
76 a6 := attributes.New(key{}, stringerVal{s: "two"})
77 a7 := attributes.New(key{}, stringVal{s: "two"})
78 a8 := attributes.New(1, true)
79 fmt.Println("a1:", a1.String())
80 fmt.Println("a2:", a2.String())
81 fmt.Println("a3:", a3.String())
82 fmt.Println("a4:", a4.String())
83 fmt.Println("a5:", a5.String())
84 fmt.Println("a6:", a6.String())
85 fmt.Println("a7:", a7.String())
86 fmt.Println("a8:", a8.String())
87 // Output:
88 // a1: {"<%!p(attributes_test.key={})>": "<nil>" }
89 // a2: {"<%!p(attributes_test.key={})>": "<nil>" }
90 // a3: {"<%!p(attributes_test.key={})>": "<0x0>" }
91 // a4: {"<%!p(attributes_test.key={})>": "<%!p(<nil>)>" }
92 // a5: {"<%!p(attributes_test.key={})>": "<%!p(int=1)>" }
93 // a6: {"<%!p(attributes_test.key={})>": "two" }
94 // a7: {"<%!p(attributes_test.key={})>": "<%!p(attributes_test.stringVal={two})>" }
95 // a8: {"<%!p(int=1)>": "<%!p(bool=true)>" }
96}
97
98// Test that two attributes with different content are not Equal.
99func TestEqual(t *testing.T) {

Callers

nothing calls this directly

Calls 3

NewFunction · 0.92
PrintlnMethod · 0.80
StringMethod · 0.65

Tested by

no test coverage detected