diff options
author | lxl-renren <gnnu_d13@163.com> | 2024-01-12 15:09:17 +0000 |
---|---|---|
committer | Gopher Robot <gobot@golang.org> | 2024-01-17 17:58:34 +0000 |
commit | f2794207adabc3130e79aa6e701782b8aed69e25 (patch) | |
tree | a34002a4d9f1d2fa763eeeb9602c9538bd7d29de | |
parent | 8e658eee9c7a67a8a79a8308695920ac9917566c (diff) | |
download | go-f2794207adabc3130e79aa6e701782b8aed69e25.tar.gz go-f2794207adabc3130e79aa6e701782b8aed69e25.zip |
cmp: add test case for uinitptr
Change-Id: Iebe79be01eb5208e9b9dea9297c464fe2b2dd3dd
GitHub-Last-Rev: 875ab08627b1fb0db3dc2a14ac332fdbc9af8b4b
GitHub-Pull-Request: golang/go#65017
Reviewed-on: https://go-review.googlesource.com/c/go/+/554595
Reviewed-by: Keith Randall <khr@google.com>
Reviewed-by: Keith Randall <khr@golang.org>
Reviewed-by: Bryan Mills <bcmills@google.com>
Auto-Submit: Keith Randall <khr@golang.org>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
-rw-r--r-- | src/cmp/cmp_test.go | 10 |
1 files changed, 10 insertions, 0 deletions
diff --git a/src/cmp/cmp_test.go b/src/cmp/cmp_test.go index dcf783af51..e265464f4f 100644 --- a/src/cmp/cmp_test.go +++ b/src/cmp/cmp_test.go @@ -11,9 +11,12 @@ import ( "slices" "sort" "testing" + "unsafe" ) var negzero = math.Copysign(0, -1) +var nonnilptr uintptr = uintptr(unsafe.Pointer(&negzero)) +var nilptr uintptr = uintptr(unsafe.Pointer(nil)) var tests = []struct { x, y any @@ -45,6 +48,9 @@ var tests = []struct { {0.0, negzero, 0}, {negzero, 1.0, -1}, {negzero, -1.0, +1}, + {nilptr, nonnilptr, -1}, + {nonnilptr, nilptr, 1}, + {nonnilptr, nonnilptr, 0}, } func TestLess(t *testing.T) { @@ -57,6 +63,8 @@ func TestLess(t *testing.T) { b = cmp.Less(test.x.(string), test.y.(string)) case float64: b = cmp.Less(test.x.(float64), test.y.(float64)) + case uintptr: + b = cmp.Less(test.x.(uintptr), test.y.(uintptr)) } if b != (test.compare < 0) { t.Errorf("Less(%v, %v) == %t, want %t", test.x, test.y, b, test.compare < 0) @@ -74,6 +82,8 @@ func TestCompare(t *testing.T) { c = cmp.Compare(test.x.(string), test.y.(string)) case float64: c = cmp.Compare(test.x.(float64), test.y.(float64)) + case uintptr: + c = cmp.Compare(test.x.(uintptr), test.y.(uintptr)) } if c != test.compare { t.Errorf("Compare(%v, %v) == %d, want %d", test.x, test.y, c, test.compare) |