@@ -34,6 +34,14 @@ func (s stringVal) Equal(o any) bool {
34
34
return ok && s .s == os .s
35
35
}
36
36
37
+ type stringerVal struct {
38
+ s string
39
+ }
40
+
41
+ func (s stringerVal ) String () string {
42
+ return s .s
43
+ }
44
+
37
45
func ExampleAttributes () {
38
46
type keyOne struct {}
39
47
type keyTwo struct {}
@@ -57,6 +65,33 @@ func ExampleAttributes_WithValue() {
57
65
// Key two: {two}
58
66
}
59
67
68
+ func 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
+ fmt .Println ("a1:" , a1 .String ())
79
+ fmt .Println ("a2:" , a2 .String ())
80
+ fmt .Println ("a3:" , a3 .String ())
81
+ fmt .Println ("a4:" , a4 .String ())
82
+ fmt .Println ("a5:" , a5 .String ())
83
+ fmt .Println ("a6:" , a6 .String ())
84
+ fmt .Println ("a7:" , a7 .String ())
85
+ // Output:
86
+ // a1: {"<%!p(attributes_test.key={})>": "<nil>" }
87
+ // a2: {"<%!p(attributes_test.key={})>": "<nil>" }
88
+ // a3: {"<%!p(attributes_test.key={})>": "<0x0>" }
89
+ // a4: {"<%!p(attributes_test.key={})>": "<nil>" }
90
+ // a5: {"<%!p(attributes_test.key={})>": "<%!p(int=1)>" }
91
+ // a6: {"<%!p(attributes_test.key={})>": "two" }
92
+ // a7: {"<%!p(attributes_test.key={})>": "<%!p(attributes_test.stringVal={two})>" }
93
+ }
94
+
60
95
// Test that two attributes with the same content are Equal.
61
96
func TestEqual (t * testing.T ) {
62
97
type keyOne struct {}
0 commit comments