| 3 | import "testing" |
| 4 | |
| 5 | func TestPatch(t *testing.T) { |
| 6 | type test struct{ title, parsed, raw, expected string } |
| 7 | for _, test := range []test{{ |
| 8 | title: "empty", |
| 9 | }, { |
| 10 | title: "not escaped, empty raw", |
| 11 | parsed: "/foo/bar", |
| 12 | expected: "/foo/bar", |
| 13 | }, { |
| 14 | title: "already escaped, empty raw (invalid case)", |
| 15 | parsed: "/foo%2Fbar", |
| 16 | expected: "/foo%2Fbar", |
| 17 | }, { |
| 18 | title: "only raw (invalid case)", |
| 19 | raw: "/foo/bar", |
| 20 | }, { |
| 21 | title: "not reserved", |
| 22 | raw: "/foo%2Abar", |
| 23 | parsed: "/foo*bar", |
| 24 | expected: "/foo*bar", |
| 25 | }, { |
| 26 | title: "reserved", |
| 27 | raw: "/foo%2Fbar", |
| 28 | parsed: "/foo/bar", |
| 29 | expected: "/foo%2Fbar", |
| 30 | }, { |
| 31 | title: "reserved, lowercase", |
| 32 | raw: "/foo%2fbar", |
| 33 | parsed: "/foo/bar", |
| 34 | expected: "/foo%2fbar", |
| 35 | }, { |
| 36 | title: "modified, too short", |
| 37 | raw: "/foo%2Fbar", |
| 38 | parsed: "/foo/", |
| 39 | expected: "/foo/", |
| 40 | }, { |
| 41 | title: "modified, too short, before escape", |
| 42 | raw: "/foo%2Fbar", |
| 43 | parsed: "/foo", |
| 44 | expected: "/foo", |
| 45 | }, { |
| 46 | title: "modified, too long", |
| 47 | raw: "/foo%2Fbar", |
| 48 | parsed: "/foo/bar/baz", |
| 49 | expected: "/foo/bar/baz", |
| 50 | }, { |
| 51 | title: "modified, different", |
| 52 | raw: "/foo%2Fbar", |
| 53 | parsed: "/foo/baz", |
| 54 | expected: "/foo/baz", |
| 55 | }, { |
| 56 | title: "modified, different escaped", |
| 57 | raw: "/foo%2Fbar", |
| 58 | parsed: "/foo*bar", |
| 59 | expected: "/foo*bar", |
| 60 | }, { |
| 61 | title: "damaged raw (invalid case)", |
| 62 | raw: "/foo%2", |