aboutsummaryrefslogtreecommitdiff
path: root/src/runtime/string_test.go
diff options
context:
space:
mode:
authorAustin Clements <austin@google.com>2019-12-02 17:32:01 -0500
committerAustin Clements <austin@google.com>2019-12-05 01:48:12 +0000
commitfa3a121a79f85a4c957f29372b5ebfde7211a980 (patch)
tree499bc58b5e809186bd76d63b072dc7cabab1493a /src/runtime/string_test.go
parent709dbd28708eab97993ca06adea74be392c05c1c (diff)
downloadgo-fa3a121a79f85a4c957f29372b5ebfde7211a980.tar.xz
runtime: add a simple version number parser
This will be used to parse the Linux kernel versions, but this code is generic and can be tested on its own. For #35777. Change-Id: If1df48d07250e5855dde45bc9d57c66f777b9fb4 Reviewed-on: https://go-review.googlesource.com/c/go/+/209597 Run-TryBot: Austin Clements <austin@google.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Ian Lance Taylor <iant@golang.org> Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
Diffstat (limited to 'src/runtime/string_test.go')
-rw-r--r--src/runtime/string_test.go31
1 files changed, 31 insertions, 0 deletions
diff --git a/src/runtime/string_test.go b/src/runtime/string_test.go
index a1716fa32f..80c5fa6406 100644
--- a/src/runtime/string_test.go
+++ b/src/runtime/string_test.go
@@ -454,3 +454,34 @@ func TestAtoi32(t *testing.T) {
}
}
}
+
+type parseReleaseTest struct {
+ in string
+ major, minor, patch int
+}
+
+var parseReleaseTests = []parseReleaseTest{
+ {"", -1, -1, -1},
+ {"x", -1, -1, -1},
+ {"5", 5, 0, 0},
+ {"5.12", 5, 12, 0},
+ {"5.12-x", 5, 12, 0},
+ {"5.12.1", 5, 12, 1},
+ {"5.12.1-x", 5, 12, 1},
+ {"5.12.1.0", 5, 12, 1},
+ {"5.20496382327982653440", -1, -1, -1},
+}
+
+func TestParseRelease(t *testing.T) {
+ for _, test := range parseReleaseTests {
+ major, minor, patch, ok := runtime.ParseRelease(test.in)
+ if !ok {
+ major, minor, patch = -1, -1, -1
+ }
+ if test.major != major || test.minor != minor || test.patch != patch {
+ t.Errorf("parseRelease(%q) = (%v, %v, %v) want (%v, %v, %v)",
+ test.in, major, minor, patch,
+ test.major, test.minor, test.patch)
+ }
+ }
+}