MCPcopy Create free account
hub / github.com/francoispqt/gojay / TestEncodingEmbeddedJSON

Function TestEncodingEmbeddedJSON

encode_embedded_json_test.go:49–137  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

47}
48
49func TestEncodingEmbeddedJSON(t *testing.T) {
50 t.Run("basic-embedded-json", func(t *testing.T) {
51 ej := EmbeddedJSON([]byte(`"test"`))
52 b := &strings.Builder{}
53 enc := BorrowEncoder(b)
54 err := enc.Encode(&ej)
55 assert.Nil(t, err, "err should be nil")
56 assert.Equal(t, b.String(), `"test"`, "b should be equal to content of EmbeddedJSON")
57 })
58 t.Run("basic-embedded-json-marshal-api", func(t *testing.T) {
59 ej := EmbeddedJSON([]byte(`"test"`))
60 b, err := Marshal(&ej)
61 assert.Nil(t, err, "err should be nil")
62 assert.Equal(t, string(b), `"test"`, "b should be equal to content of EmbeddedJSON")
63 })
64 t.Run("object-embedded-json", func(t *testing.T) {
65 req := Request{
66 id: "test",
67 method: "GET",
68 params: EmbeddedJSON([]byte(`"test"`)),
69 }
70 b := &strings.Builder{}
71 enc := BorrowEncoder(b)
72 err := enc.EncodeObject(&req)
73 assert.Nil(t, err, "err should be nil")
74 assert.Equal(
75 t,
76 b.String(),
77 `{"id":"test","method":"GET","params":"test","params3":"test","more":0}`,
78 "b should be equal to content of EmbeddedJSON",
79 )
80 })
81 t.Run("array-embedded-json", func(t *testing.T) {
82 ear := EmbeddedJSONArr{
83 []byte(`"test"`),
84 []byte(`{"test":"test"}`),
85 }
86 b := &strings.Builder{}
87 enc := BorrowEncoder(b)
88 err := enc.EncodeArray(ear)
89 assert.Nil(t, err, "err should be nil")
90 assert.Equal(
91 t,
92 b.String(),
93 `["test",{"test":"test"}]`,
94 "b should be equal to content of EmbeddedJSON",
95 )
96 })
97 t.Run("array-embedded-json-omit-empty", func(t *testing.T) {
98 ear := EmbeddedJSONOmitEmptyArr{
99 []byte(`"test"`),
100 []byte(``),
101 []byte(`{"test":"test"}`),
102 []byte(``),
103 []byte(`{"test":"test"}`),
104 }
105 b := &strings.Builder{}
106 enc := BorrowEncoder(b)

Callers

nothing calls this directly

Calls 12

EncodeMethod · 0.95
EncodeObjectMethod · 0.95
EncodeArrayMethod · 0.95
EncodeEmbeddedJSONMethod · 0.95
EmbeddedJSONTypeAlias · 0.85
BorrowEncoderFunction · 0.85
MarshalFunction · 0.85
TestWriterErrorTypeAlias · 0.85
NewEncoderFunction · 0.85
StringMethod · 0.45
ErrorMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…