44
55namespace 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 ]
128public 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 ]
193141public 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+ }
0 commit comments