MCPcopy Create free account
hub / github.com/WICG/webpackage / TestParseString

Function TestParseString

go/signedexchange/structuredheader/parser_test.go:51–89  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

49}
50
51func TestParseString(t *testing.T) {
52 cases := []struct {
53 input string
54 shouldSucceed bool
55 expected string
56 rest string
57 }{
58 {``, false, "", ""},
59 {`"`, false, "", ""},
60 {`""`, true, "", ""},
61 {`"abc"`, true, "abc", ""},
62 {`"abc`, false, "", ""},
63 {`abc"`, false, "", ""},
64 {`"abc"def`, true, "abc", "def"},
65 {`"abc\"def"`, true, "abc\"def", ""},
66 {`"abc\\def"`, true, "abc\\def", ""},
67 {`"abc\`, false, "", ""},
68 {`"abc\"`, false, "", ""},
69 {`"\n"`, false, "", ""},
70 {"\"\u2318\"", false, "", ""},
71 }
72 for _, c := range cases {
73 p := &parser{c.input}
74 s, err := p.parseString()
75 if c.shouldSucceed {
76 if err != nil {
77 t.Errorf("parseString(%q) unexpectedly failed: %v", c.input, err)
78 }
79 if s != c.expected {
80 t.Errorf("parseString(%q): got %v, want %v", c.input, s, c.expected)
81 }
82 if p.input != c.rest {
83 t.Errorf("parseString(%q): remaining input was %q, should be %q", c.input, p.input, c.rest)
84 }
85 } else if err == nil {
86 t.Errorf("parseString(%q) did not fail", c.input)
87 }
88 }
89}
90
91func TestParseKey(t *testing.T) {
92 cases := []struct {

Callers

nothing calls this directly

Calls 1

parseStringMethod · 0.95

Tested by

no test coverage detected