github.com/dominikszabo/hugo-ds-clean@v0.47.1/helpers/hugo_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 helpers
    15  
    16  import (
    17  	"testing"
    18  
    19  	"github.com/stretchr/testify/assert"
    20  	"github.com/stretchr/testify/require"
    21  )
    22  
    23  func TestHugoVersion(t *testing.T) {
    24  	assert.Equal(t, "0.15-DEV", hugoVersion(0.15, 0, "-DEV"))
    25  	assert.Equal(t, "0.15.2-DEV", hugoVersion(0.15, 2, "-DEV"))
    26  
    27  	v := HugoVersion{Number: 0.21, PatchLevel: 0, Suffix: "-DEV"}
    28  
    29  	require.Equal(t, v.ReleaseVersion().String(), "0.21")
    30  	require.Equal(t, "0.21-DEV", v.String())
    31  	require.Equal(t, "0.22", v.Next().String())
    32  	nextVersionString := v.Next().Version()
    33  	require.Equal(t, "0.22", nextVersionString.String())
    34  	require.True(t, nextVersionString.Eq("0.22"))
    35  	require.False(t, nextVersionString.Eq("0.21"))
    36  	require.True(t, nextVersionString.Eq(nextVersionString))
    37  	require.Equal(t, "0.20.3", v.NextPatchLevel(3).String())
    38  }
    39  
    40  func TestCompareVersions(t *testing.T) {
    41  	require.Equal(t, 0, compareVersions(0.20, 0, 0.20))
    42  	require.Equal(t, 0, compareVersions(0.20, 0, float32(0.20)))
    43  	require.Equal(t, 0, compareVersions(0.20, 0, float64(0.20)))
    44  	require.Equal(t, 1, compareVersions(0.19, 1, 0.20))
    45  	require.Equal(t, 1, compareVersions(0.19, 3, "0.20.2"))
    46  	require.Equal(t, -1, compareVersions(0.19, 1, 0.01))
    47  	require.Equal(t, 1, compareVersions(0, 1, 3))
    48  	require.Equal(t, 1, compareVersions(0, 1, int32(3)))
    49  	require.Equal(t, 1, compareVersions(0, 1, int64(3)))
    50  	require.Equal(t, 0, compareVersions(0.20, 0, "0.20"))
    51  	require.Equal(t, 0, compareVersions(0.20, 1, "0.20.1"))
    52  	require.Equal(t, -1, compareVersions(0.20, 1, "0.20"))
    53  	require.Equal(t, 1, compareVersions(0.20, 0, "0.20.1"))
    54  	require.Equal(t, 1, compareVersions(0.20, 1, "0.20.2"))
    55  	require.Equal(t, 1, compareVersions(0.21, 1, "0.22.1"))
    56  	require.Equal(t, -1, compareVersions(0.22, 0, "0.22-DEV"))
    57  	require.Equal(t, 1, compareVersions(0.22, 0, "0.22.1-DEV"))
    58  	require.Equal(t, 1, compareVersionsWithSuffix(0.22, 0, "-DEV", "0.22"))
    59  	require.Equal(t, -1, compareVersionsWithSuffix(0.22, 1, "-DEV", "0.22"))
    60  	require.Equal(t, 0, compareVersionsWithSuffix(0.22, 1, "-DEV", "0.22.1-DEV"))
    61  
    62  }
    63  
    64  func TestParseHugoVersion(t *testing.T) {
    65  	require.Equal(t, "0.25", MustParseHugoVersion("0.25").String())
    66  	require.Equal(t, "0.25.2", MustParseHugoVersion("0.25.2").String())
    67  	require.Equal(t, "0.25-test", MustParseHugoVersion("0.25-test").String())
    68  	require.Equal(t, "0.25-DEV", MustParseHugoVersion("0.25-DEV").String())
    69  
    70  }