upgrade_test.go 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. // Copyright (C) 2014 Jakob Borg and Contributors (see the CONTRIBUTORS file).
  2. // All rights reserved. Use of this source code is governed by an MIT-style
  3. // license that can be found in the LICENSE file.
  4. package upgrade
  5. import "testing"
  6. var testcases = []struct {
  7. a, b string
  8. r int
  9. }{
  10. {"0.1.2", "0.1.2", 0},
  11. {"0.1.3", "0.1.2", 1},
  12. {"0.1.1", "0.1.2", -1},
  13. {"0.3.0", "0.1.2", 1},
  14. {"0.0.9", "0.1.2", -1},
  15. {"1.1.2", "0.1.2", 1},
  16. {"0.1.2", "1.1.2", -1},
  17. {"0.1.10", "0.1.9", 1},
  18. {"0.10.0", "0.2.0", 1},
  19. {"30.10.0", "4.9.0", 1},
  20. {"0.9.0-beta7", "0.9.0-beta6", 1},
  21. {"1.0.0-alpha", "1.0.0-alpha.1", -1},
  22. {"1.0.0-alpha.1", "1.0.0-alpha.beta", -1},
  23. {"1.0.0-alpha.beta", "1.0.0-beta", -1},
  24. {"1.0.0-beta", "1.0.0-beta.2", -1},
  25. {"1.0.0-beta.2", "1.0.0-beta.11", -1},
  26. {"1.0.0-beta.11", "1.0.0-rc.1", -1},
  27. {"1.0.0-rc.1", "1.0.0", -1},
  28. {"1.0.0+45", "1.0.0+23-dev-foo", 0},
  29. {"1.0.0-beta.23+45", "1.0.0-beta.23+23-dev-foo", 0},
  30. {"1.0.0-beta.3+99", "1.0.0-beta.24+0", -1},
  31. }
  32. func TestCompareVersions(t *testing.T) {
  33. for _, tc := range testcases {
  34. if r := CompareVersions(tc.a, tc.b); r != tc.r {
  35. t.Errorf("compareVersions(%q, %q): %d != %d", tc.a, tc.b, r, tc.r)
  36. }
  37. }
  38. }