You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
assertThrows(()=>store.detach(observer),mod.UnknownObserverError,"Attempted removal of unattached observer.","Should throw on removal of unattached observer.")
155
+
});
156
+
157
+
// Mark: StoreStack tests
158
+
Deno.test("An instance of StoreStack can be instantiated",()=>{
159
+
conststack=newmod.StoreStack()asunknown;
160
+
161
+
assertInstanceOf(stack,mod.StoreStack);
162
+
});
163
+
164
+
Deno.test("A store can be added to a stack without providing a pointer, accessed with the returned pointer and can be removed",()=>{
165
+
conststack=newmod.StoreStack();
166
+
167
+
conststore=newmod.Store(0);
168
+
constptr=stack.addStore(store);
169
+
170
+
conststore2=newmod.Store(1);
171
+
172
+
assertExists(ptr,"ptr should not be undefined.");
173
+
assertExists(stack.get<number>(ptr),"The pointer should be allocated");
174
+
assertEquals(stack.get<number>(ptr)!.state,store.state,"The states should match");
175
+
176
+
// Cannot be added twice at address without override
177
+
assertThrows(()=>stack.addStoreAtPointer(store,ptr),mod.MemoryAllocationError,"Attempted to insert store at already allocated memory address without explicit override.","Should not be able to add at address without override.");
assertExists(stack.get<number>(ptr),"The pointer should be allocated");
183
+
assertEquals(stack.get<number>(ptr)!.state,store2.state,"The states should match");
184
+
185
+
stack.removeStore(ptr);
186
+
187
+
assertEquals(typeofstack.get(ptr),"undefined","The pointer should be unallocated");
188
+
189
+
// But cannot be removed twice
190
+
assertThrows(()=>stack.removeStore(ptr),mod.NullPointerError,"Attempted to access unallocated memory address.","Should not be able to delete the store twice.");
assertEquals(typeofstack.get(pointer1),"undefined","Pointer should not already be allocated");
212
+
213
+
// Creating a store
214
+
stack.upsert(defaultValue1,pointer1);
215
+
216
+
assertExists(stack.get(pointer1),"Store should now exist");
217
+
assertEquals(stack.get(pointer1)!.state,defaultValue1,"State should equal "+defaultValue1);
218
+
219
+
stack.upsert(defaultValue2,pointer1);
220
+
221
+
assertNotEquals(stack.get(pointer1)!.state,defaultValue2,"Because the store already exists, it should not override its value");
222
+
223
+
// Attaching an observer
224
+
stack.upsert(defaultValue1,pointer1,observer);
225
+
stack.get<number>(pointer1)!.set(defaultValue2);
226
+
227
+
assertEquals(observerOuput,defaultValue2,"observerOutput and defaultValue2 should match");
228
+
229
+
// Throwing on reattaching observer
230
+
assertThrows(()=>stack.upsert(defaultValue1,pointer1,observer),mod.DuplicateObserverError,"This observer is already attached to the store.","Should trigger a duplicate observer error");
0 commit comments