1 | Unit CharUtilsUnitTests;
|
---|
2 |
|
---|
3 | // NewView - a new OS/2 Help Viewer
|
---|
4 | // Copyright 2006-2009 Ronald Brill (rbri at rbri dot de)
|
---|
5 | // This software is released under the GNU Public License - see readme.txt
|
---|
6 |
|
---|
7 | // UnitTests for CharUtilsUnit
|
---|
8 |
|
---|
9 | Interface
|
---|
10 |
|
---|
11 | uses
|
---|
12 | Classes,
|
---|
13 | SysUtils,
|
---|
14 | TestAssert,
|
---|
15 | CharUtilsUnit;
|
---|
16 |
|
---|
17 | FUNCTION getCharUtilsUnitTests : TList;
|
---|
18 |
|
---|
19 |
|
---|
20 | Implementation
|
---|
21 |
|
---|
22 | PROCEDURE testCharIsDigit_True;
|
---|
23 | VAR
|
---|
24 | tmpResult : boolean;
|
---|
25 | BEGIN
|
---|
26 | tmpResult := CharIsDigit('0');
|
---|
27 | assertTrue('testCharIsDigit_True - 0', tmpResult);
|
---|
28 |
|
---|
29 | tmpResult := CharIsDigit('1');
|
---|
30 | assertTrue('testCharIsDigit_True - 1', tmpResult);
|
---|
31 |
|
---|
32 | tmpResult := CharIsDigit('2');
|
---|
33 | assertTrue('testCharIsDigit_True - 2', tmpResult);
|
---|
34 |
|
---|
35 | tmpResult := CharIsDigit('3');
|
---|
36 | assertTrue('testCharIsDigit_True - 3', tmpResult);
|
---|
37 |
|
---|
38 | tmpResult := CharIsDigit('4');
|
---|
39 | assertTrue('testCharIsDigit_True - 4', tmpResult);
|
---|
40 |
|
---|
41 | tmpResult := CharIsDigit('5');
|
---|
42 | assertTrue('testCharIsDigit_True - 5', tmpResult);
|
---|
43 |
|
---|
44 | tmpResult := CharIsDigit('6');
|
---|
45 | assertTrue('testCharIsDigit_True - 6', tmpResult);
|
---|
46 |
|
---|
47 | tmpResult := CharIsDigit('7');
|
---|
48 | assertTrue('testCharIsDigit_True - 7', tmpResult);
|
---|
49 |
|
---|
50 | tmpResult := CharIsDigit('8');
|
---|
51 | assertTrue('testCharIsDigit_True - 8', tmpResult);
|
---|
52 |
|
---|
53 | tmpResult := CharIsDigit('9');
|
---|
54 | assertTrue('testCharIsDigit_True - 9', tmpResult);
|
---|
55 | END;
|
---|
56 |
|
---|
57 |
|
---|
58 | PROCEDURE testCharIsDigit_False;
|
---|
59 | VAR
|
---|
60 | tmpResult : boolean;
|
---|
61 | BEGIN
|
---|
62 | tmpResult := CharIsDigit('/');
|
---|
63 | assertFalse('testCharIsDigit_False - /', tmpResult);
|
---|
64 |
|
---|
65 | tmpResult := CharIsDigit(':');
|
---|
66 | assertFalse('testCharIsDigit_False - :', tmpResult);
|
---|
67 |
|
---|
68 | tmpResult := CharIsDigit(CharTAB);
|
---|
69 | assertFalse('testCharIsDigit_False - CharTAB', tmpResult);
|
---|
70 |
|
---|
71 | tmpResult := CharIsDigit('a');
|
---|
72 | assertFalse('testCharIsDigit_False - a', tmpResult);
|
---|
73 |
|
---|
74 | tmpResult := CharIsDigit('z');
|
---|
75 | assertFalse('testCharIsDigit_False - z', tmpResult);
|
---|
76 |
|
---|
77 | tmpResult := CharIsDigit('A');
|
---|
78 | assertFalse('testCharIsDigit_False - A', tmpResult);
|
---|
79 |
|
---|
80 | tmpResult := CharIsDigit('Z');
|
---|
81 | assertFalse('testCharIsDigit_False - Z', tmpResult);
|
---|
82 |
|
---|
83 | tmpResult := CharIsDigit(#127);
|
---|
84 | assertFalse('testCharIsDigit_False - #127', tmpResult);
|
---|
85 |
|
---|
86 | tmpResult := CharIsDigit(#255);
|
---|
87 | assertFalse('testCharIsDigit_False - #255', tmpResult);
|
---|
88 |
|
---|
89 | END;
|
---|
90 |
|
---|
91 |
|
---|
92 | // ----------------------------------------------------------
|
---|
93 |
|
---|
94 |
|
---|
95 | PROCEDURE testCharIsAlpha_True;
|
---|
96 | VAR
|
---|
97 | tmpResult : boolean;
|
---|
98 | BEGIN
|
---|
99 | tmpResult := CharIsAlpha('A');
|
---|
100 | assertTrue('testCharIsAlpha_True - A', tmpResult);
|
---|
101 |
|
---|
102 | tmpResult := CharIsAlpha('B');
|
---|
103 | assertTrue('testCharIsAlpha_True - B', tmpResult);
|
---|
104 |
|
---|
105 | tmpResult := CharIsAlpha('X');
|
---|
106 | assertTrue('testCharIsAlpha_True - X', tmpResult);
|
---|
107 |
|
---|
108 | tmpResult := CharIsAlpha('Z');
|
---|
109 | assertTrue('testCharIsAlpha_True - Z', tmpResult);
|
---|
110 |
|
---|
111 | tmpResult := CharIsAlpha('a');
|
---|
112 | assertTrue('testCharIsAlpha_True - a', tmpResult);
|
---|
113 |
|
---|
114 | tmpResult := CharIsAlpha('b');
|
---|
115 | assertTrue('testCharIsAlpha_True - b', tmpResult);
|
---|
116 |
|
---|
117 | tmpResult := CharIsAlpha('x');
|
---|
118 | assertTrue('testCharIsAlpha_True - x', tmpResult);
|
---|
119 |
|
---|
120 | tmpResult := CharIsAlpha('z');
|
---|
121 | assertTrue('testCharIsAlpha_True - z', tmpResult);
|
---|
122 |
|
---|
123 | END;
|
---|
124 |
|
---|
125 |
|
---|
126 | PROCEDURE testCharIsAlpha_False;
|
---|
127 | VAR
|
---|
128 | tmpResult : boolean;
|
---|
129 | BEGIN
|
---|
130 | tmpResult := CharIsAlpha('@');
|
---|
131 | assertFalse('testCharIsAlpha_False - @', tmpResult);
|
---|
132 |
|
---|
133 | tmpResult := CharIsAlpha('[');
|
---|
134 | assertFalse('testCharIsAlpha_False - [', tmpResult);
|
---|
135 |
|
---|
136 | tmpResult := CharIsAlpha(#140);
|
---|
137 | assertFalse('testCharIsAlpha_False - #140', tmpResult);
|
---|
138 |
|
---|
139 | tmpResult := CharIsAlpha('{');
|
---|
140 | assertFalse('testCharIsAlpha_False - {', tmpResult);
|
---|
141 |
|
---|
142 | END;
|
---|
143 |
|
---|
144 |
|
---|
145 | // ---------------
|
---|
146 | // ---- PChar ----
|
---|
147 | // ---------------
|
---|
148 |
|
---|
149 |
|
---|
150 | PROCEDURE testStrPasWithLength_Empty;
|
---|
151 | VAR
|
---|
152 | tmpPChar : PChar;
|
---|
153 | tmpResult : String;
|
---|
154 | BEGIN
|
---|
155 | tmpPChar := '';
|
---|
156 | tmpResult := StrPasWithLength(tmpPChar, 0);
|
---|
157 |
|
---|
158 | assertEqualsAnsiString('testStrPasWithLength_Empty', '', tmpResult);
|
---|
159 | END;
|
---|
160 |
|
---|
161 |
|
---|
162 | PROCEDURE testStrPasWithLength_EmptyLengt11;
|
---|
163 | VAR
|
---|
164 | tmpPChar : PChar;
|
---|
165 | tmpResult : String;
|
---|
166 | BEGIN
|
---|
167 | tmpPChar := '';
|
---|
168 | tmpResult := StrPasWithLength(tmpPChar, 11);
|
---|
169 |
|
---|
170 | assertEqualsAnsiString('testStrPasWithLength_EmptyLengt11', '', tmpResult);
|
---|
171 | END;
|
---|
172 |
|
---|
173 |
|
---|
174 | PROCEDURE testStrPasWithLength_Lengt0;
|
---|
175 | VAR
|
---|
176 | tmpPChar : PChar;
|
---|
177 | tmpResult : String;
|
---|
178 | BEGIN
|
---|
179 | tmpPChar := 'abc';
|
---|
180 | tmpResult := StrPasWithLength(tmpPChar, 0);
|
---|
181 |
|
---|
182 | assertEqualsAnsiString('testStrPasWithLength_Lengt0', '', tmpResult);
|
---|
183 | END;
|
---|
184 |
|
---|
185 |
|
---|
186 | PROCEDURE testStrPasWithLength_FirstChar;
|
---|
187 | VAR
|
---|
188 | tmpPChar : PChar;
|
---|
189 | tmpResult : String;
|
---|
190 | BEGIN
|
---|
191 | tmpPChar := 'abc';
|
---|
192 | tmpResult := StrPasWithLength(tmpPChar, 1);
|
---|
193 |
|
---|
194 | assertEqualsAnsiString('testStrPasWithLength_FirstChar', 'a', tmpResult);
|
---|
195 | END;
|
---|
196 |
|
---|
197 |
|
---|
198 | PROCEDURE testStrPasWithLength_ExactLength;
|
---|
199 | VAR
|
---|
200 | tmpPChar : PChar;
|
---|
201 | tmpResult : String;
|
---|
202 | BEGIN
|
---|
203 | tmpPChar := 'abc';
|
---|
204 | tmpResult := StrPasWithLength(tmpPChar, 3);
|
---|
205 |
|
---|
206 | assertEqualsAnsiString('testStrPasWithLength_ExactLength', 'abc', tmpResult);
|
---|
207 | END;
|
---|
208 |
|
---|
209 |
|
---|
210 | PROCEDURE testStrPasWithLength_LengthOneToBig;
|
---|
211 | VAR
|
---|
212 | tmpPChar : PChar;
|
---|
213 | tmpResult : String;
|
---|
214 | BEGIN
|
---|
215 | tmpPChar := 'abc';
|
---|
216 | tmpResult := StrPasWithLength(tmpPChar, 4);
|
---|
217 |
|
---|
218 | assertEqualsAnsiString('testStrPasWithLength_LengthOneToBig', 'abc', tmpResult);
|
---|
219 | END;
|
---|
220 |
|
---|
221 |
|
---|
222 | PROCEDURE testStrPasWithLength_LengthNegative;
|
---|
223 | VAR
|
---|
224 | tmpPChar : PChar;
|
---|
225 | tmpResult : String;
|
---|
226 | BEGIN
|
---|
227 | tmpPChar := 'abc';
|
---|
228 | tmpResult := StrPasWithLength(tmpPChar, -4);
|
---|
229 |
|
---|
230 | assertEqualsAnsiString('testStrPasWithLength_LengthNegative', '', tmpResult);
|
---|
231 | END;
|
---|
232 |
|
---|
233 |
|
---|
234 | // ----------------------------------------------------------
|
---|
235 |
|
---|
236 | PROCEDURE testPCharPointerDiff_Same;
|
---|
237 | VAR
|
---|
238 | tmpMinuend : PChar;
|
---|
239 | tmpSubtrahend : PChar;
|
---|
240 | tmpResult : Longword;
|
---|
241 | BEGIN
|
---|
242 | tmpMinuend := 'abc';
|
---|
243 | tmpSubtrahend := tmpMinuend;
|
---|
244 | tmpResult := PCharPointerDiff(tmpMinuend, tmpSubtrahend);
|
---|
245 |
|
---|
246 | assertEqualsLongWord('testPCharPointerDiff_Same', 0, tmpResult);
|
---|
247 | END;
|
---|
248 |
|
---|
249 |
|
---|
250 | PROCEDURE testPCharPointerDiff;
|
---|
251 | VAR
|
---|
252 | tmpMinuend : PChar;
|
---|
253 | tmpSubtrahend : PChar;
|
---|
254 | tmpResult : Longword;
|
---|
255 | BEGIN
|
---|
256 | tmpSubtrahend := 'abcdef';
|
---|
257 | tmpMinuend := tmpSubtrahend + 2;
|
---|
258 | assertEqualsString('testPCharPointerDiff', 'cdef', StrPas(tmpMinuend));
|
---|
259 |
|
---|
260 | tmpResult := PCharPointerDiff(tmpMinuend, tmpSubtrahend);
|
---|
261 |
|
---|
262 | assertEqualsLongWord('testPCharPointerDiff_Same', 2, tmpResult);
|
---|
263 | END;
|
---|
264 |
|
---|
265 |
|
---|
266 | // ----------------------------------------------------------
|
---|
267 |
|
---|
268 |
|
---|
269 | FUNCTION getCharUtilsUnitTests : TList;
|
---|
270 | BEGIN
|
---|
271 | result := TList.Create;
|
---|
272 |
|
---|
273 | result.add(@testCharIsDigit_True);
|
---|
274 | result.add(@testCharIsDigit_False);
|
---|
275 |
|
---|
276 | result.add(@testCharIsAlpha_True);
|
---|
277 | result.add(@testCharIsAlpha_False);
|
---|
278 |
|
---|
279 |
|
---|
280 | result.add(@testStrPasWithLength_Empty);
|
---|
281 | result.add(@testStrPasWithLength_EmptyLengt11);
|
---|
282 | result.add(@testStrPasWithLength_Lengt0);
|
---|
283 | result.add(@testStrPasWithLength_FirstChar);
|
---|
284 | result.add(@testStrPasWithLength_ExactLength);
|
---|
285 | result.add(@testStrPasWithLength_LengthOneToBig);
|
---|
286 | result.add(@testStrPasWithLength_LengthNegative);
|
---|
287 |
|
---|
288 | result.add(@testPCharPointerDiff_Same);
|
---|
289 | result.add(@testPCharPointerDiff);
|
---|
290 |
|
---|
291 | END;
|
---|
292 |
|
---|
293 | END.
|
---|