Exemple #1
0
func TestEmojiWithPunctuation(t *testing.T) {
	is := is.New(t)
	src := []byte(`":beer:"?`)
	notes, err := emoji.Find(src)
	is.NoErr(err)
	is.OK(notes)
	is.Equal(len(notes), 1)
	is.Equal(notes[0].Val, []byte(`:beer:`))
	is.Equal(notes[0].Start, 1)
	is.Equal(notes[0].End(), 1+len(notes[0].Val))
	is.Equal(notes[0].Kind, "emoji")

	e := anno.Expander{
		"emoji": emoji.Expand,
	}
	is.Equal(e.Expand(string(src), notes), `"🍺"?`)

}
Exemple #2
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>.`)

}
Exemple #3
0
func TestEmoji(t *testing.T) {
	is := is.New(t)
	src := []byte(":beer: makes me want to :smile: you know.")
	notes, err := emoji.Find(src)
	is.NoErr(err)
	is.OK(notes)
	is.Equal(len(notes), 2)
	is.Equal(notes[0].Val, []byte(":beer:"))
	is.Equal(notes[0].Start, 0)
	is.Equal(notes[0].End(), 0+len(notes[0].Val))
	is.Equal(notes[0].Kind, "emoji")
	is.Equal(notes[1].Val, []byte(":smile:"))
	is.Equal(notes[1].Start, 24)
	is.Equal(notes[1].End(), 24+len(notes[1].Val))
	is.Equal(notes[1].Kind, "emoji")

	e := anno.Expander{
		"emoji": emoji.Expand,
	}
	is.Equal(e.Expand(string(src), notes), "🍺 makes me want to 😄 you know.")

}