-
Notifications
You must be signed in to change notification settings - Fork 3
/
example_test.go
60 lines (45 loc) · 1.09 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
package numwords
import "fmt"
func Example() {
s := "I've got three apples and two and a half bananas"
fmt.Println(ParseString(s))
s = "My chili won second place at the county fair"
fmt.Println(ParseString(s))
i, _ := ParseInt("fourteen ninety two")
fmt.Println(i)
f, _ := ParseFloat("eight and three quarters")
fmt.Println(f)
// Output:
// I've got 3 apples and 2.5 bananas
// My chili won 2nd place at the county fair
// 1492
// 8.75
}
func ExampleParseString() {
s := "I've got three apples and two and a half bananas"
fmt.Println(ParseString(s))
// Output:
// I've got 3 apples and 2.5 bananas
}
func ExampleParseFloat() {
f, _ := ParseFloat("eight and three quarters")
fmt.Println(f)
// Output:
// 8.75
}
func ExampleParseInt() {
i, _ := ParseInt("fourteen ninety two")
fmt.Println(i)
// Output:
// 1492
}
func ExampleIncludeSecond() {
s := "My chili won second place at the county fair"
fmt.Println(ParseString(s))
s = "One second ago"
IncludeSecond(false)
fmt.Println(ParseString(s))
// Output:
// My chili won 2nd place at the county fair
// 1 second ago
}