func (*suite) TestCompare(c *gc.C) { cmpTests := []struct { v1, v2 string compare int }{ {"1.0.0", "1.0.0", 0}, {"01.0.0", "1.0.0", 0}, {"10.0.0", "9.0.0", 1}, {"1.0.0", "1.0.1", -1}, {"1.0.1", "1.0.0", 1}, {"1.0.0", "1.1.0", -1}, {"1.1.0", "1.0.0", 1}, {"1.0.0", "2.0.0", -1}, {"1.2-alpha1", "1.2.0", -1}, {"1.2-alpha2", "1.2-alpha1", 1}, {"1.2-alpha2.1", "1.2-alpha2", 1}, {"1.2-alpha2.2", "1.2-alpha2.1", 1}, {"1.2-beta1", "1.2-alpha1", 1}, {"1.2-beta1", "1.2-alpha2.1", 1}, {"1.2-beta1", "1.2.0", -1}, {"1.2.1", "1.2.0", 1}, {"2.0.0", "1.0.0", 1}, {"2.0.0.0", "2.0.0", 0}, {"2.0.0.0", "2.0.0.0", 0}, {"2.0.0.1", "2.0.0.0", 1}, {"2.0.1.10", "2.0.0.0", 1}, } for i, test := range cmpTests { c.Logf("test %d", i) v1, err := version.Parse(test.v1) c.Assert(err, gc.IsNil) v2, err := version.Parse(test.v2) c.Assert(err, gc.IsNil) compare := v1.Compare(v2) c.Check(compare, gc.Equals, test.compare) // Check that reversing the operands has // the expected result. compare = v2.Compare(v1) c.Check(compare, gc.Equals, -test.compare) } }
func (*suite) TestParse(c *gc.C) { for i, test := range parseTests { c.Logf("test %d", i) got, err := version.Parse(test.v) if test.err != "" { c.Assert(err, gc.ErrorMatches, test.err) } else { c.Assert(err, gc.IsNil) c.Assert(got, gc.Equals, test.expect) c.Check(got.IsDev(), gc.Equals, test.dev) c.Check(got.String(), gc.Equals, test.v) } } }