]> Sergey Matveev's repositories - btrtrc.git/blob - webseed/request_test.go
f7c18a03fdb92df6e4649d71019a581dbada6833
[btrtrc.git] / webseed / request_test.go
1 package webseed
2
3 import (
4         "net/url"
5         "testing"
6
7         qt "github.com/frankban/quicktest"
8 )
9
10 func TestTrailingPath(t *testing.T) {
11         c := qt.New(t)
12         test := func(parts []string, result string) {
13                 unescaped, err := url.QueryUnescape(trailingPath(parts[0], parts[1:]))
14                 if !c.Check(err, qt.IsNil) {
15                         return
16                 }
17                 c.Check(unescaped, qt.Equals, result)
18         }
19         test([]string{"a_b-c", "d + e.f"}, "a_b-c/d + e.f")
20         test([]string{"a_1-b_c2", "d 3. (e, f).g"},
21                 "a_1-b_c2/d 3. (e, f).g",
22         )
23 }
24
25 func TestTrailingPathForEmptyInfoName(t *testing.T) {
26         qt.Check(t, trailingPath("", []string{`ノ┬─┬ノ ︵ ( \o°o)\`}), qt.Equals, "%E3%83%8E%E2%94%AC%E2%94%80%E2%94%AC%E3%83%8E+%EF%B8%B5+%28+%5Co%C2%B0o%29%5C")
27         qt.Check(t, trailingPath("", []string{"hello", "world"}), qt.Equals, "hello/world")
28         qt.Check(t, trailingPath("war", []string{"and", "peace"}), qt.Equals, "war/and/peace")
29 }