-
Notifications
You must be signed in to change notification settings - Fork 6
/
utils_test.go
82 lines (76 loc) · 1.38 KB
/
utils_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
package main
import (
"fmt"
"testing"
)
func Example_capitalize() {
fmt.Println(capitalize("hello"))
fmt.Println(capitalize(""))
fmt.Println(capitalize("t"))
// output:
// Hello
//
// T
}
func Example_between() {
fmt.Println(between("AB", "A", "B"))
fmt.Println(between("co ow", "c", "w"))
fmt.Println(between("", "", ""))
fmt.Println(between(" ,\\__/,", ",", ","))
fmt.Println(between("AB", "B", "A"))
fmt.Println(between("hhii", "h", "i"))
// output:
//
// o o
//
// \__/
//
// hi
}
func Example_betweenQuotes() {
fmt.Println(betweenQuotes(`"hi"`))
fmt.Println(betweenQuotes(`asdf "hi" asdf`))
fmt.Println(betweenQuotes(`asdf ""hi"" asdf`))
fmt.Println(betweenQuotes(`asdf "'hi'" asdf`))
fmt.Println(betweenQuotes(`asdf '"hi asdf`))
fmt.Println(betweenQuotes(`asdf '"hi'" asdf`))
// output:
// hi
// hi
// "hi"
// 'hi'
//
// hi'
}
func Example_betweenQuotesOrAfterEquals() {
fmt.Println(betweenQuotesOrAfterEquals("a = 123"))
fmt.Println(betweenQuotesOrAfterEquals(`"asdf"`))
fmt.Println(betweenQuotesOrAfterEquals(`x = "z = fnufnu"`))
// output:
// 123
// asdf
// z = fnufnu
}
func TestHas(t *testing.T) {
if !has("a b c", "b") {
t.Fail()
}
if !has("a b b c", "b") {
t.Fail()
}
if has("", "a") {
t.Fail()
}
if has(" ", "a") {
t.Fail()
}
if has(" ", " ") {
t.Fail()
}
if has(" ", " ") {
t.Fail()
}
if !has(`"a"`, `"a"`) {
t.Fail()
}
}