File: string_test.go

package info (click to toggle)
golang-github-vdemeester-shakers 0.0~git20160210.0.24d7f1d-2
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 192 kB
  • ctags: 158
  • sloc: sh: 159; makefile: 25
file content (162 lines) | stat: -rw-r--r-- 6,433 bytes parent folder | download | duplicates (3)
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
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
package shakers

import (
	"github.com/go-check/check"
)

func init() {
	check.Suite(&StringCheckerS{})
}

type StringCheckerS struct{}

func (s *StringCheckerS) TestContains(c *check.C) {
	testInfo(c, Contains, "Contains", []string{"obtained", "substring"})

	testCheck(c, Contains, true, "", "abcd", "bc")
	testCheck(c, Contains, false, "", "abcd", "efg")
	testCheck(c, Contains, false, "", "", "bc")
	testCheck(c, Contains, true, "", "abcd", "")
	testCheck(c, Contains, true, "", "", "")

	testCheck(c, Contains, false, "obtained value is not a string and has no .String().", 12, "1")
	testCheck(c, Contains, false, "substring value must be a string.", "", 1)
}

func (s *StringCheckerS) TestContainsAny(c *check.C) {
	testInfo(c, ContainsAny, "ContainsAny", []string{"obtained", "chars"})

	testCheck(c, ContainsAny, true, "", "abcd", "b")
	testCheck(c, ContainsAny, true, "", "abcd", "b & c")
	testCheck(c, ContainsAny, false, "", "abcd", "e")
	testCheck(c, ContainsAny, false, "", "", "bc")
	testCheck(c, ContainsAny, false, "", "abcd", "")
	testCheck(c, ContainsAny, false, "", "", "")

	testCheck(c, ContainsAny, false, "obtained value is not a string and has no .String().", 12, "1")
	testCheck(c, ContainsAny, false, "chars value must be a string.", "", 1)
}

func (s *StringCheckerS) TestHasPrefix(c *check.C) {
	testInfo(c, HasPrefix, "HasPrefix", []string{"obtained", "prefix"})

	testCheck(c, HasPrefix, true, "", "abcd", "ab")
	testCheck(c, HasPrefix, false, "", "abcd", "efg")
	testCheck(c, HasPrefix, false, "", "", "bc")
	testCheck(c, HasPrefix, true, "", "abcd", "")
	testCheck(c, HasPrefix, true, "", "", "")

	testCheck(c, HasPrefix, false, "obtained value is not a string and has no .String().", 12, "1")
	testCheck(c, HasPrefix, false, "prefix value must be a string.", "", 1)
}

func (s *StringCheckerS) TestHasSuffix(c *check.C) {
	testInfo(c, HasSuffix, "HasSuffix", []string{"obtained", "suffix"})

	testCheck(c, HasSuffix, true, "", "abcd", "cd")
	testCheck(c, HasSuffix, false, "", "abcd", "efg")
	testCheck(c, HasSuffix, false, "", "", "bc")
	testCheck(c, HasSuffix, true, "", "abcd", "")
	testCheck(c, HasSuffix, true, "", "", "")

	testCheck(c, HasSuffix, false, "obtained value is not a string and has no .String().", 12, "1")
	testCheck(c, HasSuffix, false, "suffix value must be a string.", "", 1)
}

func (s *StringCheckerS) TestEqualFold(c *check.C) {
	testInfo(c, EqualFold, "EqualFold", []string{"obtained", "expected"})

	testCheck(c, EqualFold, true, "", "abcd", "ABCD")
	testCheck(c, EqualFold, true, "", "abcd", "AbCd")
	testCheck(c, EqualFold, true, "", "", "")
	testCheck(c, EqualFold, true, "", "๐Ÿธ", "๐Ÿธ")
	testCheck(c, EqualFold, false, "", "๐Ÿญ", "๐Ÿน")
	testCheck(c, EqualFold, false, "", "abcd", "acde")
	testCheck(c, EqualFold, false, "", "", "bc")
	testCheck(c, EqualFold, false, "", "abcd", "")

	testCheck(c, EqualFold, false, "obtained value is not a string and has no .String().", 12, "1")
	testCheck(c, EqualFold, false, "expected value must be a string.", "", 1)
}

func (s *StringCheckerS) TestCount(c *check.C) {
	testInfo(c, Count, "Count", []string{"obtained", "sep", "expected"})

	testCheck(c, Count, true, "", "abcd", "a", 1)
	testCheck(c, Count, true, "", "abcdAbcd", "a", 1)
	testCheck(c, Count, true, "", "abcd", "e", 0)
	testCheck(c, Count, true, "", "ABCD", "a", 0)
	testCheck(c, Count, true, "", "aaaaa", "a", 5)
	testCheck(c, Count, true, "", "๐Ÿญ๐Ÿน", "๐Ÿน", 1)
	testCheck(c, Count, false, "", "aaaaa", "a", 1)
	testCheck(c, Count, false, "", "abcd", "a", 0)
	testCheck(c, Count, false, "", "๐Ÿญ๐Ÿน", "a", 1)

	testCheck(c, Count, false, "obtained value is not a string and has no .String().", 12, "1", 1)
	testCheck(c, Count, false, "sep value must be a string.", "", 1, 1)
	testCheck(c, Count, false, "", "", "", "")
}

func (s *StringCheckerS) TestIndex(c *check.C) {
	testInfo(c, Index, "Index", []string{"obtained", "sep", "expected"})

	testCheck(c, Index, true, "", "abcd", "a", 0)
	testCheck(c, Index, true, "", "abcdAbcd", "a", 0)
	testCheck(c, Index, true, "", "abcdAbcd", "A", 4)
	testCheck(c, Index, true, "", "abcd", "e", -1)
	testCheck(c, Index, true, "", "ABCD", "a", -1)
	testCheck(c, Index, true, "", "aaaaa", "a", 0)
	testCheck(c, Index, false, "", "dcba", "a", 0)
	testCheck(c, Index, false, "", "abcd", "d", 0)

	testCheck(c, Index, false, "obtained value is not a string and has no .String().", 12, "1", 1)
	testCheck(c, Index, false, "sep value must be a string.", "", 1, 1)
	testCheck(c, Index, false, "", "", "", "")
}

func (s *StringCheckerS) TestIndexAny(c *check.C) {
	testInfo(c, IndexAny, "IndexAny", []string{"obtained", "chars", "expected"})

	testCheck(c, IndexAny, true, "", "abcd", "b", 1)
	testCheck(c, IndexAny, true, "", "abcdAbcd", "b & c", 1)
	testCheck(c, IndexAny, true, "", "abcdAbcd", "bc", 1)
	testCheck(c, IndexAny, true, "", "abcdAbcde", "A & e", 4)
	testCheck(c, IndexAny, true, "", "abcdAbcde", "Ae", 4)
	testCheck(c, IndexAny, true, "", "abcd", "e", -1)
	testCheck(c, IndexAny, true, "", "ABCD", "a", -1)
	testCheck(c, IndexAny, false, "", "abcd", "d", 0)
	testCheck(c, IndexAny, false, "", "dcba", "a & b", 0)
	testCheck(c, IndexAny, false, "", "dcba", "ab", 0)

	testCheck(c, IndexAny, false, "obtained value is not a string and has no .String().", 12, "1", 1)
	testCheck(c, IndexAny, false, "chars value must be a string.", "", 1, 1)
	testCheck(c, IndexAny, false, "", "", "", "")
}

func (s *StringCheckerS) TestIsLower(c *check.C) {
	testInfo(c, IsLower, "IsLower", []string{"obtained"})

	testCheck(c, IsLower, true, "", "abcd")
	testCheck(c, IsLower, true, "", "1234")
	testCheck(c, IsLower, true, "", "abcd abcde")
	testCheck(c, IsLower, true, "", "ั…ะปะตะฑ")
	testCheck(c, IsLower, false, "", "ABCD")
	testCheck(c, IsLower, false, "", "Abcd")
	testCheck(c, IsLower, false, "", "ABCD ABCD")

	testCheck(c, IsLower, false, "obtained value is not a string and has no .String().", 12)
}

func (s *StringCheckerS) TestIsUpper(c *check.C) {
	testInfo(c, IsUpper, "IsUpper", []string{"obtained"})

	testCheck(c, IsUpper, true, "", "1234")
	testCheck(c, IsUpper, true, "", "ABCD")
	testCheck(c, IsUpper, true, "", "ABCD ABCD")
	testCheck(c, IsUpper, true, "", "ะฅะ›ะ•ะ‘")
	testCheck(c, IsUpper, false, "", "abcd")
	testCheck(c, IsUpper, false, "", "Abcd")
	testCheck(c, IsUpper, false, "", "abcd abcde")

	testCheck(c, IsUpper, false, "obtained value is not a string and has no .String().", 12)
}