-
Notifications
You must be signed in to change notification settings - Fork 662
Expand file tree
/
Copy pathLegacyFormattingSyntaxTests.cs
More file actions
138 lines (113 loc) · 4.24 KB
/
LegacyFormattingSyntaxTests.cs
File metadata and controls
138 lines (113 loc) · 4.24 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
using System.Globalization;
using GitVersion.Core.Tests.Helpers;
using GitVersion.Formatting;
namespace GitVersion.Core.Tests.Formatting;
[TestFixture]
public class LegacyFormattingSyntaxTests
{
[Test]
public void FormatWith_LegacyZeroFallbackSyntax_ShouldWork()
{
var semanticVersion = new SemanticVersion
{
Major = 6,
Minor = 13,
Patch = 54,
PreReleaseTag = new SemanticVersionPreReleaseTag("gv6", 1, true),
BuildMetaData = new SemanticVersionBuildMetaData()
{
Branch = "feature/gv6",
VersionSourceSha = "versionSourceSha",
Sha = "489a0c0ab425214def918e36399f3cc3c9a9c42d",
ShortSha = "489a0c0",
CommitsSinceVersionSource = 2,
CommitDate = DateTimeOffset.Parse("2025-08-12", CultureInfo.InvariantCulture)
}
};
const string template = "{MajorMinorPatch}{PreReleaseLabelWithDash}{CommitsSinceVersionSource:0000;;''}";
const string expected = "6.13.54-gv60002";
var actual = template.FormatWith(semanticVersion, new TestEnvironment());
actual.ShouldBe(expected);
}
[Test]
public void FormatWith_LegacyThreeSectionSyntax_ShouldWork()
{
var testObject = new { Value = -5 };
const string template = "{Value:positive;negative;zero}";
const string expected = "negative";
var actual = template.FormatWith(testObject, new TestEnvironment());
actual.ShouldBe(expected);
}
[Test]
public void FormatWith_LegacyTwoSectionSyntax_ShouldWork()
{
var testObject = new { Value = -10 };
const string template = "{Value:positive;negative}";
const string expected = "negative";
var actual = template.FormatWith(testObject, new TestEnvironment());
actual.ShouldBe(expected);
}
[Test]
public void FormatWith_LegacyZeroValue_ShouldUseThirdSection()
{
var testObject = new { Value = 0 };
const string template = "{Value:pos;neg;ZERO}";
const string expected = "ZERO";
var actual = template.FormatWith(testObject, new TestEnvironment());
actual.ShouldBe(expected);
}
[Test]
public void FormatWith_MixedLegacyAndNewSyntax_ShouldWork()
{
var testObject = new
{
OldStyle = 0,
NewStyle = 42,
RegularProp = "test"
};
const string template = "{OldStyle:pos;neg;''}{NewStyle:0000 ?? 'fallback'}{RegularProp}";
const string expected = "0042test";
var actual = template.FormatWith(testObject, new TestEnvironment());
actual.ShouldBe(expected);
}
[Test]
public void FormatWith_LegacyWithStandardFormatSpecifiers_ShouldWork()
{
var testObject = new { Amount = 1234.56 };
const string template = "{Amount:C2;(C2);'No Amount'}";
const string expected = "¤1,234.56";
var actual = template.FormatWith(testObject, new TestEnvironment());
actual.ShouldBe(expected);
}
[Test]
public void FormatWith_Issue4654ExactCase_ShouldWork()
{
var semanticVersion = new SemanticVersion
{
Major = 6,
Minor = 13,
Patch = 54,
PreReleaseTag = new SemanticVersionPreReleaseTag("gv6", 1, true),
BuildMetaData = new SemanticVersionBuildMetaData("Branch.feature-gv6")
{
CommitsSinceVersionSource = 2
}
};
var mainBranchVersion = new SemanticVersion
{
Major = 6,
Minor = 13,
Patch = 54,
PreReleaseTag = new SemanticVersionPreReleaseTag(string.Empty, 0, true),
BuildMetaData = new SemanticVersionBuildMetaData()
{
CommitsSinceVersionSource = 0
}
};
const string template = "{MajorMinorPatch}{PreReleaseLabelWithDash}{CommitsSinceVersionSource:0000;;''}";
var featureResult = template.FormatWith(semanticVersion, new TestEnvironment());
featureResult.ShouldBe("6.13.54-gv60002");
var mainResult = template.FormatWith(mainBranchVersion, new TestEnvironment());
mainResult.ShouldBe("6.13.54");
}
}