104 lines
2.2 KiB
Go
104 lines
2.2 KiB
Go
package gemini
|
|
|
|
import (
|
|
"reflect"
|
|
"testing"
|
|
)
|
|
|
|
func TestParseURL(t *testing.T) {
|
|
t.Parallel()
|
|
input := "gemini://caolan.uk/cgi-bin/weather.py/wxfcs/3162"
|
|
parsed, err := ParseURL(input, "")
|
|
value, _ := parsed.Value()
|
|
if err != nil || !(value == "gemini://caolan.uk:1965/cgi-bin/weather.py/wxfcs/3162") {
|
|
t.Errorf("fail: %s", parsed)
|
|
}
|
|
}
|
|
|
|
func TestDeriveAbsoluteURL_abs_url_input(t *testing.T) {
|
|
t.Parallel()
|
|
currentURL := URL{
|
|
Protocol: "gemini",
|
|
Hostname: "smol.gr",
|
|
Port: 1965,
|
|
Path: "/a/b",
|
|
Descr: "Nothing",
|
|
Full: "gemini://smol.gr:1965/a/b",
|
|
}
|
|
input := "gemini://a.b/c"
|
|
output, err := DeriveAbsoluteURL(currentURL, input)
|
|
if err != nil {
|
|
t.Errorf("fail: %v", err)
|
|
}
|
|
expected := &URL{
|
|
Protocol: "gemini",
|
|
Hostname: "a.b",
|
|
Port: 1965,
|
|
Path: "/c",
|
|
Descr: "",
|
|
Full: "gemini://a.b:1965/c",
|
|
}
|
|
pass := reflect.DeepEqual(output, expected)
|
|
if !pass {
|
|
t.Errorf("fail: %#v != %#v", output, expected)
|
|
}
|
|
}
|
|
|
|
func TestDeriveAbsoluteURL_abs_path_input(t *testing.T) {
|
|
t.Parallel()
|
|
currentURL := URL{
|
|
Protocol: "gemini",
|
|
Hostname: "smol.gr",
|
|
Port: 1965,
|
|
Path: "/a/b",
|
|
Descr: "Nothing",
|
|
Full: "gemini://smol.gr:1965/a/b",
|
|
}
|
|
input := "/c"
|
|
output, err := DeriveAbsoluteURL(currentURL, input)
|
|
if err != nil {
|
|
t.Errorf("fail: %v", err)
|
|
}
|
|
expected := &URL{
|
|
Protocol: "gemini",
|
|
Hostname: "smol.gr",
|
|
Port: 1965,
|
|
Path: "/c",
|
|
Descr: "",
|
|
Full: "gemini://smol.gr:1965/c",
|
|
}
|
|
pass := reflect.DeepEqual(output, expected)
|
|
if !pass {
|
|
t.Errorf("fail: %#v != %#v", output, expected)
|
|
}
|
|
}
|
|
|
|
func TestDeriveAbsoluteURL_rel_path_input(t *testing.T) {
|
|
t.Parallel()
|
|
currentURL := URL{
|
|
Protocol: "gemini",
|
|
Hostname: "smol.gr",
|
|
Port: 1965,
|
|
Path: "/a/b",
|
|
Descr: "Nothing",
|
|
Full: "gemini://smol.gr:1965/a/b",
|
|
}
|
|
input := "c/d"
|
|
output, err := DeriveAbsoluteURL(currentURL, input)
|
|
if err != nil {
|
|
t.Errorf("fail: %v", err)
|
|
}
|
|
expected := &URL{
|
|
Protocol: "gemini",
|
|
Hostname: "smol.gr",
|
|
Port: 1965,
|
|
Path: "/a/b/c/d",
|
|
Descr: "",
|
|
Full: "gemini://smol.gr:1965/a/b/c/d",
|
|
}
|
|
pass := reflect.DeepEqual(output, expected)
|
|
if !pass {
|
|
t.Errorf("fail: %#v != %#v", output, expected)
|
|
}
|
|
}
|