Skip to content

Commit 641f943

Browse files
authored
Merge pull request #220 from sempare/test-number-iteration
#219 test enumerating an array of numbers
2 parents 85a36f1 + 4241813 commit 641f943

File tree

3 files changed

+104
-1
lines changed

3 files changed

+104
-1
lines changed

Sempare.Template.Tester.dpr

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,8 @@ uses
6060
Sempare.Template.TestLexer in 'tests\Sempare.Template.TestLexer.pas',
6161
Sempare.Template.TestFunctions in 'tests\Sempare.Template.TestFunctions.pas',
6262
Sempare.Template.TestVirtualMethods in 'tests\Sempare.Template.TestVirtualMethods.pas',
63-
Sempare.Template.TestMap in 'tests\Sempare.Template.TestMap.pas';
63+
Sempare.Template.TestMap in 'tests\Sempare.Template.TestMap.pas',
64+
Sempare.Template.TestSupport in 'tests\Sempare.Template.TestSupport.pas';
6465

6566
var
6667
runner: ITestRunner;

Sempare.Template.Tester.dproj

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,7 @@
9494
<DCCReference Include="tests\Sempare.Template.TestFunctions.pas"/>
9595
<DCCReference Include="tests\Sempare.Template.TestVirtualMethods.pas"/>
9696
<DCCReference Include="tests\Sempare.Template.TestMap.pas"/>
97+
<DCCReference Include="tests\Sempare.Template.TestSupport.pas"/>
9798
<BuildConfiguration Include="Base">
9899
<Key>Base</Key>
99100
</BuildConfiguration>
@@ -187,6 +188,7 @@
187188
<ProjectRoot Platform="OSXARM64" Name="$(PROJECTNAME)"/>
188189
<ProjectRoot Platform="Win32" Name="$(PROJECTNAME)"/>
189190
<ProjectRoot Platform="Win64" Name="$(PROJECTNAME)"/>
191+
<ProjectRoot Platform="Win64x" Name="$(PROJECTNAME)"/>
190192
</Deployment>
191193
<Platforms>
192194
<Platform value="Android">False</Platform>
Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
unit Sempare.Template.TestSupport;
2+
(*%*************************************************************************************************
3+
* ___ *
4+
* / __| ___ _ __ _ __ __ _ _ _ ___ *
5+
* \__ \ / -_) | ' \ | '_ \ / _` | | '_| / -_) *
6+
* |___/ \___| |_|_|_| | .__/ \__,_| |_| \___| *
7+
* |_| *
8+
****************************************************************************************************
9+
* *
10+
* Sempare Template Engine *
11+
* *
12+
* *
13+
* https://github.com/sempare/sempare-delphi-template-engine *
14+
****************************************************************************************************
15+
* *
16+
* Copyright (c) 2019-2025 Sempare Limited *
17+
* *
18+
* Contact: info@sempare.ltd *
19+
* *
20+
* Licensed under the Apache Version 2.0 or the Sempare Commercial License *
21+
* You may not use this file except in compliance with one of these Licenses. *
22+
* You may obtain a copy of the Licenses at *
23+
* *
24+
* https://www.apache.org/licenses/LICENSE-2.0 *
25+
* https://github.com/sempare/sempare-delphi-template-engine/blob/master/docs/commercial.license.md *
26+
* *
27+
* Unless required by applicable law or agreed to in writing, software *
28+
* distributed under the Licenses is distributed on an "AS IS" BASIS, *
29+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. *
30+
* See the License for the specific language governing permissions and *
31+
* limitations under the License. *
32+
* *
33+
*************************************************************************************************%*)
34+
35+
interface
36+
37+
uses
38+
DUnitX.TestFramework;
39+
40+
type
41+
42+
[TestFixture]
43+
TTestSupport = class
44+
public
45+
46+
[Test]
47+
procedure TestSuspectedArrayNumbersNotHandledGHIssue219;
48+
49+
end;
50+
51+
implementation
52+
53+
uses
54+
System.SysUtils,
55+
Sempare.Template;
56+
57+
{ TTestSupport }
58+
59+
procedure TTestSupport.TestSuspectedArrayNumbersNotHandledGHIssue219;
60+
var
61+
LTemplate: string;
62+
LResult: string;
63+
LExpected: string;
64+
begin
65+
LTemplate := //
66+
'<% arr := [4,5,6] %>' + sLineBreak + //
67+
sLineBreak + //
68+
'<%- for x of arr %>' + sLineBreak + //
69+
'<% x %>' + sLineBreak + //
70+
'<% end %>';
71+
72+
LExpected := //
73+
sLineBreak + //
74+
sLineBreak + //
75+
'4' + sLineBreak + //
76+
'5' + sLineBreak + //
77+
'6' + sLineBreak; //
78+
79+
LResult := Template.Eval(LTemplate);
80+
81+
Assert.AreEqual(LExpected, LResult);
82+
83+
LTemplate := //
84+
'<% arr := [''4'',''5'',''6''] %>' + sLineBreak + //
85+
sLineBreak + //
86+
'<%- for x of arr %>' + sLineBreak + //
87+
'<% x %>' + sLineBreak + //
88+
'<% end %>';
89+
90+
LResult := Template.Eval(LTemplate);
91+
92+
Assert.AreEqual(LExpected, LResult);
93+
94+
end;
95+
96+
initialization
97+
98+
TDUnitX.RegisterTestFixture(TTestSupport);
99+
100+
end.

0 commit comments

Comments
 (0)