@@ -28,4 +28,125 @@ public void Submodule_RecognizedWithCorrectVersion()
2828 Assert . Equal ( "3ea7f010c3" , oracleB . GitCommitIdShort ) ;
2929 }
3030 }
31+
32+ [ Fact ]
33+ public void MajorMinorPrereleaseBuildMetadata ( )
34+ {
35+ VersionOptions workingCopyVersion = new VersionOptions
36+ {
37+ Version = SemanticVersion . Parse ( "7.8-beta.3+metadata.4" ) ,
38+ } ;
39+ this . WriteVersionFile ( workingCopyVersion ) ;
40+ this . InitializeSourceControl ( ) ;
41+ var oracle = VersionOracle . Create ( this . RepoPath ) ;
42+ Assert . Equal ( "7.8" , oracle . MajorMinorVersion . ToString ( ) ) ;
43+ Assert . Equal ( oracle . VersionHeight , oracle . BuildNumber ) ;
44+
45+ Assert . Equal ( "-beta.3" , oracle . PrereleaseVersion ) ;
46+ ////Assert.Equal("+metadata.4", oracle.BuildMetadataFragment);
47+
48+ Assert . Equal ( 1 , oracle . VersionHeight ) ;
49+ Assert . Equal ( 0 , oracle . VersionHeightOffset ) ;
50+ }
51+
52+ [ Fact ]
53+ public void MajorMinorBuildPrereleaseBuildMetadata ( )
54+ {
55+ VersionOptions workingCopyVersion = new VersionOptions
56+ {
57+ Version = SemanticVersion . Parse ( "7.8.9-beta.3+metadata.4" ) ,
58+ } ;
59+ this . WriteVersionFile ( workingCopyVersion ) ;
60+ this . InitializeSourceControl ( ) ;
61+ var oracle = VersionOracle . Create ( this . RepoPath ) ;
62+ Assert . Equal ( "7.8" , oracle . MajorMinorVersion . ToString ( ) ) ;
63+ Assert . Equal ( 9 , oracle . BuildNumber ) ;
64+ Assert . Equal ( oracle . VersionHeight + oracle . VersionHeightOffset , oracle . Version . Revision ) ;
65+
66+ Assert . Equal ( "-beta.3" , oracle . PrereleaseVersion ) ;
67+ ////Assert.Equal("+metadata.4", oracle.BuildMetadataFragment);
68+
69+ Assert . Equal ( 1 , oracle . VersionHeight ) ;
70+ Assert . Equal ( 0 , oracle . VersionHeightOffset ) ;
71+ }
72+
73+ [ Fact ]
74+ public void HeightInPrerelease ( )
75+ {
76+ VersionOptions workingCopyVersion = new VersionOptions
77+ {
78+ Version = SemanticVersion . Parse ( "7.8.9-beta.{height}.foo" ) ,
79+ BuildNumberOffset = 2 ,
80+ } ;
81+ this . WriteVersionFile ( workingCopyVersion ) ;
82+ this . InitializeSourceControl ( ) ;
83+ var oracle = VersionOracle . Create ( this . RepoPath ) ;
84+ Assert . Equal ( "7.8" , oracle . MajorMinorVersion . ToString ( ) ) ;
85+ Assert . Equal ( 9 , oracle . BuildNumber ) ;
86+ Assert . Equal ( oracle . VersionHeight + oracle . VersionHeightOffset , oracle . Version . Revision ) ;
87+
88+ Assert . Equal ( "-beta." + ( oracle . VersionHeight + oracle . VersionHeightOffset ) + ".foo" , oracle . PrereleaseVersion ) ;
89+
90+ Assert . Equal ( 1 , oracle . VersionHeight ) ;
91+ Assert . Equal ( 2 , oracle . VersionHeightOffset ) ;
92+ }
93+
94+ [ Fact ( Skip = "Build metadata not yet retained from version.json" ) ]
95+ public void HeightInBuildMetadata ( )
96+ {
97+ VersionOptions workingCopyVersion = new VersionOptions
98+ {
99+ Version = SemanticVersion . Parse ( "7.8.9-beta+another.{height}.foo" ) ,
100+ BuildNumberOffset = 2 ,
101+ } ;
102+ this . WriteVersionFile ( workingCopyVersion ) ;
103+ this . InitializeSourceControl ( ) ;
104+ var oracle = VersionOracle . Create ( this . RepoPath ) ;
105+ Assert . Equal ( "7.8" , oracle . MajorMinorVersion . ToString ( ) ) ;
106+ Assert . Equal ( 9 , oracle . BuildNumber ) ;
107+ Assert . Equal ( oracle . VersionHeight + oracle . VersionHeightOffset , oracle . Version . Revision ) ;
108+
109+ Assert . Equal ( "-beta" , oracle . PrereleaseVersion ) ;
110+ Assert . Equal ( "+another." + ( oracle . VersionHeight + oracle . VersionHeightOffset ) + ".foo" , oracle . BuildMetadataFragment ) ;
111+
112+ Assert . Equal ( 1 , oracle . VersionHeight ) ;
113+ Assert . Equal ( 2 , oracle . VersionHeightOffset ) ;
114+ }
115+
116+ [ Theory ]
117+ [ InlineData ( "7.8.9-foo.25" , "7.8.9-foo-0025" ) ]
118+ [ InlineData ( "7.8.9-foo.25s" , "7.8.9-foo-25s" ) ]
119+ [ InlineData ( "7.8.9-foo.s25" , "7.8.9-foo-s25" ) ]
120+ [ InlineData ( "7.8.9-foo.25.bar-24.13-11" , "7.8.9-foo-0025-bar-24-13-11" ) ]
121+ [ InlineData ( "7.8.9-25.bar.baz-25" , "7.8.9-0025-bar-baz-25" ) ]
122+ [ InlineData ( "7.8.9-foo.5.bar.1.43.baz" , "7.8.9-foo-0005-bar-0001-0043-baz" ) ]
123+ public void SemVer1PrereleaseConversion ( string semVer2 , string semVer1 )
124+ {
125+ VersionOptions workingCopyVersion = new VersionOptions
126+ {
127+ Version = SemanticVersion . Parse ( semVer2 ) ,
128+ BuildNumberOffset = 2 ,
129+ } ;
130+ this . WriteVersionFile ( workingCopyVersion ) ;
131+ this . InitializeSourceControl ( ) ;
132+ var oracle = VersionOracle . Create ( this . RepoPath ) ;
133+ oracle . PublicRelease = true ;
134+ Assert . Equal ( semVer1 , oracle . SemVer1 ) ;
135+ }
136+
137+ [ Fact ]
138+ public void SemVer1PrereleaseConversionPadding ( )
139+ {
140+ VersionOptions workingCopyVersion = new VersionOptions
141+ {
142+ Version = SemanticVersion . Parse ( "7.8.9-foo.25" ) ,
143+ BuildNumberOffset = 2 ,
144+ SemVer1NumericIdentifierPadding = 3 ,
145+ } ;
146+ this . WriteVersionFile ( workingCopyVersion ) ;
147+ this . InitializeSourceControl ( ) ;
148+ var oracle = VersionOracle . Create ( this . RepoPath ) ;
149+ oracle . PublicRelease = true ;
150+ Assert . Equal ( "7.8.9-foo-025" , oracle . SemVer1 ) ;
151+ }
31152}
0 commit comments