diff options
| author | William Boman <william@redwill.se> | 2023-04-28 12:46:31 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2023-04-28 10:46:31 +0000 |
| commit | 2a3ea96af1793b1635c172f34761a8512e2dbf12 (patch) | |
| tree | a5df3086813bb23974f0d40709af218cdf8b32f8 /tests | |
| parent | feat(ui): add keymap setting for toggling package installation log (#1268) (diff) | |
| download | mason-2a3ea96af1793b1635c172f34761a8512e2dbf12.tar mason-2a3ea96af1793b1635c172f34761a8512e2dbf12.tar.gz mason-2a3ea96af1793b1635c172f34761a8512e2dbf12.tar.bz2 mason-2a3ea96af1793b1635c172f34761a8512e2dbf12.tar.lz mason-2a3ea96af1793b1635c172f34761a8512e2dbf12.tar.xz mason-2a3ea96af1793b1635c172f34761a8512e2dbf12.tar.zst mason-2a3ea96af1793b1635c172f34761a8512e2dbf12.zip | |
chore(Optional): add :and_then() (#1270)
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/mason-core/optional_spec.lua | 45 |
1 files changed, 45 insertions, 0 deletions
diff --git a/tests/mason-core/optional_spec.lua b/tests/mason-core/optional_spec.lua index b1a4f41a..fed6deba 100644 --- a/tests/mason-core/optional_spec.lua +++ b/tests/mason-core/optional_spec.lua @@ -92,3 +92,48 @@ describe("Optional.ok_or()", function() assert.equals("I'm empty.", result:err_or_nil()) end) end) + +describe("Optional.or_()", function() + it("should run supplier if value is not present", function() + local spy = spy.new(function() + return Optional.of "Hello world!" + end) + assert.same(Optional.of "Hello world!", Optional.empty():or_(spy)) + assert.spy(spy).was_called(1) + + assert.same(Optional.empty(), Optional.empty():or_(Optional.empty)) + end) + + it("should not run supplier if value is present", function() + local spy = spy.new(function() + return Optional.of "Hello world!" + end) + assert.same(Optional.of "Hello world!", Optional.of("Hello world!"):or_(spy)) + assert.spy(spy).was_called(0) + end) +end) + +describe("Optional.and_then()", function() + it("should run supplier if value is present", function() + local spy = spy.new(function(value) + return Optional.of(("%s world!"):format(value)) + end) + assert.same(Optional.of "Hello world!", Optional.of("Hello"):and_then(spy)) + assert.spy(spy).was_called(1) + + assert.same( + Optional.empty(), + Optional.empty():and_then(function() + return Optional.of "Nothing." + end) + ) + end) + + it("should not run supplier if value is not present", function() + local spy = spy.new(function() + return Optional.of "Hello world!" + end) + assert.same(Optional.empty(), Optional.empty():and_then(spy)) + assert.spy(spy).was_called(0) + end) +end) |
