Debian Codegraph @

cpu/parse_test.go

raw
1 // Copyright 2022 The Go Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style
3 // license that can be found in the LICENSE file.
4
5 package cpu
6
7 import "testing"
8
9 type parseReleaseTest struct {
10 in string
11 major, minor, patch int
12 }
13
14 var parseReleaseTests = []parseReleaseTest{
15 {"", -1, -1, -1},
16 {"x", -1, -1, -1},
17 // A single component is not enough; major+minor are required.
18 {"5", -1, -1, -1},
19 {"5-x", -1, -1, -1},
20 {"5.12", 5, 12, 0},
21 {"5.12-x", 5, 12, 0},
22 {"5.12.1", 5, 12, 1},
23 {"5.12.1-x", 5, 12, 1},
24 {"5.12.1.0", 5, 12, 1},
25 {"5.15.0-91-generic", 5, 15, 0},
26 {"4.19.0+", 4, 19, 0},
27 {"6.6.0-rc1", 6, 6, 0},
28 // Synology embedded Linux appends a platform identifier after an
29 // underscore. See golang/go#79612.
30 {"3.4.35_hi3535", 3, 4, 35},
31 {"2.6.32_synology", 2, 6, 32},
32 {"5.20496382327982653440", -1, -1, -1},
33 }
34
35 func TestParseRelease(t *testing.T) {
36 for _, test := range parseReleaseTests {
37 major, minor, patch, ok := parseRelease(test.in)
38 if !ok {
39 major, minor, patch = -1, -1, -1
40 }
41 if test.major != major || test.minor != minor || test.patch != patch {
42 t.Errorf("parseRelease(%q) = (%v, %v, %v) want (%v, %v, %v)",
43 test.in, major, minor, patch,
44 test.major, test.minor, test.patch)
45 }
46 }
47 }