Skip to content

Commit 1f19a05

Browse files
committed
Improve coverage of large heads with more complex code
1 parent af6d6b2 commit 1f19a05

1 file changed

Lines changed: 48 additions & 21 deletions

File tree

lib/elixir/test/elixir/module/types/integration_test.exs

Lines changed: 48 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -931,29 +931,56 @@ defmodule Module.Types.IntegrationTest do
931931
test "redundant clause checking of open maps with distinct keys" do
932932
files = %{
933933
"large_head.ex" => """
934-
defmodule LargeHead do
935-
def id(%{node_id: id}) when is_binary(id), do: id
936-
def id(%{node: %{id: id}}) when is_binary(id), do: id
937-
def id(%{cluster: %{node_id: id}}) when is_binary(id), do: id
938-
def id(%{graph: %{node_id: id}}) when is_binary(id), do: id
939-
def id(%{vertex: %{node_id: id}}) when is_binary(id), do: id
940-
def id(%{collection: %{graph_id: id} = collection}) when is_binary(id), do: id(collection)
941-
def id(%{element: %{} = element}), do: id(element)
942-
def id(%{cluster_id: id}) when is_binary(id), do: id
943-
def id(%{region_id: id}) when is_binary(id), do: id
944-
def id(%{graph_id: id}) when is_binary(id), do: id
945-
def id(%{vertex_id: id}) when is_binary(id), do: id
946-
def id(%{path_id: id}) when is_binary(id), do: id
947-
def id(%{tree_id: id}) when is_binary(id), do: id
948-
def id(%{collection_id: id}) when is_binary(id), do: id
949-
def id(%{segment_id: id}) when is_binary(id), do: id
950-
def id(%{edge_id: id}) when is_binary(id), do: id
951-
def nested_access(%{graph: graph} = collection) do
952-
<<_::binary>> = id(graph)
953-
if collection.graph.cluster_id do
954-
{graph.id, graph.node_id, collection.graph.cluster_id}
934+
defmodule GraphResolver do
935+
def resolve(%{resource: node, member: vertex} = edge) do
936+
graph_id = fetch_id(edge.resource)
937+
938+
with %{id: id} <- vertex do
939+
{node.project_id, node.id, node.parent_id, [id], graph_id}
940+
end
941+
end
942+
943+
def fetch_id(%{id: id}) when is_binary(id), do: id
944+
def fetch_id(%{account_id: id}) when is_binary(id), do: id
945+
def fetch_id(%{account: %{id: id}}) when is_binary(id), do: id
946+
def fetch_id(%{team: %{account_id: id}}) when is_binary(id), do: id
947+
def fetch_id(%{project: %{account_id: id}}) when is_binary(id), do: id
948+
def fetch_id(%{asset: %{account_id: id}}) when is_binary(id), do: id
949+
950+
def fetch_id(%{collection: %{project_id: id} = collection}) when is_binary(id),
951+
do: fetch_id(collection)
952+
953+
def fetch_id(%{item: %{} = item}), do: fetch_id(item)
954+
def fetch_id(%{team_id: id}) when is_binary(id), do: local_id(:team, id)
955+
def fetch_id(%{workspace_id: id}) when is_binary(id), do: local_id(:team, id)
956+
def fetch_id(%{project_id: id}) when is_binary(id), do: local_id(:project, id)
957+
def fetch_id(%{asset_id: id}) when is_binary(id), do: remote_id(id)
958+
def fetch_id(%{portal_id: id}) when is_binary(id), do: remote_id(id)
959+
def fetch_id(%{codex_id: id}) when is_binary(id), do: remote_id(id)
960+
def fetch_id(%{vertex_id: id}) when is_binary(id), do: remote_id(id)
961+
def fetch_id(%{edge_id: id}) when is_binary(id), do: remote_id(id)
962+
def fetch_id(%{comment_id: id}) when is_binary(id), do: remote_id(id)
963+
964+
def fetch_id(%struct{id: id}) do
965+
case struct do
966+
Team -> local_id(:team, id)
967+
Project -> local_id(:project, id)
968+
Asset -> remote_id(id)
969+
Portal -> remote_id(id)
970+
Codex -> remote_id(id)
971+
CommentAttachment -> remote_id(id)
972+
Vertex -> remote_id(id)
973+
Edge -> remote_id(id)
955974
end
956975
end
976+
977+
defp local_id(type, id) when type in ~w(project team)a do
978+
{:local, type, id}
979+
end
980+
981+
defp remote_id(id) do
982+
{:remote, id}
983+
end
957984
end
958985
"""
959986
}

0 commit comments

Comments
 (0)