Unit test and fix for literal percent characters in NamedFormat
This commit is contained in:
parent
2b51a19169
commit
be474bd006
62
UnitTests/Units/NamedFormatTest.pas
Normal file
62
UnitTests/Units/NamedFormatTest.pas
Normal 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.
|
@ -9,7 +9,8 @@ uses
|
|||||||
PersistTest in 'Units\PersistTest.pas',
|
PersistTest in 'Units\PersistTest.pas',
|
||||||
X2UtSingleInstance in '..\X2UtSingleInstance.pas',
|
X2UtSingleInstance in '..\X2UtSingleInstance.pas',
|
||||||
X2UtHashes in '..\X2UtHashes.pas',
|
X2UtHashes in '..\X2UtHashes.pas',
|
||||||
X2UtHashesVariants in '..\X2UtHashesVariants.pas';
|
X2UtHashesVariants in '..\X2UtHashesVariants.pas',
|
||||||
|
NamedFormatTest in 'Units\NamedFormatTest.pas';
|
||||||
|
|
||||||
//SettingsTest in 'Units\SettingsTest.pas',
|
//SettingsTest in 'Units\SettingsTest.pas',
|
||||||
//IniParserTest in 'Units\IniParserTest.pas';
|
//IniParserTest in 'Units\IniParserTest.pas';
|
||||||
|
@ -54,6 +54,7 @@
|
|||||||
<DCCReference Include="..\X2UtSingleInstance.pas" />
|
<DCCReference Include="..\X2UtSingleInstance.pas" />
|
||||||
<DCCReference Include="Units\BitsTest.pas" />
|
<DCCReference Include="Units\BitsTest.pas" />
|
||||||
<DCCReference Include="Units\HashesTest.pas" />
|
<DCCReference Include="Units\HashesTest.pas" />
|
||||||
|
<DCCReference Include="Units\NamedFormatTest.pas" />
|
||||||
<DCCReference Include="Units\PersistTest.pas" />
|
<DCCReference Include="Units\PersistTest.pas" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
</Project>
|
</Project>
|
@ -175,7 +175,8 @@ begin
|
|||||||
|
|
||||||
currentPos := nameEnd;
|
currentPos := nameEnd;
|
||||||
end;
|
end;
|
||||||
end;
|
end else
|
||||||
|
StreamWriteChar(formatStream, currentPos^);
|
||||||
end else
|
end else
|
||||||
StreamWriteChar(formatStream, currentPos^);
|
StreamWriteChar(formatStream, currentPos^);
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user