1
0
mirror of synced 2024-12-23 01:33:08 +01:00
x2utils/UnitTests/Units/NamedFormatTest.pas

63 lines
1.5 KiB
ObjectPascal
Raw Normal View History

unit NamedFormatTest;
interface
uses
TestFramework;
type
TNamedFormatTest = class(TTestCase)
published
procedure TestString;
procedure TestNumbers;
procedure TestUnusedKeys;
procedure TestLiteralPercent;
procedure TestLiteralPercentLiteralBracket;
end;
implementation
uses
X2UtNamedFormat;
{ TNamedFormatTest }
procedure TNamedFormatTest.TestString;
begin
CheckEquals('Key = Value', NamedFormat('%<NamedKey>:s = %<NamedValue>:s', ['NamedValue', 'Value',
'NamedKey', 'Key']));
end;
procedure TNamedFormatTest.TestNumbers;
begin
CheckEquals('The answer is, in fact, 42',
NamedFormat('The %<Answer>:s is, in fact, %<LifeUniverseEverything>:d', ['Answer', 'answer',
'LifeUniverseEverything', 42]));
end;
procedure TNamedFormatTest.TestUnusedKeys;
begin
CheckEquals('Used', NamedFormat('%<Used>:s', ['Used', 'Used',
'NotUsed', 'NotUsed']));
end;
procedure TNamedFormatTest.TestLiteralPercent;
begin
CheckEquals('LIKE ''Test%''', NamedFormat('LIKE ''%<Value>:s%%''', ['Value', 'Test']));
end;
procedure TNamedFormatTest.TestLiteralPercentLiteralBracket;
begin
CheckEquals('%<Test', NamedFormat('%%<%<Value>:s', ['Value', 'Test']));
end;
initialization
RegisterTest(TNamedFormatTest.Suite);
end.