mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2025-08-29 12:30:36 +02:00
codetools: fixed StringToPascalConst, added tests, bug #30955
git-svn-id: trunk@53383 -
This commit is contained in:
parent
c2d88c8f48
commit
7ca0140e65
@ -5101,7 +5101,8 @@ begin
|
|||||||
end;
|
end;
|
||||||
|
|
||||||
function StringToPascalConst(const s: string): string;
|
function StringToPascalConst(const s: string): string;
|
||||||
// converts s to
|
// converts s to a Pascal string literal
|
||||||
|
// e.g. foo becomes 'foo', bytes 0..31 become #ord
|
||||||
|
|
||||||
function Convert(var DestStr: string): integer;
|
function Convert(var DestStr: string): integer;
|
||||||
var
|
var
|
||||||
@ -5111,8 +5112,9 @@ function StringToPascalConst(const s: string): string;
|
|||||||
InString: Boolean;
|
InString: Boolean;
|
||||||
begin
|
begin
|
||||||
SrcLen:=length(s);
|
SrcLen:=length(s);
|
||||||
DestPos:=0;
|
DestPos:=1;
|
||||||
InString:=false;
|
if DestStr<>'' then DestStr[DestPos]:='''';
|
||||||
|
InString:=true;
|
||||||
for SrcPos:=1 to SrcLen do begin
|
for SrcPos:=1 to SrcLen do begin
|
||||||
inc(DestPos);
|
inc(DestPos);
|
||||||
c:=s[SrcPos];
|
c:=s[SrcPos];
|
||||||
@ -5126,8 +5128,8 @@ function StringToPascalConst(const s: string): string;
|
|||||||
if DestStr<>'' then
|
if DestStr<>'' then
|
||||||
DestStr[DestPos]:=c;
|
DestStr[DestPos]:=c;
|
||||||
if c='''' then begin
|
if c='''' then begin
|
||||||
if DestStr<>'' then DestStr[DestPos]:='''';
|
|
||||||
inc(DestPos);
|
inc(DestPos);
|
||||||
|
if DestStr<>'' then DestStr[DestPos]:='''';
|
||||||
end;
|
end;
|
||||||
end else begin
|
end else begin
|
||||||
// special char
|
// special char
|
||||||
|
@ -1,19 +1,23 @@
|
|||||||
{
|
{
|
||||||
Test with:
|
Test with:
|
||||||
./runtests --format=plain --suite=TTestBasicCodeTools
|
./testcodetools --format=plain --suite=TTestBasicCodeTools
|
||||||
./runtests --format=plain --suite=TestFindLineEndOrCodeInFrontOfPosition
|
./testcodetools --format=plain --suite=TestFindLineEndOrCodeInFrontOfPosition
|
||||||
./runtests --format=plain --suite=TestHasTxtWord
|
./testcodetools --format=plain --suite=TestHasTxtWord
|
||||||
./runtests --format=plain --suite=TestBasicFindCommentEnd
|
./testcodetools --format=plain --suite=TestBasicFindCommentEnd
|
||||||
./runtests --format=plain --suite=TestBasicFindNextComment
|
./testcodetools --format=plain --suite=TestBasicFindNextComment
|
||||||
./runtests --format=plain --suite=TestCompareTextIgnoringSpace
|
./testcodetools --format=plain --suite=TestCompareTextIgnoringSpace
|
||||||
./runtests --format=plain --suite=TestCleanCodeFromComments
|
./testcodetools --format=plain --suite=TestCleanCodeFromComments
|
||||||
./runtests --format=plain --suite=TestGuessIndentSize
|
./testcodetools --format=plain --suite=TestGuessIndentSize
|
||||||
./runtests --format=plain --suite=TestReindent
|
./testcodetools --format=plain --suite=TestReindent
|
||||||
./runtests --format=plain --suite=TestSimpleFormat
|
./testcodetools --format=plain --suite=TestSimpleFormat
|
||||||
./runtests --format=plain --suite=TestDateToCfgStr
|
./testcodetools --format=plain --suite=TestStringToPascalConst
|
||||||
./runtests --format=plain --suite=TestFilenameIsMatching
|
|
||||||
./runtests --format=plain --suite=TestExtractFileUnitname
|
./testcodetools --format=plain --suite=TestDateToCfgStr
|
||||||
./runtests --format=plain --suite=TestChangeLineEndings
|
./testcodetools --format=plain --suite=TestFilenameIsMatching
|
||||||
|
./testcodetools --format=plain --suite=TestExtractFileUnitname
|
||||||
|
./testcodetools --format=plain --suite=TestParseFPCParameters
|
||||||
|
|
||||||
|
./testcodetools --format=plain --suite=TestChangeLineEndings
|
||||||
}
|
}
|
||||||
unit TestBasicCodetools;
|
unit TestBasicCodetools;
|
||||||
|
|
||||||
@ -41,6 +45,7 @@ type
|
|||||||
procedure TestGuessIndentSize;
|
procedure TestGuessIndentSize;
|
||||||
procedure TestReIndent;
|
procedure TestReIndent;
|
||||||
procedure TestSimpleFormat;
|
procedure TestSimpleFormat;
|
||||||
|
procedure TestStringToPascalConst;
|
||||||
// FileProcs
|
// FileProcs
|
||||||
procedure TestDateToCfgStr;
|
procedure TestDateToCfgStr;
|
||||||
procedure TestFilenameIsMatching;
|
procedure TestFilenameIsMatching;
|
||||||
@ -292,6 +297,27 @@ begin
|
|||||||
t('A%1:s%0:sB',['Foo','Bar'],'ABarFooB');
|
t('A%1:s%0:sB',['Foo','Bar'],'ABarFooB');
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
procedure TTestBasicCodeTools.TestStringToPascalConst;
|
||||||
|
|
||||||
|
procedure t(s, Expected: string);
|
||||||
|
var
|
||||||
|
Actual: String;
|
||||||
|
begin
|
||||||
|
Actual:=StringToPascalConst(s);
|
||||||
|
AssertEquals('StringToPascalConst <'+DbgStr(s)+'>',Expected,Actual);
|
||||||
|
end;
|
||||||
|
|
||||||
|
begin
|
||||||
|
t('','''''');
|
||||||
|
t('Foo','''Foo''');
|
||||||
|
t('Foo"','''Foo"''');
|
||||||
|
t('Foo''','''Foo''''''');
|
||||||
|
t('Fo''o','''Fo''''o''');
|
||||||
|
t('''Foo','''''''Foo''');
|
||||||
|
t('Foo'#10,'''Foo''#10');
|
||||||
|
t('Foo'#10'Bar','''Foo''#10''Bar''');
|
||||||
|
end;
|
||||||
|
|
||||||
procedure TTestBasicCodeTools.TestDateToCfgStr;
|
procedure TTestBasicCodeTools.TestDateToCfgStr;
|
||||||
|
|
||||||
procedure t(const Date: TDateTime; const aFormat, Expected: string);
|
procedure t(const Date: TDateTime; const aFormat, Expected: string);
|
||||||
|
Loading…
Reference in New Issue
Block a user