-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCallStatementTests.cs
More file actions
74 lines (61 loc) · 2.25 KB
/
Copy pathCallStatementTests.cs
File metadata and controls
74 lines (61 loc) · 2.25 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
using System.Text;
using Cutout.Tests.Extensions;
namespace Cutout.Tests;
public static partial class CallTemplates
{
public sealed record Product(string Title);
private const string CallExample1 = "Some text before {% call Case2(product.Title) %}";
[Template(CallExample1)]
public static partial void Case1(this StringBuilder builder, Product product);
private const string CallExample2 = "The product title is {{ title }}";
[Template(CallExample2)]
public static partial void Case2(this StringBuilder builder, string title);
private const string CallExample3 = """
This is an example with a call with leading whitespace,
```
{% call Case4(product) %}
```
""";
[Template(CallExample3)]
public static partial void Case3(this StringBuilder builder, Product product);
private const string CallExample4 = """
The title in two calls,
{{ product.Title }}
{{ product.Title.ToLowerInvariant() }}
""";
[Template(CallExample4)]
public static partial void Case4(this StringBuilder builder, Product product);
}
public sealed class CallStatementTests
{
[Fact(DisplayName = "A call statement can used")]
public void Case1()
{
var builder = new StringBuilder();
builder.Case1(new CallTemplates.Product("Awesome Shoes"));
Assert.Equal("Some text before The product title is Awesome Shoes", builder.ToString());
}
[Fact(DisplayName = "Case1 produces the expected source")]
public Task Case1a() =>
"""
[Template("Some text before {% call Case2(product) %}")]
public static partial void Test(this StringBuilder builder, string product);
""".VerifyTemplate();
[Fact(DisplayName = "A call statement with leading whitespace can used")]
public void Case2()
{
var builder = new StringBuilder();
builder.Case3(new CallTemplates.Product("Awesome Shoes"));
Assert.Equal(
"""
This is an example with a call with leading whitespace,
```
The title in two calls,
Awesome Shoes
awesome shoes
```
""",
builder.ToString()
);
}
}