MCPcopy Index your code
hub / github.com/WICG/webpackage / TestEncodeTextString

Function TestEncodeTextString

go/internal/cbor/encoder_test.go:89–123  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

87}
88
89func TestEncodeTextString(t *testing.T) {
90 var textTests = []struct {
91 s string
92 encoding string
93 }{
94 {"", "60"},
95 {"a", "6161"},
96 {"IETF", "6449455446"},
97 {`"\`, "62225c"},
98 {"\u00fc", "62c3bc"},
99 {"\u6c34", "63e6b0b4"},
100 {"\U00010151", "64f0908591"},
101 }
102 for _, test := range textTests {
103 var b bytes.Buffer
104 e := NewEncoder(&b)
105
106 if err := e.EncodeTextString(test.s); err != nil {
107 t.Errorf("Encode. err: %v", err)
108 continue
109 }
110 exp := fromHex(test.encoding)
111
112 if !bytes.Equal(exp, b.Bytes()) {
113 t.Errorf("\"%s\" expected to encode to %v, actual %v", test.s, exp, b.Bytes())
114 }
115 }
116
117 var b bytes.Buffer
118 e := NewEncoder(&b)
119 str := "\x80 <- invalid UTF-8"
120 if err := e.EncodeTextString(str); err == nil {
121 t.Errorf("Expected an error for malformed UTF-8 (%q)", str)
122 }
123}
124
125func TestEncodeMapWithDuplicatedKeys(t *testing.T) {
126 entries := []*MapEntryEncoder{

Callers

nothing calls this directly

Calls 3

EncodeTextStringMethod · 0.95
NewEncoderFunction · 0.85
fromHexFunction · 0.85

Tested by

no test coverage detected