Skip to content

Commit 3629aef

Browse files
committed
Refactor
1 parent c757b53 commit 3629aef

File tree

8 files changed

+212
-234
lines changed

8 files changed

+212
-234
lines changed
Lines changed: 1 addition & 138 deletions
Original file line numberDiff line numberDiff line change
@@ -1,142 +1,5 @@
1-
using System.Globalization;
2-
using GitVersion.Core.Tests.Helpers;
3-
using GitVersion.Formatting;
4-
51
namespace GitVersion.Core.Tests.Formatting;
62

7-
[TestFixture]
8-
public class LegacyFormattingSyntaxTests
9-
{
10-
[Test]
11-
public void FormatWith_LegacyZeroFallbackSyntax_ShouldWork()
12-
{
13-
var semanticVersion = new SemanticVersion
14-
{
15-
Major = 6,
16-
Minor = 13,
17-
Patch = 54,
18-
PreReleaseTag = new SemanticVersionPreReleaseTag("gv6", 1, true),
19-
BuildMetaData = new SemanticVersionBuildMetaData()
20-
{
21-
Branch = "feature/gv6",
22-
VersionSourceSha = "versionSourceSha",
23-
Sha = "489a0c0ab425214def918e36399f3cc3c9a9c42d",
24-
ShortSha = "489a0c0",
25-
CommitsSinceVersionSource = 2,
26-
CommitDate = DateTimeOffset.Parse("2025-08-12", CultureInfo.InvariantCulture)
27-
}
28-
};
29-
30-
const string template = "{MajorMinorPatch}{PreReleaseLabelWithDash}{CommitsSinceVersionSource:0000;;''}";
31-
const string expected = "6.13.54-gv60002";
32-
33-
var actual = template.FormatWith(semanticVersion, new TestEnvironment());
34-
35-
actual.ShouldBe(expected);
36-
}
37-
38-
[Test]
39-
public void FormatWith_LegacyThreeSectionSyntax_ShouldWork()
40-
{
41-
var testObject = new { Value = -5 };
42-
const string template = "{Value:positive;negative;zero}";
43-
const string expected = "negative";
44-
45-
var actual = template.FormatWith(testObject, new TestEnvironment());
46-
47-
actual.ShouldBe(expected);
48-
}
49-
50-
[Test]
51-
public void FormatWith_LegacyTwoSectionSyntax_ShouldWork()
52-
{
53-
var testObject = new { Value = -10 };
54-
const string template = "{Value:positive;negative}";
55-
const string expected = "negative";
56-
57-
var actual = template.FormatWith(testObject, new TestEnvironment());
58-
59-
actual.ShouldBe(expected);
60-
}
61-
62-
[Test]
63-
public void FormatWith_LegacyZeroValue_ShouldUseThirdSection()
64-
{
65-
var testObject = new { Value = 0 };
66-
const string template = "{Value:pos;neg;ZERO}";
67-
const string expected = "ZERO";
68-
69-
var actual = template.FormatWith(testObject, new TestEnvironment());
70-
71-
actual.ShouldBe(expected);
72-
}
73-
74-
[Test]
75-
public void FormatWith_MixedLegacyAndNewSyntax_ShouldWork()
76-
{
77-
var testObject = new
78-
{
79-
OldStyle = 0,
80-
NewStyle = 42,
81-
RegularProp = "test"
82-
};
83-
const string template = "{OldStyle:pos;neg;''}{NewStyle:0000 ?? 'fallback'}{RegularProp}";
84-
const string expected = "0042test";
85-
86-
var actual = template.FormatWith(testObject, new TestEnvironment());
87-
88-
actual.ShouldBe(expected);
89-
}
90-
91-
[Test]
92-
public void FormatWith_LegacyWithStandardFormatSpecifiers_ShouldWork()
93-
{
94-
var testObject = new { Amount = 1234.56 };
95-
const string template = "{Amount:C2;(C2);'No Amount'}";
96-
const string expected = "¤1,234.56";
97-
98-
var actual = template.FormatWith(testObject, new TestEnvironment());
99-
100-
actual.ShouldBe(expected);
101-
}
102-
103-
[Test]
104-
public void FormatWith_Issue4654ExactCase_ShouldWork()
105-
{
106-
var semanticVersion = new SemanticVersion
107-
{
108-
Major = 6,
109-
Minor = 13,
110-
Patch = 54,
111-
PreReleaseTag = new SemanticVersionPreReleaseTag("gv6", 1, true),
112-
BuildMetaData = new SemanticVersionBuildMetaData("Branch.feature-gv6")
113-
{
114-
CommitsSinceVersionSource = 2
115-
}
116-
};
117-
118-
var mainBranchVersion = new SemanticVersion
119-
{
120-
Major = 6,
121-
Minor = 13,
122-
Patch = 54,
123-
PreReleaseTag = new SemanticVersionPreReleaseTag(string.Empty, 0, true),
124-
BuildMetaData = new SemanticVersionBuildMetaData()
125-
{
126-
CommitsSinceVersionSource = 0
127-
}
128-
};
129-
130-
const string template = "{MajorMinorPatch}{PreReleaseLabelWithDash}{CommitsSinceVersionSource:0000;;''}";
131-
132-
var featureResult = template.FormatWith(semanticVersion, new TestEnvironment());
133-
featureResult.ShouldBe("6.13.54-gv60002");
134-
135-
var mainResult = template.FormatWith(mainBranchVersion, new TestEnvironment());
136-
mainResult.ShouldBe("6.13.54");
137-
}
138-
}
139-
1403
[TestFixture]
1414
public class LegacyRegexPatternTests
1425
{
@@ -169,4 +32,4 @@ public void ExpandTokensRegex_ShouldHandleMixedSyntax()
16932
var oldMatch = matches[1];
17033
oldMatch.Groups["member"].Value.ShouldBe("OldStyle");
17134
}
172-
}
35+
}

src/GitVersion.Core.Tests/Formatting/DateFormatterTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
using System.Globalization;
22
using GitVersion.Formatting;
33

4-
namespace GitVersion.Tests.Formatting;
4+
namespace GitVersion.Core.Tests.Formatting;
55

66
[TestFixture]
77
public class DateFormatterTests
Lines changed: 138 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,138 @@
1+
using System.Globalization;
2+
using GitVersion.Core.Tests.Helpers;
3+
using GitVersion.Formatting;
4+
5+
namespace GitVersion.Core.Tests.Formatting;
6+
7+
[TestFixture]
8+
public class LegacyFormattingSyntaxTests
9+
{
10+
[Test]
11+
public void FormatWith_LegacyZeroFallbackSyntax_ShouldWork()
12+
{
13+
var semanticVersion = new SemanticVersion
14+
{
15+
Major = 6,
16+
Minor = 13,
17+
Patch = 54,
18+
PreReleaseTag = new SemanticVersionPreReleaseTag("gv6", 1, true),
19+
BuildMetaData = new SemanticVersionBuildMetaData()
20+
{
21+
Branch = "feature/gv6",
22+
VersionSourceSha = "versionSourceSha",
23+
Sha = "489a0c0ab425214def918e36399f3cc3c9a9c42d",
24+
ShortSha = "489a0c0",
25+
CommitsSinceVersionSource = 2,
26+
CommitDate = DateTimeOffset.Parse("2025-08-12", CultureInfo.InvariantCulture)
27+
}
28+
};
29+
30+
const string template = "{MajorMinorPatch}{PreReleaseLabelWithDash}{CommitsSinceVersionSource:0000;;''}";
31+
const string expected = "6.13.54-gv60002";
32+
33+
var actual = template.FormatWith(semanticVersion, new TestEnvironment());
34+
35+
actual.ShouldBe(expected);
36+
}
37+
38+
[Test]
39+
public void FormatWith_LegacyThreeSectionSyntax_ShouldWork()
40+
{
41+
var testObject = new { Value = -5 };
42+
const string template = "{Value:positive;negative;zero}";
43+
const string expected = "negative";
44+
45+
var actual = template.FormatWith(testObject, new TestEnvironment());
46+
47+
actual.ShouldBe(expected);
48+
}
49+
50+
[Test]
51+
public void FormatWith_LegacyTwoSectionSyntax_ShouldWork()
52+
{
53+
var testObject = new { Value = -10 };
54+
const string template = "{Value:positive;negative}";
55+
const string expected = "negative";
56+
57+
var actual = template.FormatWith(testObject, new TestEnvironment());
58+
59+
actual.ShouldBe(expected);
60+
}
61+
62+
[Test]
63+
public void FormatWith_LegacyZeroValue_ShouldUseThirdSection()
64+
{
65+
var testObject = new { Value = 0 };
66+
const string template = "{Value:pos;neg;ZERO}";
67+
const string expected = "ZERO";
68+
69+
var actual = template.FormatWith(testObject, new TestEnvironment());
70+
71+
actual.ShouldBe(expected);
72+
}
73+
74+
[Test]
75+
public void FormatWith_MixedLegacyAndNewSyntax_ShouldWork()
76+
{
77+
var testObject = new
78+
{
79+
OldStyle = 0,
80+
NewStyle = 42,
81+
RegularProp = "test"
82+
};
83+
const string template = "{OldStyle:pos;neg;''}{NewStyle:0000 ?? 'fallback'}{RegularProp}";
84+
const string expected = "0042test";
85+
86+
var actual = template.FormatWith(testObject, new TestEnvironment());
87+
88+
actual.ShouldBe(expected);
89+
}
90+
91+
[Test]
92+
public void FormatWith_LegacyWithStandardFormatSpecifiers_ShouldWork()
93+
{
94+
var testObject = new { Amount = 1234.56 };
95+
const string template = "{Amount:C2;(C2);'No Amount'}";
96+
const string expected = "¤1,234.56";
97+
98+
var actual = template.FormatWith(testObject, new TestEnvironment());
99+
100+
actual.ShouldBe(expected);
101+
}
102+
103+
[Test]
104+
public void FormatWith_Issue4654ExactCase_ShouldWork()
105+
{
106+
var semanticVersion = new SemanticVersion
107+
{
108+
Major = 6,
109+
Minor = 13,
110+
Patch = 54,
111+
PreReleaseTag = new SemanticVersionPreReleaseTag("gv6", 1, true),
112+
BuildMetaData = new SemanticVersionBuildMetaData("Branch.feature-gv6")
113+
{
114+
CommitsSinceVersionSource = 2
115+
}
116+
};
117+
118+
var mainBranchVersion = new SemanticVersion
119+
{
120+
Major = 6,
121+
Minor = 13,
122+
Patch = 54,
123+
PreReleaseTag = new SemanticVersionPreReleaseTag(string.Empty, 0, true),
124+
BuildMetaData = new SemanticVersionBuildMetaData()
125+
{
126+
CommitsSinceVersionSource = 0
127+
}
128+
};
129+
130+
const string template = "{MajorMinorPatch}{PreReleaseLabelWithDash}{CommitsSinceVersionSource:0000;;''}";
131+
132+
var featureResult = template.FormatWith(semanticVersion, new TestEnvironment());
133+
featureResult.ShouldBe("6.13.54-gv60002");
134+
135+
var mainResult = template.FormatWith(mainBranchVersion, new TestEnvironment());
136+
mainResult.ShouldBe("6.13.54");
137+
}
138+
}

src/GitVersion.Core.Tests/Formatting/StringFormatterTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
using GitVersion.Formatting;
22

3-
namespace GitVersion.Tests.Formatting;
3+
namespace GitVersion.Core.Tests.Formatting;
44

55
[TestFixture]
66
public class StringFormatterTests

src/GitVersion.Core.Tests/Formatting/ValueFormatterTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
using System.Globalization;
22
using GitVersion.Formatting;
33

4-
namespace GitVersion.Tests.Formatting;
4+
namespace GitVersion.Core.Tests.Formatting;
55

66
[TestFixture]
77
public class ValueFormatterTests

0 commit comments

Comments
 (0)