2014-07-12 15:45:33 -07:00
|
|
|
// Copyright (C) 2014 Jakob Borg and Contributors (see the CONTRIBUTORS file).
|
|
|
|
// All rights reserved. Use of this source code is governed by an MIT-style
|
|
|
|
// license that can be found in the LICENSE file.
|
2014-06-01 13:50:14 -07:00
|
|
|
|
2014-07-31 07:01:23 -07:00
|
|
|
package upgrade
|
2014-05-24 14:22:08 -07:00
|
|
|
|
|
|
|
import "testing"
|
|
|
|
|
|
|
|
var testcases = []struct {
|
|
|
|
a, b string
|
|
|
|
r int
|
|
|
|
}{
|
|
|
|
{"0.1.2", "0.1.2", 0},
|
|
|
|
{"0.1.3", "0.1.2", 1},
|
|
|
|
{"0.1.1", "0.1.2", -1},
|
|
|
|
{"0.3.0", "0.1.2", 1},
|
|
|
|
{"0.0.9", "0.1.2", -1},
|
|
|
|
{"1.1.2", "0.1.2", 1},
|
|
|
|
{"0.1.2", "1.1.2", -1},
|
|
|
|
{"0.1.10", "0.1.9", 1},
|
|
|
|
{"0.10.0", "0.2.0", 1},
|
|
|
|
{"30.10.0", "4.9.0", 1},
|
2014-07-29 23:57:27 -07:00
|
|
|
{"0.9.0-beta7", "0.9.0-beta6", 1},
|
|
|
|
{"1.0.0-alpha", "1.0.0-alpha.1", -1},
|
|
|
|
{"1.0.0-alpha.1", "1.0.0-alpha.beta", -1},
|
|
|
|
{"1.0.0-alpha.beta", "1.0.0-beta", -1},
|
|
|
|
{"1.0.0-beta", "1.0.0-beta.2", -1},
|
|
|
|
{"1.0.0-beta.2", "1.0.0-beta.11", -1},
|
|
|
|
{"1.0.0-beta.11", "1.0.0-rc.1", -1},
|
|
|
|
{"1.0.0-rc.1", "1.0.0", -1},
|
2014-05-24 14:22:08 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestCompareVersions(t *testing.T) {
|
|
|
|
for _, tc := range testcases {
|
2014-07-31 07:01:23 -07:00
|
|
|
if r := CompareVersions(tc.a, tc.b); r != tc.r {
|
2014-05-24 14:22:08 -07:00
|
|
|
t.Errorf("compareVersions(%q, %q): %d != %d", tc.a, tc.b, r, tc.r)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|