diff options
| author | William Boman <william@redwill.se> | 2022-10-09 23:14:15 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2022-10-09 23:14:15 +0200 |
| commit | f336a8fac9090b4f8f5b3b430b5870efbd4b9113 (patch) | |
| tree | 5f2199e61ac2b0f3814df7dabe7c7eb7cf07cc80 /tests/mason-core/result_spec.lua | |
| parent | feat(registry): add iferr tool for Go (#528) (diff) | |
| download | mason-f336a8fac9090b4f8f5b3b430b5870efbd4b9113.tar mason-f336a8fac9090b4f8f5b3b430b5870efbd4b9113.tar.gz mason-f336a8fac9090b4f8f5b3b430b5870efbd4b9113.tar.bz2 mason-f336a8fac9090b4f8f5b3b430b5870efbd4b9113.tar.lz mason-f336a8fac9090b4f8f5b3b430b5870efbd4b9113.tar.xz mason-f336a8fac9090b4f8f5b3b430b5870efbd4b9113.tar.zst mason-f336a8fac9090b4f8f5b3b430b5870efbd4b9113.zip | |
feat(npm): speed up checking for new versions (#530)
Diffstat (limited to 'tests/mason-core/result_spec.lua')
| -rw-r--r-- | tests/mason-core/result_spec.lua | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/tests/mason-core/result_spec.lua b/tests/mason-core/result_spec.lua index 737d8c56..ee722281 100644 --- a/tests/mason-core/result_spec.lua +++ b/tests/mason-core/result_spec.lua @@ -153,4 +153,25 @@ describe("result", function() assert.is_true(getmetatable(opt) == Optional) assert.is_false(opt:is_present()) end) + + it("should chain results", function() + local success = Result.success("First"):and_then(function(value) + return Result.success(value .. " Second") + end) + local failure = Result.success("Error"):and_then(Result.failure) + + assert.is_true(success:is_success()) + assert.equals("First Second", success:get_or_nil()) + assert.is_true(failure:is_failure()) + assert.equals("Error", failure:err_or_nil()) + end) + + it("should not chain results upon failure", function() + local chain = spy.new() + local failure = Result.failure("Error"):and_then(chain) + + assert.is_true(failure:is_failure()) + assert.equals("Error", failure:err_or_nil()) + assert.spy(chain).was_not_called() + end) end) |
