fcl-css: added test lpi, ignore lib, run from other dir, cleaned up

This commit is contained in:
mattias 2022-09-05 22:37:28 +02:00
parent f097d1ea35
commit e01ab79823
5 changed files with 88 additions and 35 deletions

View File

@ -1 +1,2 @@
testcss
lib

View File

@ -1,6 +1,6 @@
{
This file is part of the Free Pascal Run time library.
Copyright (c) 2022- by Michael Van Canneyt (michael@freepascal.org)
Copyright (c) 2022 by Michael Van Canneyt (michael@freepascal.org)
This file contains the tests for the CSS parser
@ -19,7 +19,7 @@ unit tcCSSParser;
interface
uses
Classes, SysUtils, fpcunit, testutils, testregistry, fpcssparser, fpcsstree;
Classes, SysUtils, fpcunit, testregistry, fpcssparser, fpcsstree;
type
@ -31,7 +31,7 @@ type
FSource : TStringStream;
FParser : TCSSParser;
FToFree: TCSSElement;
procedure clear;
procedure Clear;
function GetRule: TCSSRuleElement;
protected
procedure SetUp; override;
@ -39,7 +39,7 @@ type
Procedure CreateParser(Const ASource : string);
procedure Parse;
procedure Parse(Const aSource : String);
function ParseRule(Const aSource : String) : TCSSRuleElement;
function ParseRule(Const aSource : String) : TCSSRuleElement;
procedure AssertEquals(AMessage: String; AExpected, AActual: TCSSUnits); overload;
procedure AssertEquals(AMessage: String; AExpected, AActual: TCSSBinaryOperation); overload;
Function CheckClass(Const aMsg : String; aExpectedClass : TCSSElementClass; aActual : TCSSElement) : TCSSElement;
@ -465,19 +465,13 @@ begin
end;
procedure TTestCSSParser.TestQueryPrefixedEmptyRule;
var
R : TCSSRuleElement;
begin
R:=ParseRule('@media only screen and (-webkit-min-device-pixel-ratio: 2), only screen and (min-device-pixel-ratio: 3) { }');
ParseRule('@media only screen and (-webkit-min-device-pixel-ratio: 2), only screen and (min-device-pixel-ratio: 3) { }');
end;
procedure TTestCSSParser.TestCommaPrefixedEmptyRule;
var
R : TCSSRuleElement;
sel: TCSSArrayElement;
begin
R:=ParseRule('#facebox .tl,#facebox .tl { }');
ParseRule('#facebox .tl,#facebox .tl { }');
end;
procedure TTestCSSParser.TestOneDeclarationIDValue;
@ -631,20 +625,13 @@ begin
end;
procedure TTestCSSParser.TestOneDeclarationNoColon;
Var
R : TCSSRuleElement;
begin
R:=ParseRule('@a b { 0% { d: e; } }');
ParseRule('@a b { 0% { d: e; } }');
end;
procedure TTestCSSParser.TestTwoDeclarationNoColon;
Var
R : TCSSRuleElement;
begin
R:=ParseRule('@a b { 0% { d: e; } 100% { f : g; } }');
ParseRule('@a b { 0% { d: e; } 100% { f : g; } }');
end;
procedure TTestCSSParser.TestOneEmptyDeclaration;
@ -654,18 +641,15 @@ begin
R:=ParseRule('{ ; }');
AssertEquals('selector count',0,R.SelectorCount);
AssertEquals('declaration count',0,R.ChildCount);
end;
procedure TTestCSSParser.TestImportAtKeyWord;
var
R : TCSSAtRuleElement;
// D : TCSSDeclarationElement;
begin
R:=TCSSAtRuleElement(CheckClass('at',TCSSAtRuleElement,ParseRule('@import url("abc.css");')));
AssertEquals('selector count',1,R.SelectorCount);
AssertEquals('declaration count',0,R.ChildCount);
end;
procedure TTestCSSParser.TestMediaPrint;
@ -676,14 +660,14 @@ end;
procedure TTestCSSParser.TestSupportsFunction;
begin
ParseRule('@supports ((position: -webkit-sticky) or (position: sticky)) {'+ sLineBreak+
' .sticky-top { '+ sLineBreak+
' position: -webkit-sticky; '+ sLineBreak+
' position: sticky; '+ sLineBreak+
' top: 0; '+ sLineBreak+
' z-index: 1020; '+ sLineBreak+
' } '+ sLineBreak+
'} '
);
' .sticky-top { '+ sLineBreak+
' position: -webkit-sticky; '+ sLineBreak+
' position: sticky; '+ sLineBreak+
' top: 0; '+ sLineBreak+
' z-index: 1020; '+ sLineBreak+
' } '+ sLineBreak+
'} '
);
end;
@ -708,7 +692,7 @@ begin
FSource:=Nil;
end;
procedure TTestBaseCSSParser.clear;
procedure TTestBaseCSSParser.Clear;
begin
if FParseResult<>FToFree then

View File

@ -20,7 +20,7 @@ unit tcCSSScanner;
interface
uses
TypInfo, Classes, SysUtils, fpcunit, testutils, testregistry, fpcssscanner;
TypInfo, Classes, SysUtils, fpcunit, testregistry, fpcssscanner;
type
TTestLineReader = Class(TTestCase)

View File

@ -0,0 +1,64 @@
<?xml version="1.0" encoding="UTF-8"?>
<CONFIG>
<ProjectOptions>
<Version Value="12"/>
<General>
<Flags>
<MainUnitHasCreateFormStatements Value="False"/>
<MainUnitHasTitleStatement Value="False"/>
<MainUnitHasScaledStatement Value="False"/>
<UseDefaultCompilerOptions Value="True"/>
</Flags>
<SessionStorage Value="InProjectDir"/>
<Title Value="testcss"/>
<UseAppBundle Value="False"/>
<ResourceType Value="res"/>
</General>
<BuildModes>
<Item Name="Default" Default="True"/>
</BuildModes>
<PublishOptions>
<Version Value="2"/>
<UseFileFilters Value="True"/>
</PublishOptions>
<RunParams>
<FormatVersion Value="2"/>
</RunParams>
<Units>
<Unit>
<Filename Value="testcss.lpr"/>
<IsPartOfProject Value="True"/>
</Unit>
</Units>
</ProjectOptions>
<CompilerOptions>
<Version Value="11"/>
<Target>
<Filename Value="testcss"/>
</Target>
<SearchPaths>
<IncludeFiles Value="$(ProjOutDir)"/>
<OtherUnitFiles Value="../src"/>
<UnitOutputDirectory Value="lib/$(TargetCPU)-$(TargetOS)"/>
</SearchPaths>
<Other>
<CustomOptions Value="-dVerboseCSSParser"/>
<OtherDefines Count="1">
<Define0 Value="VerboseCSSParser"/>
</OtherDefines>
</Other>
</CompilerOptions>
<Debugging>
<Exceptions>
<Item>
<Name Value="EAbort"/>
</Item>
<Item>
<Name Value="ECodetoolError"/>
</Item>
<Item>
<Name Value="EFOpenError"/>
</Item>
</Exceptions>
</Debugging>
</CONFIG>

View File

@ -3,7 +3,7 @@ program testcss;
{$mode objfpc}{$H+}
uses
Classes, consoletestrunner, tccssScanner, tccssparser, tccsstree;
Classes, sysutils, consoletestrunner, tcCSSScanner, tcCSSParser, tcCSSTree;
type
@ -16,11 +16,15 @@ type
var
Application: TMyTestRunner;
Dir: String;
begin
DefaultFormat:=fPlain;
DefaultRunAllTests:=True;
Application := TMyTestRunner.Create(nil);
Dir:=ExtractFilePath(Application.ExeName);
if Dir<>'' then
SetCurrentDir(Dir);
Application.Initialize;
Application.Title := 'CSS tests runner';
Application.Run;