1 module ut.exclusive; 2 3 4 import fearless.sharing; 5 import unit_threaded; 6 7 8 @("GC exclusive int") 9 @safe unittest { 10 auto e = gcExclusive!int(42); 11 } 12 13 @("GC exclusive struct moved payload") 14 @safe unittest { 15 16 static struct Foo { 17 int i; 18 } 19 20 auto foo = Foo(42); 21 auto e = gcExclusive(foo); 22 23 // should be reset to T.init 24 foo.should == foo.init; 25 26 { 27 auto p = e.lock; 28 p.reference.should == Foo(42); 29 } 30 } 31 32 @("GC exclusive struct with indirection moved payload") 33 @safe unittest { 34 struct Struct { 35 int[] ints; 36 } 37 38 auto s = Struct([1, 2, 3, 4]); 39 auto i = s.ints; 40 static assert(!__traits(compiles, gcExclusive(s))); 41 } 42 43 @("RC exclusive int default allocator") 44 @system unittest { 45 auto e = rcExclusive!int(42); 46 } 47 48 @("RC exclusive struct default allocator") 49 @system unittest { 50 static struct Foo { 51 int i; 52 double d; 53 } 54 55 auto e = rcExclusive!Foo(42, 33.3); 56 { 57 auto p = e.lock; 58 p.reference.i.should == 42; 59 p.reference.d.should ~ 33.3; 60 } 61 } 62 63 @("RC exclusive struct mallocator") 64 @system unittest { 65 66 import std.experimental.allocator.mallocator: Mallocator; 67 68 static struct Foo { 69 int i; 70 double d; 71 } 72 73 auto e = rcExclusive!Foo(Mallocator.instance, 42, 33.3); 74 { 75 auto p = e.lock; 76 p.reference.i.should == 42; 77 p.reference.d.should ~ 33.3; 78 } 79 } 80 81 @("RC exclusive struct test allocator") 82 @system unittest { 83 84 import test_allocator: TestAllocator; 85 86 static struct Foo { 87 int i; 88 double d; 89 } 90 91 auto allocator = TestAllocator(); 92 auto e = rcExclusive!Foo(&allocator, 42, 33.3); 93 { 94 auto p = e.lock; 95 p.reference.i.should == 42; 96 p.reference.d.should ~ 33.3; 97 } 98 }