(t *testing.T)
| 87 | } |
| 88 | |
| 89 | func 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 | |
| 125 | func TestEncodeMapWithDuplicatedKeys(t *testing.T) { |
| 126 | entries := []*MapEntryEncoder{ |
nothing calls this directly
no test coverage detected