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