-
Notifications
You must be signed in to change notification settings - Fork 12
/
examples_test.go
128 lines (103 loc) Β· 2.68 KB
/
examples_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
package turtle
import (
"fmt"
"os"
)
// Example for using the Emojis map to find an
// emoji for the specified name.
func ExampleEmojis() {
name := "turtle"
emoji, ok := Emojis[name]
if !ok {
fmt.Fprintf(os.Stderr, "no emoji found for name: %v\n", name)
os.Exit(1)
}
fmt.Printf("Name: %q\n", emoji.Name)
fmt.Printf("Char: %s\n", emoji.Char)
fmt.Printf("Category: %q\n", emoji.Category)
fmt.Printf("Keywords: %q\n", emoji.Keywords)
// Output:
// Name: "turtle"
// Char: π’
// Category: "animals_and_nature"
// Keywords: ["animal" "slow" "nature" "tortoise"]
}
// Example for using the EmojisByChar map to find an
// emoji for the specified emoji character.
func ExampleEmojisByChar() {
char := "π’"
emoji, ok := EmojisByChar[char]
if !ok {
fmt.Fprintf(os.Stderr, "no emoji found for char: %v\n", char)
os.Exit(1)
}
fmt.Printf("Name: %q\n", emoji.Name)
fmt.Printf("Char: %s\n", emoji.Char)
fmt.Printf("Category: %q\n", emoji.Category)
fmt.Printf("Keywords: %q\n", emoji.Keywords)
// Output:
// Name: "turtle"
// Char: π’
// Category: "animals_and_nature"
// Keywords: ["animal" "slow" "nature" "tortoise"]
}
// Example for using the Category function to find all
// emojis of the specified category.
func ExampleCategory() {
c := "travel_and_places"
emojis := Category(c)
if emojis == nil {
fmt.Fprintf(os.Stderr, "no emojis found for category: %v\n", c)
os.Exit(1)
}
fmt.Printf("%s: %s\n", c, emojis[:3])
// Output:
// travel_and_places: [π‘ βοΈ π]
}
// Example for using the Keyword function to find all
// emojis with the specified keyword.
func ExampleKeyword() {
k := "happy"
emojis := Keyword(k)
if emojis == nil {
fmt.Fprintf(os.Stderr, "no emoji found for keyword: %v\n", k)
os.Exit(1)
}
fmt.Printf("%s: %s", k, emojis[:4])
// Output:
// happy: [π π π π]
}
// Example for using the Search function to find all
// emojis with a name that contains the search string.
func ExampleSearch() {
s := "computer"
emojis := Search(s)
if emojis == nil {
fmt.Fprintf(os.Stderr, "no emojis found for search: %v\n", s)
os.Exit(1)
}
fmt.Printf("%s: %s", s, emojis)
// Output:
// computer: [π» π± π₯]
}
// Example for using the Filter function to find all
// emojis in a category with a specific keyword
func ExampleFilter() {
emojis := Filter(func(e *Emoji) bool {
if e.Category == "animals_and_nature" {
for _, keyword := range e.Keywords {
if keyword == "world" {
return true
}
}
}
return false
})
if emojis == nil {
fmt.Fprintf(os.Stderr, "no emojis found in animals_and_nature with keyword world\n")
os.Exit(1)
}
fmt.Printf("emojis: %s", emojis)
// Output:
// emojis: [π π π]
}