add generics test

This commit is contained in:
Jaremy Creechley 2023-09-13 11:59:49 -07:00
parent ee02aa8322
commit bcce5331bb
No known key found for this signature in database
GPG Key ID: 4E66FB67B21D3300

View File

@ -10,13 +10,21 @@ include pkg/datastore/threads/sharedptr
include pkg/datastore/threads/databuffer
type TestObj = object
val: ref int
type
TestObj = object
val: ref int
TestObjGen[T] = object
val: ref T
proc `=destroy`(obj: var TestObj) =
echo "test obj destroy"
obj.val[] = 0
proc `=destroy`[T: int](obj: var TestObjGen[T]) =
echo "test obj destroy"
obj.val[] = 0
proc destroyTest(intref: ref int) =
let a: SharedPtr[TestObj] = newSharedPtr(unsafeIsolate TestObj(val: intref))
echo "a[]: ", a[]
@ -77,3 +85,15 @@ suite "Share buffer test":
finally:
a.release()
check intref[] == 0
test "test destroy release generic no proc":
echo "\nintref setup:\n"
let intref: ref int = new(ref int)
intref[] = 30
var b: SharedPtr[TestObjGen[int]] = newSharedPtr(unsafeIsolate TestObjGen[int](val: intref))
try:
echo "a[]: ", b[]
check b[].val[] == 30
finally:
b.release()
check intref[] == 0