Skip to content

Commit

Permalink
Construct test data at runtime (instead of literal expressions) to av…
Browse files Browse the repository at this point in the history
…oid compiler error on unmatched clause in R.or_else/2 macro
  • Loading branch information
skirino committed Feb 9, 2025
1 parent d393a12 commit 23767d7
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions test/result_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -105,10 +105,13 @@ defmodule Croma.ResultTest do
end

test "or_else/2" do
o1 = {:ok, 1}
o2 = {:ok, 2}
e1 = {:error, :foo}
e2 = {:error, :bar}
# Note: Since `R.or_else/2` is a macro (for lazy evaluation of the 2nd argument),
# we need to construct `o1` etc. at runtime (instead of a literal) in order to
# avoid compiler warnings on `the following clause will never match`.
o1 = int2result(0)
o2 = int2result(2)
e1 = int2result(1)
e2 = int2result(3)
assert R.or_else(o1, o2) == o1
assert R.or_else(o1, e2) == o1
assert R.or_else(e1, o2) == o2
Expand Down

0 comments on commit 23767d7

Please sign in to comment.