forked from sebastienros/fluid
-
Notifications
You must be signed in to change notification settings - Fork 0
/
CycleStatementTests.cs
159 lines (133 loc) · 4.26 KB
/
CycleStatementTests.cs
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
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
using System.IO;
using System.Text.Encodings.Web;
using System.Threading.Tasks;
using Fluid.Ast;
using Fluid.Values;
using Xunit;
namespace Fluid.Tests
{
public class CycleStatementTests
{
private LiteralExpression LIT(string text)
{
return new LiteralExpression(new StringValue(text));
}
private LiteralExpression LIT(int number)
{
return new LiteralExpression(NumberValue.Create(number));
}
[Fact]
public async Task CycleEvaluatesEachValue()
{
var e = new CycleStatement(
null,
new[] {
LIT("a"), LIT("b"), LIT("c")
}
);
var context = new TemplateContext();
var sw = new StringWriter();
for (var i=1; i<=10; i++)
{
await e.WriteToAsync(sw, HtmlEncoder.Default, context);
}
Assert.Equal("abcabcabca", sw.ToString());
}
[Fact]
public async Task CycleEvaluatesGroupsValue()
{
var group1 = new CycleStatement(
LIT("x"),
new[] {
LIT("a"), LIT("b"), LIT("c")
}
);
var group2 = new CycleStatement(
LIT("y"),
new[] {
LIT("a"), LIT("b"), LIT("c")
}
);
var context = new TemplateContext();
var sw = new StringWriter();
for (var i = 1; i <= 5; i++)
{
await group1.WriteToAsync(sw, HtmlEncoder.Default, context);
await group2.WriteToAsync(sw, HtmlEncoder.Default, context);
}
Assert.Equal("aabbccaabb", sw.ToString());
}
[Fact]
public async Task CycleShouldGroupByStringRepresentation()
{
var group1 = new CycleStatement(
LIT(2),
new[] {
LIT("a"), LIT("b"), LIT("c")
}
);
var group2 = new CycleStatement(
LIT("2"),
new[] {
LIT("a"), LIT("b"), LIT("c")
}
);
var context = new TemplateContext();
var sw = new StringWriter();
for (var i = 1; i <= 5; i++)
{
await group1.WriteToAsync(sw, HtmlEncoder.Default, context);
await group2.WriteToAsync(sw, HtmlEncoder.Default, context);
}
Assert.Equal("abcabcabca", sw.ToString());
}
[Fact]
public async Task CycleShouldSupportNumbers()
{
var group1 = new CycleStatement(
LIT("x"),
new[] {
LIT(1), LIT(2), LIT(3)
}
);
var group2 = new CycleStatement(
LIT("y"),
new[] {
LIT("a"), LIT("b"), LIT("c")
}
);
var context = new TemplateContext();
var sw = new StringWriter();
for (var i = 1; i <= 5; i++)
{
await group1.WriteToAsync(sw, HtmlEncoder.Default, context);
await group2.WriteToAsync(sw, HtmlEncoder.Default, context);
}
Assert.Equal("1a2b3c1a2b", sw.ToString());
}
[Fact]
public async Task CycleAlternateValuesList()
{
var group1 = new CycleStatement(
null,
new[] {
LIT("a"), LIT("b"), LIT("c")
}
);
var group2 = new CycleStatement(
null,
new[] {
LIT("d"), LIT("e"), LIT("f")
}
);
var context = new TemplateContext();
var sw = new StringWriter();
for (var i = 1; i <= 5; i++)
{
await group1.WriteToAsync(sw, HtmlEncoder.Default, context);
await group2.WriteToAsync(sw, HtmlEncoder.Default, context);
}
Assert.Equal("aecdbfaecd", sw.ToString());
}
}
}