This repository has been archived by the owner on Jan 25, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
strings_test.go
119 lines (97 loc) · 2.52 KB
/
strings_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
// Copyright 2013 Vedran Vuk. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package strings
import (
"strings"
"testing"
)
func TestRuneFunctions(t *testing.T) {
in := "teststring"
if LeftByRune(in, 4) != "test" {
t.Error("LeftByRune() failed.")
}
if RightByRune(in, 6) != "string" {
t.Error("RightByRune() failed.")
}
if MidByRune(in, 2, 4) != "stst" {
t.Error("MidByRune() failed.")
}
if !ContainsOther("abcde", "abc") {
t.Error("ContainsOther() failed.")
}
in = strings.Repeat("A", 1024)
a := LenLimitByRune(in, 500)
if len(a) != 500 {
t.Error("LenLimitByRune() failed.")
}
b := LenSplitByRune(in, 384)
if len(b) != 3 {
t.Error("LenSplitByRune() failed.")
} else {
if len(b[0]) != 384 || len(b[1]) != 384 || len(b[2]) != 256 {
t.Error("LenSplitByRune() failed.")
}
}
}
func TestStringFunctions(t *testing.T) {
in := "teststring"
if FetchLeft(in, "str") != "test" {
t.Error("FetchLeft() failed.")
}
if FetchRight(in, "est") != "string" {
t.Error("FetchRight() failed.")
}
if FetchLeftFold(in, "STR") != "test" {
t.Error("FetchLeftFold() failed.")
}
if FetchRightFold(in, "EST") != "string" {
t.Error("FetchRightFold() failed.")
}
if !HasPrefixFold(in, "TEST") {
t.Error("HasPrefixFold() failed.")
}
if !HasSuffixFold(in, "STRING") {
t.Error("HasSuffixFold() failed.")
}
i := Indexes("a.b.c.d.e", ".")
if len(i) != 4 {
t.Error("Indexes() failed.")
}
if i[0] != 1 && i[1] != 3 && i[2] != 5 && i[3] != 7 {
t.Error("Indexes() failed.")
}
j := IndexesFold("1a2a3a4a5", "A")
if len(j) != 4 {
t.Error("Indexes() failed.")
}
if j[0] != 1 && j[1] != 3 && j[2] != 5 && j[3] != 7 {
t.Error("Indexes() failed.")
}
if !MatchesWildcard("Dickson", "?ic*n") {
t.Error("MatchesWildcard() failed")
}
if !MatchesWildcard("Sensible", "se?s*le") {
t.Error("MatchesWildcard() failed")
}
if MatchesWildcard("ThisIsWrong", "?hi*IswrongO") {
t.Error("MatchesWildcard() failed")
}
}
func TestAsciiFunctions(t *testing.T) {
if !IsNumsOnly("12345") {
t.Error("IsNumsOnly() failed.")
}
if !IsAlphaLowerOnly("abcde") {
t.Error("IsAlphaLowerOnly() failed.")
}
if !IsAlphaUpperOnly("ABCDE") {
t.Error("IsAlphaUpperOnly() failed.")
}
if !IsAlphaOnly("abcdeABCDE") {
t.Error("IsAlphaOnly() failed.")
}
if !IsAlphaNumsOnly("12345abcdeABCDE") {
t.Error("IsAlphaNumsOnly() failed.")
}
}