-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathEdgeCaseSimplePatternTests.cs
More file actions
159 lines (130 loc) · 5.38 KB
/
Copy pathEdgeCaseSimplePatternTests.cs
File metadata and controls
159 lines (130 loc) · 5.38 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
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 MattSourceGenHelpers.Abstractions;
namespace MattSourceGenHelpers.Tests;
[TestFixture]
public class EdgeCaseSimplePatternTests
{
// -----------------------------------------------------------------------
// Void return type
// -----------------------------------------------------------------------
[Test]
public void VoidReturnGenerator_MethodIsCallable()
{
TestVoidClass instance = new TestVoidClass();
Assert.DoesNotThrow(() => instance.DoSomething());
}
[Test]
public void VoidReturnGenerator_ProducesExpectedGeneratedCode()
{
string generatedCode = GeneratedCodeTestHelper.ReadGeneratedCode("TestVoidClass_DoSomething.g.cs");
string expectedCode = """
namespace MattSourceGenHelpers.Tests;
partial class TestVoidClass
{
public partial void DoSomething()
{
}
}
""".ReplaceLineEndings("\n").TrimEnd();
Assert.That(generatedCode, Is.EqualTo(expectedCode));
}
// -----------------------------------------------------------------------
// Bool return type
// -----------------------------------------------------------------------
[Test]
public void BoolReturnGenerator_ProducesExpectedRuntimeOutput()
{
bool result = TestBoolReturnClass.IsEnabled();
Assert.That(result, Is.True);
}
[Test]
public void BoolReturnGenerator_ProducesExpectedGeneratedCode()
{
string generatedCode = GeneratedCodeTestHelper.ReadGeneratedCode("TestBoolReturnClass_IsEnabled.g.cs");
string expectedCode = """
namespace MattSourceGenHelpers.Tests;
static partial class TestBoolReturnClass
{
public static partial bool IsEnabled()
{
return true;
}
}
""".ReplaceLineEndings("\n").TrimEnd();
Assert.That(generatedCode, Is.EqualTo(expectedCode));
}
// -----------------------------------------------------------------------
// Char return type
// -----------------------------------------------------------------------
[Test]
public void CharReturnGenerator_ProducesExpectedRuntimeOutput()
{
char result = TestCharReturnClass.GetSymbol();
Assert.That(result, Is.EqualTo('A'));
}
[Test]
public void CharReturnGenerator_ProducesExpectedGeneratedCode()
{
string generatedCode = GeneratedCodeTestHelper.ReadGeneratedCode("TestCharReturnClass_GetSymbol.g.cs");
string expectedCode = """
namespace MattSourceGenHelpers.Tests;
static partial class TestCharReturnClass
{
public static partial char GetSymbol()
{
return 'A';
}
}
""".ReplaceLineEndings("\n").TrimEnd();
Assert.That(generatedCode, Is.EqualTo(expectedCode));
}
// -----------------------------------------------------------------------
// Internal method accessibility
// -----------------------------------------------------------------------
[Test]
public void InternalMethodGenerator_ProducesExpectedRuntimeOutput()
{
TestInternalMethodClass instance = new TestInternalMethodClass();
string result = instance.GetValue();
Assert.That(result, Is.EqualTo("internal_value"));
}
[Test]
public void InternalMethodGenerator_ProducesExpectedGeneratedCode()
{
string generatedCode = GeneratedCodeTestHelper.ReadGeneratedCode("TestInternalMethodClass_GetValue.g.cs");
string expectedCode = """
namespace MattSourceGenHelpers.Tests;
partial class TestInternalMethodClass
{
internal partial string GetValue()
{
return "internal_value";
}
}
""".ReplaceLineEndings("\n").TrimEnd();
Assert.That(generatedCode, Is.EqualTo(expectedCode));
}
}
public partial class TestVoidClass
{
public partial void DoSomething();
[GeneratesMethod(nameof(DoSomething))]
private static void DoSomething_Generator() { }
}
public static partial class TestBoolReturnClass
{
public static partial bool IsEnabled();
[GeneratesMethod(nameof(IsEnabled))]
private static bool IsEnabled_Generator() => true;
}
public static partial class TestCharReturnClass
{
public static partial char GetSymbol();
[GeneratesMethod(nameof(GetSymbol))]
private static char GetSymbol_Generator() => 'A';
}
public partial class TestInternalMethodClass
{
internal partial string GetValue();
[GeneratesMethod(nameof(GetValue))]
private static string GetValue_Generator() => "internal_value";
}