tcsysutils.pas 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. unit tcsysutils;
  2. {$mode ObjFPC}
  3. interface
  4. uses
  5. Classes, SysUtils, fpcunit, testregistry;
  6. Type
  7. { TTestSysutils }
  8. TTestSysutils = Class(TTestCase)
  9. private
  10. procedure TestFormat(Fmt: String; const Args: array of const;
  11. aResult: String);
  12. Published
  13. Procedure TestFormatSimple;
  14. end;
  15. implementation
  16. Procedure TTestSysutils.TestFormat(Fmt : String; Const Args : Array of const; aResult : String);
  17. begin
  18. AssertEquals('Format >>'+Fmt+'<<',aResult,Format(Fmt,Args));
  19. end;
  20. Procedure TTestSysutils.TestFormatSimple;
  21. begin
  22. // Just 1 data item
  23. TestFormat('%s', ['Hello'],'Hello');
  24. // A mix of literal text and a data item
  25. TestFormat('String = %s', ['Hello'],'String = Hello');
  26. // Examples of each of the data types
  27. TestFormat('Decimal = %d', [-123],'Decimal = -123');
  28. {$IFDEF PAS2JS}
  29. TestFormat('Exponent = %e', [12345.678],'Exponent = 1.23E+4');
  30. {$ELSE}
  31. TestFormat('Exponent = %e', [12345.678],'Exponent = 1.2345678000000000E+004');
  32. {$ENDIF}
  33. TestFormat('Fixed = %f', [12345.678],'Fixed = 12345.68');
  34. TestFormat('General = %g', [12345.678],'General = 12345.678');
  35. TestFormat('Number = %n', [12345.678],'Number = 12,345.68');
  36. {$IFDEF PAS2JS}
  37. TestFormat('Money = %m', [12345.678],'Money = $12,345.68');
  38. {$ELSE}
  39. TestFormat('Money = %m', [12345.678],'Money = 12,345.68$');
  40. {$ENDIF}
  41. TestFormat('String = %s', ['Hello'],'String = Hello');
  42. TestFormat('Unsigned decimal = %u', [123],'Unsigned decimal = 123');
  43. TestFormat('Hexadecimal = %x', [140],'Hexadecimal = 8C');
  44. end;
  45. initialization
  46. RegisterTests([TTestSysUtils]);
  47. end.