2020-12-19 19:43:54 -05:00
|
|
|
//nolint: lll
|
2021-12-23 00:23:06 -05:00
|
|
|
package client
|
2020-08-27 19:57:06 -04:00
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
)
|
|
|
|
|
|
|
|
var normalizeURLTests = []struct {
|
|
|
|
u string
|
|
|
|
expected string
|
|
|
|
}{
|
|
|
|
{"gemini://example.com:1965/", "gemini://example.com/"},
|
|
|
|
{"gemini://example.com", "gemini://example.com/"},
|
|
|
|
{"//example.com", "gemini://example.com/"},
|
|
|
|
{"//example.com:1965", "gemini://example.com/"},
|
|
|
|
{"//example.com:123/", "gemini://example.com:123/"},
|
|
|
|
{"gemini://example.com/", "gemini://example.com/"},
|
|
|
|
{"gemini://example.com/#fragment", "gemini://example.com/"},
|
|
|
|
{"gemini://example.com#fragment", "gemini://example.com/"},
|
|
|
|
{"gemini://user@example.com/", "gemini://example.com/"},
|
|
|
|
// Other schemes, URL isn't modified
|
|
|
|
{"mailto:example@example.com", "mailto:example@example.com"},
|
|
|
|
{"magnet:?xt=urn:btih:test", "magnet:?xt=urn:btih:test"},
|
|
|
|
{"https://example.com", "https://example.com"},
|
2020-12-19 19:41:25 -05:00
|
|
|
// Fixing URL tests
|
2023-05-19 20:08:12 -04:00
|
|
|
// Some commented out due to #324
|
2023-11-03 11:34:18 -04:00
|
|
|
//{"gemini://geminiprotocol.net/%64%6f%63%73/%66%61%71%2e%67%6d%69", "gemini://geminiprotocol.net/docs/faq.gmi"},
|
2020-12-19 19:41:25 -05:00
|
|
|
{"gemini://example.com/蛸", "gemini://example.com/%E8%9B%B8"},
|
2023-11-03 11:34:18 -04:00
|
|
|
//{"gemini://geminiprotocol.net/%64%6f%63%73/;;.'%66%61%71蛸%2e%67%6d%69", "gemini://geminiprotocol.net/docs/%3B%3B.%27faq%E8%9B%B8.gmi"},
|
2020-12-19 19:41:25 -05:00
|
|
|
{"gemini://example.com/?%2Ch%64ello蛸", "gemini://example.com/?%2Chdello%E8%9B%B8"},
|
2021-02-17 09:25:02 -05:00
|
|
|
// IPv6 tests, see #195
|
|
|
|
{"gemini://[::1]", "gemini://[::1]/"},
|
|
|
|
{"gemini://[::1]:1965", "gemini://[::1]/"},
|
|
|
|
{"gemini://[::1]/test", "gemini://[::1]/test"},
|
|
|
|
{"gemini://[::1]:1965/test", "gemini://[::1]/test"},
|
2020-08-27 19:57:06 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestNormalizeURL(t *testing.T) {
|
|
|
|
for _, tt := range normalizeURLTests {
|
2021-12-23 00:23:06 -05:00
|
|
|
actual := NormalizeURL(tt.u)
|
2020-08-27 19:57:06 -04:00
|
|
|
if actual != tt.expected {
|
|
|
|
t.Errorf("normalizeURL(%s): expected %s, actual %s", tt.u, tt.expected, actual)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|