| 1 | // Copyright (C) MongoDB, Inc. 2023-present. |
| 2 | // |
| 3 | // Licensed under the Apache License, Version 2.0 (the "License"); you may |
| 4 | // not use this file except in compliance with the License. You may obtain |
| 5 | // a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 |
| 6 | |
| 7 | package ptrutilscip-go gomod go.mongodb.org/mongo-driver . `go.mongodb.org/mongo-driver/internal/ptrutil`/ |
| 8 | |
| 9 | import ( |
| 10 | "testingscip-go gomod github.com/golang/go/src go1.18 testing/" |
| 11 | |
| 12 | "go.mongodb.org/mongo-driver/internal/assertscip-go gomod go.mongodb.org/mongo-driver . `go.mongodb.org/mongo-driver/internal/assert`/" |
| 13 | ) |
| 14 | |
| 15 | func TestCompareInt64scip-go gomod go.mongodb.org/mongo-driver . `go.mongodb.org/mongo-driver/internal/ptrutil`/TestCompareInt64().(t *testingscip-go gomod github.com/golang/go/src go1.18 testing/.Tscip-go gomod github.com/golang/go/src go1.18 testing/T#) { |
| 16 | t.Parallelscip-go gomod github.com/golang/go/src go1.18 testing/T#Parallel().() |
| 17 | |
| 18 | int64ToPtr := func(i64 int64) *int64 { return &i64 } |
| 19 | int64Ptr := int64ToPtr(1) |
| 20 | |
| 21 | tests := []struct { |
| 22 | name string |
| 23 | ptr1, ptr2 *int64 |
| 24 | want int |
| 25 | }{ |
| 26 | { |
| 27 | name: "empty", |
| 28 | want: 0, |
| 29 | }, |
| 30 | { |
| 31 | name: "ptr1 nil", |
| 32 | ptr2: int64ToPtr(1), |
| 33 | want: -2, |
| 34 | }, |
| 35 | { |
| 36 | name: "ptr2 nil", |
| 37 | ptr1: int64ToPtr(1), |
| 38 | want: 2, |
| 39 | }, |
| 40 | { |
| 41 | name: "ptr1 and ptr2 have same value, different address", |
| 42 | ptr1: int64ToPtr(1), |
| 43 | ptr2: int64ToPtr(1), |
| 44 | want: 0, |
| 45 | }, |
| 46 | { |
| 47 | name: "ptr1 and ptr2 have the same address", |
| 48 | ptr1: int64Ptr, |
| 49 | ptr2: int64Ptr, |
| 50 | want: 0, |
| 51 | }, |
| 52 | { |
| 53 | name: "ptr1 GT ptr2", |
| 54 | ptr1: int64ToPtr(1), |
| 55 | ptr2: int64ToPtr(0), |
| 56 | want: 1, |
| 57 | }, |
| 58 | { |
| 59 | name: "ptr1 LT ptr2", |
| 60 | ptr1: int64ToPtr(0), |
| 61 | ptr2: int64ToPtr(1), |
| 62 | want: -1, |
| 63 | }, |
| 64 | } |
| 65 | |
| 66 | for _, test := range tests { |
| 67 | test := test // capture the range variable |
| 68 | |
| 69 | t.Runscip-go gomod github.com/golang/go/src go1.18 testing/T#Run().(test.name, func(t *testingscip-go gomod github.com/golang/go/src go1.18 testing/.Tscip-go gomod github.com/golang/go/src go1.18 testing/T#) { |
| 70 | t.Parallelscip-go gomod github.com/golang/go/src go1.18 testing/T#Parallel().() |
| 71 | |
| 72 | got := CompareInt64scip-go gomod go.mongodb.org/mongo-driver . `go.mongodb.org/mongo-driver/internal/ptrutil`/CompareInt64().(test.ptr1, test.ptr2) |
| 73 | assertscip-go gomod go.mongodb.org/mongo-driver . `go.mongodb.org/mongo-driver/internal/assert`/.Equalscip-go gomod go.mongodb.org/mongo-driver . `go.mongodb.org/mongo-driver/internal/assert`/Equal().(t, test.want, got, "compareInt64() = %v, wanted %v", got, test.want) |
| 74 | }) |
| 75 | } |
| 76 | } |