Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(706)

Side by Side Diff: vpython/python/version_test.go

Issue 2874683002: vpython: Version parser from PEP440. (Closed)
Patch Set: stronger test case Created 3 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « vpython/python/version.go ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2017 The LUCI Authors. All rights reserved. 1 // Copyright 2017 The LUCI Authors. All rights reserved.
2 // Use of this source code is governed under the Apache License, Version 2.0 2 // Use of this source code is governed under the Apache License, Version 2.0
3 // that can be found in the LICENSE file. 3 // that can be found in the LICENSE file.
4 4
5 package python 5 package python
6 6
7 import ( 7 import (
8 "fmt" 8 "fmt"
9 "sort" 9 "sort"
10 "testing" 10 "testing"
(...skipping 10 matching lines...) Expand all
21 t.Parallel() 21 t.Parallel()
22 22
23 successes := []struct { 23 successes := []struct {
24 input string 24 input string
25 v Version 25 v Version
26 }{ 26 }{
27 {"", Version{}}, 27 {"", Version{}},
28 {"2", Version{2, 0, 0}}, 28 {"2", Version{2, 0, 0}},
29 {"2.7", Version{2, 7, 0}}, 29 {"2.7", Version{2, 7, 0}},
30 {"2.7.12", Version{2, 7, 12}}, 30 {"2.7.12", Version{2, 7, 12}},
31 {"2.7.12+", Version{2, 7, 12}},
32 {"2.7.12+local version string", Version{2, 7, 12}},
33 {"1.4rc1", Version{1, 4, 0}},
34 {"2.7a3", Version{2, 7, 0}},
35 {"1.0b2.post345.dev456", Version{1, 0, 0}},
36 {"1.0+abc.7", Version{1, 0, 0}},
37 {"1.0.dev4", Version{1, 0, 0}},
38 {"1.0.post4", Version{1, 0, 0}},
39 {"2!1.0", Version{1, 0, 0}},
31 {"1000.0.1", Version{1000, 0, 1}}, 40 {"1000.0.1", Version{1000, 0, 1}},
32 } 41 }
33 42
34 failures := []struct { 43 failures := []struct {
35 input string 44 input string
36 err string 45 err string
37 }{ 46 }{
38 » » {"a", "invalid number value"}, 47 » » {"a", "non-canonical Python version string"},
39 » » {"1.2.3.4", "unsupported number of parts"},
40 » » {"1.-2.1337", "must not be negative"},
41 {"0.1.2", "version is incomplete"}, 48 {"0.1.2", "version is incomplete"},
42 » » {"1.1.X", "invalid patch value"}, 49 » » {"1.1.X", "non-canonical Python version string"},
43 » » {"1.Y.1", "invalid minor value"},
44 » » {"Y.1.1", "invalid major value"},
45 } 50 }
46 51
47 Convey(`Testing ParseVersion`, t, func() { 52 Convey(`Testing ParseVersion`, t, func() {
48 for _, tc := range successes { 53 for _, tc := range successes {
49 Convey(fmt.Sprintf(`Success: %q`, tc.input), func() { 54 Convey(fmt.Sprintf(`Success: %q`, tc.input), func() {
50 v, err := ParseVersion(tc.input) 55 v, err := ParseVersion(tc.input)
51 So(err, ShouldBeNil) 56 So(err, ShouldBeNil)
52 So(v, ShouldResemble, tc.v) 57 So(v, ShouldResemble, tc.v)
53 }) 58 })
54 } 59 }
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after
176 So(cp, ShouldResemble, s) 181 So(cp, ShouldResemble, s)
177 }) 182 })
178 }) 183 })
179 } 184 }
180 185
181 type versionSlice []Version 186 type versionSlice []Version
182 187
183 func (s versionSlice) Len() int { return len(s) } 188 func (s versionSlice) Len() int { return len(s) }
184 func (s versionSlice) Less(i, j int) bool { return s[i].Less(&s[j]) } 189 func (s versionSlice) Less(i, j int) bool { return s[i].Less(&s[j]) }
185 func (s versionSlice) Swap(i, j int) { s[i], s[j] = s[j], s[i] } 190 func (s versionSlice) Swap(i, j int) { s[i], s[j] = s[j], s[i] }
OLDNEW
« no previous file with comments | « vpython/python/version.go ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698