-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBoolSwitchKeyTests.cs
More file actions
54 lines (46 loc) · 1.9 KB
/
Copy pathBoolSwitchKeyTests.cs
File metadata and controls
54 lines (46 loc) · 1.9 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
using MattSourceGenHelpers.Abstractions;
// ReSharper disable ConvertClosureToMethodGroup
namespace MattSourceGenHelpers.Tests;
[TestFixture]
public class BoolSwitchKeyTests
{
[TestCase(true, "Yes")]
[TestCase(false, "No")]
public void BoolSwitchKey_ProducesExpectedRuntimeOutput(bool flag, string expected)
{
string result = TestBoolSwitchClass.GetBoolLabel(flag);
Assert.That(result, Is.EqualTo(expected));
}
[Test]
public void BoolSwitchKey_ProducesExpectedGeneratedCode()
{
string generatedCode = GeneratedCodeTestHelper.ReadGeneratedCode("TestBoolSwitchClass_GetBoolLabel.g.cs");
string expectedCode = """
namespace MattSourceGenHelpers.Tests;
static partial class TestBoolSwitchClass
{
public static partial string GetBoolLabel(bool flag)
{
switch (flag)
{
case true: return "Yes";
case false: return "No";
default: return "Unknown";
}
}
}
""".ReplaceLineEndings("\n").TrimEnd();
Assert.That(generatedCode, Is.EqualTo(expectedCode));
}
}
public static partial class TestBoolSwitchClass
{
public static partial string GetBoolLabel(bool flag);
[GeneratesMethod(nameof(GetBoolLabel))]
[SwitchCase(arg1: true)]
[SwitchCase(arg1: false)]
static string GetBoolLabel_Generator(bool flag) => flag ? "Yes" : "No";
[GeneratesMethod(nameof(GetBoolLabel))]
[SwitchDefault]
static Func<bool, string> GetBoolLabel_Default() => _ => "Unknown";
}