Menu

[r3902]: / branches / parsnip / Src / UTestUnitDlgMgr.pas  Maximize  Restore  History

Download this file

123 lines (103 with data), 3.2 kB

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
{
* This Source Code Form is subject to the terms of the Mozilla Public License,
* v. 2.0. If a copy of the MPL was not distributed with this file, You can
* obtain one at http://mozilla.org/MPL/2.0/
*
* Copyright (C) 2009-2013, Peter Johnson (www.delphidabbler.com).
*
* $Rev$
* $Date$
*
* Implements a static class that creates and displays a Pascal test unit in a
* dialogue box.
}
unit UTestUnitDlgMgr;
interface
uses
// Delphi
Classes,
// Project
CS.SourceCode.Languages,
DB.USnippet,
UBaseObjects,
UEncodings;
type
/// <summary>Static class that creates and displays a Pascal test unit in a
/// dialogue box.</summary>
TTestUnitDlgMgr = class(TNoConstructObject)
strict private
/// <summary>Generates source code a test unit for the given snippet's
/// source code.</summary>
class function GenerateTestUnit(const Snippet: TSnippet): string;
/// <summary>Syntax highlights the given source code with a highlighter
/// suitable for the given language and returns the highlighted code as
/// XHTML.</summary>
class function HighlightSource(const SourceCode: string;
const Language: TSourceCodeLanguage): TEncodedData;
public
/// <summary>Generates and displays a syntax highlighted test compile unit
/// in a dialogue box.</summary>
/// <param name="Owner">TComponent [in] Component that owns the dialogue
/// box.</param>
/// <param name="Snippet">TSnippet [in] Snippet for which test unit is to
/// be displayed.</param>
class procedure DisplayTestUnit(const Owner: TComponent;
const Snippet: TSnippet);
end;
implementation
uses
// Delphi
SysUtils,
// Project
CS.Config,
CS.SourceCode.Hiliter.Brushes,
CS.SourceCode.Hiliter.Renderers,
CS.SourceCode.Hiliter.Themes,
FmPreviewDlg,
UPreferences,
CS.SourceCode.Pascal.TestUnit;
{ TTestUnitDlgMgr }
class procedure TTestUnitDlgMgr.DisplayTestUnit(const Owner: TComponent;
const Snippet: TSnippet);
var
XHTMLDoc: TEncodedData; // syntax highlighted source code XHTML
resourcestring
sDlgTitle = 'Test Unit for %s'; // caption of dialog box
begin
XHTMLDoc := HighlightSource(
GenerateTestUnit(Snippet),
TConfig.Instance.SourceCodeLanguages[Snippet.Language]
);
TPreviewDlg.Execute(
Owner, XHTMLDoc, dtHTML, Format(sDlgTitle, [Snippet.DisplayName])
);
end;
class function TTestUnitDlgMgr.GenerateTestUnit(const Snippet: TSnippet):
string;
begin
with TPascalTestUnit.Create(Snippet) do
try
Result := GenerateUnitSource;
finally
Free;
end;
end;
class function TTestUnitDlgMgr.HighlightSource(const SourceCode: string;
const Language: TSourceCodeLanguage): TEncodedData;
var
Brush: TSyntaxHiliterBrush; // syntax highlighter brush for language
Theme: TSyntaxHiliteTheme; // syntax highlighter theme
resourcestring
sDlgTitle = 'Test Unit for %s'; // caption of dialog box
begin
Theme := TConfig.Instance.HiliterThemes[
Preferences.CurrentHiliteThemeIds[htkUI]
];
Brush := TSyntaxHiliterBrushes.CreateBrush(Language.HiliterBrushID);
try
Result := TXHTMLDocumentHiliter.Hilite(SourceCode, Brush, Theme);
finally
Brush.Free;
end;
end;
end.
Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.