forked from viamrobotics/goutils
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ref_test.go
28 lines (24 loc) · 907 Bytes
/
ref_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
package utils
import (
"testing"
"go.viam.com/test"
)
func TestRefCountedValue(t *testing.T) {
rcv := NewRefCountedValue(nil)
test.That(t, func() { rcv.Deref() }, test.ShouldPanic)
test.That(t, rcv.Ref(), test.ShouldBeNil)
test.That(t, rcv.Ref(), test.ShouldBeNil)
test.That(t, rcv.Deref(), test.ShouldBeFalse)
test.That(t, rcv.Deref(), test.ShouldBeTrue)
test.That(t, func() { rcv.Deref() }, test.ShouldPanic)
test.That(t, func() { rcv.Ref() }, test.ShouldPanic)
someIntPtr := 5
rcv = NewRefCountedValue(&someIntPtr)
test.That(t, func() { rcv.Deref() }, test.ShouldPanic)
test.That(t, rcv.Ref(), test.ShouldEqual, &someIntPtr)
test.That(t, rcv.Ref(), test.ShouldEqual, &someIntPtr)
test.That(t, rcv.Deref(), test.ShouldBeFalse)
test.That(t, rcv.Deref(), test.ShouldBeTrue)
test.That(t, func() { rcv.Deref() }, test.ShouldPanic)
test.That(t, func() { rcv.Ref() }, test.ShouldPanic)
}