diff --git a/README.md b/README.md index 3d93f76..6823036 100644 --- a/README.md +++ b/README.md @@ -9,7 +9,7 @@ local Promise = require("promise") local promise = Promise:new(function(resolve, reject) resolve("some result") -end):thenCall(function(result) +end):and_then(function(result) vim.print("this gets called with some result: " .. result) end):catch(function(err) vim.print("no error here, this doesnt get called") @@ -60,7 +60,7 @@ correct and memory efficient, handles edge cases like stack overflow on large co -- promise example local promise = Promise:new(function(resolve, reject) resolve({ last_name = "Nakri" }) - end):thenCall(function(result) + end):and_then(function(result) vim.print("last_name should be: " .. result.last_name) end) local me = await(promise) diff --git a/lua/promise/all.lua b/lua/promise/all.lua index ace4c79..eff6bab 100644 --- a/lua/promise/all.lua +++ b/lua/promise/all.lua @@ -18,9 +18,9 @@ return function(list) end for i, item in ipairs(list) do - if type(item) == "table" and type(item.thenCall) == "function" then + if type(item) == "table" and type(item.and_then) == "function" then item - :thenCall(function(value) + :and_then(function(value) results[i] = value remaining = remaining - 1 check_completion() diff --git a/lua/promise/all_settled.lua b/lua/promise/all_settled.lua index bb2062f..31f6592 100644 --- a/lua/promise/all_settled.lua +++ b/lua/promise/all_settled.lua @@ -19,10 +19,10 @@ return function(list) end for i, item in ipairs(list) do - if type(item) == "table" and type(item.thenCall) == "function" then - item:thenCall(function(value) - if type(value) == "table" and type(value.thenCall) == "function" then - value:thenCall(function(resolvedValue) + if type(item) == "table" and type(item.and_then) == "function" then + item:and_then(function(value) + if type(value) == "table" and type(value.and_then) == "function" then + value:and_then(function(resolvedValue) settle("fulfilled", i, resolvedValue) end, function(reason) settle("rejected", i, reason) diff --git a/lua/promise/auto.lua b/lua/promise/auto.lua index 32a44a1..e08167a 100644 --- a/lua/promise/auto.lua +++ b/lua/promise/auto.lua @@ -57,7 +57,7 @@ return function(inputs) -- If no dependencies, run the task immediately if #taskDependencies == 0 then - local promise = Promise.resolve():thenCall(taskFn):thenCall(function(result) + local promise = Promise.resolve():and_then(taskFn):and_then(function(result) results[taskName] = result return result end) @@ -78,10 +78,10 @@ return function(inputs) -- Run task after all dependencies are resolved local promise = Promise.all(dependencyPromises) - :thenCall(function(depResults) + :and_then(function(depResults) return taskFn(unpack(depResults)) end) - :thenCall(function(result) + :and_then(function(result) results[taskName] = result return result end) @@ -98,7 +98,7 @@ return function(inputs) -- Wait for all tasks to complete Promise.all(allPromises) - :thenCall(function() + :and_then(function() resolve(results) end) :catch(function(err) diff --git a/lua/promise/build_task.lua b/lua/promise/build_task.lua index a5ae538..547b583 100644 --- a/lua/promise/build_task.lua +++ b/lua/promise/build_task.lua @@ -15,7 +15,7 @@ return function(promise_returning_func, ...) end local result = promise_returning_func(unpack(target_arguments)) - if type(result) == "table" and type(result.thenCall) == "function" then + if type(result) == "table" and type(result.and_then) == "function" then return result end diff --git a/lua/promise/hash.lua b/lua/promise/hash.lua index a47f68d..3cac452 100644 --- a/lua/promise/hash.lua +++ b/lua/promise/hash.lua @@ -1,9 +1,9 @@ local function resolveNestedPromises(value) local Promise = require("promise") - if type(value) == "table" and type(value.thenCall) == "function" then + if type(value) == "table" and type(value.and_then) == "function" then -- If the value is a promise, resolve it and recursively resolve any nested values - return value:thenCall(resolveNestedPromises) + return value:and_then(resolveNestedPromises) elseif type(value) == "table" then -- If the value is a table, recursively resolve all its entries local keys = {} @@ -13,7 +13,7 @@ local function resolveNestedPromises(value) table.insert(promises, resolveNestedPromises(v)) end - return Promise.all(promises):thenCall(function(resolvedValues) + return Promise.all(promises):and_then(function(resolvedValues) local resolvedTable = {} for i, key in ipairs(keys) do resolvedTable[key] = resolvedValues[i] @@ -36,7 +36,7 @@ return function(hashTable) for key, promise in pairs(hashTable) do remaining = remaining + 1 resolveNestedPromises(promise) - :thenCall(function(value) + :and_then(function(value) results[key] = value remaining = remaining - 1 if remaining == 0 then diff --git a/lua/promise/hash_settled.lua b/lua/promise/hash_settled.lua index 8573a7b..d0b0997 100644 --- a/lua/promise/hash_settled.lua +++ b/lua/promise/hash_settled.lua @@ -1,10 +1,10 @@ local function settleNestedPromises(value) local Promise = require("promise") - if type(value) == "table" and type(value.thenCall) == "function" then + if type(value) == "table" and type(value.and_then) == "function" then -- Handle promise-like objects return value - :thenCall(function(resolvedValue) + :and_then(function(resolvedValue) return settleNestedPromises(resolvedValue) end) :catch(function(reason) @@ -19,7 +19,7 @@ local function settleNestedPromises(value) table.insert(promises, settleNestedPromises(v)) end - return Promise.all(promises):thenCall(function(resolvedValues) + return Promise.all(promises):and_then(function(resolvedValues) local settledTable = {} for i, key in ipairs(keys) do settledTable[key] = resolvedValues[i] @@ -43,7 +43,7 @@ return function(hashTable) remaining = remaining + 1 settleNestedPromises(promise) - :thenCall(function(resolvedValue) + :and_then(function(resolvedValue) if resolvedValue.status == "fulfilled" or resolvedValue.status == "rejected" then results[key] = resolvedValue else diff --git a/lua/promise/init.lua b/lua/promise/init.lua index 9c9cc55..dd221d4 100644 --- a/lua/promise/init.lua +++ b/lua/promise/init.lua @@ -49,9 +49,8 @@ function Promise.await(promise) errored = true end - promise:thenCall(handleResolution, handleRejection) + promise:and_then(handleResolution, handleRejection) - -- Use vim.wait to periodically check the promise state while not resolved and not errored do vim.wait(10, function() -- Return false to continue waiting diff --git a/lua/promise/new.lua b/lua/promise/new.lua index 4e8ddf3..cb97fe4 100644 --- a/lua/promise/new.lua +++ b/lua/promise/new.lua @@ -27,12 +27,12 @@ local function adopt_promise_state(promise, x, resolve, reject) end if x and (type(x) == "table" or is_callable(x)) then - local success, thenCall - success, thenCall = pcall(function() - return x.thenCall + local success, and_then + success, and_then = pcall(function() + return x.and_then end) - if success and is_callable(thenCall) then + if success and is_callable(and_then) then local called = false local function resolve_once(y) @@ -52,7 +52,7 @@ local function adopt_promise_state(promise, x, resolve, reject) end local success_inner, err = pcall(function() - thenCall(x, resolve_once, reject_once) + and_then(x, resolve_once, reject_once) end) if not success_inner then @@ -62,7 +62,7 @@ local function adopt_promise_state(promise, x, resolve, reject) if success then resolve(x) else - reject(thenCall) + reject(and_then) end end else @@ -79,7 +79,7 @@ return function(Promise, executor) _state = "pending", -- 'pending', 'fulfilled', 'rejected' _value = nil, _reason = nil, - _thenCallbacks = {}, + _and_thenbacks = {}, _finallyCallbacks = {}, _triggerUnhandledRejection = function(self, reason) if not self._caught then @@ -101,7 +101,7 @@ return function(Promise, executor) if newState == "fulfilled" then promise._value = result - for _, callbackPair in ipairs(promise._thenCallbacks) do + for _, callbackPair in ipairs(promise._and_thenbacks) do if callbackPair[1] then defer(Promise, function() callbackPair[1](result) @@ -110,7 +110,7 @@ return function(Promise, executor) end elseif newState == "rejected" then promise._reason = result - for _, callbackPair in ipairs(promise._thenCallbacks) do + for _, callbackPair in ipairs(promise._and_thenbacks) do if callbackPair[2] then defer(Promise, function() callbackPair[2](result) @@ -124,7 +124,7 @@ return function(Promise, executor) end -- Clear callbacks after execution - promise._thenCallbacks = nil + promise._and_thenbacks = nil promise._finallyCallbacks = nil end @@ -163,7 +163,7 @@ return function(Promise, executor) end) coroutine.resume(co) - function promise:thenCall(onFulfilled, onRejected) + function promise:and_then(onFulfilled, onRejected) self._caught = true local nextPromise nextPromise = Promise:new(function(resolve, reject) @@ -191,7 +191,7 @@ return function(Promise, executor) elseif self._state == "rejected" then handleCallback(onRejected, self._reason, resolve, reject) elseif self._state == "pending" then - table.insert(self._thenCallbacks, { + table.insert(self._and_thenbacks, { function(value) handleCallback(onFulfilled, value, resolve, reject) end, @@ -208,7 +208,7 @@ return function(Promise, executor) function promise:catch(onRejected) self._caught = true - return self:thenCall(nil, onRejected) + return self:and_then(nil, onRejected) end function promise:finally(onFinally) diff --git a/lua/promise/parallel.lua b/lua/promise/parallel.lua index 6ca9cd0..c4a112f 100644 --- a/lua/promise/parallel.lua +++ b/lua/promise/parallel.lua @@ -13,12 +13,12 @@ return function(tasks) for i, task in ipairs(tasks) do local result = task() - if type(result) ~= "table" or type(result.thenCall) ~= "function" then + if type(result) ~= "table" or type(result.and_then) ~= "function" then return reject("Promise.parallel: all functions must return a promise") end result - :thenCall(function(value) + :and_then(function(value) if has_rejected then return end diff --git a/lua/promise/race.lua b/lua/promise/race.lua index fc038fe..1d29922 100644 --- a/lua/promise/race.lua +++ b/lua/promise/race.lua @@ -3,9 +3,9 @@ return function(promises) return Promise:new(function(resolve, reject) local function handleResolution(value) - if type(value) == "table" and type(value.thenCall) == "function" then + if type(value) == "table" and type(value.and_then) == "function" then -- If the resolved value is a promise, continue racing with it - value:thenCall(handleResolution, reject) + value:and_then(handleResolution, reject) else -- Otherwise, resolve with the value resolve(value) @@ -13,9 +13,9 @@ return function(promises) end local function handleRejection(reason) - if type(reason) == "table" and type(reason.thenCall) == "function" then + if type(reason) == "table" and type(reason.and_then) == "function" then -- If the rejection reason is a promise, continue racing with it - reason:thenCall(resolve, handleRejection) + reason:and_then(resolve, handleRejection) else -- Otherwise, reject with the reason reject(reason) @@ -23,9 +23,9 @@ return function(promises) end for _, item in ipairs(promises) do - if type(item) == "table" and type(item.thenCall) == "function" then + if type(item) == "table" and type(item.and_then) == "function" then -- Handle promise-like objects - item:thenCall(handleResolution, handleRejection) + item:and_then(handleResolution, handleRejection) else -- Resolve immediately if it's not a promise resolve(item) diff --git a/lua/promise/series.lua b/lua/promise/series.lua index ebafa74..88a44c2 100644 --- a/lua/promise/series.lua +++ b/lua/promise/series.lua @@ -22,13 +22,13 @@ return function(inputs) return end - if type(promise) ~= "table" or type(promise.thenCall) ~= "function" then + if type(promise) ~= "table" or type(promise.and_then) ~= "function" then reject("Promise.series: all functions must return a promise") return end promise - :thenCall(function(result) + :and_then(function(result) table.insert(results, result) next() -- Proceed to the next function in the series end) diff --git a/lua/promise/try_each.lua b/lua/promise/try_each.lua index d6870a2..2f9d18c 100644 --- a/lua/promise/try_each.lua +++ b/lua/promise/try_each.lua @@ -16,7 +16,7 @@ return function(promises) index = index + 1 currentPromise - :thenCall(function(value) + :and_then(function(value) -- Resolve as soon as the first promise resolves resolve(value) end) diff --git a/lua/promise/waterfall.lua b/lua/promise/waterfall.lua index a0af51d..566da37 100644 --- a/lua/promise/waterfall.lua +++ b/lua/promise/waterfall.lua @@ -17,9 +17,9 @@ return function(tasks) if not status then reject(result) else - if type(result) == "table" and type(result.thenCall) == "function" then + if type(result) == "table" and type(result.and_then) == "function" then result - :thenCall(function(nextResult) + :and_then(function(nextResult) next(index + 1, nextResult) end) :catch(function(err) diff --git a/tests/promise/all_settled_spec.lua b/tests/promise/all_settled_spec.lua index b86ea9b..6cf9f7e 100644 --- a/tests/promise/all_settled_spec.lua +++ b/tests/promise/all_settled_spec.lua @@ -15,7 +15,7 @@ describe("Promise.Promise.all_settled", function() end) Promise.all_settled({ promise1, promise2, promise3 }) - :thenCall(function(results) + :and_then(function(results) assert.are.same({ { status = "fulfilled", value = 1 }, { status = "fulfilled", value = 2 }, @@ -40,7 +40,7 @@ describe("Promise.Promise.all_settled", function() end) Promise.all_settled({ promise1, promise2, promise3 }) - :thenCall(function(results) + :and_then(function(results) assert.are.same({ { status = "rejected", value = "Error 1" }, { status = "rejected", value = "Error 2" }, @@ -65,7 +65,7 @@ describe("Promise.Promise.all_settled", function() end) Promise.all_settled({ promise1, promise2, promise3 }) - :thenCall(function(results) + :and_then(function(results) assert.are.same({ { status = "fulfilled", value = 1 }, { status = "rejected", value = "Error 2" }, @@ -86,7 +86,7 @@ describe("Promise.Promise.all_settled", function() local value2 = 3 Promise.all_settled({ value1, promise1, value2 }) - :thenCall(function(results) + :and_then(function(results) assert.are.same({ { status = "fulfilled", value = 1 }, { status = "fulfilled", value = 2 }, @@ -101,7 +101,7 @@ describe("Promise.Promise.all_settled", function() async_it("resolves immediately with an empty array", function(done) Promise.all_settled({}) - :thenCall(function(results) + :and_then(function(results) assert.are.same({}, results) done() end) @@ -130,7 +130,7 @@ describe("Promise.Promise.all_settled", function() end) Promise.all_settled({ promise1, promise2, promise3 }) - :thenCall(function(results) + :and_then(function(results) assert.are.same({ { status = "fulfilled", value = 1 }, { status = "rejected", value = "Error 2" }, @@ -149,7 +149,7 @@ describe("Promise.Promise.all_settled", function() end) Promise.all_settled({ promise }) - :thenCall(function(results) + :and_then(function(results) assert.are.same({ { status = "fulfilled", value = 1 }, }, results) @@ -166,7 +166,7 @@ describe("Promise.Promise.all_settled", function() end) Promise.all_settled({ promise }) - :thenCall(function(results) + :and_then(function(results) assert.are.same({ { status = "rejected", value = "Error 1" }, }, results) @@ -184,7 +184,7 @@ describe("Promise.Promise.all_settled", function() local complexObject = { nested = { 1, 2, 3 }, key = "value" } Promise.all_settled({ promise1, complexObject }) - :thenCall(function(results) + :and_then(function(results) assert.are.same({ { status = "fulfilled", value = { key = "value" } }, { status = "fulfilled", value = { nested = { 1, 2, 3 }, key = "value" } }, @@ -198,7 +198,7 @@ describe("Promise.Promise.all_settled", function() async_it("handles promise-like objects correctly", function(done) local promiseLike = { - thenCall = function(self, onFulfilled, onRejected) + and_then = function(self, onFulfilled, onRejected) onFulfilled(42) end, } @@ -208,7 +208,7 @@ describe("Promise.Promise.all_settled", function() end) Promise.all_settled({ promise1, promiseLike }) - :thenCall(function(results) + :and_then(function(results) assert.are.same({ { status = "fulfilled", value = 1 }, { status = "fulfilled", value = 42 }, @@ -222,7 +222,7 @@ describe("Promise.Promise.all_settled", function() async_it("handles rejected promise-like objects correctly", function(done) local promiseLike = { - thenCall = function(self, onFulfilled, onRejected) + and_then = function(self, onFulfilled, onRejected) onRejected("Rejected by promise-like") end, } @@ -232,7 +232,7 @@ describe("Promise.Promise.all_settled", function() end) Promise.all_settled({ promise1, promiseLike }) - :thenCall(function(results) + :and_then(function(results) assert.are.same({ { status = "fulfilled", value = 1 }, { status = "rejected", value = "Rejected by promise-like" }, @@ -258,7 +258,7 @@ describe("Promise.Promise.all_settled", function() end) Promise.all_settled({ promise1, promise2 }) - :thenCall(function(results) + :and_then(function(results) assert.are.same(results[1].status, "fulfilled") assert.are.same(results[2].status, "rejected") done() diff --git a/tests/promise/all_spec.lua b/tests/promise/all_spec.lua index cf58af7..0295837 100644 --- a/tests/promise/all_spec.lua +++ b/tests/promise/all_spec.lua @@ -15,7 +15,7 @@ describe("Promise.all", function() end) Promise.all({ promise1, promise2, promise3 }) - :thenCall(function(results) + :and_then(function(results) assert.are.same({ 1, 2, 3 }, results) done() end) @@ -36,7 +36,7 @@ describe("Promise.all", function() end) Promise.all({ promise1, promise2, promise3 }) - :thenCall(function() + :and_then(function() error("Promise.all should not resolve when one promise rejects.") end) :catch(function(reason) @@ -47,7 +47,7 @@ describe("Promise.all", function() async_it("resolves immediately with an empty array", function(done) Promise.all({}) - :thenCall(function(results) + :and_then(function(results) assert.are.same({}, results) done() end) @@ -68,7 +68,7 @@ describe("Promise.all", function() end) Promise.all({ promise1, promise2, promise3 }) - :thenCall(function() + :and_then(function() error("Promise.all should not resolve when one promise rejects.") end) :catch(function(reason) @@ -97,7 +97,7 @@ describe("Promise.all", function() end) Promise.all({ promise1, promise2, promise3 }) - :thenCall(function(results) + :and_then(function(results) assert.are.same({ 1, 2, 3 }, results) done() end) @@ -114,7 +114,7 @@ describe("Promise.all", function() local value2 = 3 Promise.all({ value1, promise1, value2 }) - :thenCall(function(results) + :and_then(function(results) assert.are.same({ 1, 2, 3 }, results) done() end) @@ -143,7 +143,7 @@ describe("Promise.all", function() end) Promise.all({ promise1, promise2, promise3 }) - :thenCall(function(results) + :and_then(function(results) assert.are.same({ 1, 2, 3 }, results) done() end) @@ -172,7 +172,7 @@ describe("Promise.all", function() end) Promise.all({ promise1, promise2, promise3 }) - :thenCall(function() + :and_then(function() error("Promise.all should not resolve when one promise rejects.") end) :catch(function(reason) diff --git a/tests/promise/auto_spec.lua b/tests/promise/auto_spec.lua index df72cc4..8e56bd2 100644 --- a/tests/promise/auto_spec.lua +++ b/tests/promise/auto_spec.lua @@ -25,7 +25,7 @@ describe("Promise.auto", function() }, } - Promise.auto(tasks):thenCall(function(results) + Promise.auto(tasks):and_then(function(results) assert.are.same({ task1 = "Result from task1", task2 = "Result from task2", @@ -67,7 +67,7 @@ describe("Promise.auto", function() }, } - Promise.auto(tasks):thenCall(function(results) + Promise.auto(tasks):and_then(function(results) assert.are.same({ task1 = "Result from task1", task2 = "Result from task1 -> Result from task2", @@ -110,7 +110,7 @@ describe("Promise.auto", function() }, } - Promise.auto(tasks):thenCall(function(results) + Promise.auto(tasks):and_then(function(results) assert.are.same({ task1 = "Result from task1", task2 = "Result from task2", @@ -142,7 +142,7 @@ describe("Promise.auto", function() }, } - Promise.auto(tasks):thenCall(function(results) + Promise.auto(tasks):and_then(function(results) assert.are.same({ task1 = "Result from task1", task2 = "Result from task2 with no dependencies", @@ -157,7 +157,7 @@ describe("Promise.auto", function() task2 = { "task1", function() end }, } - Promise.auto(tasks):thenCall(function() end):catch(function(err) + Promise.auto(tasks):and_then(function() end):catch(function(err) assert.has.match("Circular dependency detected", err) done() end) @@ -168,7 +168,7 @@ describe("Promise.auto", function() task1 = { "task2", function() end }, } - Promise.auto(tasks):thenCall(function() end):catch(function(err) + Promise.auto(tasks):and_then(function() end):catch(function(err) assert.has.match("Task 'task2' not found", err) done() end) @@ -198,7 +198,7 @@ describe("Promise.auto", function() } Promise.auto(tasks) - :thenCall(function() + :and_then(function() -- This should not be called error("Promise.auto should not resolve when a task fails") end) @@ -229,7 +229,7 @@ describe("Promise.auto", function() }, } - Promise.auto(tasks):thenCall(function(results) + Promise.auto(tasks):and_then(function(results) assert.are.same({ task1 = "Result from task1", task2 = "Result from task1 -> Result from task2", diff --git a/tests/promise/build_task_spec.lua b/tests/promise/build_task_spec.lua index e1cded0..ed5d3d9 100644 --- a/tests/promise/build_task_spec.lua +++ b/tests/promise/build_task_spec.lua @@ -12,7 +12,7 @@ describe("Promise.build_task", function() local task = Promise.build_task(example_promise_function, "Hello", " ") task("World") - :thenCall(function(result) + :and_then(function(result) assert.are.equal("Hello World", result) done() end) @@ -31,7 +31,7 @@ describe("Promise.build_task", function() local task = Promise.build_task(example_promise_function) task("Foo", "Bar") - :thenCall(function(result) + :and_then(function(result) assert.are.equal("FooBar", result) done() end) @@ -49,7 +49,7 @@ describe("Promise.build_task", function() local task = Promise.build_task(example_promise_function, "Task") task() - :thenCall(function(result) + :and_then(function(result) assert.are.equal("Task success", result) done() end) @@ -80,7 +80,7 @@ describe("Promise.build_task", function() local task = Promise.build_task(example_promise_function) task() - :thenCall(function(result) + :and_then(function(result) assert.are.equal("No arguments", result) done() end) @@ -98,7 +98,7 @@ describe("Promise.build_task", function() local task = Promise.build_task(example_promise_function, "Hello", ", ") task("world", "!") - :thenCall(function(result) + :and_then(function(result) assert.are.equal("Hello, world!", result) done() end) diff --git a/tests/promise/hash_settled_spec.lua b/tests/promise/hash_settled_spec.lua index eeaaafb..f660abb 100644 --- a/tests/promise/hash_settled_spec.lua +++ b/tests/promise/hash_settled_spec.lua @@ -13,7 +13,7 @@ describe("Promise.hash_settled", function() end), } - Promise.hash_settled(promises):thenCall(function(results) + Promise.hash_settled(promises):and_then(function(results) assert.are.same({ first = { status = "fulfilled", value = "Resolved" }, second = { status = "rejected", reason = "Rejected" }, @@ -34,7 +34,7 @@ describe("Promise.hash_settled", function() end), } - Promise.hash_settled(promises):thenCall(function(results) + Promise.hash_settled(promises):and_then(function(results) assert.are.same({ first = { status = "fulfilled", value = { nested = "Nested Resolved" } }, second = { status = "fulfilled", value = "Resolved" }, @@ -51,7 +51,7 @@ describe("Promise.hash_settled", function() end), } - Promise.hash_settled(promises):thenCall(function(results) + Promise.hash_settled(promises):and_then(function(results) assert.are.same({ first = { status = "fulfilled", value = "Immediate Value" }, second = { status = "fulfilled", value = "Resolved" }, @@ -61,7 +61,7 @@ describe("Promise.hash_settled", function() end) async_it("handles an empty table correctly", function(done) - Promise.hash_settled({}):thenCall(function(results) + Promise.hash_settled({}):and_then(function(results) assert.are.same({}, results) done() end) @@ -79,7 +79,7 @@ describe("Promise.hash_settled", function() end), } - Promise.hash_settled(promises):thenCall(function(results) + Promise.hash_settled(promises):and_then(function(results) assert.are.same({ first = { status = "fulfilled", value = { nested = { status = "rejected", reason = "Nested Rejection" } } }, second = { status = "fulfilled", value = "Resolved" }, diff --git a/tests/promise/hash_spec.lua b/tests/promise/hash_spec.lua index 722d64d..6d641e2 100644 --- a/tests/promise/hash_spec.lua +++ b/tests/promise/hash_spec.lua @@ -17,7 +17,7 @@ describe("Promise.hash", function() } Promise.hash(promises) - :thenCall(function(results) + :and_then(function(results) assert.are.same({ first = 1, second = 2, third = 3 }, results) done() end) @@ -40,7 +40,7 @@ describe("Promise.hash", function() } Promise.hash(promises) - :thenCall(function() + :and_then(function() error("Promise.hash should not resolve when one promise rejects.") end) :catch(function(reason) @@ -59,7 +59,7 @@ describe("Promise.hash", function() } Promise.hash(promises) - :thenCall(function(results) + :and_then(function(results) assert.are.same({ first = 1, second = 2, third = "non-promise" }, results) done() end) @@ -70,7 +70,7 @@ describe("Promise.hash", function() async_it("resolves immediately with an empty hash", function(done) Promise.hash({}) - :thenCall(function(results) + :and_then(function(results) assert.are.same({}, results) done() end) @@ -92,7 +92,7 @@ describe("Promise.hash", function() } Promise.hash(promises) - :thenCall(function(results) + :and_then(function(results) assert.are.same({ first = 1, second = 2, @@ -119,7 +119,7 @@ describe("Promise.hash", function() } Promise.hash(promises) - :thenCall(function(results) + :and_then(function(results) assert.are.same({ b = "B", a = "A" }, results) done() end) @@ -139,7 +139,7 @@ describe("Promise.hash", function() } Promise.hash(promises) - :thenCall(function() + :and_then(function() error("Promise.hash should not resolve when the first promise rejects.") end) :catch(function(reason) @@ -161,7 +161,7 @@ describe("Promise.hash", function() } Promise.hash(promises) - :thenCall(function(results) + :and_then(function(results) assert.are.same({ first = { nested = "Nested Resolved" }, second = "Resolved", diff --git a/tests/promise/parallel_spec.lua b/tests/promise/parallel_spec.lua index 511e88b..d0d8af2 100644 --- a/tests/promise/parallel_spec.lua +++ b/tests/promise/parallel_spec.lua @@ -29,7 +29,7 @@ describe("Promise.parallel", function() } Promise.parallel(tasks) - :thenCall(function(results) + :and_then(function(results) assert.are.same({ 1, 2, 3 }, results) done() end) @@ -64,7 +64,7 @@ describe("Promise.parallel", function() } Promise.parallel(tasks) - :thenCall(function(results) + :and_then(function(results) error("Promise.parallel should have rejected") end) :catch(function(err) @@ -75,7 +75,7 @@ describe("Promise.parallel", function() async_it("resolves immediately if given an empty list", function(done) Promise.parallel({}) - :thenCall(function(results) + :and_then(function(results) assert.are.same({}, results) done() end) @@ -108,7 +108,7 @@ describe("Promise.parallel", function() } Promise.parallel(tasks) - :thenCall(function(results) + :and_then(function(results) assert.are.same({ 1, 2, 3 }, results) done() end) @@ -139,7 +139,7 @@ describe("Promise.parallel", function() } Promise.parallel(tasks) - :thenCall(function(results) + :and_then(function(results) error("Promise.parallel should have rejected") end) :catch(function(err) diff --git a/tests/promise/race_spec.lua b/tests/promise/race_spec.lua index 2fd8c0e..f87e23d 100644 --- a/tests/promise/race_spec.lua +++ b/tests/promise/race_spec.lua @@ -18,7 +18,7 @@ describe("Promise.race", function() end) Promise.race({ promise1, promise2 }) - :thenCall(function(result) + :and_then(function(result) assert.are.equal("Second", result) done() end) @@ -40,7 +40,7 @@ describe("Promise.race", function() end) Promise.race({ promise1, promise2 }) - :thenCall(function() + :and_then(function() error("Promise.race should not resolve when one promise rejects.") end) :catch(function(reason) @@ -58,7 +58,7 @@ describe("Promise.race", function() end) Promise.race({ nonPromise, promise }) - :thenCall(function(result) + :and_then(function(result) assert.are.equal("Immediate Value", result) done() end) @@ -75,7 +75,7 @@ describe("Promise.race", function() end) Promise.race({ promise }) - :thenCall(function() + :and_then(function() error("Promise.race should not resolve if the first item is a rejected promise.") end) :catch(function(reason) @@ -86,7 +86,7 @@ describe("Promise.race", function() async_it("handles an empty array correctly, promise should be forever pending", function(done) Promise.race({}) - :thenCall(function() + :and_then(function() assert.True(false, "code should not reach here") end) :catch(function() @@ -114,7 +114,7 @@ describe("Promise.race", function() local nonPromise = "Immediate Value" Promise.race({ nonPromise, promise1, promise2 }) - :thenCall(function(result) + :and_then(function(result) assert.are.equal("Immediate Value", result) done() end) @@ -141,7 +141,7 @@ describe("Promise.race", function() end) Promise.race({ promise1, promise2 }) - :thenCall(function(result) + :and_then(function(result) error("Promise.race should not proceed if the second promise rejects first.") end) :catch(function(result) @@ -162,7 +162,7 @@ describe("Promise.race", function() end Promise.race(promises) - :thenCall(function(result) + :and_then(function(result) assert.are.equal(1, result) done() end) diff --git a/tests/promise/series_spec.lua b/tests/promise/series_spec.lua index 33cd24c..7df8f45 100644 --- a/tests/promise/series_spec.lua +++ b/tests/promise/series_spec.lua @@ -25,7 +25,7 @@ describe("Promise.series", function() end Promise.series({ task1, task2 }) - :thenCall(function(results) + :and_then(function(results) assert.are.same({ "Result 1", "Result 2" }, results) assert.are.same({ "task1", "task2" }, call_order) done() @@ -53,7 +53,7 @@ describe("Promise.series", function() end Promise.series({ task1, task2 }) - :thenCall(function() + :and_then(function() error("Promise.series should not resolve if any promise rejects") end) :catch(function(err) @@ -64,7 +64,7 @@ describe("Promise.series", function() async_it("resolves immediately with an empty input list", function(done) Promise.series({}) - :thenCall(function(results) + :and_then(function(results) assert.are.same({}, results) done() end) @@ -79,7 +79,7 @@ describe("Promise.series", function() end Promise.series({ task1 }) - :thenCall(function() + :and_then(function() error("Promise.series should reject if a function does not return a promise") end) :catch(function(err) @@ -102,7 +102,7 @@ describe("Promise.series", function() end Promise.series({ task1, task2 }) - :thenCall(function() + :and_then(function() error("Promise.series should not resolve if a function throws an error") end) :catch(function(err) diff --git a/tests/promise/try_each_spec.lua b/tests/promise/try_each_spec.lua index af7e0f4..d73401d 100644 --- a/tests/promise/try_each_spec.lua +++ b/tests/promise/try_each_spec.lua @@ -23,7 +23,7 @@ describe("Promise.try_each", function() end) Promise.try_each({ promise1, promise2, promise3 }) - :thenCall(function(result) + :and_then(function(result) assert.are.equal("Success 2", result) done() end) @@ -52,7 +52,7 @@ describe("Promise.try_each", function() end) Promise.try_each({ promise1, promise2, promise3 }) - :thenCall(function() + :and_then(function() error("try_each should not resolve if all promises fail.") end) :catch(function(reason) @@ -81,7 +81,7 @@ describe("Promise.try_each", function() end) Promise.try_each({ promise1, promise2, promise3 }) - :thenCall(function(result) + :and_then(function(result) assert.are.equal("Immediate Success", result) done() end) @@ -92,7 +92,7 @@ describe("Promise.try_each", function() async_it("rejects immediately if the list is empty", function(done) Promise.try_each({}) - :thenCall(function() + :and_then(function() error("try_each should not resolve if the list is empty.") end) :catch(function(reason) @@ -127,7 +127,7 @@ describe("Promise.try_each", function() end) Promise.try_each({ promise1, promise2, promise3, promise4 }) - :thenCall(function(result) + :and_then(function(result) assert.are.equal("Success 3", result) done() end) @@ -144,7 +144,7 @@ describe("Promise.try_each", function() end) Promise.try_each({ promise }) - :thenCall(function(result) + :and_then(function(result) assert.are.equal("Single Success", result) done() end) @@ -161,7 +161,7 @@ describe("Promise.try_each", function() end) Promise.try_each({ promise }) - :thenCall(function() + :and_then(function() error("try_each should not resolve if the single promise is rejected.") end) :catch(function(reason) diff --git a/tests/promise/waterfall_spec.lua b/tests/promise/waterfall_spec.lua index e6f2f8c..a995b8f 100644 --- a/tests/promise/waterfall_spec.lua +++ b/tests/promise/waterfall_spec.lua @@ -29,7 +29,7 @@ describe("Promise.waterfall", function() } Promise.waterfall(tasks) - :thenCall(function(result) + :and_then(function(result) assert.are.equal(4, result) done() end) @@ -68,14 +68,14 @@ describe("Promise.waterfall", function() assert.are.equal("Error in second task", err) done() end) - :thenCall(function() + :and_then(function() error("Promise.waterfall should not resolve if a task rejects.") end) end) async_it("resolves immediately with empty tasks", function(done) Promise.waterfall({}) - :thenCall(function(result) + :and_then(function(result) assert.are.equal(nil, result) done() end) @@ -110,7 +110,7 @@ describe("Promise.waterfall", function() assert.is_true(string.find(err, "Promise.waterfall: all functions must return a promise") ~= nil) done() end) - :thenCall(function() + :and_then(function() error("Promise.waterfall should not resolve if a task does not return a promise.") end) end) @@ -142,7 +142,7 @@ describe("Promise.waterfall", function() assert.has.match("Error in second task", err) done() end) - :thenCall(function() + :and_then(function() error("Promise.waterfall should not resolve if a task throws an error.") end) end) @@ -177,7 +177,7 @@ describe("Promise.waterfall", function() } Promise.waterfall(tasks) - :thenCall(function(result) + :and_then(function(result) assert.are.equal(4, result) done() end) diff --git a/tests/promiseA+/2.1.2_spec.lua b/tests/promiseA+/2.1.2_spec.lua index 7340131..46df77e 100644 --- a/tests/promiseA+/2.1.2_spec.lua +++ b/tests/promiseA+/2.1.2_spec.lua @@ -11,7 +11,7 @@ describe("2.1.2.1: When fulfilled, a promise: must not transition to any other s local fulfillment = spy.new(function() end) local rejection = spy.new(function() end) - promise:thenCall(fulfillment, rejection) + promise:and_then(fulfillment, rejection) Timers.set_timeout(function() assert.spy(fulfillment).was_called() @@ -26,7 +26,7 @@ describe("2.1.2.1: When fulfilled, a promise: must not transition to any other s local promise, resolve, reject = Promise.with_resolvers() - promise:thenCall(fulfillment, rejection) + promise:and_then(fulfillment, rejection) resolve(dummy) reject(dummy) @@ -44,7 +44,7 @@ describe("2.1.2.1: When fulfilled, a promise: must not transition to any other s local promise, resolve, reject = Promise.with_resolvers() - promise:thenCall(fulfillment, rejection) + promise:and_then(fulfillment, rejection) Timers.set_timeout(function() resolve(dummy) @@ -65,7 +65,7 @@ describe("2.1.2.1: When fulfilled, a promise: must not transition to any other s local promise, resolve, reject = Promise.with_resolvers() - promise:thenCall(fulfillment, rejection) + promise:and_then(fulfillment, rejection) resolve(dummy) diff --git a/tests/promiseA+/2.1.3_spec.lua b/tests/promiseA+/2.1.3_spec.lua index ac77dd6..7ecb40a 100644 --- a/tests/promiseA+/2.1.3_spec.lua +++ b/tests/promiseA+/2.1.3_spec.lua @@ -11,7 +11,7 @@ describe("2.1.3.1: When rejected, a promise: must not transition to any other st local fulfillment = spy.new(function() end) local rejection = spy.new(function() end) - promise:thenCall(fulfillment, rejection) + promise:and_then(fulfillment, rejection) Timers.set_timeout(function() assert.spy(rejection).was_called() @@ -26,7 +26,7 @@ describe("2.1.3.1: When rejected, a promise: must not transition to any other st local promise, resolve, reject = Promise.with_resolvers() - promise:thenCall(fulfillment, rejection) + promise:and_then(fulfillment, rejection) reject(dummy) resolve(dummy) @@ -45,7 +45,7 @@ describe("2.1.3.1: When rejected, a promise: must not transition to any other st local promise, resolve, reject = Promise.with_resolvers() - promise:thenCall(fulfillment, rejection) + promise:and_then(fulfillment, rejection) Timers.set_timeout(function() reject(dummy) @@ -65,7 +65,7 @@ describe("2.1.3.1: When rejected, a promise: must not transition to any other st local promise, resolve, reject = Promise.with_resolvers() - promise:thenCall(fulfillment, rejection) + promise:and_then(fulfillment, rejection) reject(dummy) diff --git a/tests/promiseA+/2.2.1_spec.lua b/tests/promiseA+/2.2.1_spec.lua index 243bef0..d4b586a 100644 --- a/tests/promiseA+/2.2.1_spec.lua +++ b/tests/promiseA+/2.2.1_spec.lua @@ -8,7 +8,7 @@ describe("2.2.1: Both `onFulfilled` and `onRejected` are optional arguments.", f describe("applied to a directly-rejected promise", function() local function testNonFunction(non_function, string_representation) async_it("`onFulfilled` is " .. string_representation, function(done) - Promise.reject(dummy):thenCall(non_function, function() + Promise.reject(dummy):and_then(non_function, function() done() end) end) @@ -23,7 +23,7 @@ describe("2.2.1: Both `onFulfilled` and `onRejected` are optional arguments.", f describe("applied to a promise rejected and then chained off of", function() local function testNonFunction(nonFunction, stringRepresentation) async_it("`onFulfilled` is " .. stringRepresentation, function(done) - Promise.reject(dummy):thenCall(function() end, nil):thenCall(nonFunction, function() + Promise.reject(dummy):and_then(function() end, nil):and_then(nonFunction, function() done() end) end) @@ -40,7 +40,7 @@ describe("2.2.1: Both `onFulfilled` and `onRejected` are optional arguments.", f describe("applied to a directly-fulfilled promise", function() local function testNonFunction(nonFunction, stringRepresentation) async_it("`onRejected` is " .. stringRepresentation, function(done) - Promise.resolve(dummy):thenCall(function() + Promise.resolve(dummy):and_then(function() done() end, nonFunction) end) @@ -55,7 +55,7 @@ describe("2.2.1: Both `onFulfilled` and `onRejected` are optional arguments.", f describe("applied to a promise fulfilled and then chained off of", function() local function testNonFunction(nonFunction, stringRepresentation) async_it("`onFulfilled` is " .. stringRepresentation, function(done) - Promise.resolve(dummy):thenCall(nil, function() end):thenCall(function() + Promise.resolve(dummy):and_then(nil, function() end):and_then(function() done() end, nonFunction) end) diff --git a/tests/promiseA+/2.2.2_spec.lua b/tests/promiseA+/2.2.2_spec.lua index a560e36..397853b 100644 --- a/tests/promiseA+/2.2.2_spec.lua +++ b/tests/promiseA+/2.2.2_spec.lua @@ -12,7 +12,7 @@ describe("2.2.2: If `onFulfilled` is a function,", function() "2.2.2.1: it must be called after `promise` is fulfilled, with `promise`’s fulfillment value as its first argument.", function() Helper.test_fulfilled(it, sentinel, function(promise, done) - promise:thenCall(function(value) + promise:and_then(function(value) assert.are.equal(value, sentinel) done() end) @@ -25,7 +25,7 @@ describe("2.2.2: If `onFulfilled` is a function,", function() local promise, resolve = Promise.with_resolvers() local fulfillment = spy.new(function() end) - promise:thenCall(fulfillment) + promise:and_then(fulfillment) Timers.set_timeout(function() resolve(dummy) @@ -41,7 +41,7 @@ describe("2.2.2: If `onFulfilled` is a function,", function() local promise = Promise:new(function() end) local fulfillment = spy.new(function() end) - promise:thenCall(fulfillment) + promise:and_then(fulfillment) Timers.set_timeout(function() assert.spy(fulfillment).was_not_called() @@ -53,7 +53,7 @@ describe("2.2.2: If `onFulfilled` is a function,", function() describe("2.2.2.3: it must not be called more than once.", function() async_it("already-fulfilled", function(done) local callback = spy.new(function() end) - Promise.resolve(dummy):thenCall(callback) + Promise.resolve(dummy):and_then(callback) Timers.set_timeout(function() assert.spy(callback).was_called(1) @@ -65,7 +65,7 @@ describe("2.2.2: If `onFulfilled` is a function,", function() local promise, resolve = Promise.with_resolvers() local callback = spy.new(function() end) - promise:thenCall(callback) + promise:and_then(callback) resolve(dummy) resolve(dummy) @@ -80,7 +80,7 @@ describe("2.2.2: If `onFulfilled` is a function,", function() local promise, resolve = Promise.with_resolvers() local callback = spy.new(function() end) - promise:thenCall(callback) + promise:and_then(callback) Timers.set_timeout(function() resolve(dummy) @@ -97,7 +97,7 @@ describe("2.2.2: If `onFulfilled` is a function,", function() local promise, resolve = Promise.with_resolvers() local callback = spy.new(function() end) - promise:thenCall(callback) + promise:and_then(callback) resolve(dummy) @@ -118,14 +118,14 @@ describe("2.2.2: If `onFulfilled` is a function,", function() local callback_2 = spy.new(function() end) local callback_3 = spy.new(function() end) - promise:thenCall(callback_1) + promise:and_then(callback_1) Timers.set_timeout(function() - promise:thenCall(callback_2) + promise:and_then(callback_2) end, 50) Timers.set_timeout(function() - promise:thenCall(callback_3) + promise:and_then(callback_3) end, 100) Timers.set_timeout(function() @@ -145,9 +145,9 @@ describe("2.2.2: If `onFulfilled` is a function,", function() local callback_1 = spy.new(function() end) local callback_2 = spy.new(function() end) - promise:thenCall(callback_1) + promise:and_then(callback_1) resolve(dummy) - promise:thenCall(callback_2) + promise:and_then(callback_2) Timers.set_timeout(function() assert.spy(callback_1).was_called(1) diff --git a/tests/promiseA+/2.2.3_spec.lua b/tests/promiseA+/2.2.3_spec.lua index 091c1dc..9171f7b 100644 --- a/tests/promiseA+/2.2.3_spec.lua +++ b/tests/promiseA+/2.2.3_spec.lua @@ -12,7 +12,7 @@ describe("2.2.2: If `onRejected` is a function,", function() "2.2.2.1: it must be called after `promise` is rejected, with `promise`’s rejection reason as its first argument.", function() Helper.test_rejected(async_it, sentinel, function(promise, done) - promise:thenCall(nil, function(value) + promise:and_then(nil, function(value) assert.are.equals(value, sentinel) done() end) @@ -25,7 +25,7 @@ describe("2.2.2: If `onRejected` is a function,", function() local promise, _, reject = Promise.with_resolvers() local rejection = spy.new(function() end) - promise:thenCall(nil, rejection) + promise:and_then(nil, rejection) Timers.set_timeout(function() reject(dummy) @@ -41,7 +41,7 @@ describe("2.2.2: If `onRejected` is a function,", function() local promise = Promise:new(function() end) local rejection = spy.new(function() end) - promise:thenCall(nil, rejection) + promise:and_then(nil, rejection) Timers.set_timeout(function() assert.spy(rejection).was_not_called() @@ -53,7 +53,7 @@ describe("2.2.2: If `onRejected` is a function,", function() describe("2.2.3.3: it must not be called more than once.", function() async_it("already-rejected", function(done) local callback = spy.new(function() end) - Promise.reject(dummy):thenCall(nil, callback) + Promise.reject(dummy):and_then(nil, callback) Timers.set_timeout(function() assert.spy(callback).was_called(1) @@ -65,7 +65,7 @@ describe("2.2.2: If `onRejected` is a function,", function() local promise, _, reject = Promise.with_resolvers() local callback = spy.new(function() end) - promise:thenCall(nil, callback) + promise:and_then(nil, callback) reject(dummy) reject(dummy) @@ -80,7 +80,7 @@ describe("2.2.2: If `onRejected` is a function,", function() local promise, _, reject = Promise.with_resolvers() local callback = spy.new(function() end) - promise:thenCall(nil, callback) + promise:and_then(nil, callback) Timers.set_timeout(function() reject(dummy) @@ -97,7 +97,7 @@ describe("2.2.2: If `onRejected` is a function,", function() local promise, _, reject = Promise.with_resolvers() local callback = spy.new(function() end) - promise:thenCall(nil, callback) + promise:and_then(nil, callback) reject(dummy) @@ -118,14 +118,14 @@ describe("2.2.2: If `onRejected` is a function,", function() local callback_2 = spy.new(function() end) local callback_3 = spy.new(function() end) - promise:thenCall(nil, callback_1) + promise:and_then(nil, callback_1) Timers.set_timeout(function() - promise:thenCall(nil, callback_2) + promise:and_then(nil, callback_2) end, 50) Timers.set_timeout(function() - promise:thenCall(nil, callback_3) + promise:and_then(nil, callback_3) end, 100) Timers.set_timeout(function() @@ -145,9 +145,9 @@ describe("2.2.2: If `onRejected` is a function,", function() local callback_1 = spy.new(function() end) local callback_2 = spy.new(function() end) - promise:thenCall(nil, callback_1) + promise:and_then(nil, callback_1) reject(dummy) - promise:thenCall(nil, callback_2) + promise:and_then(nil, callback_2) Timers.set_timeout(function() assert.spy(callback_1).was_called(1) diff --git a/tests/promiseA+/2.2.4_spec.lua b/tests/promiseA+/2.2.4_spec.lua index 849e27f..09b5ad6 100644 --- a/tests/promiseA+/2.2.4_spec.lua +++ b/tests/promiseA+/2.2.4_spec.lua @@ -12,7 +12,7 @@ describe( Helper.test_fulfilled(async_it, dummy, function(promise, done) local thenHasReturned = false - promise:thenCall(function() + promise:and_then(function() assert.is_true(thenHasReturned) done() end) @@ -23,7 +23,7 @@ describe( Helper.test_rejected(async_it, dummy, function(promise, done) local thenHasReturned = false - promise:thenCall(nil, function() + promise:and_then(nil, function() assert.is_true(thenHasReturned) done() end) @@ -37,7 +37,7 @@ describe( local promise, resolve = Promise.with_resolvers() local onFulfilledCalled = false - promise:thenCall(function() + promise:and_then(function() onFulfilledCalled = true end) @@ -52,7 +52,7 @@ describe( resolve(dummy) - promise:thenCall(function() + promise:and_then(function() onFulfilledCalled = true end) @@ -63,8 +63,8 @@ describe( local promise = Promise.resolve(dummy) local firstOnFulfilledFinished = false - promise:thenCall(function() - promise:thenCall(function() + promise:and_then(function() + promise:and_then(function() assert.is_true(firstOnFulfilledFinished) done() end) @@ -77,8 +77,8 @@ describe( local promise2 = Promise.resolve(dummy) local firstOnRejectedFinished = false - promise:thenCall(nil, function() - promise2:thenCall(function() + promise:and_then(nil, function() + promise2:and_then(function() assert.is_true(firstOnRejectedFinished) done() end) @@ -95,7 +95,7 @@ describe( firstStackFinished = true end, 0) - promise:thenCall(function() + promise:and_then(function() assert.is_true(firstStackFinished) done() end) @@ -107,7 +107,7 @@ describe( local promise, _, reject = Promise.with_resolvers() local onRejectedCalled = false - promise:thenCall(nil, function() + promise:and_then(nil, function() onRejectedCalled = true end) @@ -122,7 +122,7 @@ describe( reject(dummy) - promise:thenCall(nil, function() + promise:and_then(nil, function() onRejectedCalled = true end) @@ -134,8 +134,8 @@ describe( local promise2 = Promise.reject(dummy) local firstOnFulfilledFinished = false - promise:thenCall(function() - promise2:thenCall(nil, function() + promise:and_then(function() + promise2:and_then(nil, function() assert.is_true(firstOnFulfilledFinished) done() end) @@ -147,8 +147,8 @@ describe( local promise = Promise.reject(dummy) local firstOnRejectedFinished = false - promise:thenCall(nil, function() - promise:thenCall(nil, function() + promise:and_then(nil, function() + promise:and_then(nil, function() assert.is_true(firstOnRejectedFinished) done() end) @@ -165,7 +165,7 @@ describe( firstStackFinished = true end, 0) - promise:thenCall(nil, function() + promise:and_then(nil, function() assert.is_true(firstStackFinished) done() end) diff --git a/tests/promiseA+/2.2.6_spec.lua b/tests/promiseA+/2.2.6_spec.lua index 9d91808..3c2668f 100644 --- a/tests/promiseA+/2.2.6_spec.lua +++ b/tests/promiseA+/2.2.6_spec.lua @@ -39,11 +39,11 @@ describe("2.2.6: `next` may be called multiple times on the same promise.", func end) local rejected_spy = spy.new(function() end) - promise:thenCall(handler1, rejected_spy) - promise:thenCall(handler2, rejected_spy) - promise:thenCall(handler3, rejected_spy) + promise:and_then(handler1, rejected_spy) + promise:and_then(handler2, rejected_spy) + promise:and_then(handler3, rejected_spy) - promise:thenCall(function(value) + promise:and_then(function(value) assert.are.equal(value, sentinel) assert.spy(handler1).was_called_with(sentinel) @@ -70,11 +70,11 @@ describe("2.2.6: `next` may be called multiple times on the same promise.", func end) local rejected_spy = spy.new(function() end) - promise:thenCall(handler1, spy) - promise:thenCall(handler2, spy) - promise:thenCall(handler3, spy) + promise:and_then(handler1, spy) + promise:and_then(handler2, spy) + promise:and_then(handler3, spy) - promise:thenCall(function(value) + promise:and_then(function(value) assert.are.equal(value, sentinel) assert.spy(handler1).was_called_with(sentinel) @@ -93,30 +93,30 @@ describe("2.2.6: `next` may be called multiple times on the same promise.", func local semiDone = callbackAggregator(3, done) promise - :thenCall(function() + :and_then(function() return sentinel end) - :thenCall(function(value) + :and_then(function(value) assert.are.equals(value, sentinel) semiDone() end) promise - :thenCall(function() + :and_then(function() error(sentinel2) end) - :thenCall(nil, function(reason) + :and_then(nil, function(reason) assert.are.equals(reason, sentinel2) semiDone() end) promise - :thenCall(function() + :and_then(function() return sentinel3 end) - :thenCall(function(value) + :and_then(function(value) assert.are.equals(value, sentinel3) semiDone() @@ -137,11 +137,11 @@ describe("2.2.6: `next` may be called multiple times on the same promise.", func local handler2 = ordered_callback(2) local handler3 = ordered_callback(3) - promise:thenCall(handler1) - promise:thenCall(handler2) - promise:thenCall(handler3) + promise:and_then(handler1) + promise:and_then(handler2) + promise:and_then(handler3) - promise:thenCall(function() + promise:and_then(function() assert.are.same(content, { 1, 2, 3 }) done() end) @@ -160,13 +160,13 @@ describe("2.2.6: `next` may be called multiple times on the same promise.", func local handler2 = ordered_callback(2) local handler3 = ordered_callback(3) - promise:thenCall(function() + promise:and_then(function() handler1() - promise:thenCall(handler3) + promise:and_then(handler3) end) - promise:thenCall(handler2) + promise:and_then(handler2) - promise:thenCall(function() + promise:and_then(function() -- Give implementations a bit of extra time to flush their internal queue, if necessary. Timers.set_timeout(function() assert.are.same(content, { 1, 2, 3 }) @@ -196,11 +196,11 @@ describe("2.2.6: `next` may be called multiple times on the same promise.", func local fulfill_spy = spy.new(function() end) - promise:thenCall(fulfill_spy, handler1) - promise:thenCall(fulfill_spy, handler2) - promise:thenCall(fulfill_spy, handler3) + promise:and_then(fulfill_spy, handler1) + promise:and_then(fulfill_spy, handler2) + promise:and_then(fulfill_spy, handler3) - promise:thenCall(nil, function(reason) + promise:and_then(nil, function(reason) assert.are.equals(reason, sentinel) assert.spy(handler1).called_with(sentinel) @@ -226,11 +226,11 @@ describe("2.2.6: `next` may be called multiple times on the same promise.", func end) local fulfill_spy = spy.new(function() end) - promise:thenCall(fulfill_spy, handler1) - promise:thenCall(fulfill_spy, handler2) - promise:thenCall(fulfill_spy, handler3) + promise:and_then(fulfill_spy, handler1) + promise:and_then(fulfill_spy, handler2) + promise:and_then(fulfill_spy, handler3) - promise:thenCall(nil, function(reason) + promise:and_then(nil, function(reason) assert.are.equals(reason, sentinel) assert.spy(handler1).called_with(sentinel) @@ -248,28 +248,28 @@ describe("2.2.6: `next` may be called multiple times on the same promise.", func local semiDone = callbackAggregator(3, done) promise - :thenCall(nil, function() + :and_then(nil, function() return sentinel end) - :thenCall(function(value) + :and_then(function(value) assert.are.equals(value, sentinel) semiDone() end) promise - :thenCall(nil, function() + :and_then(nil, function() error(sentinel2) end) - :thenCall(nil, function(reason) + :and_then(nil, function(reason) assert.are.equals(reason, sentinel2) semiDone() end) promise - :thenCall(nil, function() + :and_then(nil, function() return sentinel3 end) - :thenCall(function(value) + :and_then(function(value) assert.are.equals(value, sentinel3) semiDone() end) @@ -289,11 +289,11 @@ describe("2.2.6: `next` may be called multiple times on the same promise.", func local handler2 = ordered_callback(2) local handler3 = ordered_callback(3) - promise:thenCall(nil, handler1) - promise:thenCall(nil, handler2) - promise:thenCall(nil, handler3) + promise:and_then(nil, handler1) + promise:and_then(nil, handler2) + promise:and_then(nil, handler3) - promise:thenCall(nil, function() + promise:and_then(nil, function() assert.are.same(content, { 1, 2, 3 }) done() end) @@ -312,13 +312,13 @@ describe("2.2.6: `next` may be called multiple times on the same promise.", func local handler2 = ordered_callback(2) local handler3 = ordered_callback(3) - promise:thenCall(nil, function() + promise:and_then(nil, function() handler1() - promise:thenCall(nil, handler3) + promise:and_then(nil, handler3) end) - promise:thenCall(nil, handler2) + promise:and_then(nil, handler2) - promise:thenCall(nil, function() + promise:and_then(nil, function() -- Give implementations a bit of extra time to flush their internal queue, if necessary. Timers.set_timeout(function() assert.are.same(content, { 1, 2, 3 }) diff --git a/tests/promiseA+/2.2.7_spec.lua b/tests/promiseA+/2.2.7_spec.lua index 9bc3ddf..86970c6 100644 --- a/tests/promiseA+/2.2.7_spec.lua +++ b/tests/promiseA+/2.2.7_spec.lua @@ -11,10 +11,10 @@ local other = { other = "other" } -- a value we don't want to be strict equal to describe("2.2.7: `next` must return a promise: `promise2 = promise1:next(onFulfilled, onRejected)`", function() it("is a promise", function() local promise1 = Promise:new(function() end) - local promise2 = promise1:thenCall() + local promise2 = promise1:and_then() assert.are.same(type(promise2), "table") - assert.are.same(type(promise2.thenCall), "function") + assert.are.same(type(promise2.and_then), "function") end) describe( @@ -30,23 +30,23 @@ describe("2.2.7: `next` must return a promise: `promise2 = promise1:next(onFulfi local function testReason(expectedReason, stringRepresentation) describe("The reason is " .. stringRepresentation, function() Helper.test_fulfilled(async_it, dummy, function(promise1, done) - local promise2 = promise1:thenCall(function() + local promise2 = promise1:and_then(function() error(expectedReason) end) - promise2:thenCall(nil, function(actualReason) + promise2:and_then(nil, function(actualReason) assert.are.equals(actualReason, expectedReason) done() end) end) Helper.test_rejected(async_it, dummy, function(promise1, done) - local promise2 = promise1:thenCall(nil, function() + local promise2 = promise1:and_then(nil, function() error(expectedReason) end) promise2 - :thenCall(nil, function(actualReason) + :and_then(nil, function(actualReason) assert.are.equals(actualReason, expectedReason) done() end) @@ -69,10 +69,10 @@ describe( describe("`onFulfilled` is " .. stringRepresentation, function() Helper.test_fulfilled(async_it, sentinel, function(promise1, done) Timers.set_timeout(function() - local promise2 = promise1:thenCall(nonFunction) + local promise2 = promise1:and_then(nonFunction) promise2 - :thenCall(function(value) + :and_then(function(value) assert.are.equals(value, sentinel) done() end) @@ -100,9 +100,9 @@ describe( local function testNonFunction(nonFunction, stringRepresentation) describe("`onRejected` is " .. stringRepresentation, function() Helper.test_rejected(async_it, sentinel, function(promise1, done) - local promise2 = promise1:thenCall(nil, nonFunction) + local promise2 = promise1:and_then(nil, nonFunction) - promise2:thenCall(nil, function(reason) + promise2:and_then(nil, function(reason) assert.are.equals(reason, sentinel) done() end) diff --git a/tests/promiseA+/2.3.1_spec.lua b/tests/promiseA+/2.3.1_spec.lua index bb086ba..2daff83 100644 --- a/tests/promiseA+/2.3.1_spec.lua +++ b/tests/promiseA+/2.3.1_spec.lua @@ -9,11 +9,11 @@ describe( async_it("via return from a fulfilled promise", function(done) local promise - promise = Promise.resolve(dummy):thenCall(function() + promise = Promise.resolve(dummy):and_then(function() return promise end) - promise:thenCall(nil, function(reason) + promise:and_then(nil, function(reason) assert.is_truthy(string.find(reason, "TypeError")) done() end) @@ -22,11 +22,11 @@ describe( async_it("via return from a rejected promise", function(done) local promise - promise = Promise.reject(dummy):thenCall(nil, function() + promise = Promise.reject(dummy):and_then(nil, function() return promise end) - promise:thenCall(nil, function(reason) + promise:and_then(nil, function(reason) assert.is_truthy(string.find(reason, "TypeError")) done() end) diff --git a/tests/promiseA+/2.3.2_spec.lua b/tests/promiseA+/2.3.2_spec.lua index 756d380..461b49c 100644 --- a/tests/promiseA+/2.3.2_spec.lua +++ b/tests/promiseA+/2.3.2_spec.lua @@ -8,7 +8,7 @@ local sentinel = { sentinel = "sentinel" } -- a sentinel fulfillment value to te local function testPromiseResolution(it, xFactory, test) it("via return from a fulfilled promise", function(done) - local promise = Promise.resolve(dummy):thenCall(function() + local promise = Promise.resolve(dummy):and_then(function() return xFactory() end) @@ -16,7 +16,7 @@ local function testPromiseResolution(it, xFactory, test) end) it("via return from a rejected promise", function(done) - local promise = Promise.reject(dummy):thenCall(nil, function() + local promise = Promise.reject(dummy):and_then(nil, function() return xFactory() end) @@ -34,7 +34,7 @@ describe("2.3.2: If `x` is a promise, adopt its state", function() local fulfillment = spy.new(function() end) local rejection = spy.new(function() end) - promise:thenCall(fulfillment, rejection) + promise:and_then(fulfillment, rejection) Timers.set_timeout(function() assert.spy(fulfillment).was_not_called() @@ -52,7 +52,7 @@ describe("2.3.2: If `x` is a promise, adopt its state", function() end testPromiseResolution(async_it, xFactory, function(promise, done) - promise:thenCall(function(value) + promise:and_then(function(value) assert.are.equals(value, sentinel) done() end) @@ -71,7 +71,7 @@ describe("2.3.2: If `x` is a promise, adopt its state", function() end testPromiseResolution(async_it, xFactory, function(promise, done) - promise:thenCall(function(value) + promise:and_then(function(value) assert.are_equals(value, sentinel) done() end) @@ -86,7 +86,7 @@ describe("2.3.2: If `x` is a promise, adopt its state", function() end testPromiseResolution(async_it, xFactory, function(promise, done) - promise:thenCall(nil, function(reason) + promise:and_then(nil, function(reason) assert.are_equals(reason, sentinel) done() end) @@ -105,7 +105,7 @@ describe("2.3.2: If `x` is a promise, adopt its state", function() end testPromiseResolution(async_it, xFactory, function(promise, done) - promise:thenCall(nil, function(reason) + promise:and_then(nil, function(reason) assert.are_equals(reason, sentinel) done() end) diff --git a/tests/promiseA+/2.3.3_spec.lua b/tests/promiseA+/2.3.3_spec.lua index c586aeb..ec911b7 100644 --- a/tests/promiseA+/2.3.3_spec.lua +++ b/tests/promiseA+/2.3.3_spec.lua @@ -12,7 +12,7 @@ local sentinelArray = { sentinel } -- a sentinel fulfillment value to test when local function testPromiseResolution(it, xFactory, test) it("via return from a fulfilled promise", function(done) - local promise = Promise.resolve(dummy):thenCall(function() + local promise = Promise.resolve(dummy):and_then(function() return xFactory() end) @@ -20,7 +20,7 @@ local function testPromiseResolution(it, xFactory, test) end) it("via return from a rejected promise", function(done) - local promise = Promise.reject(dummy):thenCall(nil, function() + local promise = Promise.reject(dummy):and_then(nil, function() return xFactory() end) @@ -34,7 +34,7 @@ local function testCallingResolvePromise(yFactory, stringRepresentation, test) local function xFactory() return { type = "synchronous resolution", - thenCall = function(instance, resolvePromise) + and_then = function(instance, resolvePromise) resolvePromise(yFactory()) end, } @@ -47,7 +47,7 @@ local function testCallingResolvePromise(yFactory, stringRepresentation, test) local function xFactory() return { type = "asynchronous resolution", - thenCall = function(instance, resolvePromise) + and_then = function(instance, resolvePromise) Timers.set_timeout(function() resolvePromise(yFactory()) end, 0) @@ -65,7 +65,7 @@ local function testCallingRejectPromise(r, stringRepresentation, test) describe("`next` calls `rejectPromise` synchronously", function() local function xFactory() return { - thenCall = function(instance, resolvePromise, rejectPromise) + and_then = function(instance, resolvePromise, rejectPromise) rejectPromise(r) end, } @@ -77,7 +77,7 @@ local function testCallingRejectPromise(r, stringRepresentation, test) describe("`next` calls `rejectPromise` asynchronously", function() local function xFactory() return { - thenCall = function(instance, resolvePromise, rejectPromise) + and_then = function(instance, resolvePromise, rejectPromise) Timers.set_timeout(function() rejectPromise(r) end, 0) @@ -93,7 +93,7 @@ end local function testCallingResolvePromiseFulfillsWith(yFactory, stringRepresentation, fulfillmentValue) testCallingResolvePromise(yFactory, stringRepresentation, function(promise, done) Timers.set_timeout(function() - promise:thenCall(function(value) + promise:and_then(function(value) assert.are.equals(fulfillmentValue, value) done() end) @@ -104,7 +104,7 @@ end local function testCallingResolvePromiseRejectsWith(yFactory, stringRepresentation, rejectionReason) testCallingResolvePromise(yFactory, stringRepresentation, function(promise, done) Timers.set_timeout(function() - promise:thenCall(nil, function(reason) + promise:and_then(nil, function(reason) assert.are.equals(reason, rejectionReason) done() end) @@ -115,7 +115,7 @@ end local function testCallingRejectPromiseRejectsWith(reason, stringRepresentation) testCallingRejectPromise(reason, stringRepresentation, function(promise, done) Timers.set_timeout(function() - promise:thenCall(nil, function(rejectionReason) + promise:and_then(nil, function(rejectionReason) assert.are.equals(rejectionReason, reason) done() end) @@ -137,7 +137,7 @@ describe("2.3.3: Otherwise, if `x` is an object or function,", function() local mt = { __index = function(table, key) - if key == "thenCall" then + if key == "and_then" then numberOfTimesNextWasRetrieved = numberOfTimesNextWasRetrieved + 1 return function(instance, onFulfilled) onFulfilled(dummy) @@ -152,7 +152,7 @@ describe("2.3.3: Otherwise, if `x` is an object or function,", function() testPromiseResolution(async_it, xFactory, function(promise, done) Timers.set_timeout(function() - promise:thenCall(function() + promise:and_then(function() assert.are.equals(1, numberOfTimesNextWasRetrieved) done() end) @@ -169,7 +169,7 @@ describe("2.3.3: Otherwise, if `x` is an object or function,", function() local x = {} local mt = { __index = function(table, key) - if key == "thenCall" then + if key == "and_then" then error(e) end end, @@ -181,7 +181,7 @@ describe("2.3.3: Otherwise, if `x` is an object or function,", function() describe("`e` is " .. stringRepresentation, function() testPromiseResolution(async_it, xFactory, function(promise, done) - promise:thenCall(nil, function(reason) + promise:and_then(nil, function(reason) assert.are.equals(reason, e) done() end) @@ -203,7 +203,7 @@ describe("2.3.3: Otherwise, if `x` is an object or function,", function() local x x = { line = 200, - thenCall = function(promise, onFulfilled, onRejected) + and_then = function(promise, onFulfilled, onRejected) assert.are.equals(promise, x) assert.are.equals(type(onFulfilled), "function") assert.are.equals(type(onRejected), "function") @@ -216,7 +216,7 @@ describe("2.3.3: Otherwise, if `x` is an object or function,", function() testPromiseResolution(async_it, xFactory, function(promise, done) Timers.set_timeout(function() - promise:thenCall(function() + promise:and_then(function() done() end) end, 100) @@ -296,7 +296,7 @@ describe("2.3.3: Otherwise, if `x` is an object or function,", function() describe("calling `resolvePromise` then `rejectPromise`, both synchronously", function() local function xFactory() return { - thenCall = function(instance, resolvePromise, rejectPromise) + and_then = function(instance, resolvePromise, rejectPromise) resolvePromise(sentinel) rejectPromise(other) end, @@ -304,7 +304,7 @@ describe("2.3.3: Otherwise, if `x` is an object or function,", function() end testPromiseResolution(async_it, xFactory, function(promise, done) - promise:thenCall(function(value) + promise:and_then(function(value) assert.are.equals(value, sentinel) done() end) @@ -314,7 +314,7 @@ describe("2.3.3: Otherwise, if `x` is an object or function,", function() describe("calling `resolvePromise` synchronously then `rejectPromise` asynchronously", function() local function xFactory() return { - thenCall = function(instance, resolvePromise, rejectPromise) + and_then = function(instance, resolvePromise, rejectPromise) resolvePromise(sentinel) Timers.set_timeout(function() @@ -325,7 +325,7 @@ describe("2.3.3: Otherwise, if `x` is an object or function,", function() end testPromiseResolution(async_it, xFactory, function(promise, done) - promise:thenCall(function(value) + promise:and_then(function(value) assert.are.equals(value, sentinel) done() end) @@ -335,7 +335,7 @@ describe("2.3.3: Otherwise, if `x` is an object or function,", function() describe("calling `resolvePromise` then `rejectPromise`, both asynchronously", function() local function xFactory() return { - thenCall = function(instance, resolvePromise, rejectPromise) + and_then = function(instance, resolvePromise, rejectPromise) Timers.set_timeout(function() resolvePromise(sentinel) end, 50) @@ -348,7 +348,7 @@ describe("2.3.3: Otherwise, if `x` is an object or function,", function() end testPromiseResolution(async_it, xFactory, function(promise, done) - promise:thenCall(function(value) + promise:and_then(function(value) assert.are.equals(value, sentinel) done() end) @@ -365,7 +365,7 @@ describe("2.3.3: Otherwise, if `x` is an object or function,", function() end, 50) return { - thenCall = function(instance, resolvePromise, rejectPromise) + and_then = function(instance, resolvePromise, rejectPromise) resolvePromise(promise) rejectPromise(other) end, @@ -373,7 +373,7 @@ describe("2.3.3: Otherwise, if `x` is an object or function,", function() end testPromiseResolution(async_it, xFactory, function(promise, done) - promise:thenCall(function(value) + promise:and_then(function(value) assert.are.equals(value, sentinel) done() end) @@ -391,7 +391,7 @@ describe("2.3.3: Otherwise, if `x` is an object or function,", function() end, 50) return { - thenCall = function(instance, resolvePromise, rejectPromise) + and_then = function(instance, resolvePromise, rejectPromise) resolvePromise(promise) rejectPromise(other) end, @@ -399,7 +399,7 @@ describe("2.3.3: Otherwise, if `x` is an object or function,", function() end testPromiseResolution(async_it, xFactory, function(promise, done) - promise:thenCall(nil, function(reason) + promise:and_then(nil, function(reason) assert.are.equals(reason, sentinel) done() end) @@ -410,7 +410,7 @@ describe("2.3.3: Otherwise, if `x` is an object or function,", function() describe("calling `rejectPromise` then `resolvePromise`, both synchronously", function() local function xFactory() return { - thenCall = function(instance, resolvePromise, rejectPromise) + and_then = function(instance, resolvePromise, rejectPromise) rejectPromise(sentinel) resolvePromise(other) end, @@ -418,7 +418,7 @@ describe("2.3.3: Otherwise, if `x` is an object or function,", function() end testPromiseResolution(async_it, xFactory, function(promise, done) - promise:thenCall(nil, function(reason) + promise:and_then(nil, function(reason) assert.are.equals(reason, sentinel) done() end) @@ -428,7 +428,7 @@ describe("2.3.3: Otherwise, if `x` is an object or function,", function() describe("calling `rejectPromise` synchronously then `resolvePromise` asynchronously", function() local function xFactory() return { - thenCall = function(instance, resolvePromise, rejectPromise) + and_then = function(instance, resolvePromise, rejectPromise) rejectPromise(sentinel) Timers.set_timeout(function() @@ -439,7 +439,7 @@ describe("2.3.3: Otherwise, if `x` is an object or function,", function() end testPromiseResolution(async_it, xFactory, function(promise, done) - promise:thenCall(nil, function(reason) + promise:and_then(nil, function(reason) assert.are.equals(reason, sentinel) done() end) @@ -449,7 +449,7 @@ describe("2.3.3: Otherwise, if `x` is an object or function,", function() describe("calling `rejectPromise` then `resolvePromise`, both asynchronously", function() local function xFactory() return { - thenCall = function(instance, resolvePromise, rejectPromise) + and_then = function(instance, resolvePromise, rejectPromise) Timers.set_timeout(function() rejectPromise(sentinel) end, 50) @@ -462,7 +462,7 @@ describe("2.3.3: Otherwise, if `x` is an object or function,", function() end testPromiseResolution(async_it, xFactory, function(promise, done) - promise:thenCall(nil, function(reason) + promise:and_then(nil, function(reason) assert.are.equals(reason, sentinel) done() end) @@ -472,7 +472,7 @@ describe("2.3.3: Otherwise, if `x` is an object or function,", function() describe("calling `resolvePromise` twice synchronously", function() local function xFactory() return { - thenCall = function(instance, resolvePromise) + and_then = function(instance, resolvePromise) resolvePromise(sentinel) resolvePromise(other) end, @@ -480,7 +480,7 @@ describe("2.3.3: Otherwise, if `x` is an object or function,", function() end testPromiseResolution(async_it, xFactory, function(promise, done) - promise:thenCall(function(value) + promise:and_then(function(value) assert.are.equals(value, sentinel) done() end) @@ -490,7 +490,7 @@ describe("2.3.3: Otherwise, if `x` is an object or function,", function() describe("calling `resolvePromise` twice, first synchronously then asynchronously", function() local function xFactory() return { - thenCall = function(instance, resolvePromise) + and_then = function(instance, resolvePromise) resolvePromise(sentinel) Timers.set_timeout(function() @@ -501,7 +501,7 @@ describe("2.3.3: Otherwise, if `x` is an object or function,", function() end testPromiseResolution(async_it, xFactory, function(promise, done) - promise:thenCall(function(value) + promise:and_then(function(value) assert.are.equals(value, sentinel) done() end) @@ -511,7 +511,7 @@ describe("2.3.3: Otherwise, if `x` is an object or function,", function() describe("calling `resolvePromise` twice, both times asynchronously", function() local function xFactory() return { - thenCall = function(instance, resolvePromise) + and_then = function(instance, resolvePromise) Timers.set_timeout(function() resolvePromise(sentinel) end, 10) @@ -524,7 +524,7 @@ describe("2.3.3: Otherwise, if `x` is an object or function,", function() end testPromiseResolution(async_it, xFactory, function(promise, done) - promise:thenCall(function(value) + promise:and_then(function(value) assert.are.equals(sentinel, value) done() end) @@ -542,7 +542,7 @@ describe("2.3.3: Otherwise, if `x` is an object or function,", function() end, 10) return { - thenCall = function(instance, resolvePromise) + and_then = function(instance, resolvePromise) resolvePromise(promise) resolvePromise(other) end, @@ -550,7 +550,7 @@ describe("2.3.3: Otherwise, if `x` is an object or function,", function() end testPromiseResolution(async_it, xFactory, function(promise, done) - promise:thenCall(function(value) + promise:and_then(function(value) assert.are.equals(value, sentinel) done() end) @@ -569,7 +569,7 @@ describe("2.3.3: Otherwise, if `x` is an object or function,", function() end, 50) return { - thenCall = function(instance, resolvePromise) + and_then = function(instance, resolvePromise) resolvePromise(promise) resolvePromise(other) end, @@ -577,7 +577,7 @@ describe("2.3.3: Otherwise, if `x` is an object or function,", function() end testPromiseResolution(async_it, xFactory, function(promise, done) - promise:thenCall(nil, function(reason) + promise:and_then(nil, function(reason) assert.are.equals(reason, sentinel) done() end) @@ -588,7 +588,7 @@ describe("2.3.3: Otherwise, if `x` is an object or function,", function() describe("calling `rejectPromise` twice synchronously", function() local function xFactory() return { - thenCall = function(instance, resolvePromise, rejectPromise) + and_then = function(instance, resolvePromise, rejectPromise) rejectPromise(sentinel) rejectPromise(other) end, @@ -596,7 +596,7 @@ describe("2.3.3: Otherwise, if `x` is an object or function,", function() end testPromiseResolution(async_it, xFactory, function(promise, done) - promise:thenCall(nil, function(reason) + promise:and_then(nil, function(reason) assert.are.equals(reason, sentinel) done() end) @@ -606,7 +606,7 @@ describe("2.3.3: Otherwise, if `x` is an object or function,", function() describe("calling `rejectPromise` twice, first synchronously then asynchronously", function() local function xFactory() return { - thenCall = function(instance, resolvePromise, rejectPromise) + and_then = function(instance, resolvePromise, rejectPromise) rejectPromise(sentinel) Timers.set_timeout(function() @@ -617,7 +617,7 @@ describe("2.3.3: Otherwise, if `x` is an object or function,", function() end testPromiseResolution(async_it, xFactory, function(promise, done) - promise:thenCall(nil, function(reason) + promise:and_then(nil, function(reason) assert.are.equals(reason, sentinel) done() end) @@ -627,7 +627,7 @@ describe("2.3.3: Otherwise, if `x` is an object or function,", function() describe("calling `rejectPromise` twice, both times asynchronously", function() local function xFactory() return { - thenCall = function(instance, resolvePromise, rejectPromise) + and_then = function(instance, resolvePromise, rejectPromise) Timers.set_timeout(function() rejectPromise(sentinel) end, 10) @@ -640,7 +640,7 @@ describe("2.3.3: Otherwise, if `x` is an object or function,", function() end testPromiseResolution(async_it, xFactory, function(promise, done) - promise:thenCall(nil, function(reason) + promise:and_then(nil, function(reason) assert.are.equals(reason, sentinel) done() end) @@ -652,7 +652,7 @@ describe("2.3.3: Otherwise, if `x` is an object or function,", function() local function xFactory() return { - thenCall = function(instance, resolvePromise, rejectPromise) + and_then = function(instance, resolvePromise, rejectPromise) savedResolvePromise = resolvePromise savedRejectPromise = rejectPromise end, @@ -668,7 +668,7 @@ describe("2.3.3: Otherwise, if `x` is an object or function,", function() local timesFulfilled = 0 local timesRejected = 0 - promise:thenCall(function() + promise:and_then(function() timesFulfilled = timesFulfilled + 1 end, function() timesRejected = timesRejected + 1 @@ -703,7 +703,7 @@ describe("2.3.3: Otherwise, if `x` is an object or function,", function() describe("`resolvePromise` was called with a non-nextable", function() local function xFactory() return { - thenCall = function(instance, resolvePromise) + and_then = function(instance, resolvePromise) resolvePromise(sentinel) error(other) end, @@ -711,7 +711,7 @@ describe("2.3.3: Otherwise, if `x` is an object or function,", function() end testPromiseResolution(async_it, xFactory, function(promise, done) - promise:thenCall(function(value) + promise:and_then(function(value) assert.are.equals(value, sentinel) done() end) @@ -726,7 +726,7 @@ describe("2.3.3: Otherwise, if `x` is an object or function,", function() end, 50) return { - thenCall = function(instance, resolvePromise) + and_then = function(instance, resolvePromise) resolvePromise(promise) error(other) end, @@ -734,7 +734,7 @@ describe("2.3.3: Otherwise, if `x` is an object or function,", function() end testPromiseResolution(async_it, xFactory, function(promise, done) - promise:thenCall(function(value) + promise:and_then(function(value) assert.are.equals(value, sentinel) done() end) @@ -749,7 +749,7 @@ describe("2.3.3: Otherwise, if `x` is an object or function,", function() end, 50) return { - thenCall = function(instance, resolvePromise) + and_then = function(instance, resolvePromise) resolvePromise(promise) error(other) end, @@ -757,7 +757,7 @@ describe("2.3.3: Otherwise, if `x` is an object or function,", function() end testPromiseResolution(async_it, xFactory, function(promise, done) - promise:thenCall(nil, function(reason) + promise:and_then(nil, function(reason) assert.are.equals(reason, sentinel) done() end) @@ -767,7 +767,7 @@ describe("2.3.3: Otherwise, if `x` is an object or function,", function() describe("`rejectPromise` was called", function() local function xFactory() return { - thenCall = function(instance, resolvePromise, rejectPromise) + and_then = function(instance, resolvePromise, rejectPromise) rejectPromise(sentinel) error(other) end, @@ -775,7 +775,7 @@ describe("2.3.3: Otherwise, if `x` is an object or function,", function() end testPromiseResolution(async_it, xFactory, function(promise, done) - promise:thenCall(nil, function(reason) + promise:and_then(nil, function(reason) assert.are.equals(reason, sentinel) done() end) @@ -785,7 +785,7 @@ describe("2.3.3: Otherwise, if `x` is an object or function,", function() describe("`resolvePromise` then `rejectPromise` were called", function() local function xFactory() return { - thenCall = function(instance, resolvePromise, rejectPromise) + and_then = function(instance, resolvePromise, rejectPromise) resolvePromise(sentinel) rejectPromise(other) error(other) @@ -794,7 +794,7 @@ describe("2.3.3: Otherwise, if `x` is an object or function,", function() end testPromiseResolution(async_it, xFactory, function(promise, done) - promise:thenCall(function(value) + promise:and_then(function(value) assert.are.equals(value, sentinel) done() end) @@ -804,7 +804,7 @@ describe("2.3.3: Otherwise, if `x` is an object or function,", function() describe("`rejectPromise` then `resolvePromise` were called", function() local function xFactory() return { - thenCall = function(instance, resolvePromise, rejectPromise) + and_then = function(instance, resolvePromise, rejectPromise) rejectPromise(sentinel) resolvePromise(other) error(other) @@ -813,7 +813,7 @@ describe("2.3.3: Otherwise, if `x` is an object or function,", function() end testPromiseResolution(async_it, xFactory, function(promise, done) - promise:thenCall(nil, function(reason) + promise:and_then(nil, function(reason) assert.are.equals(reason, sentinel) done() end) @@ -825,14 +825,14 @@ describe("2.3.3: Otherwise, if `x` is an object or function,", function() describe("straightforward case", function() local function xFactory() return { - thenCall = function() + and_then = function() error(sentinel) end, } end testPromiseResolution(async_it, xFactory, function(promise, done) - promise:thenCall(nil, function(reason) + promise:and_then(nil, function(reason) assert.are.equals(reason, sentinel) done() end) @@ -842,7 +842,7 @@ describe("2.3.3: Otherwise, if `x` is an object or function,", function() describe("`resolvePromise` is called asynchronously before the `throw`", function() local function xFactory() return { - thenCall = function(instance, resolvePromise) + and_then = function(instance, resolvePromise) Timers.set_timeout(function() resolvePromise(other) end, 0) @@ -852,7 +852,7 @@ describe("2.3.3: Otherwise, if `x` is an object or function,", function() end testPromiseResolution(async_it, xFactory, function(promise, done) - promise:thenCall(nil, function(reason) + promise:and_then(nil, function(reason) assert.are.equals(reason, sentinel) done() end) @@ -862,7 +862,7 @@ describe("2.3.3: Otherwise, if `x` is an object or function,", function() describe("`rejectPromise` is called asynchronously before the `throw`", function() local function xFactory() return { - thenCall = function(instance, resolvePromise, rejectPromise) + and_then = function(instance, resolvePromise, rejectPromise) Timers.set_timeout(function() rejectPromise(other) end, 0) @@ -872,7 +872,7 @@ describe("2.3.3: Otherwise, if `x` is an object or function,", function() end testPromiseResolution(async_it, xFactory, function(promise, done) - promise:thenCall(nil, function(reason) + promise:and_then(nil, function(reason) assert.are.equals(reason, sentinel) done() end) @@ -884,7 +884,7 @@ describe("2.3.3: Otherwise, if `x` is an object or function,", function() ) describe("2.3.3.4: If `next` is not a function, fulfill promise with `x`", function() - local function testFulfillViaNonFunction(thenCall, stringRepresentation) + local function testFulfillViaNonFunction(and_then, stringRepresentation) describe("`next` is " .. stringRepresentation, function() local x = nil @@ -893,12 +893,12 @@ describe("2.3.3: Otherwise, if `x` is an object or function,", function() end before_each(function() - x = { thenCall = thenCall } + x = { and_then = and_then } end) testPromiseResolution(async_it, xFactory, function(promise, done) Timers.set_timeout(function() - promise:thenCall(function(value) + promise:and_then(function(value) assert.are.equals(value, x) done() end) diff --git a/tests/promiseA+/2.3.4_spec.lua b/tests/promiseA+/2.3.4_spec.lua index 69c312d..594b06c 100644 --- a/tests/promiseA+/2.3.4_spec.lua +++ b/tests/promiseA+/2.3.4_spec.lua @@ -8,22 +8,22 @@ describe("2.3.4: If `x` is not an object or function, fulfill `promise` with `x` local function testValue(expectedValue, stringRepresentation) describe("The value is " .. stringRepresentation, function() Helper.test_fulfilled(async_it, dummy, function(promise1, done) - local promise2 = promise1:thenCall(function() + local promise2 = promise1:and_then(function() return expectedValue end) - promise2:thenCall(function(actualValue) + promise2:and_then(function(actualValue) assert.are.equals(actualValue, expectedValue) done() end) end) Helper.test_rejected(async_it, dummy, function(promise1, done) - local promise2 = promise1:thenCall(nil, function() + local promise2 = promise1:and_then(nil, function() return expectedValue end) - promise2:thenCall(function(actualValue) + promise2:and_then(function(actualValue) assert.are.equals(actualValue, expectedValue) done() end) diff --git a/tests/promiseA+/helpers/init.lua b/tests/promiseA+/helpers/init.lua index a6fd7a7..03e6407 100644 --- a/tests/promiseA+/helpers/init.lua +++ b/tests/promiseA+/helpers/init.lua @@ -79,7 +79,7 @@ Helper.reasons = { return {} end, ["an always-pending nextable"] = function() - return { thenCall = function() end } + return { and_then = function() end } end, ["a fulfilled promise"] = function() return Helper.resolved(dummy) diff --git a/tests/promiseA+/helpers/nextables.lua b/tests/promiseA+/helpers/nextables.lua index 69650c3..8d58c8e 100644 --- a/tests/promiseA+/helpers/nextables.lua +++ b/tests/promiseA+/helpers/nextables.lua @@ -8,7 +8,7 @@ local Nextable = {} Nextable.fulfilled = { ["a synchronously-fulfilled custom nextable"] = function(value) return { - thenCall = function(instance, onFulfilled) + and_then = function(instance, onFulfilled) onFulfilled(value) end, } @@ -16,7 +16,7 @@ Nextable.fulfilled = { ["an asynchronously-fulfilled custom nextable"] = function(value) return { - thenCall = function(instance, onFulfilled) + and_then = function(instance, onFulfilled) Timers.set_timeout(function() onFulfilled(value) end, 0) @@ -30,7 +30,7 @@ Nextable.fulfilled = { local x = {} local mt = { __index = function(table, key) - if key == "thenCall" then + if key == "and_then" then if numberOfTimesNextRetrieved == 0 then numberOfTimesNextRetrieved = numberOfTimesNextRetrieved + 1 return function(instance, onFulfilled) @@ -45,7 +45,7 @@ Nextable.fulfilled = { ["a nextable that tries to fulfill twice"] = function(value) return { - thenCall = function(instance, onFulfilled) + and_then = function(instance, onFulfilled) onFulfilled(value) onFulfilled(other) end, @@ -54,7 +54,7 @@ Nextable.fulfilled = { ["a nextable that fulfills but then throws"] = function(value) return { - thenCall = function(instance, onFulfilled) + and_then = function(instance, onFulfilled) onFulfilled(value) error(other) end, @@ -79,7 +79,7 @@ Nextable.fulfilled = { Nextable.rejected = { ["a synchronously-rejected custom nextable"] = function(reason) return { - thenCall = function(instance, onFulfilled, onRejected) + and_then = function(instance, onFulfilled, onRejected) onRejected(reason) end, } @@ -87,7 +87,7 @@ Nextable.rejected = { ["an asynchronously-rejected custom nextable"] = function(reason) return { - thenCall = function(instance, onFulfilled, onRejected) + and_then = function(instance, onFulfilled, onRejected) Timers.set_timeout(function() onRejected(reason) end, 0) @@ -101,7 +101,7 @@ Nextable.rejected = { local x = {} local mt = { __index = function(table, key) - if key == "thenCall" then + if key == "and_then" then if numberOfTimesNextRetrieved == 0 then numberOfTimesNextRetrieved = numberOfTimesNextRetrieved + 1 return function(instance, onFulfilled, onRejected) @@ -115,7 +115,7 @@ Nextable.rejected = { end, ["a nextable that immediately throws in `next`"] = function(reason) return { - thenCall = function() + and_then = function() error(reason) end, } @@ -124,7 +124,7 @@ Nextable.rejected = { local x = {} local mt = { __index = function(table, key) - if key == "thenCall" then + if key == "and_then" then error(reason) end end,