(t *testing.T)
| 5 | ) |
| 6 | |
| 7 | func TestStringDecode(t *testing.T) { |
| 8 | cases := []struct { |
| 9 | in string |
| 10 | expected string |
| 11 | }{ |
| 12 | // middle |
| 13 | {`"foo bar"`, `foo bar`}, |
| 14 | {`"foo\\bar"`, `foo\bar`}, |
| 15 | {`"foo\"bar"`, `foo"bar`}, |
| 16 | {`"foo\'bar"`, `foo'bar`}, |
| 17 | {`"foo\075bar"`, `foo=bar`}, |
| 18 | {`"foo\tbar"`, "foo\tbar"}, |
| 19 | {`"foo\vbar"`, "foo\vbar"}, |
| 20 | {`"foo\u003dbar"`, "foo=bar"}, |
| 21 | {`"foo\u{00000000003d}bar"`, "foo=bar"}, |
| 22 | |
| 23 | // end |
| 24 | {`"foo\075"`, `foo=`}, |
| 25 | {`"foo\x3d"`, `foo=`}, |
| 26 | {`"foo\\"`, `foo\`}, |
| 27 | |
| 28 | // start |
| 29 | {`"\075foo"`, `=foo`}, |
| 30 | {`"\x3dfoo"`, `=foo`}, |
| 31 | {`"\\foo"`, `\foo`}, |
| 32 | |
| 33 | // pairs |
| 34 | {`"\075\x3d"`, `==`}, |
| 35 | {`"\u{00000003d}\x3d"`, `==`}, |
| 36 | |
| 37 | // Invalid |
| 38 | {`"\poo"`, `poo`}, |
| 39 | {`"\u{0003doops"`, `=oops`}, |
| 40 | |
| 41 | // real-world |
| 42 | {`"/help/doc/user_ed.jsp?loc\x3dhelp\x26target\x3d"`, "/help/doc/user_ed.jsp?loc=help&target="}, |
| 43 | } |
| 44 | |
| 45 | for _, c := range cases { |
| 46 | actual := DecodeString(c.in) |
| 47 | if c.expected != actual { |
| 48 | t.Errorf("Want %s for DecodeString(%s); have %s", c.expected, c.in, actual) |
| 49 | } |
| 50 | } |
| 51 | } |
| 52 | |
| 53 | func BenchmarkDecodeString(b *testing.B) { |
| 54 | inputs := []string{ |
nothing calls this directly
no test coverage detected