package router import "testing" func TestFirstURL(t *testing.T) { cases := []struct { text string want string }{ {"посмотри https://example.org/page — что там?", "https://example.org/page"}, {"почитай http://example.org/a/b?x=1 и скажи", "http://example.org/a/b?x=1"}, {"вот ссылка: https://example.org/page.", "https://example.org/page"}, {"https://ru.wikipedia.org/wiki/Небо_(значения)", "https://ru.wikipedia.org/wiki/Небо_(значения)"}, // No scheme ⇒ no fetch. A bare dotted word is not an instruction to // reach out to the network. {"посмотри на example.org", ""}, {"открой файл config.json", ""}, {"что нового?", ""}, {"https://", ""}, {"", ""}, } for _, c := range cases { got, ok := FirstURL(c.text) if c.want == "" { if ok { t.Errorf("FirstURL(%q) = %q, want no match", c.text, got) } continue } if !ok || got != c.want { t.Errorf("FirstURL(%q) = %q, %v; want %q", c.text, got, ok, c.want) } } }