MCPcopy Index your code
hub / github.com/valyala/quicktemplate / testAppendJSONString

Function testAppendJSONString

jsonstring_test.go:26–46  ·  view source on GitHub ↗
(t *testing.T, s string)

Source from the content-addressed store, hash-verified

24}
25
26func testAppendJSONString(t *testing.T, s string) {
27 expectedResult, err := json.Marshal(s)
28 if err != nil {
29 t.Fatalf("unexpected error when encoding string %q: %s", s, err)
30 }
31 expectedResult = expectedResult[1 : len(expectedResult)-1]
32
33 bb := AcquireByteBuffer()
34 bb.B = AppendJSONString(bb.B[:0], s, false)
35 result := string(bb.B)
36 ReleaseByteBuffer(bb)
37
38 if strings.Contains(result, "'") {
39 t.Fatalf("json string shouldn't contain single quote: %q, src %q", result, s)
40 }
41 result = strings.Replace(result, `\u0027`, "'", -1)
42 result = strings.Replace(result, ">", `\u003e`, -1)
43 if result != string(expectedResult) {
44 t.Fatalf("unexpected result %q. Expecting %q. original string %q", result, expectedResult, s)
45 }
46}

Callers 1

TestAppendJSONStringFunction · 0.85

Calls 3

AcquireByteBufferFunction · 0.85
AppendJSONStringFunction · 0.85
ReleaseByteBufferFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…