Debian Codegraph @

tools/build-tool/tests/testtoolproject.pas

raw
1 {
2 Copyright 2019-2022 Michalis Kamburelis.
3
4 This file is part of "Castle Game Engine".
5
6 "Castle Game Engine" is free software; see the file COPYING.txt,
7 included in this distribution, for details about the copyright.
8
9 "Castle Game Engine" is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
12
13 ----------------------------------------------------------------------------
14 }
15
16 { Automatic tests of ToolProject unit. }
17 unit TestToolProject;
18
19 interface
20
21 uses
22 Classes, SysUtils, CastleTester,
23 ToolProject;
24
25 type
26 TTestToolProject = class(TCastleTestCase)
27 published
28 procedure TestMacros;
29 end;
30
31 implementation
32
33 uses CastleStringUtils, CastleUriUtils, CastleFilesUtils, CastleVectors,
34 CastleConfig;
35
36 procedure TTestToolProject.TestMacros;
37 var
38 P: TCastleProject;
39 begin
40 P := TCastleProject.Create(UriToFilenameSafe(ResolveCastleDataURL('castle-data:/test_project/')));
41 try
42 AssertEquals('My Test Project', P.ReplaceMacros('${CAPTION}'));
43 AssertEquals('test_project', P.ReplaceMacros('${NAME}'));
44 AssertEquals('blabla My Test Project asdasdas', P.ReplaceMacros('blabla ${CAPTION} asdasdas'));
45
46 // test calculate
47 AssertEquals('blabla 3', P.ReplaceMacros('blabla ${CALCULATE 1+2}'));
48 AssertEquals('blabla ohyes:My Test Project', P.ReplaceMacros('blabla ${CALCULATE if(${CAPTION} <> '''', ''ohyes:'' + ${CAPTION}, ''undefined caption'')}'));
49
50 // test if
51 AssertEquals('blabla asd after', P.ReplaceMacros('blabla ${IF true}asd${ELSE}koko${ENDIF} after'));
52 AssertEquals('has caption', P.ReplaceMacros('${IF ${CAPTION} <> ''''}has caption${ELSE}no caption${ENDIF}'));
53 AssertEquals('has caption', P.ReplaceMacros('${IF ${CAPTION} <> ''''}has caption${ENDIF}'));
54 AssertEquals('no EDITOR_UNITS', P.ReplaceMacros('${IF ${EDITOR_UNITS} <> ''''}has EDITOR_UNITS${ELSE}no EDITOR_UNITS${ENDIF}'));
55 AssertEquals('', P.ReplaceMacros('${IF ${EDITOR_UNITS} <> ''''}has EDITOR_UNITS${ENDIF}'));
56 finally FreeAndNil(P) end;
57 end;
58
59 initialization
60 RegisterTest(TTestToolProject);
61 end.