Skip to content

Commit 66964cb

Browse files
committed
Bring Access.fetch/2 tests back
1 parent d9356c3 commit 66964cb

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

lib/elixir/test/elixir/access_test.exs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ defmodule AccessTest do
2121

2222
test "for nil" do
2323
assert nil[:foo] == nil
24+
assert Access.fetch(nil, :foo) == :error
2425
assert Access.get(nil, :foo) == nil
2526
assert_raise ArgumentError, "could not put/update key :foo on a nil value", fn ->
2627
Access.get_and_update(nil, :foo, fn nil -> {:ok, :bar} end)
@@ -32,6 +33,9 @@ defmodule AccessTest do
3233
assert [foo: [bar: :baz]][:foo][:bar] == :baz
3334
assert [foo: [bar: :baz]][:fuu][:bar] == nil
3435

36+
assert Access.fetch([foo: :bar], :foo) == {:ok, :bar}
37+
assert Access.fetch([foo: :bar], :bar) == :error
38+
3539
assert Access.get([foo: :bar], :foo) == :bar
3640
assert Access.get_and_update([], :foo, fn nil -> {:ok, :baz} end) == {:ok, [foo: :baz]}
3741
assert Access.get_and_update([foo: :bar], :foo, fn :bar -> {:ok, :baz} end) == {:ok, [foo: :baz]}
@@ -43,6 +47,9 @@ defmodule AccessTest do
4347
assert %{1.0 => 1.0}[1.0] == 1.0
4448
assert %{1 => 1}[1.0] == nil
4549

50+
assert Access.fetch(%{foo: :bar}, :foo) == {:ok, :bar}
51+
assert Access.fetch(%{foo: :bar}, :bar) == :error
52+
4653
assert Access.get(%{foo: :bar}, :foo) == :bar
4754
assert Access.get_and_update(%{}, :foo, fn nil -> {:ok, :baz} end) == {:ok, %{foo: :baz}}
4855
assert Access.get_and_update(%{foo: :bar}, :foo, fn :bar -> {:ok, :baz} end) == {:ok, %{foo: :baz}}

0 commit comments

Comments
 (0)