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

Function TestEncoderStringEncodeAPI

encode_string_test.go:10–119  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

8)
9
10func TestEncoderStringEncodeAPI(t *testing.T) {
11 t.Run("basic", func(t *testing.T) {
12 builder := &strings.Builder{}
13 enc := NewEncoder(builder)
14 err := enc.EncodeString("hello world")
15 assert.Nil(t, err, "Error should be nil")
16 assert.Equal(
17 t,
18 `"hello world"`,
19 builder.String(),
20 "Result of marshalling is different as the one expected")
21 })
22 t.Run("utf8", func(t *testing.T) {
23 builder := &strings.Builder{}
24 enc := NewEncoder(builder)
25 err := enc.EncodeString("漢字𩸽")
26 assert.Nil(t, err, "Error should be nil")
27 assert.Equal(
28 t,
29 `"漢字𩸽"`,
30 builder.String(),
31 "Result of marshalling is different as the one expected")
32 })
33 t.Run("utf8-multibyte", func(t *testing.T) {
34 str := "テュールスト マーティン ヤコブ 😁"
35 builder := &strings.Builder{}
36 enc := NewEncoder(builder)
37 err := enc.EncodeString(str)
38 assert.Nil(t, err, "Error should be nil")
39 assert.Equal(
40 t,
41 `"テュールスト マーティン ヤコブ 😁"`,
42 builder.String(),
43 "Result of marshalling is different as the one expected")
44 })
45 t.Run("escaped-sequence1", func(t *testing.T) {
46 str := `テュールスト マ\ーテ
47ィン ヤコブ 😁`
48 builder := &strings.Builder{}
49 enc := NewEncoder(builder)
50 err := enc.EncodeString(str)
51 assert.Nil(t, err, "Error should be nil")
52 assert.Equal(
53 t,
54 `"テュールスト マ\\ーテ\nィン ヤコブ 😁"`,
55 builder.String(),
56 "Result of marshalling is different as the one expected")
57 })
58 t.Run("escaped-sequence2", func(t *testing.T) {
59 str := `テュールスト マ\ーテ
60ィン ヤコブ 😁 `
61 builder := &strings.Builder{}
62 enc := NewEncoder(builder)
63 err := enc.EncodeString(str)
64 assert.Nil(t, err, "Error should be nil")
65 assert.Equal(
66 t,
67 `"テュールスト マ\\ーテ\nィン ヤコブ 😁\t"`,

Callers

nothing calls this directly

Calls 3

EncodeStringMethod · 0.95
NewEncoderFunction · 0.85
StringMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…