-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTest__String.cs
157 lines (127 loc) · 8.07 KB
/
Test__String.cs
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
namespace TEST;
internal static partial class Program {
static void Test__String() {
PRINT("\n[Utility.STR]");
//PRINT($"{}");
//======================================================================================================================================================
RESULT("RandomDigits()", true
&& RandomDigits(5).Length == 5
&& RandomDigits(5).IsNumeric() == true
);
//======================================================================================================================================================
RESULT("ToBool()", true
&& "true".ToBool() == true
&& "True".ToBool() == true
&& "TRUE".ToBool() == true
&& "TrUe".ToBool() == true
&& "tRuE".ToBool() == true
&& "false".ToBool() == false
&& "False".ToBool() == false
&& "FALSE".ToBool() == false
&& "FaLsE".ToBool() == false
&& "fAlSe".ToBool() == false
&& "".ToBool() == false
&& "blarg".ToBool() == false
);
//RESULT("ToDateTime()", true
// && "".ToDateTime() == System.DateTime.MinValue
//);
RESULT("ToIpAddress()", true
&& "" .ToIpAddress().Equals(new System.Net.IPAddress(0))
&& " " .ToIpAddress().Equals(new System.Net.IPAddress(0))
&& "blarg" .ToIpAddress().Equals(new System.Net.IPAddress(0))
&& "0" .ToIpAddress().Equals(new System.Net.IPAddress(0))
&& "0.0.0.0" .ToIpAddress().Equals(new System.Net.IPAddress(0))
&& "127.0.0.1" .ToIpAddress().Equals(new System.Net.IPAddress(new byte[] { 0x7F, 0x00, 0x00, 0x01 }))
&& "192.168.0.1" .ToIpAddress().Equals(new System.Net.IPAddress(new byte[] { 0xC0, 0xA8, 0x00, 0x01 }))
&& "255.255.255.255".ToIpAddress().Equals(new System.Net.IPAddress(new byte[] { 0xFF, 0xFF, 0xFF, 0xFF }))
);
RESULT("ToNameValueCollection()", true
&& "ABC=123, def=Xyz, G=456, H=1.414, i=0, ABC=789".ToNameValueCollection()["ABC"] == "123,789"
&& "ABC=123, def=Xyz, G=456, H=1.414, i=0, ABC=789".ToNameValueCollection()["def"] == "Xyz"
&& "ABC=123, def=Xyz, G=456, H=1.414, i=0, ABC=789".ToNameValueCollection()["G"] == "456"
&& "ABC=123, def=Xyz, G=456, H=1.414, i=0, ABC=789".ToNameValueCollection()["H"] == "1.414"
&& "ABC=123, def=Xyz, G=456, H=1.414, i=0, ABC=789".ToNameValueCollection()["i"] == "0"
);
//======================================================================================================================================================
RESULT("ByteArrayToString()", true
&& ByteArrayToString(new byte[] { 0xFF, 0xCC, 0xAA }) == "FF CC AA "
&& ByteArrayToString(new byte[] { 0xFF, 0xCC, 0xAA, 0x99, 0x77, 0x55, 0x33, 0x11 }, 3) == "FF CC AA \n99 77 55 \n33 11 "
);
RESULT(".EnumerableToString()", true
&& EnumerableToString(new string[] { "Aa", "Bb", "Cc", "Dd", "Ee", "Ff", "Gg", "Hh", "Ii" }) == "Aa, Bb, Cc, Dd, Ee, Ff, Gg, Hh, Ii"
&& EnumerableToString("AaBbCcDdEeFfGgHhIi") == "A, a, B, b, C, c, D, d, E, e, F, f, G, g, H, h, I, i"
&& EnumerableToString(new int[] { 1, 2, 3 }) == "1, 2, 3"
);
RESULT(".IntToBinaryString()", true
&& IntToBinaryString((sbyte ) 0x7F) == "01111111"
&& IntToBinaryString((short ) 0x7FFF) == "01111111_11111111"
&& IntToBinaryString((int ) 0x7FFF_FFFF) == "01111111_11111111_11111111_11111111"
&& IntToBinaryString((long )0x7FFF_FFFF_FFFF_FFFF) == "01111111_11111111_11111111_11111111_11111111_11111111_11111111_11111111"
&& IntToBinaryString((byte ) 0xFF) == "11111111"
&& IntToBinaryString((ushort) 0xFFFF) == "11111111_11111111"
&& IntToBinaryString((uint ) 0xFFFF_FFFF) == "11111111_11111111_11111111_11111111"
&& IntToBinaryString((ulong )0xFFFF_FFFF_FFFF_FFFF) == "11111111_11111111_11111111_11111111_11111111_11111111_11111111_11111111"
);
//======================================================================================================================================================
RESULT(".IsNumeric()", true
&& "123".IsNumeric() == true
&& "-123".IsNumeric() == false
&& "-123".IsNumeric(true) == true
&& "-123.456".IsNumeric(true) == false
&& "-123.456".IsNumeric(true,true) == true
&& "123.456".IsNumeric(false,true) == true
&& "ab12".IsNumeric() == false
&& "123_".IsNumeric() == false
&& "123 ".IsNumeric() == false
);
RESULT(".IsValidEmailAddress()", true
&& "user@sub.domain.top".IsValidEmailAddress() == true
&& "user@sub.domain.top".IsValidEmailAddress("top", "domain", "sub" ) == true
&& "user@sub.domain.top".IsValidEmailAddress("top", "domain" ) == true
&& "user@sub.domain.top".IsValidEmailAddress("top" ) == true
&& "user@sub.domain.top".IsValidEmailAddress("top", "domain", "blarg") == false
&& "user@sub.domain.top".IsValidEmailAddress("top", "blarg" ) == false
&& "user@sub.domain.top".IsValidEmailAddress("blarg" ) == false
);
RESULT(".IsVoid()", true
&& "blarg".IsVoid() == false
&& " ".IsVoid() == true
&& " \n ".IsVoid() == true
&& " \t ".IsVoid() == true
&& "\n\t ".IsVoid() == true
&& "".IsVoid() == true
&& ((string)null).IsVoid() == true
);
//======================================================================================================================================================
RESULT(".ContainsAny()", true
&& "blarg".ContainsAny( new string[] {"ugh", "arg"} ) == true
);
RESULT(".ContainsAny_GetMatches()", true
&& "blarg".ContainsAny_GetMatches( new string[] {"bla", "ugh", "arg"} )[0] == "bla"
&& "blarg".ContainsAny_GetMatches( new string[] {"bla", "ugh", "arg"} )[1] == "arg"
);
//======================================================================================================================================================
RESULT(".Indent()", true
&& "blarg\nblarg\nblarg".Indent() == " blarg\n blarg\n blarg"
);
RESULT(".InsertEvery()", true
&& "blargblargblarg".InsertEvery(5, ", ") == "blarg, blarg, blarg"
);
RESULT(".Pad()", true
&& "blarg".Pad(-10) == " blarg"
&& "blarg".Pad( 10) == "blarg "
);
RESULT(".Prepend()", true
&& "blarg\nblarg\nblarg".Prepend(" ~~ ") == " ~~ blarg\n ~~ blarg\n ~~ blarg"
);
RESULT(".Repeat()", true
&& $"{"blarg".Repeat(3)}{" ".Repeat(4)}{"blarg".Repeat(3)}" == "blargblargblarg blargblargblarg"
&& $"{"blarg".Repeat(3)}{"\n".Repeat(4)}{"blarg".Repeat(3)}" == "blargblargblarg\n\n\n\nblargblargblarg"
);
RESULT(".ToTitleCase()", true
&& "blarg BLARG bLaRg".ToTitleCase() == "Blarg Blarg Blarg"
);
//======================================================================================================================================================
}
}