Skip to content

Commit c10fa98

Browse files
committed
Bug: fix displaying maps with structs as keys (#571)
* Added test case * Fixed typo * Added datetime to test * Fixed issue * Added test * Added example with DateTime * Removed dbg
1 parent 0db9e55 commit c10fa98

File tree

3 files changed

+51
-0
lines changed

3 files changed

+51
-0
lines changed

dev/live_views/main.ex

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,13 @@ defmodule LiveDebuggerDev.LiveViews.Main do
1616
|> assign(func: fn a -> {:ok, a} end)
1717
|> assign(single_element_list: [%Phoenix.LiveComponent.CID{cid: 1}])
1818
|> assign(list: [%Phoenix.LiveComponent.CID{cid: 1}, %Phoenix.LiveComponent.CID{cid: 2}])
19+
|> assign(
20+
cid_map: %{
21+
%Phoenix.LiveComponent.CID{cid: 1} => "1",
22+
%Phoenix.LiveComponent.CID{cid: 2} => DateTime.utc_now(),
23+
DateTime.utc_now() => "DateTime"
24+
}
25+
)
1926
|> assign(
2027
long_assign:
2128
"Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed do eiusmod tempor incididunt ut labore et dolore magna aliqua."

lib/live_debugger/utils/term_parser.ex

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,9 @@ defmodule LiveDebugger.Utils.TermParser do
122122

123123
%{content: [span]} ->
124124
{%{span | text: inspect(key, width: :infinity)}, black(" => ")}
125+
126+
%{content: _content} ->
127+
{%{text: inspect(key, width: :infinity), color: "text-code-1"}, black(" => ")}
125128
end
126129

127130
case to_node(value, suffix) do

test/utils/term_parser_test.exs

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -354,6 +354,47 @@ defmodule LiveDebugger.Utils.TermParserTest do
354354

355355
assert TermParser.term_to_display_tree(term) == expected
356356
end
357+
358+
test "parses map with struct keys correctly" do
359+
term = %{
360+
%Phoenix.LiveComponent.CID{cid: 1} => "CID",
361+
Date.new(2025, 7, 8) => "Date"
362+
}
363+
364+
expected = %{
365+
kind: "map",
366+
children: [
367+
%{
368+
kind: "binary",
369+
children: nil,
370+
content: [
371+
%{text: "{:ok, ~D[2025-07-08]}", color: "text-code-2"},
372+
%{text: " => ", color: "text-code-2"},
373+
%{text: "\"Date\"", color: "text-code-4"},
374+
%{text: ",", color: "text-code-2"}
375+
],
376+
expanded_before: nil,
377+
expanded_after: nil
378+
},
379+
%{
380+
kind: "binary",
381+
children: nil,
382+
content: [
383+
%{text: "%Phoenix.LiveComponent.CID{cid: 1}", color: "text-code-1"},
384+
%{text: " => ", color: "text-code-2"},
385+
%{text: "\"CID\"", color: "text-code-4"}
386+
],
387+
expanded_before: nil,
388+
expanded_after: nil
389+
}
390+
],
391+
content: [%{text: "%{...}", color: "text-code-2"}],
392+
expanded_before: [%{text: "%{", color: "text-code-2"}],
393+
expanded_after: [%{text: "}", color: "text-code-2"}]
394+
}
395+
396+
assert TermParser.term_to_display_tree(term) == expected
397+
end
357398
end
358399

359400
describe "term_to_copy_string/1" do

0 commit comments

Comments
 (0)