github.com/graemephi/kahugo@v0.62.3-0.20211121071557-d78c0423784d/common/hugo/version_test.go (about) 1 // Copyright 2015 The Hugo Authors. All rights reserved. 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); 4 // you may not use this file except in compliance with the License. 5 // You may obtain a copy of the License at 6 // http://www.apache.org/licenses/LICENSE-2.0 7 // 8 // Unless required by applicable law or agreed to in writing, software 9 // distributed under the License is distributed on an "AS IS" BASIS, 10 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 11 // See the License for the specific language governing permissions and 12 // limitations under the License. 13 14 package hugo 15 16 import ( 17 "testing" 18 19 qt "github.com/frankban/quicktest" 20 ) 21 22 func TestHugoVersion(t *testing.T) { 23 c := qt.New(t) 24 25 c.Assert(version(0.15, 0, "-DEV"), qt.Equals, "0.15-DEV") 26 c.Assert(version(0.15, 2, "-DEV"), qt.Equals, "0.15.2-DEV") 27 28 v := Version{Number: 0.21, PatchLevel: 0, Suffix: "-DEV"} 29 30 c.Assert(v.ReleaseVersion().String(), qt.Equals, "0.21") 31 c.Assert(v.String(), qt.Equals, "0.21-DEV") 32 c.Assert(v.Next().String(), qt.Equals, "0.22") 33 nextVersionString := v.Next().Version() 34 c.Assert(nextVersionString.String(), qt.Equals, "0.22") 35 c.Assert(nextVersionString.Eq("0.22"), qt.Equals, true) 36 c.Assert(nextVersionString.Eq("0.21"), qt.Equals, false) 37 c.Assert(nextVersionString.Eq(nextVersionString), qt.Equals, true) 38 c.Assert(v.NextPatchLevel(3).String(), qt.Equals, "0.20.3") 39 40 // We started to use full semver versions even for main 41 // releases in v0.54.0 42 v = Version{Number: 0.53, PatchLevel: 0} 43 c.Assert(v.String(), qt.Equals, "0.53") 44 c.Assert(v.Next().String(), qt.Equals, "0.54.0") 45 c.Assert(v.Next().Next().String(), qt.Equals, "0.55.0") 46 v = Version{Number: 0.54, PatchLevel: 0, Suffix: "-DEV"} 47 c.Assert(v.String(), qt.Equals, "0.54.0-DEV") 48 } 49 50 func TestCompareVersions(t *testing.T) { 51 c := qt.New(t) 52 53 c.Assert(compareVersions(0.20, 0, 0.20), qt.Equals, 0) 54 c.Assert(compareVersions(0.20, 0, float32(0.20)), qt.Equals, 0) 55 c.Assert(compareVersions(0.20, 0, float64(0.20)), qt.Equals, 0) 56 c.Assert(compareVersions(0.19, 1, 0.20), qt.Equals, 1) 57 c.Assert(compareVersions(0.19, 3, "0.20.2"), qt.Equals, 1) 58 c.Assert(compareVersions(0.19, 1, 0.01), qt.Equals, -1) 59 c.Assert(compareVersions(0, 1, 3), qt.Equals, 1) 60 c.Assert(compareVersions(0, 1, int32(3)), qt.Equals, 1) 61 c.Assert(compareVersions(0, 1, int64(3)), qt.Equals, 1) 62 c.Assert(compareVersions(0.20, 0, "0.20"), qt.Equals, 0) 63 c.Assert(compareVersions(0.20, 1, "0.20.1"), qt.Equals, 0) 64 c.Assert(compareVersions(0.20, 1, "0.20"), qt.Equals, -1) 65 c.Assert(compareVersions(0.20, 0, "0.20.1"), qt.Equals, 1) 66 c.Assert(compareVersions(0.20, 1, "0.20.2"), qt.Equals, 1) 67 c.Assert(compareVersions(0.21, 1, "0.22.1"), qt.Equals, 1) 68 c.Assert(compareVersions(0.22, 0, "0.22-DEV"), qt.Equals, -1) 69 c.Assert(compareVersions(0.22, 0, "0.22.1-DEV"), qt.Equals, 1) 70 c.Assert(compareVersionsWithSuffix(0.22, 0, "-DEV", "0.22"), qt.Equals, 1) 71 c.Assert(compareVersionsWithSuffix(0.22, 1, "-DEV", "0.22"), qt.Equals, -1) 72 c.Assert(compareVersionsWithSuffix(0.22, 1, "-DEV", "0.22.1-DEV"), qt.Equals, 0) 73 } 74 75 func TestParseHugoVersion(t *testing.T) { 76 c := qt.New(t) 77 78 c.Assert(MustParseVersion("0.25").String(), qt.Equals, "0.25") 79 c.Assert(MustParseVersion("0.25.2").String(), qt.Equals, "0.25.2") 80 c.Assert(MustParseVersion("0.25-test").String(), qt.Equals, "0.25-test") 81 c.Assert(MustParseVersion("0.25-DEV").String(), qt.Equals, "0.25-DEV") 82 } 83 84 func TestGoMinorVersion(t *testing.T) { 85 c := qt.New(t) 86 c.Assert(goMinorVersion("go1.12.5"), qt.Equals, 12) 87 c.Assert(goMinorVersion("go1.14rc1"), qt.Equals, 14) 88 c.Assert(GoMinorVersion() >= 11, qt.Equals, true) 89 }