Skip to content

Commit c757b53

Browse files
committed
Green
1 parent 32b8c05 commit c757b53

File tree

5 files changed

+177
-133
lines changed

5 files changed

+177
-133
lines changed

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

Lines changed: 5 additions & 77 deletions
Original file line numberDiff line numberDiff line change
@@ -4,21 +4,12 @@
44

55
namespace GitVersion.Core.Tests.Formatting;
66

7-
/// <summary>
8-
/// Tests for backward compatibility with legacy .NET composite format syntax (;;)
9-
/// These tests document the expected behavior before implementing the fix.
10-
/// </summary>
117
[TestFixture]
128
public class LegacyFormattingSyntaxTests
139
{
14-
/// <summary>
15-
/// Test that the old ;;'' syntax for zero-value fallbacks still works
16-
/// This is the exact case from issue #4654
17-
/// </summary>
1810
[Test]
1911
public void FormatWith_LegacyZeroFallbackSyntax_ShouldWork()
2012
{
21-
// Arrange
2213
var semanticVersion = new SemanticVersion
2314
{
2415
Major = 6,
@@ -36,119 +27,82 @@ public void FormatWith_LegacyZeroFallbackSyntax_ShouldWork()
3627
}
3728
};
3829

39-
// The exact template from the issue
4030
const string template = "{MajorMinorPatch}{PreReleaseLabelWithDash}{CommitsSinceVersionSource:0000;;''}";
41-
const string expected = "6.13.54-gv60002"; // Should format CommitsSinceVersionSource as 0002, not show literal text
31+
const string expected = "6.13.54-gv60002";
4232

43-
// Act
4433
var actual = template.FormatWith(semanticVersion, new TestEnvironment());
4534

46-
// Assert
4735
actual.ShouldBe(expected);
4836
}
4937

50-
/// <summary>
51-
/// Test that legacy positive/negative/zero section syntax works
52-
/// </summary>
5338
[Test]
5439
public void FormatWith_LegacyThreeSectionSyntax_ShouldWork()
5540
{
56-
// Arrange
5741
var testObject = new { Value = -5 };
5842
const string template = "{Value:positive;negative;zero}";
5943
const string expected = "negative";
6044

61-
// Act
6245
var actual = template.FormatWith(testObject, new TestEnvironment());
6346

64-
// Assert
6547
actual.ShouldBe(expected);
6648
}
6749

68-
/// <summary>
69-
/// Test that legacy two-section syntax works (positive;negative)
70-
/// </summary>
7150
[Test]
7251
public void FormatWith_LegacyTwoSectionSyntax_ShouldWork()
7352
{
74-
// Arrange
7553
var testObject = new { Value = -10 };
7654
const string template = "{Value:positive;negative}";
7755
const string expected = "negative";
7856

79-
// Act
8057
var actual = template.FormatWith(testObject, new TestEnvironment());
8158

82-
// Assert
8359
actual.ShouldBe(expected);
8460
}
8561

86-
/// <summary>
87-
/// Test that zero values use the third section in legacy syntax
88-
/// </summary>
8962
[Test]
9063
public void FormatWith_LegacyZeroValue_ShouldUseThirdSection()
9164
{
92-
// Arrange
9365
var testObject = new { Value = 0 };
9466
const string template = "{Value:pos;neg;ZERO}";
9567
const string expected = "ZERO";
9668

97-
// Act
9869
var actual = template.FormatWith(testObject, new TestEnvironment());
9970

100-
// Assert
10171
actual.ShouldBe(expected);
10272
}
10373

104-
/// <summary>
105-
/// Test mixed usage: some properties with legacy syntax, others with new syntax
106-
/// </summary>
10774
[Test]
10875
public void FormatWith_MixedLegacyAndNewSyntax_ShouldWork()
10976
{
110-
// Arrange
11177
var testObject = new
11278
{
11379
OldStyle = 0,
11480
NewStyle = 42,
11581
RegularProp = "test"
11682
};
11783
const string template = "{OldStyle:pos;neg;''}{NewStyle:0000 ?? 'fallback'}{RegularProp}";
118-
const string expected = "0042test"; // Empty string for zero, 0042 for 42, test as-is
84+
const string expected = "0042test";
11985

120-
// Act
12186
var actual = template.FormatWith(testObject, new TestEnvironment());
12287

123-
// Assert
12488
actual.ShouldBe(expected);
12589
}
12690

127-
/// <summary>
128-
/// Test that complex legacy format with actual .NET format specifiers works
129-
/// </summary>
13091
[Test]
13192
public void FormatWith_LegacyWithStandardFormatSpecifiers_ShouldWork()
13293
{
133-
// Arrange
13494
var testObject = new { Amount = 1234.56 };
13595
const string template = "{Amount:C2;(C2);'No Amount'}";
136-
const string expected = "¤1,234.56"; // Should format as currency
96+
const string expected = "¤1,234.56";
13797

138-
// Act
13998
var actual = template.FormatWith(testObject, new TestEnvironment());
14099

141-
// Assert
142100
actual.ShouldBe(expected);
143101
}
144102

145-
/// <summary>
146-
/// Test that the original failing case from issue #4654 works exactly as expected
147-
/// </summary>
148103
[Test]
149104
public void FormatWith_Issue4654ExactCase_ShouldWork()
150105
{
151-
// Arrange - recreate the exact scenario from the issue
152106
var semanticVersion = new SemanticVersion
153107
{
154108
Major = 6,
@@ -161,7 +115,6 @@ public void FormatWith_Issue4654ExactCase_ShouldWork()
161115
}
162116
};
163117

164-
// This should work on main branch where PreReleaseLabelWithDash would be empty
165118
var mainBranchVersion = new SemanticVersion
166119
{
167120
Major = 6,
@@ -176,69 +129,44 @@ public void FormatWith_Issue4654ExactCase_ShouldWork()
176129

177130
const string template = "{MajorMinorPatch}{PreReleaseLabelWithDash}{CommitsSinceVersionSource:0000;;''}";
178131

179-
// Act & Assert for feature branch
180132
var featureResult = template.FormatWith(semanticVersion, new TestEnvironment());
181133
featureResult.ShouldBe("6.13.54-gv60002");
182134

183-
// Act & Assert for main branch (zero commits should show empty string)
184135
var mainResult = template.FormatWith(mainBranchVersion, new TestEnvironment());
185-
mainResult.ShouldBe("6.13.54"); // Empty PreReleaseLabelWithDash and empty string for zero commits
136+
mainResult.ShouldBe("6.13.54");
186137
}
187138
}
188139

189-
/// <summary>
190-
/// Tests specifically for the regex pattern changes to ensure backward compatibility
191-
/// </summary>
192140
[TestFixture]
193141
public class LegacyRegexPatternTests
194142
{
195-
/// <summary>
196-
/// Test that the ExpandTokensRegex can parse legacy semicolon syntax
197-
/// </summary>
198143
[Test]
199144
public void ExpandTokensRegex_ShouldParseLegacySemicolonSyntax()
200145
{
201-
// Arrange
202146
const string input = "{CommitsSinceVersionSource:0000;;''}";
203147

204-
// Act
205148
var matches = RegexPatterns.Common.ExpandTokensRegex().Matches(input);
206149

207-
// Assert
208150
matches.Count.ShouldBe(1);
209151
var match = matches[0];
210152
match.Groups["member"].Value.ShouldBe("CommitsSinceVersionSource");
211-
212-
// The format group should capture the entire format including semicolons
213-
// This test documents what should happen - the format might need to be "0000;;''"
214-
// or the regex might need to separate format and fallback parts
215153
match.Groups["format"].Success.ShouldBeTrue();
216-
// The exact capture will depend on implementation - this test will guide the regex design
217154
}
218155

219-
/// <summary>
220-
/// Test that both new and old syntax can coexist in the same template
221-
/// </summary>
222156
[Test]
223157
public void ExpandTokensRegex_ShouldHandleMixedSyntax()
224158
{
225-
// Arrange
226159
const string input = "{NewStyle:0000 ?? 'fallback'} {OldStyle:pos;neg;zero}";
227160

228-
// Act
229161
var matches = RegexPatterns.Common.ExpandTokensRegex().Matches(input);
230162

231-
// Assert
232163
matches.Count.ShouldBe(2);
233164

234-
// First match: new syntax
235165
var newMatch = matches[0];
236166
newMatch.Groups["member"].Value.ShouldBe("NewStyle");
237167
newMatch.Groups["fallback"].Value.ShouldBe("fallback");
238168

239-
// Second match: old syntax
240169
var oldMatch = matches[1];
241170
oldMatch.Groups["member"].Value.ShouldBe("OldStyle");
242-
// Format handling for legacy syntax TBD based on implementation approach
243171
}
244-
}
172+
}

src/GitVersion.Core.Tests/Issues/Issue4654Tests.cs

Lines changed: 4 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -4,26 +4,13 @@
44

55
namespace GitVersion.Core.Tests.Issues;
66

7-
/// <summary>
8-
/// Tests for Issue #4654 - Incorrect output for assembly-informational-version
9-
/// https://github.com/GitTools/GitVersion/issues/4654
10-
///
11-
/// These tests document the expected behavior before implementing the fix.
12-
/// Currently FAILING - will pass once backward compatibility is implemented.
13-
/// </summary>
147
[TestFixture]
158
public class Issue4654Tests
169
{
17-
/// <summary>
18-
/// Reproduce the exact issue reported in #4654
19-
/// Expected: "6.13.54-gv60002"
20-
/// Actual (broken): "6.13.54-gv6-CommitsSinceVersionSource-0000-----"
21-
/// </summary>
2210
[Test]
2311
[Category("Issue4654")]
2412
public void Issue4654_ExactReproduction_ShouldFormatCorrectly()
2513
{
26-
// Arrange - exact data from the issue
2714
var semanticVersion = new SemanticVersion
2815
{
2916
Major = 6,
@@ -42,23 +29,17 @@ public void Issue4654_ExactReproduction_ShouldFormatCorrectly()
4229
}
4330
};
4431

45-
// Add derived properties that would be available in real GitVersion
4632
var extendedVersion = new
4733
{
48-
// Core properties
4934
semanticVersion.Major,
5035
semanticVersion.Minor,
5136
semanticVersion.Patch,
5237
semanticVersion.BuildMetaData.CommitsSinceVersionSource,
53-
54-
// Derived properties
5538
MajorMinorPatch = $"{semanticVersion.Major}.{semanticVersion.Minor}.{semanticVersion.Patch}",
5639
PreReleaseLabel = semanticVersion.PreReleaseTag.Name,
5740
PreReleaseLabelWithDash = string.IsNullOrEmpty(semanticVersion.PreReleaseTag.Name)
5841
? ""
5942
: $"-{semanticVersion.PreReleaseTag.Name}",
60-
61-
// Other properties from the issue JSON
6243
AssemblySemFileVer = "6.13.54.0",
6344
AssemblySemVer = "6.13.54.0",
6445
BranchName = "feature/gv6",
@@ -67,55 +48,38 @@ public void Issue4654_ExactReproduction_ShouldFormatCorrectly()
6748
SemVer = "6.13.54-gv6.1"
6849
};
6950

70-
// The exact template from the overrideconfig command
7151
const string template = "{MajorMinorPatch}{PreReleaseLabelWithDash}{CommitsSinceVersionSource:0000;;''}";
72-
73-
// Expected result: MajorMinorPatch + PreReleaseLabelWithDash + formatted CommitsSinceVersionSource
7452
const string expected = "6.13.54-gv60002";
7553

76-
// Act
7754
var actual = template.FormatWith(extendedVersion, new TestEnvironment());
7855

79-
// Assert
8056
actual.ShouldBe(expected, "The legacy ;;'' syntax should format CommitsSinceVersionSource as 0002, not as literal text");
8157
}
8258

83-
/// <summary>
84-
/// Test the simpler case without the legacy syntax to ensure basic formatting still works
85-
/// </summary>
8659
[Test]
8760
[Category("Issue4654")]
8861
public void Issue4654_WithoutLegacySyntax_ShouldStillWork()
8962
{
90-
// Arrange
9163
var testData = new
9264
{
9365
MajorMinorPatch = "6.13.54",
9466
PreReleaseLabelWithDash = "-gv6",
9567
CommitsSinceVersionSource = 2
9668
};
9769

98-
// Using new ?? syntax instead of ;;
9970
const string template = "{MajorMinorPatch}{PreReleaseLabelWithDash}{CommitsSinceVersionSource:0000}";
10071
const string expected = "6.13.54-gv60002";
10172

102-
// Act
10373
var actual = template.FormatWith(testData, new TestEnvironment());
10474

105-
// Assert
10675
actual.ShouldBe(expected, "New format syntax should work correctly");
10776
}
10877

109-
/// <summary>
110-
/// Test that demonstrates the current broken behavior
111-
/// This test documents what's currently happening (incorrect output)
112-
/// </summary>
11378
[Test]
11479
[Category("Issue4654")]
11580
[Category("CurrentBehavior")]
11681
public void Issue4654_CurrentBrokenBehavior_DocumentsActualOutput()
11782
{
118-
// Arrange
11983
var testData = new
12084
{
12185
MajorMinorPatch = "6.13.54",
@@ -124,53 +88,38 @@ public void Issue4654_CurrentBrokenBehavior_DocumentsActualOutput()
12488
};
12589

12690
const string template = "{MajorMinorPatch}{PreReleaseLabelWithDash}{CommitsSinceVersionSource:0000;;''}";
127-
128-
// This is what we expect it SHOULD return
12991
const string shouldBe = "6.13.54-gv60002";
13092

131-
// Act
13293
var actual = template.FormatWith(testData, new TestEnvironment());
13394

134-
// Assert - document current broken behavior
135-
// This assertion will fail until the fix is implemented
13695
if (actual == shouldBe)
13796
{
13897
Assert.Pass("The issue has been fixed!");
13998
}
14099
else
141100
{
142-
// Document what it currently returns
143101
Console.WriteLine($"Current broken output: {actual}");
144102
Console.WriteLine($"Expected output: {shouldBe}");
145-
146-
// This assertion should fail, documenting the current broken state
147103
actual.ShouldContain("CommitsSinceVersionSource");
148-
// Explanation: Currently broken - the property name appears as literal text instead of being formatted
149104
}
150105
}
151106

152-
/// <summary>
153-
/// Test edge case: zero value with legacy syntax should use empty fallback
154-
/// </summary>
155107
[Test]
156108
[Category("Issue4654")]
157109
public void Issue4654_ZeroValueWithLegacySyntax_ShouldUseEmptyFallback()
158110
{
159-
// Arrange - main branch scenario where commits since version source is 0
160111
var mainBranchData = new
161112
{
162113
MajorMinorPatch = "6.13.54",
163-
PreReleaseLabelWithDash = "", // Empty on main branch
164-
CommitsSinceVersionSource = 0 // Zero commits
114+
PreReleaseLabelWithDash = "",
115+
CommitsSinceVersionSource = 0
165116
};
166117

167118
const string template = "{MajorMinorPatch}{PreReleaseLabelWithDash}{CommitsSinceVersionSource:0000;;''}";
168-
const string expected = "6.13.54"; // Should be empty string for zero value
119+
const string expected = "6.13.54";
169120

170-
// Act
171121
var actual = template.FormatWith(mainBranchData, new TestEnvironment());
172122

173-
// Assert
174123
actual.ShouldBe(expected, "Zero values should use the third section (empty string) in legacy ;;'' syntax");
175124
}
176-
}
125+
}

0 commit comments

Comments
 (0)