tstrings1.pp 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  1. { Basic test suite for the strings unit }
  2. Program TStrings1;
  3. uses
  4. strings;
  5. procedure failed;
  6. begin
  7. writeln('Failed.');
  8. halt(1);
  9. end;
  10. procedure teststrlen;
  11. Const
  12. P1 : PChar = '';
  13. P2 : PChar = 'This is a constant pchar string';
  14. begin
  15. if strlen(P1)<>0 then
  16. failed;
  17. if strlen(P2)<>31 then
  18. failed;
  19. end;
  20. procedure teststrcomp;
  21. Const
  22. P1 : PChar = 'This is the first string.';
  23. P2 : PCHar = 'This is the second string.';
  24. P3 : PChar = 'This is the first string.';
  25. begin
  26. If StrComp (P1,P2)=0 then
  27. failed;
  28. If StrComp (P1,P3)<>0 then
  29. failed;
  30. If StrComp (P1,P2)>0 then
  31. failed;
  32. If StrComp (P2,P1)<0 then
  33. failed;
  34. end;
  35. procedure teststrpas;
  36. Const
  37. P1 : PChar = 'This is a PCHAR string';
  38. P2 : PChar = '';
  39. var
  40. S : string;
  41. begin
  42. S:=StrPas(P1);
  43. if S<>'This is a PCHAR string' then
  44. failed;
  45. S:=StrPas(P2);
  46. if S<>'' then
  47. failed;
  48. end;
  49. procedure teststrlcomp;
  50. Const
  51. P1 : PChar = 'This is the first string.';
  52. P2 : PCHar = 'This is the second string.';
  53. P3 : PChar = 'This is the first string.';
  54. Var
  55. L : Longint;
  56. begin
  57. L:=1;
  58. While StrLComp(P1,P2,L)=0 do
  59. inc (L);
  60. if L<>13 then failed;
  61. If StrLComp (P1,P2,255)=0 then
  62. failed;
  63. If StrLComp (P1,P3,100)<>0 then
  64. failed;
  65. If StrLComp (P1,P2,65535)>0 then
  66. failed;
  67. If StrLComp (P2,P1,12341234)<0 then
  68. failed;
  69. end;
  70. procedure teststrpcopy;
  71. Const
  72. S1 = 'This is a normal string.';
  73. S2 = '';
  74. Var
  75. P : array[0..255] of char;
  76. begin
  77. if StrPCopy(P,S1)<>P then
  78. failed;
  79. if StrComp(P,S1)<>0 then
  80. failed;
  81. if StrPCopy(P,S2)<>P then
  82. failed;
  83. if StrComp(P,S2)<>0 then
  84. failed;
  85. end;
  86. procedure teststrend;
  87. Const
  88. P : PChar = 'This is a PCHAR string.';
  89. begin
  90. If StrEnd(P)-P<>23 then
  91. failed;
  92. end;
  93. procedure teststrcopy;
  94. Const
  95. P1 : PChar = 'This a test string 012345678901234567890123456789012345678901234567890123456789';
  96. P2 : PChar = '';
  97. var
  98. Buf : array[0..255] of char;
  99. begin
  100. if StrCopy(Buf,P1)<>Buf then
  101. failed;
  102. if StrComp(Buf,P1)<>0 then
  103. failed;
  104. if StrCopy(Buf,P2)<>Buf then
  105. failed;
  106. if StrComp(Buf,P2)<>0 then
  107. failed;
  108. end;
  109. procedure teststrscanstrrscan;
  110. Const
  111. P : PChar = 'This is a PCHAR string.';
  112. S : Char = 's' ;
  113. begin
  114. if StrComp(StrScan(P,s),'s is a PCHAR string.')<>0 then
  115. failed;
  116. if StrComp(StrRScan(P,s),'string.')<>0 then
  117. failed;
  118. end;
  119. begin
  120. write('Testing strlen ... ');
  121. teststrlen;
  122. writeln('Success.');
  123. write('Testing strcomp ... ');
  124. teststrcomp;
  125. writeln('Success.');
  126. write('Testing strlcomp ... ');
  127. teststrlcomp;
  128. writeln('Success.');
  129. write('Testing strpas ... ');
  130. teststrpas;
  131. writeln('Success.');
  132. write('Testing strcopy ... ');
  133. teststrcopy;
  134. writeln('Success.');
  135. write('Testing strpcopy ... ');
  136. teststrpcopy;
  137. writeln('Success.');
  138. write('Testing strend ... ');
  139. teststrend;
  140. writeln('Success.');
  141. write('Testing strscan/strrscan ... ');
  142. teststrscanstrrscan;
  143. writeln('Success.');
  144. end.