unit MainUnit; {$mode objfpc}{$H+} interface uses Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs, LCLProc, contnrs, CTXMLFixFragment; type { TForm1 } TForm1 = class(TForm) procedure FormCreate(Sender: TObject); private FVerbose: boolean; public procedure TestComment; procedure TestInvalidCharacters; procedure TestOpenTag; procedure TestAttribute; procedure TestCloseTag; procedure TestBugReports; function Test(Title, Fragment, FixedFragment: string): boolean; property Verbose: boolean read FVerbose write FVerbose; end; var Form1: TForm1; implementation {$R *.lfm} { TForm1 } procedure TForm1.FormCreate(Sender: TObject); begin Verbose:=false; TestComment; TestInvalidCharacters; TestOpenTag; TestAttribute; TestCloseTag; TestBugReports; end; procedure TForm1.TestComment; begin Test('close comment',''); Test('close comment and delete invalid char',''); end; procedure TForm1.TestInvalidCharacters; begin Test('delete special characters','A'#0'B'#1#127,'AB'); Test('replace tag characters','LT< GT>AMP&','LT< GT>AMP&'); Test('lower case special characters','<','<'); end; procedure TForm1.TestOpenTag; begin Test('missing tag name','<>','<>'); Test('lower case tag name','',''); Test('invalid character in tag','','">'); end; procedure TForm1.TestAttribute; begin Test('lower case attribute name','',''); Test('missing attribute equal','',''); Test('missing attribute value','',''); Test('missing attribute quotes','',''); Test('missing attribute ending quote',''); Test('invalid character in attribute value','',''); Test('amp attribute value','',''); end; procedure TForm1.TestCloseTag; begin Test('lower case close tag name','',''); Test('close open tag','',''); Test('close open sub tag','

','

'); Test('disable invalid close tag','

','</p>'); end; procedure TForm1.TestBugReports; begin Test('15120','operator <(TPoint, TPoint): Boolean', 'operator <(TPoint, TPoint): Boolean'); Test('16671','
', '
'); end; function TForm1.Test(Title, Fragment, FixedFragment: string): boolean; var s: String; ErrorList: TObjectList; begin Result:=true; try s:=Fragment; FixFPDocFragment(s,true,true,ErrorList,Verbose); if s<>FixedFragment then begin Result:=false; debugln(['failed: ',Title]); debugln([' fragment: '+DbgStr(Fragment)]); debugln([' should: '+DbgStr(FixedFragment)]); debugln([' result: '+DbgStr(s)]); end; finally ErrorList.Free; end; end; end.