| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
package mlog |
| 6 |
|
| 7 |
import ( |
| 8 |
"bytes" |
| 9 |
"testing" |
| 10 |
|
| 11 |
"gotest.tools/v3/assert" |
| 12 |
is "gotest.tools/v3/assert/cmp" |
| 13 |
) |
| 14 |
|
| 15 |
func TestFormatWriterPlainEncodeString(t *testing.T) { |
| 16 |
var stringTests = map[string]struct { |
| 17 |
input string |
| 18 |
output string |
| 19 |
}{ |
| 20 |
"generic": {`test`, `test`}, |
| 21 |
"quote": {`"this"`, `"this"`}, |
| 22 |
"r&n": {"te\r\nst", `te\r\nst`}, |
| 23 |
"tab": {"\t what", `\t what`}, |
| 24 |
"weird chars": {"\u2028 \u2029", "\u2028 \u2029"}, |
| 25 |
"other weird chars": {`"\u003c\u0026\u003e"`, `"\u003c\u0026\u003e"`}, |
| 26 |
"invalid utf8": {"\xff\xff\xffhello", `\ufffd\ufffd\ufffdhello`}, |
| 27 |
} |
| 28 |
|
| 29 |
b := &bytes.Buffer{} |
| 30 |
for name, tt := range stringTests { |
| 31 |
b.Truncate(0) |
| 32 |
encodeStringPlain(b, tt.input) |
| 33 |
assert.Check(t, is.DeepEqual([]byte(tt.output), b.Bytes()), "%s: did not match expectation", name) |
| 34 |
} |
| 35 |
} |