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