Source file
src/runtime/print_quoted_test.go
1
2
3
4
5 package runtime_test
6
7 import (
8 "runtime"
9 "testing"
10 )
11
12 func TestPrintQuoted(t *testing.T) {
13 for _, tbl := range []struct {
14 in, expected string
15 }{
16 {in: "baz", expected: `"baz"`},
17 {in: "foobar", expected: `"foobar"`},
18
19 {in: "baz\n", expected: `"baz\n"`},
20
21 {in: "b\033it", expected: `"b\x1bit"`},
22 {in: "b\000ar", expected: `"b\x00ar"`},
23
24 {in: "b\xfdar", expected: `"b\xfdar"`},
25 {in: "b\xfda", expected: `"b\xfda"`},
26 {in: "b\xfd\xffar", expected: `"b\xfd\xffar"`},
27
28 {in: "\ufffd!!!!", expected: `"\ufffd!!!!"`},
29
30 {in: "\u1234Σ", expected: `"\u1234\u03a3"`},
31
32 {in: "fizz\tle", expected: `"fizz\tle"`},
33 {in: "\U00045678boop", expected: `"\U00045678boop"`},
34
35 {in: "fiz\\zl\re", expected: `"fiz\\zl\re"`},
36 } {
37 t.Run(tbl.in, func(t *testing.T) {
38 out := runtime.DumpPrintQuoted(tbl.in)
39 if out != tbl.expected {
40 t.Errorf("unexpected output for print(escaped(%q));\n got: %s\nwant: %s", tbl.in, out, tbl.expected)
41 }
42 })
43 }
44 }
45
View as plain text