Debian Codegraph @

formatwriter_plain_test.go

raw symbols SCIP
1 // Copyright (c) 2012-2016 Eli Janssen
2 // Use of this source code is governed by an MIT-style
3 // license that can be found in the LICENSE file.
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 }