2014-02-21 23:15:28 +00:00
|
|
|
package version
|
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
)
|
|
|
|
|
|
|
|
func assertVersion(t *testing.T, a, b string, result int) {
|
2014-04-01 22:46:52 +00:00
|
|
|
if r := Version(a).compareTo(Version(b)); r != result {
|
2014-02-21 23:15:28 +00:00
|
|
|
t.Fatalf("Unexpected version comparison result. Found %d, expected %d", r, result)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestCompareVersion(t *testing.T) {
|
|
|
|
assertVersion(t, "1.12", "1.12", 0)
|
2014-08-11 21:36:09 +00:00
|
|
|
assertVersion(t, "1.0.0", "1", 0)
|
|
|
|
assertVersion(t, "1", "1.0.0", 0)
|
2014-02-21 23:15:28 +00:00
|
|
|
assertVersion(t, "1.05.00.0156", "1.0.221.9289", 1)
|
|
|
|
assertVersion(t, "1", "1.0.1", -1)
|
|
|
|
assertVersion(t, "1.0.1", "1", 1)
|
|
|
|
assertVersion(t, "1.0.1", "1.0.2", -1)
|
|
|
|
assertVersion(t, "1.0.2", "1.0.3", -1)
|
|
|
|
assertVersion(t, "1.0.3", "1.1", -1)
|
|
|
|
assertVersion(t, "1.1", "1.1.1", -1)
|
|
|
|
assertVersion(t, "1.1.1", "1.1.2", -1)
|
|
|
|
assertVersion(t, "1.1.2", "1.2", -1)
|
|
|
|
|
|
|
|
}
|