4
4
5
5
namespace GitVersion . Core . Tests . Formatting ;
6
6
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>
11
7
[ TestFixture ]
12
8
public class LegacyFormattingSyntaxTests
13
9
{
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>
18
10
[ Test ]
19
11
public void FormatWith_LegacyZeroFallbackSyntax_ShouldWork ( )
20
12
{
21
- // Arrange
22
13
var semanticVersion = new SemanticVersion
23
14
{
24
15
Major = 6 ,
@@ -36,119 +27,82 @@ public void FormatWith_LegacyZeroFallbackSyntax_ShouldWork()
36
27
}
37
28
} ;
38
29
39
- // The exact template from the issue
40
30
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" ;
42
32
43
- // Act
44
33
var actual = template . FormatWith ( semanticVersion , new TestEnvironment ( ) ) ;
45
34
46
- // Assert
47
35
actual . ShouldBe ( expected ) ;
48
36
}
49
37
50
- /// <summary>
51
- /// Test that legacy positive/negative/zero section syntax works
52
- /// </summary>
53
38
[ Test ]
54
39
public void FormatWith_LegacyThreeSectionSyntax_ShouldWork ( )
55
40
{
56
- // Arrange
57
41
var testObject = new { Value = - 5 } ;
58
42
const string template = "{Value:positive;negative;zero}" ;
59
43
const string expected = "negative" ;
60
44
61
- // Act
62
45
var actual = template . FormatWith ( testObject , new TestEnvironment ( ) ) ;
63
46
64
- // Assert
65
47
actual . ShouldBe ( expected ) ;
66
48
}
67
49
68
- /// <summary>
69
- /// Test that legacy two-section syntax works (positive;negative)
70
- /// </summary>
71
50
[ Test ]
72
51
public void FormatWith_LegacyTwoSectionSyntax_ShouldWork ( )
73
52
{
74
- // Arrange
75
53
var testObject = new { Value = - 10 } ;
76
54
const string template = "{Value:positive;negative}" ;
77
55
const string expected = "negative" ;
78
56
79
- // Act
80
57
var actual = template . FormatWith ( testObject , new TestEnvironment ( ) ) ;
81
58
82
- // Assert
83
59
actual . ShouldBe ( expected ) ;
84
60
}
85
61
86
- /// <summary>
87
- /// Test that zero values use the third section in legacy syntax
88
- /// </summary>
89
62
[ Test ]
90
63
public void FormatWith_LegacyZeroValue_ShouldUseThirdSection ( )
91
64
{
92
- // Arrange
93
65
var testObject = new { Value = 0 } ;
94
66
const string template = "{Value:pos;neg;ZERO}" ;
95
67
const string expected = "ZERO" ;
96
68
97
- // Act
98
69
var actual = template . FormatWith ( testObject , new TestEnvironment ( ) ) ;
99
70
100
- // Assert
101
71
actual . ShouldBe ( expected ) ;
102
72
}
103
73
104
- /// <summary>
105
- /// Test mixed usage: some properties with legacy syntax, others with new syntax
106
- /// </summary>
107
74
[ Test ]
108
75
public void FormatWith_MixedLegacyAndNewSyntax_ShouldWork ( )
109
76
{
110
- // Arrange
111
77
var testObject = new
112
78
{
113
79
OldStyle = 0 ,
114
80
NewStyle = 42 ,
115
81
RegularProp = "test"
116
82
} ;
117
83
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" ;
119
85
120
- // Act
121
86
var actual = template . FormatWith ( testObject , new TestEnvironment ( ) ) ;
122
87
123
- // Assert
124
88
actual . ShouldBe ( expected ) ;
125
89
}
126
90
127
- /// <summary>
128
- /// Test that complex legacy format with actual .NET format specifiers works
129
- /// </summary>
130
91
[ Test ]
131
92
public void FormatWith_LegacyWithStandardFormatSpecifiers_ShouldWork ( )
132
93
{
133
- // Arrange
134
94
var testObject = new { Amount = 1234.56 } ;
135
95
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" ;
137
97
138
- // Act
139
98
var actual = template . FormatWith ( testObject , new TestEnvironment ( ) ) ;
140
99
141
- // Assert
142
100
actual . ShouldBe ( expected ) ;
143
101
}
144
102
145
- /// <summary>
146
- /// Test that the original failing case from issue #4654 works exactly as expected
147
- /// </summary>
148
103
[ Test ]
149
104
public void FormatWith_Issue4654ExactCase_ShouldWork ( )
150
105
{
151
- // Arrange - recreate the exact scenario from the issue
152
106
var semanticVersion = new SemanticVersion
153
107
{
154
108
Major = 6 ,
@@ -161,7 +115,6 @@ public void FormatWith_Issue4654ExactCase_ShouldWork()
161
115
}
162
116
} ;
163
117
164
- // This should work on main branch where PreReleaseLabelWithDash would be empty
165
118
var mainBranchVersion = new SemanticVersion
166
119
{
167
120
Major = 6 ,
@@ -176,69 +129,44 @@ public void FormatWith_Issue4654ExactCase_ShouldWork()
176
129
177
130
const string template = "{MajorMinorPatch}{PreReleaseLabelWithDash}{CommitsSinceVersionSource:0000;;''}" ;
178
131
179
- // Act & Assert for feature branch
180
132
var featureResult = template . FormatWith ( semanticVersion , new TestEnvironment ( ) ) ;
181
133
featureResult . ShouldBe ( "6.13.54-gv60002" ) ;
182
134
183
- // Act & Assert for main branch (zero commits should show empty string)
184
135
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" ) ;
186
137
}
187
138
}
188
139
189
- /// <summary>
190
- /// Tests specifically for the regex pattern changes to ensure backward compatibility
191
- /// </summary>
192
140
[ TestFixture ]
193
141
public class LegacyRegexPatternTests
194
142
{
195
- /// <summary>
196
- /// Test that the ExpandTokensRegex can parse legacy semicolon syntax
197
- /// </summary>
198
143
[ Test ]
199
144
public void ExpandTokensRegex_ShouldParseLegacySemicolonSyntax ( )
200
145
{
201
- // Arrange
202
146
const string input = "{CommitsSinceVersionSource:0000;;''}" ;
203
147
204
- // Act
205
148
var matches = RegexPatterns . Common . ExpandTokensRegex ( ) . Matches ( input ) ;
206
149
207
- // Assert
208
150
matches . Count . ShouldBe ( 1 ) ;
209
151
var match = matches [ 0 ] ;
210
152
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
215
153
match . Groups [ "format" ] . Success . ShouldBeTrue ( ) ;
216
- // The exact capture will depend on implementation - this test will guide the regex design
217
154
}
218
155
219
- /// <summary>
220
- /// Test that both new and old syntax can coexist in the same template
221
- /// </summary>
222
156
[ Test ]
223
157
public void ExpandTokensRegex_ShouldHandleMixedSyntax ( )
224
158
{
225
- // Arrange
226
159
const string input = "{NewStyle:0000 ?? 'fallback'} {OldStyle:pos;neg;zero}" ;
227
160
228
- // Act
229
161
var matches = RegexPatterns . Common . ExpandTokensRegex ( ) . Matches ( input ) ;
230
162
231
- // Assert
232
163
matches . Count . ShouldBe ( 2 ) ;
233
164
234
- // First match: new syntax
235
165
var newMatch = matches [ 0 ] ;
236
166
newMatch . Groups [ "member" ] . Value . ShouldBe ( "NewStyle" ) ;
237
167
newMatch . Groups [ "fallback" ] . Value . ShouldBe ( "fallback" ) ;
238
168
239
- // Second match: old syntax
240
169
var oldMatch = matches [ 1 ] ;
241
170
oldMatch . Groups [ "member" ] . Value . ShouldBe ( "OldStyle" ) ;
242
- // Format handling for legacy syntax TBD based on implementation approach
243
171
}
244
- }
172
+ }
0 commit comments