package websource import ( "slices" "testing" ) func mentioned(text string) []string { var out []string for _, u := range Mentions(text) { out = append(out, u.String()) } return out } // TestMentions: the person's own words give their http(s) URLs as typed // (made canonical) and their bare domains as https:///, in the // order written, once each. File names, e-mail addresses, abbreviations, // version numbers and refused hosts are not sources. func TestMentions(t *testing.T) { for text, want := range map[string][]string{ "Make it look like https://shop.example.com/about.": {"https://shop.example.com/about"}, "Our site is shop.example.com, and the menu is at shop.example.com/menu": {"https://shop.example.com/", "https://shop.example.com/menu"}, "(see http://Example.org/Hours?day=mon) and HTTPS://example.net": {"http://example.org/Hours?day=mon", "https://example.net/"}, "https://shop.example.com and shop.example.com again": {"https://shop.example.com/"}, "Fix README.md and main.go, like Next.js does, e.g. in v1.2.3 i.e. now": nil, "Mail owner@shop.example.com or first.last@example.org": nil, "Not http://localhost:8080/, http://10.0.0.1/ or box.example.ts.net": nil, "ftp://example.com/file and https://user:pw@example.com/": nil, "Brand: barber.example.co.uk; logo at https://cdn.example.com/logo.png)": {"https://barber.example.co.uk/", "https://cdn.example.com/logo.png"}, "": nil, } { if got := mentioned(text); !slices.Equal(got, want) { t.Errorf("%q: %v, want %v", text, got, want) } } }