tthlp4.pp 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. { %OPT=-Oonofastmath }
  2. { this tests that the correct helper is used for constants }
  3. program tthlp4;
  4. {$mode objfpc}
  5. {$apptype console}
  6. uses
  7. uthlp;
  8. procedure TestResult(aActual, aExpected, aError: LongInt);
  9. begin
  10. if aActual <> aExpected then begin
  11. Writeln('Expected: ', aExpected, ' got: ', aActual, ' error: ', aError);
  12. Halt(aError);
  13. end;
  14. end;
  15. var
  16. ml: MyLongInt;
  17. begin
  18. Writeln('Ordinal constants');
  19. TestResult(2.Test, -1, 1);
  20. TestResult(-2.Test, -1, 2);
  21. TestResult(200.Test, 1, 3);
  22. TestResult(-200.Test, -2, 4);
  23. TestResult(40000.Test, 2, 5);
  24. TestResult(-20000.Test, -2, 6);
  25. TestResult(-40000.Test, -4, 7);
  26. TestResult(70000.Test, -4, 8);
  27. TestResult(3000000000.Test, 4, 9);
  28. TestResult($1ffffffff.Test, -8, 10);
  29. TestResult($1fffffffffffffff.Test, -8, 11);
  30. Writeln('Float constants');
  31. TestResult(1.25.Test, 4, 12);
  32. {$if sizeof(Extended) = sizeof(Double)}
  33. TestResult(1.25e10.Test, 8, 14);
  34. {$else}
  35. TestResult(1.25e10.Test, 10, 14);
  36. {$endif}
  37. Writeln('Boolean constants');
  38. TestResult(True.Test, 1, 15);
  39. TestResult(False.Test, 1, 16);
  40. Writeln('String constants');
  41. TestResult('ShortString'.Test, 1, 17);
  42. TestResult('UnicodeString'#1234.Test, 4, 18);
  43. Writeln('Misc constants');
  44. TestResult(Nil.Test, 1, 19);
  45. TestResult(teOne.Test, 1, 20);
  46. TestResult('a'.Test, - 1, 21);
  47. TestResult(#1234.Test, - 2, 22);
  48. {$push}
  49. {$T-}
  50. // => Pointer
  51. TestResult((@ml).Test, 1, 23);
  52. {$T+}
  53. // => Pointer as well
  54. TestResult((@ml).Test, 1, 24);
  55. {$pop}
  56. Writeln('OK');
  57. end.