Comparison

spec/util_promise_spec.lua @ 12749:eb9814372c54

util.promise: Remove some redundant checks, add tests confirming redundancy This lines don't appear to do anything useful, and all tests pass when they are removed. Discovered via mutation testing. I added extra tests to exercise this code, because I wasn't certain that there were no side-effects caused by removal. Everything appears to be fine, thanks to the "pending" check at the start of promise_settle().
author Matthew Wild <mwild1@gmail.com>
date Fri, 07 Oct 2022 17:43:26 +0100
parent 11951:6d9e3f541830
child 12751:2639e0e1c378
comparison
equal deleted inserted replaced
12748:7b9de8109a90 12749:eb9814372c54
26 assert.equal("foo", v); 26 assert.equal("foo", v);
27 end); 27 end);
28 p:next(cb); 28 p:next(cb);
29 assert.spy(cb).was_called(0); 29 assert.spy(cb).was_called(0);
30 r("foo"); 30 r("foo");
31 assert.spy(cb).was_called(1);
32 end);
33 it("ignores resolve/reject of settled promises", function ()
34 local res, rej;
35 local p = promise.new(function (resolve, reject)
36 res, rej = resolve, reject;
37 end);
38 local cb = spy.new(function (v)
39 assert.equal("foo", v);
40 end);
41 p:next(cb, cb);
42 assert.spy(cb).was_called(0);
43 res("foo");
44 assert.spy(cb).was_called(1);
45 rej("bar");
46 assert.spy(cb).was_called(1);
47 rej(promise.resolve("bar"));
48 assert.spy(cb).was_called(1);
49 res(promise.reject("bar"));
50 assert.spy(cb).was_called(1);
51 res(promise.resolve("bar"));
31 assert.spy(cb).was_called(1); 52 assert.spy(cb).was_called(1);
32 end); 53 end);
33 it("allows chaining :next() calls", function () 54 it("allows chaining :next() calls", function ()
34 local r; 55 local r;
35 local result; 56 local result;