forked from sebastienros/fluid
-
Notifications
You must be signed in to change notification settings - Fork 0
/
UnlessStatementTests.cs
86 lines (72 loc) · 2.45 KB
/
UnlessStatementTests.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
using System.Collections.Generic;
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 UnlessStatementTests
{
private Expression TRUE = new LiteralExpression(BooleanValue.True);
private Expression FALSE = new LiteralExpression(BooleanValue.False);
private Statement[] TEXT(string text)
{
return new Statement[] { new TextSpanStatement(text) };
}
[Fact]
public async Task UnlessDoesntProcessWhenTrue()
{
var e = new UnlessStatement(
TRUE,
new List<Statement> { new TextSpanStatement("x") }
);
var sw = new StringWriter();
await e.WriteToAsync(sw, HtmlEncoder.Default, new TemplateContext());
Assert.Equal("", sw.ToString());
}
[Fact]
public async Task UnlessCanProcessWhenFalse()
{
var e = new UnlessStatement(
FALSE,
new List<Statement> { new TextSpanStatement("x") }
);
var sw = new StringWriter();
await e.WriteToAsync(sw, HtmlEncoder.Default, new TemplateContext());
Assert.Equal("x", sw.ToString());
}
[Fact]
public async Task UnlessShouldProcessElseWhenFalse()
{
var e = new UnlessStatement(
FALSE,
new List<Statement> {
new TextSpanStatement("x")
},
new ElseStatement(new List<Statement> {
new TextSpanStatement("y")
}));
var sw = new StringWriter();
await e.WriteToAsync(sw, HtmlEncoder.Default, new TemplateContext());
Assert.Equal("x", sw.ToString());
}
[Fact]
public async Task UnlessShouldProcessElseWhenTrue()
{
var e = new UnlessStatement(
TRUE,
new List<Statement> {
new TextSpanStatement("x")
},
new ElseStatement(new List<Statement> {
new TextSpanStatement("y")
})
);
var sw = new StringWriter();
await e.WriteToAsync(sw, HtmlEncoder.Default, new TemplateContext());
Assert.Equal("y", sw.ToString());
}
}
}