-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathexample_test.go
99 lines (84 loc) · 2.99 KB
/
example_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
package text_test
import (
"fmt"
"github.com/go-dedup/text"
)
// for standalone test, change package to `main` and the next func def to,
// func main() {
func ExampleTextCleanser() {
s := "Hello~~, play_ground#5!"
var fn text.TextCleanser = text.Ident
fmt.Println(fn(s))
var fn2 = text.ToLower(fn)
fmt.Println(fn2(s))
var fn3 text.TextCleanser = text.Ident
fn3 = text.ToAppend(" -GOLANG")(text.ToLower(text.ToPrepend("DECORATED: ")(fn3)))
fmt.Println(fn3(s))
// dec is now a text.TextCleanserDecorator, to use it, you still need to
// pass it the function of type text.TextCleanser that you want to decorate.
dec := text.Decorators(
text.ToAppend(" -GOLANG"),
text.SplitCamelCase,
text.ToLower,
text.ToPrepend("DECORATED: "),
text.RemovePunctuation,
)
fn4 := dec(text.Ident)
fmt.Println(fn4(s))
s += "\n.\n%% Something extra: UpperCamelCase and someInitMethod.\n"
fmt.Printf(".\n>>>>\n'%s'\n", s)
fmt.Printf("%#v\n", text.GetWords(s, dec))
dec = text.Decorators(
dec,
text.Compact,
)
fmt.Printf("%#v\n", text.GetWords(s, dec))
fn5 := text.GetWordsFactory(dec)
fmt.Printf("%#v\n", fn5(s))
s = "Andrej cabrillo Gallegos Germany Jankelowicz"
fmt.Printf(".\n>>>>\n'%s'\n", s)
dec = text.Decorators(
text.ToDoubleMetaphone,
)
fmt.Printf("%#v\n", text.GetWords(s, dec))
fmt.Printf("%#v\n", text.GetDoubleMetaphone(s, text.Decorators()))
dec = text.Decorators(
text.SplitCamelCase,
text.Compact,
)
fn5 = text.GetDoubleMetaphoneFactory(dec)
fmt.Printf("%#v\n", fn5(s))
s = "NãoMeFazMal ÇaNeMeFaitPasMal PòssoMangiâFàMâ"
fmt.Printf(".\n>>>>\n'%s'\n", s)
dec = text.Decorators(
text.SplitCamelCaseUnicode,
)
fmt.Printf("%#v\n", text.GetWords(s, dec))
// Output:
// Hello~~, play_ground#5!
// hello~~, play_ground#5!
// DECORATED: hello~~, play_ground#5! -golang
// DECORATED hello play ground 5 golang
// .
// >>>>
// 'Hello~~, play_ground#5!
// .
// %% Something extra: UpperCamelCase and someInitMethod.
// '
// []string{"DECORATED", "hello", "", "", "play", "ground", "5", "", "", "", "", "", "", "something", "extra", "upper", "camel", "case", "and", "some", "init", "method", "", "", "", "golang"}
// []string{"DECORATED", "hello", "play", "ground", "5", "something", "extra", "upper", "camel", "case", "and", "some", "init", "method", "golang"}
// []string{"DECORATED", "hello", "play", "ground", "5", "something", "extra", "upper", "camel", "case", "and", "some", "init", "method", "golang"}
// .
// >>>>
// 'Andrej cabrillo Gallegos Germany Jankelowicz'
// []string{"antrjkprlklkskrmnjnklts", "antrkprkksjrmnanklfx"}
// []string{"antrj", "antr", "kprl", "kpr", "klks", "kks", "krmn", "jrmn", "jnklts", "anklfx"}
// []string{"antrj", "antr", "kprl", "kpr", "klks", "kks", "krmn", "jrmn", "jnklts", "anklfx"}
// .
// >>>>
// 'NãoMeFazMal ÇaNeMeFaitPasMal PòssoMangiâFàMâ'
// []string{"Não", "Me", "Faz", "Mal", "Ça", "Ne", "Me", "Fait", "Pas", "Mal", "Pòsso", "Mangiâ", "Fà", "Mâ"}
}
// to show the full code in GoDoc
type dummy struct {
}