github.com/neonyo/sys@v0.0.0-20230720094341-b1ee14be3ce8/cpu/parse_test.go (about)

     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  	{"5", 5, 0, 0},
    18  	{"5.12", 5, 12, 0},
    19  	{"5.12-x", 5, 12, 0},
    20  	{"5.12.1", 5, 12, 1},
    21  	{"5.12.1-x", 5, 12, 1},
    22  	{"5.12.1.0", 5, 12, 1},
    23  	{"5.20496382327982653440", -1, -1, -1},
    24  }
    25  
    26  func TestParseRelease(t *testing.T) {
    27  	for _, test := range parseReleaseTests {
    28  		major, minor, patch, ok := parseRelease(test.in)
    29  		if !ok {
    30  			major, minor, patch = -1, -1, -1
    31  		}
    32  		if test.major != major || test.minor != minor || test.patch != patch {
    33  			t.Errorf("parseRelease(%q) = (%v, %v, %v) want (%v, %v, %v)",
    34  				test.in, major, minor, patch,
    35  				test.major, test.minor, test.patch)
    36  		}
    37  	}
    38  }