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