aboutsummaryrefslogtreecommitdiffstats
path: root/tests/mason-core/result_spec.lua
diff options
context:
space:
mode:
Diffstat (limited to 'tests/mason-core/result_spec.lua')
-rw-r--r--tests/mason-core/result_spec.lua25
1 files changed, 23 insertions, 2 deletions
diff --git a/tests/mason-core/result_spec.lua b/tests/mason-core/result_spec.lua
index ee722281..1d8f36fb 100644
--- a/tests/mason-core/result_spec.lua
+++ b/tests/mason-core/result_spec.lua
@@ -154,7 +154,7 @@ describe("result", function()
assert.is_false(opt:is_present())
end)
- it("should chain results", function()
+ it("should chain successful results", function()
local success = Result.success("First"):and_then(function(value)
return Result.success(value .. " Second")
end)
@@ -166,7 +166,7 @@ describe("result", function()
assert.equals("Error", failure:err_or_nil())
end)
- it("should not chain results upon failure", function()
+ it("should not chain failed results", function()
local chain = spy.new()
local failure = Result.failure("Error"):and_then(chain)
@@ -174,4 +174,25 @@ describe("result", function()
assert.equals("Error", failure:err_or_nil())
assert.spy(chain).was_not_called()
end)
+
+ it("should chain failed results", function()
+ local failure = Result.failure("First"):or_else(function(value)
+ return Result.failure(value .. " Second")
+ end)
+ local success = Result.failure("Error"):or_else(Result.success)
+
+ assert.is_true(success:is_success())
+ assert.equals("Error", success:get_or_nil())
+ assert.is_true(failure:is_failure())
+ assert.equals("First Second", failure:err_or_nil())
+ end)
+
+ it("should not chain successful results", function()
+ local chain = spy.new()
+ local failure = Result.success("Error"):or_else(chain)
+
+ assert.is_true(failure:is_success())
+ assert.equals("Error", failure:get_or_nil())
+ assert.spy(chain).was_not_called()
+ end)
end)