1
0
mirror of synced 2024-12-22 01:03:07 +01:00

Unit test and fix for literal percent characters in NamedFormat

This commit is contained in:
Mark van Renswoude 2013-04-10 08:25:39 +00:00
parent 2b51a19169
commit be474bd006
4 changed files with 67 additions and 2 deletions

View File

@ -0,0 +1,62 @@
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.

View File

@ -9,7 +9,8 @@ uses
PersistTest in 'Units\PersistTest.pas',
X2UtSingleInstance in '..\X2UtSingleInstance.pas',
X2UtHashes in '..\X2UtHashes.pas',
X2UtHashesVariants in '..\X2UtHashesVariants.pas';
X2UtHashesVariants in '..\X2UtHashesVariants.pas',
NamedFormatTest in 'Units\NamedFormatTest.pas';
//SettingsTest in 'Units\SettingsTest.pas',
//IniParserTest in 'Units\IniParserTest.pas';

View File

@ -54,6 +54,7 @@
<DCCReference Include="..\X2UtSingleInstance.pas" />
<DCCReference Include="Units\BitsTest.pas" />
<DCCReference Include="Units\HashesTest.pas" />
<DCCReference Include="Units\NamedFormatTest.pas" />
<DCCReference Include="Units\PersistTest.pas" />
</ItemGroup>
</Project>

View File

@ -175,7 +175,8 @@ begin
currentPos := nameEnd;
end;
end;
end else
StreamWriteChar(formatStream, currentPos^);
end else
StreamWriteChar(formatStream, currentPos^);