MCPcopy Create free account
hub / github.com/aws/smithy-go / TestEncoder

Function TestEncoder

encoding/json/encoder_test.go:10–34  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

8)
9
10func TestEncoder(t *testing.T) {
11 encoder := json.NewEncoder()
12
13 object := encoder.Object()
14
15 object.Key("stringKey").String("stringValue")
16 object.Key("integerKey").Long(1024)
17 object.Key("floatKey").Double(3.14)
18
19 subObj := object.Key("foo").Object()
20
21 subObj.Key("byteSlice").Base64EncodeBytes([]byte("foo bar"))
22 subObj.Close()
23
24 object.Close()
25
26 e := []byte(`{"stringKey":"stringValue","integerKey":1024,"floatKey":3.14,"foo":{"byteSlice":"Zm9vIGJhcg=="}}`)
27 if a := encoder.Bytes(); bytes.Compare(e, a) != 0 {
28 t.Errorf("expected %+q, but got %+q", e, a)
29 }
30
31 if a := encoder.String(); string(e) != a {
32 t.Errorf("expected %s, but got %s", e, a)
33 }
34}

Callers

nothing calls this directly

Calls 11

BytesMethod · 0.95
StringMethod · 0.95
NewEncoderFunction · 0.92
ObjectMethod · 0.80
KeyMethod · 0.80
ErrorfMethod · 0.80
StringMethod · 0.65
LongMethod · 0.45
DoubleMethod · 0.45
Base64EncodeBytesMethod · 0.45
CloseMethod · 0.45

Tested by

no test coverage detected