tw38549.pp 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226
  1. type
  2. {$ifdef SET_39}
  3. {$define SET_31}
  4. {$endif}
  5. {$ifdef SET_31}
  6. {$define SET_25}
  7. {$endif}
  8. {$ifdef SET_25}
  9. {$define SET_23}
  10. {$endif}
  11. {$ifdef SET_23}
  12. {$define SET_17}
  13. {$endif}
  14. {$ifdef SET_17}
  15. {$define SET_15}
  16. {$endif}
  17. {$ifdef SET_15}
  18. {$define SET_9}
  19. {$endif}
  20. { options for symtables }
  21. tsymtableoption = (
  22. sto_has_helper, { contains at least one helper symbol }
  23. sto_has_generic, { contains at least one generic symbol }
  24. sto_has_operator, { contains at least one operator overload }
  25. sto_needs_init_final, { the symtable needs initialization and/or
  26. finalization of variables/constants }
  27. sto_has_non_trivial_init, { contains at least on managed type that is not
  28. initialized to zero (e.g. a record with management
  29. operators }
  30. sto_above
  31. {$ifdef SET_9}
  32. ,sto_6
  33. ,sto_7
  34. ,sto_8
  35. ,sto_9
  36. {$endif}
  37. {$ifdef SET_15}
  38. ,sto_10
  39. ,sto_11
  40. ,sto_12
  41. ,sto_13
  42. ,sto_14
  43. ,sto_15
  44. {$endif}
  45. {$ifdef SET_17}
  46. ,sto_16
  47. ,sto_17
  48. {$endif}
  49. {$ifdef SET_23}
  50. ,sto_18
  51. ,sto_19
  52. ,sto_20
  53. ,sto_21
  54. ,sto_22
  55. ,sto_23
  56. {$endif}
  57. {$ifdef SET_25}
  58. ,sto_24
  59. ,sto_25
  60. {$endif}
  61. {$ifdef SET_31}
  62. ,sto_26
  63. ,sto_27
  64. ,sto_28
  65. ,sto_29
  66. ,sto_30
  67. ,sto_31
  68. {$endif}
  69. {$ifdef SET_39}
  70. ,sto_32
  71. ,sto_33
  72. ,sto_34
  73. ,sto_35
  74. ,sto_36
  75. ,sto_37
  76. ,sto_38
  77. ,sto_39
  78. {$endif}
  79. );
  80. tsymtableoptions = set of tsymtableoption;
  81. const
  82. ok_count : longint = 0;
  83. error_count : longint = 0;
  84. procedure add_error;
  85. begin
  86. writeln('New error');
  87. inc(error_count);
  88. end;
  89. procedure test(tableoptions : tsymtableoptions; expected : boolean);
  90. begin
  91. if [sto_needs_init_final,sto_has_non_trivial_init] <= tableoptions then
  92. begin
  93. if expected then
  94. begin
  95. writeln('Ok');
  96. inc(ok_count);
  97. end
  98. else
  99. add_error;
  100. end
  101. else
  102. begin
  103. if not expected then
  104. begin
  105. writeln('Ok');
  106. inc(ok_count);
  107. end
  108. else
  109. add_error;
  110. end;
  111. if tableoptions >= [sto_needs_init_final,sto_has_non_trivial_init] then
  112. begin
  113. if expected then
  114. begin
  115. writeln('Ok');
  116. inc(ok_count);
  117. end
  118. else
  119. add_error;
  120. end
  121. else
  122. begin
  123. if not expected then
  124. begin
  125. writeln('Ok');
  126. inc(ok_count);
  127. end
  128. else
  129. add_error;
  130. end
  131. end;
  132. procedure test2(tableoptions1, tableoptions2 : tsymtableoptions; expected : boolean);
  133. begin
  134. if tableoptions1 <= tableoptions2 then
  135. begin
  136. if expected then
  137. begin
  138. writeln('Ok');
  139. inc(ok_count);
  140. end
  141. else
  142. add_error;
  143. end
  144. else
  145. begin
  146. if not expected then
  147. begin
  148. writeln('Ok');
  149. inc(ok_count);
  150. end
  151. else
  152. add_error;
  153. end
  154. end;
  155. var
  156. tableoptions1, tableoptions2 : tsymtableoptions;
  157. begin
  158. tableoptions1:=[];
  159. test(tableoptions1,false);
  160. tableoptions1:=[sto_has_helper];
  161. test(tableoptions1,false);
  162. tableoptions1:=[sto_needs_init_final];
  163. test(tableoptions1,false);
  164. tableoptions1:=[sto_has_non_trivial_init];
  165. test(tableoptions1,false);
  166. tableoptions1:=[sto_needs_init_final,sto_has_non_trivial_init];
  167. test(tableoptions1,true);
  168. tableoptions1:=[sto_has_helper,sto_needs_init_final,sto_has_non_trivial_init];
  169. test(tableoptions1,true);
  170. tableoptions1:=[sto_has_helper,sto_needs_init_final,sto_has_non_trivial_init,sto_above];
  171. test(tableoptions1,true);
  172. tableoptions1:=[sto_has_helper,sto_has_non_trivial_init,sto_above];
  173. test(tableoptions1,false);
  174. tableoptions1:=[];
  175. tableoptions2:=[];
  176. test2(tableoptions1,tableoptions2,true);
  177. test2(tableoptions2,tableoptions1,true);
  178. tableoptions2:=[sto_has_helper];
  179. test2(tableoptions1,tableoptions2,true);
  180. test2(tableoptions2,tableoptions1,false);
  181. tableoptions1:=[sto_needs_init_final,sto_has_non_trivial_init];
  182. tableoptions2:=[sto_needs_init_final,sto_has_non_trivial_init,sto_has_helper];
  183. test2(tableoptions1,tableoptions2,true);
  184. test2(tableoptions2,tableoptions1,false);
  185. test2(tableoptions1,tableoptions1,true);
  186. test2(tableoptions2,tableoptions2,true);
  187. tableoptions1:=[sto_needs_init_final,sto_has_non_trivial_init];
  188. tableoptions2:=[sto_has_helper,sto_needs_init_final,sto_has_non_trivial_init];
  189. test2(tableoptions1,tableoptions2,true);
  190. test2(tableoptions2,tableoptions1,false);
  191. tableoptions1:=[sto_has_helper,sto_needs_init_final,sto_has_non_trivial_init];
  192. tableoptions2:=[sto_needs_init_final,sto_has_non_trivial_init,sto_above];
  193. test2(tableoptions1,tableoptions2,false);
  194. test2(tableoptions2,tableoptions1,false);
  195. writeln('Test for sets of size : ',sizeof(tableoptions1));
  196. if error_count > 0 then
  197. begin
  198. writeln(error_count,' test(s) failed');
  199. writeln(ok_count,' test(s) OK');
  200. halt(1);
  201. end
  202. else
  203. writeln('Test OK: ',ok_count);
  204. end.