mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2025-08-15 01:19:29 +02:00
LazUtils tests: Add a unit test for TestUTF8CompareLatinTextFast. Issue #40014. Cleanup.
This commit is contained in:
parent
7a0af825b3
commit
fa35fa3d85
@ -1,4 +1,4 @@
|
|||||||
unit testfileutil;
|
unit TestFileUtil;
|
||||||
|
|
||||||
{$mode objfpc}{$H+}
|
{$mode objfpc}{$H+}
|
||||||
|
|
||||||
|
@ -5,7 +5,7 @@ unit TestLazUTF16;
|
|||||||
interface
|
interface
|
||||||
|
|
||||||
uses
|
uses
|
||||||
Classes, SysUtils, fpcunit, testglobals, LazUTF8, LazUTF16, LazLogger;
|
Classes, SysUtils, fpcunit, TestGlobals, LazUTF8, LazUTF16, LazLogger;
|
||||||
|
|
||||||
type
|
type
|
||||||
|
|
||||||
|
@ -29,9 +29,10 @@ type
|
|||||||
procedure TestUTF8Pos;
|
procedure TestUTF8Pos;
|
||||||
procedure TestUTF8ToUTF16;
|
procedure TestUTF8ToUTF16;
|
||||||
procedure TestFindInvalidUTF8;
|
procedure TestFindInvalidUTF8;
|
||||||
procedure TestFindUnicodeToUTF8;
|
procedure TestUnicodeToUTF8;
|
||||||
procedure TestUTF8QuotedStr;
|
procedure TestUTF8QuotedStr;
|
||||||
procedure TestUTF8FixBroken;
|
procedure TestUTF8FixBroken;
|
||||||
|
procedure TestUTF8CompareLatinTextFast;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
implementation
|
implementation
|
||||||
@ -168,13 +169,13 @@ begin
|
|||||||
t(#$ED#$A0#$80,0,'3 byte encoding for reserved UTF-16 surrogate halve');
|
t(#$ED#$A0#$80,0,'3 byte encoding for reserved UTF-16 surrogate halve');
|
||||||
end;
|
end;
|
||||||
|
|
||||||
procedure TTestLazUTF8.TestFindUnicodeToUTF8;
|
procedure TTestLazUTF8.TestUnicodeToUTF8;
|
||||||
|
|
||||||
procedure t(CodePoint: cardinal; Expected: string);
|
procedure t(CodePoint: cardinal; Expected: string);
|
||||||
var
|
var
|
||||||
Actual: String;
|
Actual: String;
|
||||||
begin
|
begin
|
||||||
Actual:=LazUTF8.UnicodeToUTF8(CodePoint);
|
Actual:=UnicodeToUTF8(CodePoint);
|
||||||
AssertEquals('CodePoint='+HexStr(CodePoint,8),
|
AssertEquals('CodePoint='+HexStr(CodePoint,8),
|
||||||
dbgMemRange(PChar(Expected),length(Expected)),
|
dbgMemRange(PChar(Expected),length(Expected)),
|
||||||
dbgMemRange(PChar(Actual),length(Actual)));
|
dbgMemRange(PChar(Actual),length(Actual)));
|
||||||
@ -267,6 +268,30 @@ begin
|
|||||||
t(#$F4#$90#$80#$80,' ');
|
t(#$F4#$90#$80#$80,' ');
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
procedure TTestLazUTF8.TestUTF8CompareLatinTextFast;
|
||||||
|
var
|
||||||
|
a, b, c: String;
|
||||||
|
begin
|
||||||
|
// ASCII
|
||||||
|
AssertTrue(UTF8CompareLatinTextFast('abc', 'xyz') < 0);
|
||||||
|
AssertTrue(UTF8CompareLatinTextFast('xyz', 'abc') > 0);
|
||||||
|
AssertTrue(UTF8CompareLatinTextFast('ijk', 'ijk') = 0);
|
||||||
|
// ASCII <-> non-ASCII
|
||||||
|
AssertTrue(UTF8CompareLatinTextFast('hello', 'привет') < 0);
|
||||||
|
AssertTrue(UTF8CompareLatinTextFast('привет', 'hello') > 0);
|
||||||
|
// non-ASCII
|
||||||
|
AssertTrue(UTF8CompareLatinTextFast('привет', 'नमस्ते') < 0); // 'Hello' in Sankrit
|
||||||
|
AssertTrue(UTF8CompareLatinTextFast('नमस्ते', 'привет') > 0);
|
||||||
|
AssertTrue(UTF8CompareLatinTextFast('привет', 'привет') = 0);
|
||||||
|
// Issue #40014
|
||||||
|
a := 'abcä';
|
||||||
|
b := 'abcx';
|
||||||
|
c := 'abc|'; // '|' comes after ['a'..'z','A'..'Z'] in ASCII table.
|
||||||
|
AssertTrue('UTF8CompareLatinTextFast('+a+', '+b+')', UTF8CompareLatinTextFast(a, b) > 0);
|
||||||
|
AssertTrue('UTF8CompareLatinTextFast('+a+', '+c+')', UTF8CompareLatinTextFast(a, c) > 0);
|
||||||
|
AssertTrue('UTF8CompareLatinTextFast('+b+', '+c+')', UTF8CompareLatinTextFast(b, c) < 0);
|
||||||
|
end;
|
||||||
|
|
||||||
initialization
|
initialization
|
||||||
AddToLazUtilsTestSuite(TTestLazUTF8);
|
AddToLazUtilsTestSuite(TTestLazUTF8);
|
||||||
|
|
||||||
|
@ -16,7 +16,7 @@ interface
|
|||||||
|
|
||||||
uses
|
uses
|
||||||
Classes, SysUtils, fpcunit,
|
Classes, SysUtils, fpcunit,
|
||||||
testglobals, LazLogger, LazUTF8, LazStringUtils, LazFileUtils;
|
TestGlobals, LazLogger, LazStringUtils, LazFileUtils;
|
||||||
|
|
||||||
type
|
type
|
||||||
|
|
||||||
@ -33,7 +33,7 @@ type
|
|||||||
|
|
||||||
implementation
|
implementation
|
||||||
|
|
||||||
{ TTestLazUTF8 }
|
{ TTestLazUtils }
|
||||||
|
|
||||||
procedure TTestLazUtils.TestReplaceSubstring;
|
procedure TTestLazUtils.TestReplaceSubstring;
|
||||||
|
|
||||||
|
@ -1,35 +1,29 @@
|
|||||||
<?xml version="1.0"?>
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
<CONFIG>
|
<CONFIG>
|
||||||
<ProjectOptions>
|
<ProjectOptions>
|
||||||
<Version Value="9"/>
|
<Version Value="12"/>
|
||||||
<General>
|
<General>
|
||||||
<Flags>
|
<Flags>
|
||||||
<MainUnitHasCreateFormStatements Value="False"/>
|
<MainUnitHasCreateFormStatements Value="False"/>
|
||||||
<MainUnitHasTitleStatement Value="False"/>
|
<MainUnitHasTitleStatement Value="False"/>
|
||||||
|
<CompatibilityMode Value="True"/>
|
||||||
</Flags>
|
</Flags>
|
||||||
<SessionStorage Value="InProjectDir"/>
|
<SessionStorage Value="InProjectDir"/>
|
||||||
<MainUnit Value="0"/>
|
|
||||||
<UseAppBundle Value="False"/>
|
<UseAppBundle Value="False"/>
|
||||||
<ResourceType Value="res"/>
|
<ResourceType Value="res"/>
|
||||||
</General>
|
</General>
|
||||||
<i18n>
|
<i18n>
|
||||||
<EnableI18N LFM="False"/>
|
<EnableI18N LFM="False"/>
|
||||||
</i18n>
|
</i18n>
|
||||||
<VersionInfo>
|
|
||||||
<StringTable ProductVersion=""/>
|
|
||||||
</VersionInfo>
|
|
||||||
<BuildModes Count="1">
|
<BuildModes Count="1">
|
||||||
<Item1 Name="Default" Default="True"/>
|
<Item1 Name="Default" Default="True"/>
|
||||||
</BuildModes>
|
</BuildModes>
|
||||||
<PublishOptions>
|
<PublishOptions>
|
||||||
<Version Value="2"/>
|
<Version Value="2"/>
|
||||||
<IncludeFileFilter Value="*.(pas|pp|inc|lfm|lpr|lrs|lpi|lpk|sh|xml)"/>
|
|
||||||
<ExcludeFileFilter Value="*.(bak|ppu|o|so);*~;backup"/>
|
|
||||||
</PublishOptions>
|
</PublishOptions>
|
||||||
<RunParams>
|
<RunParams>
|
||||||
<local>
|
<local>
|
||||||
<FormatVersion Value="1"/>
|
<FormatVersion Value="1"/>
|
||||||
<LaunchingApplication PathPlusParams="/usr/bin/xterm -T 'Lazarus Run Output' -e $(LazarusDir)/tools/runwait.sh $(TargetCmdLine)"/>
|
|
||||||
</local>
|
</local>
|
||||||
</RunParams>
|
</RunParams>
|
||||||
<RequiredPackages Count="1">
|
<RequiredPackages Count="1">
|
||||||
@ -46,7 +40,7 @@
|
|||||||
</Units>
|
</Units>
|
||||||
</ProjectOptions>
|
</ProjectOptions>
|
||||||
<CompilerOptions>
|
<CompilerOptions>
|
||||||
<Version Value="10"/>
|
<Version Value="11"/>
|
||||||
<Target>
|
<Target>
|
||||||
<Filename Value="testunicode"/>
|
<Filename Value="testunicode"/>
|
||||||
</Target>
|
</Target>
|
||||||
@ -56,16 +50,9 @@
|
|||||||
</SearchPaths>
|
</SearchPaths>
|
||||||
<Linking>
|
<Linking>
|
||||||
<Debugging>
|
<Debugging>
|
||||||
<GenerateDebugInfo Value="True"/>
|
<DebugInfoType Value="dsDwarf3"/>
|
||||||
<DebugInfoType Value="dsAuto"/>
|
|
||||||
</Debugging>
|
</Debugging>
|
||||||
</Linking>
|
</Linking>
|
||||||
<Other>
|
|
||||||
<CompilerMessages>
|
|
||||||
<UseMsgFile Value="True"/>
|
|
||||||
</CompilerMessages>
|
|
||||||
<CompilerPath Value="$(CompPath)"/>
|
|
||||||
</Other>
|
|
||||||
</CompilerOptions>
|
</CompilerOptions>
|
||||||
<Debugging>
|
<Debugging>
|
||||||
<Exceptions Count="3">
|
<Exceptions Count="3">
|
||||||
|
@ -5,6 +5,9 @@
|
|||||||
<PathDelim Value="\"/>
|
<PathDelim Value="\"/>
|
||||||
<General>
|
<General>
|
||||||
<Flags>
|
<Flags>
|
||||||
|
<MainUnitHasCreateFormStatements Value="False"/>
|
||||||
|
<MainUnitHasTitleStatement Value="False"/>
|
||||||
|
<MainUnitHasScaledStatement Value="False"/>
|
||||||
<LRSInOutputDirectory Value="False"/>
|
<LRSInOutputDirectory Value="False"/>
|
||||||
<CompatibilityMode Value="True"/>
|
<CompatibilityMode Value="True"/>
|
||||||
</Flags>
|
</Flags>
|
||||||
@ -61,14 +64,14 @@
|
|||||||
</PublishOptions>
|
</PublishOptions>
|
||||||
<RunParams>
|
<RunParams>
|
||||||
<local>
|
<local>
|
||||||
<CommandLineParams Value="-s bugs.2068 --file=results.xml"/>
|
<CommandLineParams Value="--suite=TTestLazUTF8"/>
|
||||||
<LaunchingApplication PathPlusParams="\usr\X11R6\bin\xterm -T 'Lazarus Run Output' -e $(LazarusDir)\tools\runwait.sh $(TargetCmdLine)"/>
|
<LaunchingApplication PathPlusParams="\usr\X11R6\bin\xterm -T 'Lazarus Run Output' -e $(LazarusDir)\tools\runwait.sh $(TargetCmdLine)"/>
|
||||||
</local>
|
</local>
|
||||||
<FormatVersion Value="2"/>
|
<FormatVersion Value="2"/>
|
||||||
<Modes Count="1">
|
<Modes Count="1">
|
||||||
<Mode0 Name="default">
|
<Mode0 Name="default">
|
||||||
<local>
|
<local>
|
||||||
<CommandLineParams Value="-s bugs.2068 --file=results.xml"/>
|
<CommandLineParams Value="--suite=TTestLazUTF8"/>
|
||||||
<LaunchingApplication PathPlusParams="\usr\X11R6\bin\xterm -T 'Lazarus Run Output' -e $(LazarusDir)\tools\runwait.sh $(TargetCmdLine)"/>
|
<LaunchingApplication PathPlusParams="\usr\X11R6\bin\xterm -T 'Lazarus Run Output' -e $(LazarusDir)\tools\runwait.sh $(TargetCmdLine)"/>
|
||||||
</local>
|
</local>
|
||||||
</Mode0>
|
</Mode0>
|
||||||
@ -94,7 +97,7 @@
|
|||||||
<PackageName Value="lazmouseandkeyinput"/>
|
<PackageName Value="lazmouseandkeyinput"/>
|
||||||
</Item6>
|
</Item6>
|
||||||
</RequiredPackages>
|
</RequiredPackages>
|
||||||
<Units Count="14">
|
<Units Count="16">
|
||||||
<Unit0>
|
<Unit0>
|
||||||
<Filename Value="runtests.lpr"/>
|
<Filename Value="runtests.lpr"/>
|
||||||
<IsPartOfProject Value="True"/>
|
<IsPartOfProject Value="True"/>
|
||||||
@ -112,10 +115,12 @@
|
|||||||
<Unit3>
|
<Unit3>
|
||||||
<Filename Value="testglobals.pas"/>
|
<Filename Value="testglobals.pas"/>
|
||||||
<IsPartOfProject Value="True"/>
|
<IsPartOfProject Value="True"/>
|
||||||
|
<UnitName Value="TestGlobals"/>
|
||||||
</Unit3>
|
</Unit3>
|
||||||
<Unit4>
|
<Unit4>
|
||||||
<Filename Value="testunits.pas"/>
|
<Filename Value="testunits.pas"/>
|
||||||
<IsPartOfProject Value="True"/>
|
<IsPartOfProject Value="True"/>
|
||||||
|
<UnitName Value="TestUnits"/>
|
||||||
</Unit4>
|
</Unit4>
|
||||||
<Unit5>
|
<Unit5>
|
||||||
<Filename Value="lcltests\testpen.pas"/>
|
<Filename Value="lcltests\testpen.pas"/>
|
||||||
@ -128,6 +133,7 @@
|
|||||||
<Unit7>
|
<Unit7>
|
||||||
<Filename Value="lazutils\testlazutils.pas"/>
|
<Filename Value="lazutils\testlazutils.pas"/>
|
||||||
<IsPartOfProject Value="True"/>
|
<IsPartOfProject Value="True"/>
|
||||||
|
<UnitName Value="TestLazUtils"/>
|
||||||
</Unit7>
|
</Unit7>
|
||||||
<Unit8>
|
<Unit8>
|
||||||
<Filename Value="lazutils\testlazxml.pas"/>
|
<Filename Value="lazutils\testlazxml.pas"/>
|
||||||
@ -158,6 +164,16 @@
|
|||||||
<IsPartOfProject Value="True"/>
|
<IsPartOfProject Value="True"/>
|
||||||
<UnitName Value="TestSearchPathProcs"/>
|
<UnitName Value="TestSearchPathProcs"/>
|
||||||
</Unit13>
|
</Unit13>
|
||||||
|
<Unit14>
|
||||||
|
<Filename Value="lazutils\testlazutf8.pas"/>
|
||||||
|
<IsPartOfProject Value="True"/>
|
||||||
|
<UnitName Value="TestLazUTF8"/>
|
||||||
|
</Unit14>
|
||||||
|
<Unit15>
|
||||||
|
<Filename Value="lazutils\testlazloggercase.pas"/>
|
||||||
|
<IsPartOfProject Value="True"/>
|
||||||
|
<UnitName Value="TestLazLoggerCase"/>
|
||||||
|
</Unit15>
|
||||||
</Units>
|
</Units>
|
||||||
</ProjectOptions>
|
</ProjectOptions>
|
||||||
<CompilerOptions>
|
<CompilerOptions>
|
||||||
|
@ -25,11 +25,11 @@ uses
|
|||||||
cthreads,
|
cthreads,
|
||||||
{$ENDIF}
|
{$ENDIF}
|
||||||
Classes, consoletestrunner,
|
Classes, consoletestrunner,
|
||||||
testglobals, testunits, dom,
|
TestGlobals, TestUnits, DOM,
|
||||||
{Unit needed to set the LCL version and widget set name}
|
{Unit needed to set the LCL version and widget set name}
|
||||||
LCLVersion, InterfaceBase, LCLPlatformDef, lazmouseandkeyinput, Interfaces,
|
LCLVersion, InterfaceBase, LCLPlatformDef, lazmouseandkeyinput, Interfaces,
|
||||||
TestLazXML, TestAvgLvlTree, TestLConvEncoding, testlazfileutils,
|
TestLazXML, TestAvgLvlTree, TestLConvEncoding, TestLazFileUtils, TestLazUTF8,
|
||||||
TestSearchPathProcs;
|
TestLazLoggerCase, TestSearchPathProcs;
|
||||||
|
|
||||||
type
|
type
|
||||||
|
|
||||||
|
@ -16,14 +16,14 @@
|
|||||||
to the Free Software Foundation, Inc., 51 Franklin Street - Fifth Floor,
|
to the Free Software Foundation, Inc., 51 Franklin Street - Fifth Floor,
|
||||||
Boston, MA 02110-1335, USA.
|
Boston, MA 02110-1335, USA.
|
||||||
}
|
}
|
||||||
program runtestsgui;
|
program RunTestsGui;
|
||||||
|
|
||||||
{$mode objfpc}{$H+}
|
{$mode objfpc}{$H+}
|
||||||
|
|
||||||
uses
|
uses
|
||||||
Interfaces, Forms,
|
Interfaces, Forms,
|
||||||
GuiTestRunner, lazmouseandkeyinput,
|
GuiTestRunner, LazMouseAndKeyInput,
|
||||||
testunits, TestLazUtils, testmenuintf;
|
TestUnits, TestLazUtils, TestMenuIntf;
|
||||||
|
|
||||||
begin
|
begin
|
||||||
Application.Title:='Run Lazarus tests';
|
Application.Title:='Run Lazarus tests';
|
||||||
|
@ -23,7 +23,7 @@ unit TestLpi;
|
|||||||
interface
|
interface
|
||||||
|
|
||||||
uses
|
uses
|
||||||
Classes, SysUtils, strutils, fpcunit, testregistry, process, UTF8Process,
|
Classes, SysUtils, StrUtils, fpcunit, testregistry, process, UTF8Process,
|
||||||
InterfaceBase, LCLPlatformDef, LazFileUtils, LazUTF8, FileUtil,
|
InterfaceBase, LCLPlatformDef, LazFileUtils, LazUTF8, FileUtil,
|
||||||
TestGlobals;
|
TestGlobals;
|
||||||
|
|
||||||
@ -122,8 +122,7 @@ begin
|
|||||||
SearchDirectory('')
|
SearchDirectory('')
|
||||||
end;
|
end;
|
||||||
|
|
||||||
class function TLpkTest.CreateSuiteFromFile(const AName,
|
class function TLpkTest.CreateSuiteFromFile(const AName, APath: string): TTestSuite;
|
||||||
APath: string): TTestSuite;
|
|
||||||
begin
|
begin
|
||||||
Result := TTestSuite.Create(AnsiReplaceStr(AName, DirectorySeparator, '/'));
|
Result := TTestSuite.Create(AnsiReplaceStr(AName, DirectorySeparator, '/'));
|
||||||
Result.AddTest(Create(APath, 'TestCompile'));
|
Result.AddTest(Create(APath, 'TestCompile'));
|
||||||
@ -175,8 +174,7 @@ begin
|
|||||||
Result := '.lpi';
|
Result := '.lpi';
|
||||||
end;
|
end;
|
||||||
|
|
||||||
class function TLpiTest.CreateSuiteFromFile(const AName,
|
class function TLpiTest.CreateSuiteFromFile(const AName, APath: string): TTestSuite;
|
||||||
APath: string): TTestSuite;
|
|
||||||
{$IFDEF win32}
|
{$IFDEF win32}
|
||||||
var
|
var
|
||||||
AhkFileName: String;
|
AhkFileName: String;
|
||||||
|
@ -20,7 +20,7 @@
|
|||||||
to the Free Software Foundation, Inc., 51 Franklin Street - Fifth Floor,
|
to the Free Software Foundation, Inc., 51 Franklin Street - Fifth Floor,
|
||||||
Boston, MA 02110-1335, USA.
|
Boston, MA 02110-1335, USA.
|
||||||
}
|
}
|
||||||
unit testunits;
|
unit TestUnits;
|
||||||
|
|
||||||
{$mode objfpc}{$H+}
|
{$mode objfpc}{$H+}
|
||||||
|
|
||||||
@ -28,11 +28,11 @@ interface
|
|||||||
|
|
||||||
uses
|
uses
|
||||||
TestLpi, BugTestCase,
|
TestLpi, BugTestCase,
|
||||||
bug8432, testfileutil,
|
bug8432, TestFileUtil,
|
||||||
// lazutils
|
// lazutils
|
||||||
TestLazUtils, TestLazUTF8, TestLazUTF16, TestLConvEncoding, TestAvgLvlTree,
|
TestLazUtils, TestLazUTF8, TestLazUTF16, TestLConvEncoding, TestAvgLvlTree,
|
||||||
// lcltests
|
// lcltests
|
||||||
testpen, TestPreferredSize, TestTextStrings, TestListView
|
TestPen, TestPreferredSize, TestTextStrings, TestListView
|
||||||
{$IFNDEF NoSemiAutomatedTests}
|
{$IFNDEF NoSemiAutomatedTests}
|
||||||
// semi-automatic tests
|
// semi-automatic tests
|
||||||
, testpagecontrol, idesemiautotests, lclsemiautotests
|
, testpagecontrol, idesemiautotests, lclsemiautotests
|
||||||
|
Loading…
Reference in New Issue
Block a user