MCPcopy
hub / github.com/gin-gonic/gin / TestRenderJsonpJSON

Function TestRenderJsonpJSON

render/render_test.go:111–137  ·  render/render_test.go::TestRenderJsonpJSON
(t *testing.T)

Source from the content-addressed store, hash-verified

109}
110
111func TestRenderJsonpJSON(t *testing.T) {
112 w1 := httptest.NewRecorder()
113 data := map[string]any{
114 "foo": "bar",
115 }
116
117 (JsonpJSON{"x", data}).WriteContentType(w1)
118 assert.Equal(t, "application/javascript; charset=utf-8", w1.Header().Get("Content-Type"))
119
120 err1 := (JsonpJSON{"x", data}).Render(w1)
121
122 require.NoError(t, err1)
123 assert.Equal(t, "x({\"foo\":\"bar\"});", w1.Body.String())
124 assert.Equal(t, "application/javascript; charset=utf-8", w1.Header().Get("Content-Type"))
125
126 w2 := httptest.NewRecorder()
127 datas := []map[string]any{{
128 "foo": "bar",
129 }, {
130 "bar": "foo",
131 }}
132
133 err2 := (JsonpJSON{"x", datas}).Render(w2)
134 require.NoError(t, err2)
135 assert.Equal(t, "x([{\"foo\":\"bar\"},{\"bar\":\"foo\"}]);", w2.Body.String())
136 assert.Equal(t, "application/javascript; charset=utf-8", w2.Header().Get("Content-Type"))
137}
138
139type errorWriter struct {
140 bufString string

Callers

nothing calls this directly

Calls 5

WriteContentTypeMethod · 0.65
RenderMethod · 0.65
StringMethod · 0.65
GetMethod · 0.45
HeaderMethod · 0.45

Tested by

no test coverage detected