1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
|
// SPDX-FileCopyrightText: 2026 Stefan Majewsky <majewsky@gmx.net>
// SPDX-License-Identifier: Apache-2.0
package pathrouter // This file contains tests that access unexported helper functions.
import (
"net/url"
"testing"
"go.xyrillian.de/gg/assert"
)
func TestExtractPath(t *testing.T) {
extract := func(rawURL string) []string {
t.Helper()
parsedURL, err := url.Parse(rawURL)
if err != nil {
t.Fatal(err)
}
return extractPath(parsedURL)
}
assert.Equal(t, extract("http://localhost/"), []string{""})
assert.Equal(t, extract("http://localhost///"), []string{""})
assert.Equal(t, extract("http://localhost/foo"), []string{"foo"})
assert.Equal(t, extract("http://localhost///foo"), []string{"foo"})
assert.Equal(t, extract("http://localhost/foo/"), []string{"foo", ""})
assert.Equal(t, extract("http://localhost///foo///"), []string{"foo", ""})
assert.Equal(t, extract("http://localhost/foo/%2Fbar%2F"), []string{"foo", "%2Fbar%2F"})
assert.Equal(t, extract("http://localhost///foo///%2Fbar%2F"), []string{"foo", "%2Fbar%2F"})
assert.Equal(t, extract("http://localhost/foo/%2Fbar%2F/"), []string{"foo", "%2Fbar%2F", ""})
assert.Equal(t, extract("http://localhost///foo///%2Fbar%2F///"), []string{"foo", "%2Fbar%2F", ""})
}
|