Beispiel #1
0
func TestFindManyString(t *testing.T) {

	is := is.New(t)
	src := "This is a #long string written by @mat containing links to https://downlist.io/."

	notes, err := anno.FindManyString(src, anno.URLs, anno.Mentions, anno.Hashtags)
	is.NoErr(err)
	is.Equal(len(notes), 3)

}
Beispiel #2
0
func TestFindManyURLsWithPunctuation(t *testing.T) {

	is := is.New(t)
	src := "What do you think about Facebook.com and Yahoo.com and Google.com?"

	notes, err := anno.FindManyString(src, anno.URLs)
	is.NoErr(err)
	is.Equal(len(notes), 3)

}
Beispiel #3
0
func TestExpander(t *testing.T) {
	is := is.New(t)

	expander := anno.Expander{
		"url": func(b string) string {
			return fmt.Sprintf(`<a href="%[1]s">%[1]s</a>`, b)
		},
		"mention": func(b string) string {
			return fmt.Sprintf(`<a href="https://downlist.io/%[1]s">%[1]s</a>`, b)
		},
	}
	src := "This is a #long string written by @mat containing links to https://downlist.io/."
	notes, err := anno.FindManyString(src, anno.Mentions, anno.URLs, anno.Hashtags)
	is.NoErr(err)

	out := expander.Expand(src, notes)
	is.Equal(out, `This is a #long string written by <a href="https://downlist.io/@mat">@mat</a> containing links to <a href="https://downlist.io/">https://downlist.io/</a>.`)

}