gitee.com/gricks/utils@v1.0.8/version_test.go (about)

     1  package utils
     2  
     3  import (
     4  	"testing"
     5  
     6  	. "github.com/smartystreets/goconvey/convey"
     7  )
     8  
     9  func TestVersion(t *testing.T) {
    10  	Convey("TestVersion", t, func() {
    11  		vers := []string{"1.2.10", "1.2.1-alpha", "1.2.2+build.3e9fbc", "1.2.3-alpha+build.3e9fbc"}
    12  		rsts := []*Version{
    13  			{"", "", []int64{1, 2, 10}, vers[0]},
    14  			{"", "alpha", []int64{1, 2, 1}, vers[1]},
    15  			{"build.3e9fbc", "", []int64{1, 2, 2}, vers[2]},
    16  			{"build.3e9fbc", "alpha", []int64{1, 2, 3}, vers[3]},
    17  		}
    18  
    19  		for i := 0; i < len(rsts); i++ {
    20  			v, err := NewVersion(vers[i])
    21  			So(err, ShouldBeNil)
    22  			So(v, ShouldResemble, rsts[i])
    23  		}
    24  
    25  		sortedRsts := []*Version{rsts[1], rsts[2], rsts[3], rsts[0]}
    26  
    27  		Versions(rsts).Sort()
    28  
    29  		So(rsts, ShouldResemble, sortedRsts)
    30  	})
    31  }