{ This file is part of the Free Component Library (FCL) Copyright (c) 2025 by Michael Van Canneyt HTML highlighter unit test See the file COPYING.FPC, included in this distribution, for details about the copyright. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. **********************************************************************} unit unittest.html; interface {$mode objfpc}{$H+} uses Classes, SysUtils, fpcunit, testregistry, syntax.highlighter, syntax.html; type TTestHtmlHighlighter = class(TTestCase) protected procedure SetUp; override; procedure TearDown; override; private function DoHtmlHighlighting(const source: string): TSyntaxTokenArray; published procedure TestHtmlBasicTags; procedure TestHtmlAttributes; procedure TestHtmlComments; procedure TestHtmlEntities; procedure TestHtmlEmbeddedCSS; procedure TestHtmlEmbeddedJavaScript; procedure TestHtmlDoctype; procedure TestHtmlSelfClosingTags; procedure TestHtmlNestedTags; procedure TestComplexHtmlDocument; procedure TestHtmlCDATA; procedure TestCategorySystem; end; implementation procedure TTestHtmlHighlighter.SetUp; begin end; procedure TTestHtmlHighlighter.TearDown; begin // Nothing to do end; function TTestHtmlHighlighter.DoHtmlHighlighting(const source: string): TSyntaxTokenArray; var highlighter: THtmlSyntaxHighlighter; begin highlighter := THtmlSyntaxHighlighter.Create; try Result := highlighter.Execute(source); finally highlighter.Free; end; end; procedure TTestHtmlHighlighter.TestHtmlBasicTags; var tokens: TSyntaxTokenArray; begin // Test simple div tag tokens := DoHtmlHighlighting('
');
hasImg := False;
hasSlash := False;
for i := 0 to High(tokens) do
begin
if (tokens[i].Text = 'img') and (tokens[i].Kind = shKeyword) then
hasImg := True;
if (tokens[i].Text = '/') and (tokens[i].Kind = shSymbol) then
hasSlash := True;
end;
AssertTrue('Should contain img tag', hasImg);
AssertTrue('Should contain closing slash', hasSlash);
end;
procedure TTestHtmlHighlighter.TestHtmlNestedTags;
var
tokens: TSyntaxTokenArray;
tagCount: Integer;
i: Integer;
begin
tokens := DoHtmlHighlighting('Hello